ManaData.cs 16 KB

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