ManaData.cs 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699
  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 RegistValueA()
  394. {
  395. if (ManaReso.Get("B_SignIn").gameObject.activeSelf)
  396. {
  397. MainDepth = 1;
  398. }
  399. else
  400. {
  401. MainDepth = 0;
  402. }
  403. #region 读数据存档
  404. SignIndex = Data.GetPlayerInt("SignIndex");
  405. CircleTimer = Data.GetPlayerFloat("CircleTimer");
  406. List<double> dataList = Data.GetAchieveData();
  407. AD = dataList[0];
  408. Skill = dataList[1];
  409. Sign = dataList[2];
  410. Share = dataList[3];
  411. MiniGame = dataList[4];
  412. FlowerCoin = dataList[5];
  413. #endregion
  414. #region 读花朵存档
  415. List<int> flowerList = Data.GetFlowerList();
  416. for (int i = 0; i < flowerList.Count; i++)
  417. {
  418. ManaGarden.FlowerInfoList[flowerList[i]-1].Unlock = true;
  419. }
  420. List<KV<int, string>> plantList = Data.GetPlantList();
  421. for (int i = 0; i < plantList.Count; i++)
  422. {
  423. ManaGarden.PlantFlower(plantList[i].Key-1, plantList[i].Value);
  424. }
  425. #endregion
  426. }
  427. public override void RegistValueC()
  428. {
  429. #region 读技能存档
  430. float elapse = (float) DateTime.Now.Subtract(DateTime.Parse(Data.PlayerNode.SelectSingleNode("QuitTime").Attributes[0].Value)).TotalSeconds;
  431. if (elapse > 43200)
  432. {
  433. elapse = 43200;
  434. }
  435. ManaDebug.Log(string.Format("离线时间<color=red>{0}</color>", elapse));
  436. List<SkillRoot> ffCoolList = new List<SkillRoot>();
  437. List<List<SkillRoot>> ffUseList = new List<List<SkillRoot>>();
  438. if (elapse > CircleTimer)
  439. {
  440. int ffCircle = 1 + Mathf.FloorToInt((elapse - CircleTimer)/CircleTime);
  441. ManaDebug.Log(string.Format("离线周期<color=red>{0}</color>", ffCircle));
  442. for (int i = 0; i < ffCircle; i++)
  443. {
  444. ffUseList.Add(new List<SkillRoot>());
  445. }
  446. }
  447. else
  448. {
  449. ManaDebug.Log(string.Format("离线周期<color=red>{0}</color>", 0));
  450. }
  451. List<XmlAttributeCollection> attributeList = Data.GetSkillList();
  452. for (int i = 0; i < attributeList.Count; i++)
  453. {
  454. SkillRoot skillRoot = SkillDic[attributeList[i][0].Value];
  455. skillRoot.RegistReference();
  456. skillRoot.RegistValue(elapse, ffUseList, attributeList[i]);
  457. }
  458. #endregion
  459. #region 读数据存档
  460. for (int i = 0; i < Data.GetPlayerInt("Slot"); i++)
  461. {
  462. ManaGarden.UnlockSlot();
  463. }
  464. Coin = Data.GetPlayerDouble("Coin");
  465. Level = Data.GetPlayerInt("Level");
  466. Diamond = Data.GetPlayerDouble("Diamond");
  467. MiniTimer = Data.GetPlayerFloat("MiniTimer");
  468. ManaDebug.Log(string.Format("<color=red>{0:0}</color>秒后激活小游戏", MiniTimer));
  469. #endregion
  470. #region 计算离线收入
  471. float collectCoin = 0;
  472. if (ffUseList.Count > 0)
  473. {
  474. for (int i = 0; i < ffUseList.Count; i++)
  475. {
  476. for (int j = 0; j < ffCoolList.Count; j++)
  477. {
  478. if (ffCoolList[j] is Skill)
  479. {
  480. if (i == 0)
  481. {
  482. ((Skill)ffCoolList[j]).CoolTimer -= CircleTimer;
  483. }
  484. else
  485. {
  486. ((Skill)ffCoolList[j]).CoolTimer -= CircleTime;
  487. }
  488. }
  489. }
  490. for (int j = 0; j < ffUseList[i].Count; j++)
  491. {
  492. ffUseList[i][j].Annul();
  493. ffCoolList.Add(ffUseList[i][j]);
  494. }
  495. NewPerson = Person * (1 + SkillPersonBuff) + SkillPerson;
  496. NewCoinPerson = CoinPerson + SkillCoinPerson;
  497. collectCoin += (NewPerson * NewCoinPerson * CircleTime) * (1 + SkillPlus);
  498. }
  499. CircleTimer = (elapse - CircleTimer)%CircleTime;
  500. for (int j = 0; j < ffCoolList.Count; j++)
  501. {
  502. if (ffCoolList[j] is Skill)
  503. {
  504. ((Skill) ffCoolList[j]).CoolTimer -= CircleTime - CircleTimer;
  505. }
  506. }
  507. Coin += collectCoin;
  508. ManaReso.SetText("Ba_IconLab", collectCoin.ToString("0"));
  509. }
  510. else
  511. {
  512. CircleTimer = CircleTimer - elapse;
  513. ManaReso.SetText("Ba_IconLab", "0");
  514. }
  515. #endregion
  516. }
  517. public static bool Pay(double amt, Current current)
  518. {
  519. amt = (long) amt;
  520. if (current == Current.Free)
  521. {
  522. return true;
  523. }
  524. else if (current == Current.AD)
  525. {
  526. return true;
  527. }
  528. else if (current == Current.Cash)
  529. {
  530. return true;
  531. }
  532. else if (current == Current.Coin)
  533. {
  534. if (Coin >= amt)
  535. {
  536. Coin -= amt;
  537. return true;
  538. }
  539. else
  540. {
  541. ManaDebug.Log("您没有足够的金币");
  542. return false;
  543. }
  544. }
  545. else if (current == Current.Diamond)
  546. {
  547. if (Diamond >= amt)
  548. {
  549. Diamond -= amt;
  550. return true;
  551. }
  552. else
  553. {
  554. ManaDebug.Log("您没有足够的钻石");
  555. return false;
  556. }
  557. }
  558. else
  559. {
  560. throw new Exception(current.ToString());
  561. }
  562. }
  563. }