ManaData.cs 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728
  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. ManaReso.Get<Garden>("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 (Pause)
  290. {
  291. return;
  292. }
  293. if (Mini == false)
  294. {
  295. MiniTimer -= Time.deltaTime;
  296. if (MiniTimer < 0)
  297. {
  298. Mini = true;
  299. ManaReso.Get("C_MiniGame").TweenForCG();
  300. }
  301. }
  302. if (Auxiliary.AnyKeyUp)
  303. {
  304. OpTimer = 0;
  305. if (Main == 0)
  306. {
  307. ManaReso.Get("C_Main").TweenForCG();
  308. }
  309. }
  310. else
  311. {
  312. OpTimer += Time.deltaTime;
  313. if (OpTimer >= OpTime)
  314. {
  315. OpTimer = 0;
  316. if (Main == -1)
  317. {
  318. ManaReso.Get("C_Main").TweenBacCG();
  319. }
  320. }
  321. }
  322. }
  323. private void FixedUpdate()
  324. {
  325. #region 使用技能
  326. for (int i = 0; i < UseList.Count; i++)
  327. {
  328. if (UseList[i].DoUse())
  329. {
  330. i--;
  331. }
  332. }
  333. #endregion
  334. #region 冷却技能
  335. for (int i = 0; i < CoolList.Count; i++)
  336. {
  337. if (CoolList[i].DoCool())
  338. {
  339. i--;
  340. }
  341. }
  342. #endregion
  343. #region 计算参观收入
  344. CircleTimer -= Time.deltaTime;
  345. if (CircleTimer < 0)
  346. {
  347. CircleTimer = CircleTime;
  348. NewPerson = Person*(1 + SkillPersonBuff) + SkillPerson;
  349. NewCoinPerson = CoinPerson + SkillCoinPerson;
  350. float temp = (NewPerson*NewCoinPerson*CircleTime)*(1 + SkillPlus);
  351. Coin += temp;
  352. if (Main == -1)
  353. {
  354. ManaReso.GetHudText("+" + temp.ToString("0"), ManaColor.HudText, 25, ManaReso.Get("C_HudTra"), ManaReso.Get("C_Main"), false);
  355. }
  356. 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));
  357. }
  358. #endregion
  359. }
  360. public override void RegistValueA()
  361. {
  362. OpTime = 90;
  363. MiniTimer = 0;
  364. CircleTime = 10;
  365. #region 调试
  366. if (ManaReso.Get("B_SignIn").gameObject.activeSelf)
  367. {
  368. Main = 1;
  369. }
  370. else
  371. {
  372. Main = 0;
  373. }
  374. #endregion
  375. #region 读数据存档
  376. SignIndex = int.Parse(Data.PlayerNode.SelectSingleNode("SignIndex").Attributes[0].Value);
  377. ManaMiniGame.MiniGameAmt = int.Parse(Data.PlayerNode.SelectSingleNode("MiniGameAmt").Attributes[0].Value);
  378. CircleTimer = float.Parse(Data.PlayerNode.SelectSingleNode("CircleTimer").Attributes[0].Value);
  379. int slot = int.Parse(Data.PlayerNode.SelectSingleNode("Slot").Attributes[0].Value);
  380. for (int i = 0; i < slot; i++)
  381. {
  382. ManaGarden.UnlockSlot();
  383. }
  384. AD = double.Parse(Data.PlayerNode.SelectSingleNode("AchieveData").Attributes[0].Value);
  385. Skill = double.Parse(Data.PlayerNode.SelectSingleNode("AchieveData").Attributes[1].Value);
  386. Sign = double.Parse(Data.PlayerNode.SelectSingleNode("AchieveData").Attributes[2].Value);
  387. Share = double.Parse(Data.PlayerNode.SelectSingleNode("AchieveData").Attributes[3].Value);
  388. MiniGame = double.Parse(Data.PlayerNode.SelectSingleNode("AchieveData").Attributes[4].Value);
  389. FlowerCoin = double.Parse(Data.PlayerNode.SelectSingleNode("AchieveData").Attributes[5].Value);
  390. #endregion
  391. #region 读花朵存档
  392. XmlAttributeCollection attributes = Data.PlayerNode.SelectSingleNode("FlowerList").Attributes;
  393. if (!string.IsNullOrEmpty(attributes[0].Value))
  394. {
  395. string[] strings = attributes[0].Value.Split(' ');
  396. for (int i = 0; i < strings.Length; i++)
  397. {
  398. int id = int.Parse(strings[i]);
  399. ManaGarden.FlowerInfoList[id].Unlock = true;
  400. }
  401. }
  402. attributes = Data.PlayerNode.SelectSingleNode("PlantList").Attributes;
  403. for (int i = 0; i < attributes.Count; i++)
  404. {
  405. int id = int.Parse(attributes[i].Value);
  406. ManaGarden.PlantFlower(id, attributes[i].Name);
  407. }
  408. #endregion
  409. }
  410. public override void RegistValueC()
  411. {
  412. #region 读技能存档
  413. UseList = new List<SkillRoot>();
  414. CoolList = new List<Skill>();
  415. float elapse = (float) DateTime.Now.Subtract(DateTime.Parse(Data.PlayerNode.SelectSingleNode("QuitTime").Attributes[0].Value)).TotalSeconds;
  416. if (elapse > 43200)
  417. {
  418. elapse = 43200;
  419. }
  420. ManaDebug.Log(string.Format("离线时间<color=red>{0}</color>", elapse));
  421. XmlNodeList xmlNodeList = Data.PlayerNode.SelectSingleNode("SkillList").ChildNodes;
  422. List<SkillRoot> ffCoolList = new List<SkillRoot>();
  423. List<List<SkillRoot>> ffUseList = new List<List<SkillRoot>>();
  424. if (elapse > CircleTimer)
  425. {
  426. int ffCircle = 1 + Mathf.FloorToInt((elapse - CircleTimer)/CircleTime);
  427. ManaDebug.Log(string.Format("离线周期<color=red>{0}</color>", ffCircle));
  428. for (int i = 0; i < ffCircle; i++)
  429. {
  430. ffUseList.Add(new List<SkillRoot>());
  431. }
  432. }
  433. else
  434. {
  435. ManaDebug.Log(string.Format("离线周期<color=red>{0}</color>", 0));
  436. }
  437. for (int i = 0; i < xmlNodeList.Count; i++)
  438. {
  439. if (xmlNodeList[i].Attributes[0].Value == SkillType.Skill.ToString())
  440. {
  441. Skill skill = (Skill)SkillDic[xmlNodeList[i].Name];
  442. skill.RegistReference();
  443. skill.Level = int.Parse(xmlNodeList[i].Attributes[2].Value);
  444. skill.CoolTimer = float.Parse(xmlNodeList[i].Attributes[3].Value);
  445. skill.UseTimer = float.Parse(xmlNodeList[i].Attributes[4].Value);
  446. skill._ItemStatus = (SkillStatus)Enum.Parse(typeof(SkillStatus), xmlNodeList[i].Attributes[1].Value);
  447. skill.RegistValue(elapse, ffUseList);
  448. }
  449. else if (xmlNodeList[i].Attributes[0].Value == SkillType.BigSkill.ToString())
  450. {
  451. BigSkill bigSkill = (BigSkill)SkillDic[xmlNodeList[i].Name];
  452. bigSkill.RegistReference();
  453. bigSkill.Level = int.Parse(xmlNodeList[i].Attributes[3].Value);
  454. bigSkill.CoolTimer = float.Parse(xmlNodeList[i].Attributes[4].Value);
  455. bigSkill.UseTimer = float.Parse(xmlNodeList[i].Attributes[5].Value);
  456. bigSkill._ItemStatus = (SkillStatus)Enum.Parse(typeof(SkillStatus), xmlNodeList[i].Attributes[1].Value);
  457. bigSkill._BarStatus = (SkillStatus)Enum.Parse(typeof(SkillStatus), xmlNodeList[i].Attributes[2].Value);
  458. bigSkill.RegistValue(elapse, ffUseList);
  459. }
  460. else if (xmlNodeList[i].Attributes[0].Value == SkillType.Pack.ToString())
  461. {
  462. Pack pack = (Pack)SkillDic[xmlNodeList[i].Attributes[1].Value];
  463. pack.RegistReference();
  464. pack.Level = int.Parse(xmlNodeList[i].Attributes[3].Value);
  465. pack._ItemStatus = (SkillStatus)Enum.Parse(typeof(SkillStatus), xmlNodeList[i].Attributes[2].Value);
  466. pack.RegistValue(elapse, ffUseList);
  467. }
  468. else if (xmlNodeList[i].Attributes[0].Value == SkillType.Ability.ToString())
  469. {
  470. Ability ability = (Ability)SkillDic[xmlNodeList[i].Name];
  471. ability.RegistReference();
  472. ability.Level = int.Parse(xmlNodeList[i].Attributes[2].Value);
  473. ability._ItemStatus = (SkillStatus)Enum.Parse(typeof(SkillStatus), xmlNodeList[i].Attributes[1].Value);
  474. ability.RegistValue(elapse, ffUseList);
  475. }
  476. else
  477. {
  478. throw new Exception();
  479. }
  480. }
  481. #endregion
  482. #region 读数据存档
  483. Level = int.Parse(Data.PlayerNode.SelectSingleNode("Level").Attributes[0].Value);
  484. MiniTimer = float.Parse(Data.PlayerNode.SelectSingleNode("MiniTimer").Attributes[0].Value);
  485. ManaDebug.Log(string.Format("<color=red>{0:0}</color>秒后激活小游戏", MiniTimer));
  486. Coin = double.Parse(Data.PlayerNode.SelectSingleNode("Coin").Attributes[0].Value);
  487. Diamond = double.Parse(Data.PlayerNode.SelectSingleNode("Diamond").Attributes[0].Value);
  488. #endregion
  489. #region 计算离线收入
  490. float collectCoin = 0;
  491. if (ffUseList.Count > 0)
  492. {
  493. for (int i = 0; i < ffUseList.Count; i++)
  494. {
  495. for (int j = 0; j < ffCoolList.Count; j++)
  496. {
  497. if (ffCoolList[j] is Skill)
  498. {
  499. if (i == 0)
  500. {
  501. ((Skill)ffCoolList[j]).CoolTimer -= CircleTimer;
  502. }
  503. else
  504. {
  505. ((Skill)ffCoolList[j]).CoolTimer -= CircleTime;
  506. }
  507. }
  508. }
  509. for (int j = 0; j < ffUseList[i].Count; j++)
  510. {
  511. ffUseList[i][j].Annul();
  512. ffCoolList.Add(ffUseList[i][j]);
  513. }
  514. NewPerson = Person * (1 + SkillPersonBuff) + SkillPerson;
  515. NewCoinPerson = CoinPerson + SkillCoinPerson;
  516. collectCoin += (NewPerson * NewCoinPerson * CircleTime) * (1 + SkillPlus);
  517. }
  518. CircleTimer = (elapse - CircleTimer)%CircleTime;
  519. for (int j = 0; j < ffCoolList.Count; j++)
  520. {
  521. if (ffCoolList[j] is Skill)
  522. {
  523. ((Skill) ffCoolList[j]).CoolTimer -= CircleTime - CircleTimer;
  524. }
  525. }
  526. Coin += collectCoin;
  527. ManaReso.SetText("Ba_IconLab", collectCoin.ToString("0"));
  528. }
  529. else
  530. {
  531. CircleTimer = CircleTimer - elapse;
  532. ManaReso.SetText("Ba_IconLab", "0");
  533. }
  534. #endregion
  535. }
  536. public static bool Pay(double amt, Current current)
  537. {
  538. amt = (long) amt;
  539. if (current == Current.Free)
  540. {
  541. return true;
  542. }
  543. else if (current == Current.AD)
  544. {
  545. return true;
  546. }
  547. else if (current == Current.Cash)
  548. {
  549. return true;
  550. }
  551. else if (current == Current.Coin)
  552. {
  553. if (Coin >= amt)
  554. {
  555. Coin -= amt;
  556. return true;
  557. }
  558. else
  559. {
  560. ManaDebug.Log("您没有足够的金币");
  561. return false;
  562. }
  563. }
  564. else if (current == Current.Diamond)
  565. {
  566. if (Diamond >= amt)
  567. {
  568. Diamond -= amt;
  569. return true;
  570. }
  571. else
  572. {
  573. ManaDebug.Log("您没有足够的钻石");
  574. return false;
  575. }
  576. }
  577. else
  578. {
  579. throw new Exception(current.ToString());
  580. }
  581. }
  582. }