ManaData.cs 20 KB

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