ManaData.cs 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784
  1. using LitJson;
  2. using UnityEngine;
  3. using UnityEngine.EventSystems;
  4. using System;
  5. using System.Xml;
  6. using System.Collections;
  7. using System.Collections.Generic;
  8. using UnityEngine.UI;
  9. public class ManaData : Regist
  10. {
  11. #region 变量
  12. #region 成就
  13. public static double AD
  14. {
  15. get { return _AD; }
  16. set
  17. {
  18. _AD = value;
  19. ManaAchieve.UpdateStatus(AchieveType.AD, _AD);
  20. }
  21. }
  22. public static double Skill
  23. {
  24. get { return _Skill; }
  25. set
  26. {
  27. _Skill = value;
  28. ManaAchieve.UpdateStatus(AchieveType.Skill, _Skill);
  29. }
  30. }
  31. public static double Sign
  32. {
  33. get { return _Sign; }
  34. set
  35. {
  36. _Sign = value;
  37. ManaAchieve.UpdateStatus(AchieveType.Sign, _Sign);
  38. }
  39. }
  40. public static double Share
  41. {
  42. get { return _Share; }
  43. set
  44. {
  45. _Share = value;
  46. ManaAchieve.UpdateStatus(AchieveType.Share, _Share);
  47. }
  48. }
  49. public static double ElfLevel
  50. {
  51. get { return _ElfLevel; }
  52. set
  53. {
  54. _ElfLevel = value;
  55. ManaAchieve.UpdateStatus(AchieveType.ElfLevel, _ElfLevel);
  56. }
  57. }
  58. public static double TotalCoin
  59. {
  60. get { return _TotalCoin; }
  61. set
  62. {
  63. _TotalCoin = value;
  64. ManaAchieve.UpdateStatus(AchieveType.TotalCoin, _TotalCoin);
  65. }
  66. }
  67. public static double MiniGame
  68. {
  69. get { return _MiniGame; }
  70. set
  71. {
  72. _MiniGame = value;
  73. ManaAchieve.UpdateStatus(AchieveType.MiniGame, _MiniGame);
  74. }
  75. }
  76. public static double FlowerCoin
  77. {
  78. get { return _FlowerCoin; }
  79. set
  80. {
  81. _FlowerCoin = value;
  82. ManaAchieve.UpdateStatus(AchieveType.FlowerCoin, _FlowerCoin);
  83. }
  84. }
  85. private static double _AD;
  86. private static double _Skill;
  87. private static double _Sign;
  88. private static double _Share;
  89. private static double _ElfLevel;
  90. private static double _TotalCoin;
  91. private static double _MiniGame;
  92. private static double _FlowerCoin;
  93. #endregion
  94. public static int Slot
  95. {
  96. get { return _Slot; }
  97. set
  98. {
  99. _Slot = value;
  100. Garden.ValidPage = Mathf.Clamp(Mathf.CeilToInt(_Slot/7f), 1, 2);
  101. }
  102. }
  103. public static int Level
  104. {
  105. get { return _Level; }
  106. set
  107. {
  108. _Level = value;
  109. ManaDebug.Log(string.Format("已升级 花园等级 : <color=red>{0}</color>", _Level));
  110. if (TabBtn == false)
  111. {
  112. if (_Level >= 20)
  113. {
  114. TabBtn = true;
  115. ManaReso.Get<Graphic>("F_Elf").material = null;
  116. ManaReso.Get<Graphic>("F_Store").material = null;
  117. ManaReso.Get<Graphic>("F_Magic").material = null;
  118. ManaReso.Get<Graphic>("F_ElfLab").material = null;
  119. ManaReso.Get<Graphic>("F_StoreLab").material = null;
  120. ManaReso.Get<Graphic>("F_MagicLab").material = null;
  121. ManaReso.Get<Button>("F_Elf").interactable = true;
  122. ManaReso.Get<Button>("F_Store").interactable = true;
  123. ManaReso.Get<Button>("F_Magic").interactable = true;
  124. }
  125. }
  126. for (int i = 0; i < SkillList.Count; i++)
  127. {
  128. SkillList[i].UpdateStatus();
  129. }
  130. ManaAchieve.UpdateStatus(AchieveType.Garden, _Level);
  131. }
  132. }
  133. public static bool Pause
  134. {
  135. get { return _Pause; }
  136. set
  137. {
  138. _Pause = value;
  139. if (_Pause)
  140. {
  141. Time.timeScale = 0;
  142. ManaDebug.Log("<color=red>游戏暂停</color>");
  143. }
  144. else
  145. {
  146. Time.timeScale = 1;
  147. ManaDebug.Log("<color=red>游戏继续</color>");
  148. }
  149. }
  150. }
  151. public static float Person
  152. {
  153. get { return _Person; }
  154. set
  155. {
  156. _Person = value;
  157. ManaReso.SetText("F_PersonLab", _Person.ToString("0.0"));
  158. ManaAchieve.UpdateStatus(AchieveType.Person, _Person);
  159. }
  160. }
  161. public static float CoinPerson
  162. {
  163. get { return _CoinPerson; }
  164. set
  165. {
  166. _CoinPerson = value;
  167. ManaReso.SetText("F_CoinPersonLab", _CoinPerson.ToString("0.0"));
  168. }
  169. }
  170. public static double Coin
  171. {
  172. get { return _Coin; }
  173. set
  174. {
  175. if (value - _Coin > 0)
  176. {
  177. TotalCoin += value - _Coin;
  178. }
  179. _Coin = value;
  180. ManaReso.SetText("F_CoinLab", _Coin.ToString("0"));
  181. ManaReso.SetText("C_CoinLab", _Coin.ToString("0"));
  182. ManaAchieve.UpdateStatus(AchieveType.CurrentCoin, _Coin);
  183. }
  184. }
  185. public static double Diamond
  186. {
  187. get { return _Diamond; }
  188. set
  189. {
  190. _Diamond = value;
  191. ManaReso.SetText("F_DiamondLab", _Diamond.ToString("0"));
  192. }
  193. }
  194. private static int _Slot;
  195. private static int _Level;
  196. private static bool _Pause;
  197. private static float _Person;
  198. private static float _CoinPerson;
  199. private static double _Coin;
  200. private static double _Diamond;
  201. public static List<SkillRoot> SkillList
  202. {
  203. get
  204. {
  205. if (_SkillList == null)
  206. {
  207. _SkillList = new List<SkillRoot>();
  208. }
  209. return _SkillList;
  210. }
  211. set { _SkillList = value; }
  212. }
  213. public static Dictionary<string, SkillRoot> SkillDic
  214. {
  215. get
  216. {
  217. if (_SkillDic == null)
  218. {
  219. _SkillDic = new Dictionary<string, SkillRoot>();
  220. }
  221. return _SkillDic;
  222. }
  223. set { _SkillDic = value; }
  224. }
  225. public static List<SkillRoot> _SkillList;
  226. public static Dictionary<string, SkillRoot> _SkillDic;
  227. public static int SignIndex;
  228. public static int MainDepth;
  229. public static bool Mini;
  230. public static bool TabBtn;
  231. public static bool SkillBar;
  232. public static bool Connect;
  233. public static float OpTime = 90;
  234. public static float OpTimer;
  235. public static float MiniTimer;
  236. public static float CircleTime = 10;
  237. public static float CircleTimer;
  238. public static float NewPerson;
  239. public static float NewCoinPerson;
  240. public static float SkillPlus;
  241. public static float SkillPerson;
  242. public static float SkillPersonBuff;
  243. public static float SkillCoinPerson;
  244. public static List<Skill> CoolList = new List<Skill>();
  245. public static List<SkillRoot> UseList = new List<SkillRoot>();
  246. #endregion
  247. private void Update()
  248. {
  249. if (Initializer.Tutorial)
  250. {
  251. TutorialUpdate();
  252. }
  253. else
  254. {
  255. RegularUpdate();
  256. }
  257. }
  258. private void TutorialUpdate()
  259. {
  260. }
  261. private void RegularUpdate()
  262. {
  263. if (Pause)
  264. {
  265. return;
  266. }
  267. if (Mini == false)
  268. {
  269. MiniTimer -= Time.deltaTime;
  270. if (MiniTimer < 0)
  271. {
  272. Mini = true;
  273. ManaReso.Get("C_MiniGame").TweenForCG();
  274. }
  275. }
  276. if (Auxiliary.AnyKeyUp)
  277. {
  278. OpTimer = 0;
  279. if (MainDepth == 0)
  280. {
  281. ManaReso.Get("C_Main").TweenForCG();
  282. }
  283. }
  284. else
  285. {
  286. OpTimer += Time.deltaTime;
  287. if (OpTimer >= OpTime)
  288. {
  289. OpTimer = 0;
  290. if (MainDepth == -1)
  291. {
  292. ManaReso.Get("C_Main").TweenBacCG();
  293. }
  294. }
  295. }
  296. }
  297. private void FixedUpdate()
  298. {
  299. if (Initializer.Tutorial)
  300. {
  301. TutorialFixedUpdate();
  302. }
  303. else
  304. {
  305. RegularFixedUpdate();
  306. }
  307. }
  308. private void TutorialFixedUpdate()
  309. {
  310. }
  311. private void RegularFixedUpdate()
  312. {
  313. #region 技能
  314. for (int i = 0; i < UseList.Count; i++)
  315. {
  316. if (UseList[i].DoUse())
  317. {
  318. i--;
  319. }
  320. }
  321. for (int i = 0; i < CoolList.Count; i++)
  322. {
  323. if (CoolList[i].DoCool())
  324. {
  325. i--;
  326. }
  327. }
  328. #endregion
  329. #region 参观收入
  330. CircleTimer -= Time.deltaTime;
  331. if (CircleTimer < 0)
  332. {
  333. CircleTimer = CircleTime;
  334. NewPerson = Person * (1 + SkillPersonBuff) + SkillPerson;
  335. NewCoinPerson = CoinPerson + SkillCoinPerson;
  336. float temp = (NewPerson * NewCoinPerson * CircleTime) * (1 + SkillPlus);
  337. Coin += temp;
  338. if (MainDepth == -1)
  339. {
  340. ManaReso.GetHudText("+" + temp.ToString("0"), Color.white, 25, ManaReso.Get("C_PosTra"), ManaReso.Get("C_Main"), false);
  341. }
  342. ManaDebug.Log(string.Format("参观收益<color=red>{0:0}</color> = <color=red>{1}</color> * <color=red>{2}</color> * <color=red>{3}</color> * <color=red>{4}</color> (人次*金币*时间*加成)", temp, NewPerson, NewCoinPerson, CircleTime, 1 + SkillPlus));
  343. }
  344. #endregion
  345. }
  346. public override void Instantiate()
  347. {
  348. #region 生成技能条
  349. #region 读技能配置
  350. List<XmlAttributeCollection> attributeList = Data.GetSkillConfig();
  351. for (int i = 0; i < attributeList.Count; i++)
  352. {
  353. SkillRoot skillRoot;
  354. #region MyRegion
  355. if (attributeList[i].Count == 17)
  356. {
  357. skillRoot = new Pack(attributeList[i]);
  358. }
  359. else if (attributeList[i].Count == 23)
  360. {
  361. skillRoot = new Ability(attributeList[i]);
  362. }
  363. else if (attributeList[i].Count == 33)
  364. {
  365. if (string.IsNullOrEmpty(attributeList[i][4].Value))
  366. {
  367. skillRoot = new Skill(attributeList[i]);
  368. }
  369. else
  370. {
  371. skillRoot = new BigSkill(attributeList[i]);
  372. }
  373. }
  374. else
  375. {
  376. throw new Exception(attributeList[i].Count.ToString());
  377. }
  378. #endregion
  379. SkillDic.Add(skillRoot._Name, skillRoot);
  380. SkillList.Add(skillRoot);
  381. }
  382. SkillList.Sort(SkillRoot.Sort);
  383. #endregion
  384. for (int i = 0; i < SkillList.Count; i++)
  385. {
  386. if (SkillList[i].SkillTab != SkillTab.Null)
  387. {
  388. ManaReso.GetSkillItem(SkillList[i]);
  389. }
  390. }
  391. #endregion
  392. }
  393. public override void TutorialInstantiate()
  394. {
  395. Instantiate();
  396. }
  397. public override void RegistValueA()
  398. {
  399. if (ManaReso.Get("B_SignIn").gameObject.activeSelf)
  400. {
  401. MainDepth = 1;
  402. }
  403. else
  404. {
  405. MainDepth = 0;
  406. }
  407. #region 读数据存档
  408. SignIndex = Data.PlayerInt("SignIndex");
  409. CircleTimer = Data.PlayerFloat("CircleTimer");
  410. for (int i = 0; i < Data.PlayerInt("Slot"); i++)
  411. {
  412. ManaGarden.UnlockSlot();
  413. }
  414. List<double> dataList = Data.GetAchieveData();
  415. AD = dataList[0];
  416. Skill = dataList[1];
  417. Sign = dataList[2];
  418. Share = dataList[3];
  419. MiniGame = dataList[4];
  420. FlowerCoin = dataList[5];
  421. #endregion
  422. #region 读花朵存档
  423. List<int> flowerList = Data.GetFlowerList();
  424. for (int i = 0; i < flowerList.Count; i++)
  425. {
  426. ManaGarden.FlowerInfoList[flowerList[i]-1].Unlock = true;
  427. }
  428. List<KV<int, string>> plantList = Data.GetPlantList();
  429. for (int i = 0; i < plantList.Count; i++)
  430. {
  431. ManaGarden.PlantFlower(plantList[i].Key-1, plantList[i].Value);
  432. }
  433. #endregion
  434. }
  435. public override void RegistValueC()
  436. {
  437. #region 读技能存档
  438. float elapse = (float) DateTime.Now.Subtract(DateTime.Parse(Data.PlayerNode.SelectSingleNode("QuitTime").Attributes[0].Value)).TotalSeconds;
  439. if (elapse > 43200)
  440. {
  441. elapse = 43200;
  442. }
  443. ManaDebug.Log(string.Format("离线时间<color=red>{0}</color>", elapse));
  444. List<SkillRoot> ffCoolList = new List<SkillRoot>();
  445. List<List<SkillRoot>> ffUseList = new List<List<SkillRoot>>();
  446. if (elapse > CircleTimer)
  447. {
  448. int ffCircle = 1 + Mathf.FloorToInt((elapse - CircleTimer)/CircleTime);
  449. ManaDebug.Log(string.Format("离线周期<color=red>{0}</color>", ffCircle));
  450. for (int i = 0; i < ffCircle; i++)
  451. {
  452. ffUseList.Add(new List<SkillRoot>());
  453. }
  454. }
  455. else
  456. {
  457. ManaDebug.Log(string.Format("离线周期<color=red>{0}</color>", 0));
  458. }
  459. List<XmlAttributeCollection> attributeList = Data.GetSkillList();
  460. for (int i = 0; i < attributeList.Count; i++)
  461. {
  462. SkillRoot skillRoot = SkillDic[attributeList[i][0].Value];
  463. skillRoot.RegistReference();
  464. skillRoot.RegistValue(elapse, ffUseList, attributeList[i]);
  465. }
  466. #endregion
  467. #region 读数据存档
  468. Coin = Data.PlayerDouble("Coin");
  469. Level = Data.PlayerInt("Level");
  470. Diamond = Data.PlayerDouble("Diamond");
  471. MiniTimer = Data.PlayerFloat("MiniTimer");
  472. ManaDebug.Log(string.Format("<color=red>{0:0}</color>秒后激活小游戏", MiniTimer));
  473. #endregion
  474. #region 计算离线收入
  475. float collectCoin = 0;
  476. if (ffUseList.Count > 0)
  477. {
  478. for (int i = 0; i < ffUseList.Count; i++)
  479. {
  480. for (int j = 0; j < ffCoolList.Count; j++)
  481. {
  482. if (ffCoolList[j] is Skill)
  483. {
  484. if (i == 0)
  485. {
  486. ((Skill)ffCoolList[j]).CoolTimer -= CircleTimer;
  487. }
  488. else
  489. {
  490. ((Skill)ffCoolList[j]).CoolTimer -= CircleTime;
  491. }
  492. }
  493. }
  494. for (int j = 0; j < ffUseList[i].Count; j++)
  495. {
  496. ffUseList[i][j].Annul();
  497. ffCoolList.Add(ffUseList[i][j]);
  498. }
  499. NewPerson = Person * (1 + SkillPersonBuff) + SkillPerson;
  500. NewCoinPerson = CoinPerson + SkillCoinPerson;
  501. collectCoin += (NewPerson * NewCoinPerson * CircleTime) * (1 + SkillPlus);
  502. }
  503. CircleTimer = (elapse - CircleTimer)%CircleTime;
  504. for (int j = 0; j < ffCoolList.Count; j++)
  505. {
  506. if (ffCoolList[j] is Skill)
  507. {
  508. ((Skill) ffCoolList[j]).CoolTimer -= CircleTime - CircleTimer;
  509. }
  510. }
  511. Coin += collectCoin;
  512. ManaReso.SetText("Ba_IconLab", collectCoin.ToString("0"));
  513. }
  514. else
  515. {
  516. CircleTimer = CircleTimer - elapse;
  517. ManaReso.SetText("Ba_IconLab", "0");
  518. }
  519. #endregion
  520. }
  521. public override void TutorialRegistValue()
  522. {
  523. for (int i = 0; i < Data.PlayerInt("Slot"); i++)
  524. {
  525. ManaGarden.UnlockSlot();
  526. }
  527. #region 读花朵存档
  528. List<int> flowerList = Data.GetFlowerList();
  529. for (int i = 0; i < flowerList.Count; i++)
  530. {
  531. ManaGarden.FlowerInfoList[flowerList[i]-1].Unlock = true;
  532. }
  533. List<KV<int, string>> plantList = Data.GetPlantList();
  534. for (int i = 0; i < plantList.Count; i++)
  535. {
  536. ManaGarden.PlantFlower(plantList[i].Key-1, plantList[i].Value);
  537. }
  538. #endregion
  539. #region 读技能存档
  540. float elapse = (float)DateTime.Now.Subtract(DateTime.Parse(Data.PlayerNode.SelectSingleNode("QuitTime").Attributes[0].Value)).TotalSeconds;
  541. if (elapse > 43200)
  542. {
  543. elapse = 43200;
  544. }
  545. ManaDebug.Log(string.Format("离线时间<color=red>{0}</color>", elapse));
  546. List<List<SkillRoot>> ffUseList = new List<List<SkillRoot>>();
  547. if (elapse > CircleTimer)
  548. {
  549. int ffCircle = 1 + Mathf.FloorToInt((elapse - CircleTimer) / CircleTime);
  550. ManaDebug.Log(string.Format("离线周期<color=red>{0}</color>", ffCircle));
  551. for (int i = 0; i < ffCircle; i++)
  552. {
  553. ffUseList.Add(new List<SkillRoot>());
  554. }
  555. }
  556. else
  557. {
  558. ManaDebug.Log(string.Format("离线周期<color=red>{0}</color>", 0));
  559. }
  560. List<XmlAttributeCollection> attributeList = Data.GetSkillList();
  561. for (int i = 0; i < attributeList.Count; i++)
  562. {
  563. SkillRoot skillRoot = SkillDic[attributeList[i][0].Value];
  564. skillRoot.RegistReference();
  565. skillRoot.RegistValue(elapse, ffUseList, attributeList[i]);
  566. }
  567. #endregion
  568. #region 读数据存档
  569. Coin = Data.PlayerDouble("Coin");
  570. Level = Data.PlayerInt("Level");
  571. Diamond = Data.PlayerDouble("Diamond");
  572. MiniTimer = Data.PlayerFloat("MiniTimer");
  573. ManaDebug.Log(string.Format("<color=red>{0:0}</color>秒后激活小游戏", MiniTimer));
  574. #endregion
  575. }
  576. public static bool Pay(double amt, Current current)
  577. {
  578. amt = (long) amt;
  579. if (current == Current.Free)
  580. {
  581. return true;
  582. }
  583. else if (current == Current.AD)
  584. {
  585. return true;
  586. }
  587. else if (current == Current.Cash)
  588. {
  589. return true;
  590. }
  591. else if (current == Current.Coin)
  592. {
  593. if (Coin >= amt)
  594. {
  595. Coin -= amt;
  596. return true;
  597. }
  598. else
  599. {
  600. ManaDebug.Log("您没有足够的金币");
  601. return false;
  602. }
  603. }
  604. else if (current == Current.Diamond)
  605. {
  606. if (Diamond >= amt)
  607. {
  608. Diamond -= amt;
  609. return true;
  610. }
  611. else
  612. {
  613. ManaDebug.Log("您没有足够的钻石");
  614. return false;
  615. }
  616. }
  617. else
  618. {
  619. throw new Exception(current.ToString());
  620. }
  621. }
  622. }