ManaData.cs 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697
  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. if (ManaTutorial.TutorialB && !TutorialB)
  132. {
  133. if (_Level >= 200)
  134. {
  135. TutorialB = true;
  136. ManaTutorial.PrepareStep10();
  137. }
  138. }
  139. }
  140. }
  141. public static bool Pause
  142. {
  143. get { return _Pause; }
  144. set
  145. {
  146. _Pause = value;
  147. if (_Pause)
  148. {
  149. Time.timeScale = 0;
  150. ManaDebug.Log("<color=red>游戏暂停</color>");
  151. }
  152. else
  153. {
  154. Time.timeScale = 1;
  155. ManaDebug.Log("<color=red>游戏继续</color>");
  156. }
  157. }
  158. }
  159. public static float Person
  160. {
  161. get { return _Person; }
  162. set
  163. {
  164. _Person = value;
  165. ManaReso.SetText("F_PersonLab", _Person.ToString("0.0"));
  166. ManaAchieve.UpdateStatus(AchieveType.Person, _Person);
  167. }
  168. }
  169. public static float CoinPerson
  170. {
  171. get { return _CoinPerson; }
  172. set
  173. {
  174. _CoinPerson = value;
  175. ManaReso.SetText("F_CoinPersonLab", _CoinPerson.ToString("0.0"));
  176. }
  177. }
  178. public static double Coin
  179. {
  180. get { return _Coin; }
  181. set
  182. {
  183. if (value - _Coin > 0)
  184. {
  185. TotalCoin += value - _Coin;
  186. }
  187. _Coin = value;
  188. ManaReso.SetText("F_CoinLab", _Coin.ToString("0"));
  189. ManaReso.SetText("C_CoinLab", _Coin.ToString("0"));
  190. ManaAchieve.UpdateStatus(AchieveType.CurrentCoin, _Coin);
  191. }
  192. }
  193. public static double Diamond
  194. {
  195. get { return _Diamond; }
  196. set
  197. {
  198. _Diamond = value;
  199. ManaReso.SetText("F_DiamondLab", _Diamond.ToString("0"));
  200. }
  201. }
  202. private static int _Slot;
  203. private static int _Level;
  204. private static bool _Pause;
  205. private static float _Person;
  206. private static float _CoinPerson;
  207. private static double _Coin;
  208. private static double _Diamond;
  209. public static List<SkillRoot> SkillList
  210. {
  211. get
  212. {
  213. if (_SkillList == null)
  214. {
  215. _SkillList = new List<SkillRoot>();
  216. }
  217. return _SkillList;
  218. }
  219. set { _SkillList = value; }
  220. }
  221. public static Dictionary<string, SkillRoot> SkillDic
  222. {
  223. get
  224. {
  225. if (_SkillDic == null)
  226. {
  227. _SkillDic = new Dictionary<string, SkillRoot>();
  228. }
  229. return _SkillDic;
  230. }
  231. set { _SkillDic = value; }
  232. }
  233. public static List<SkillRoot> _SkillList;
  234. public static Dictionary<string, SkillRoot> _SkillDic;
  235. public static int SignIndex;
  236. public static int MainDepth;
  237. public static bool Free;
  238. public static bool Mini;
  239. public static bool TabBtn;
  240. public static bool SkillBar;
  241. public static bool Connect;
  242. public static bool TutorialB;
  243. public static float OpTime = 90;
  244. public static float OpTimer;
  245. public static float MiniTimer;
  246. public static float CircleTime = 10;
  247. public static float CircleTimer;
  248. public static float NewPerson;
  249. public static float NewCoinPerson;
  250. public static float SkillPlus;
  251. public static float SkillPerson;
  252. public static float SkillPersonBuff;
  253. public static float SkillCoinPerson;
  254. public static List<Skill> CoolList = new List<Skill>();
  255. public static List<SkillRoot> UseList = new List<SkillRoot>();
  256. #endregion
  257. private void Update()
  258. {
  259. if (ManaTutorial.TutorialA)
  260. {
  261. TutorialUpdate();
  262. }
  263. else
  264. {
  265. RegularUpdate();
  266. }
  267. }
  268. private void TutorialUpdate()
  269. {
  270. }
  271. private void RegularUpdate()
  272. {
  273. if (Pause)
  274. {
  275. return;
  276. }
  277. if (Mini == false)
  278. {
  279. MiniTimer -= Time.deltaTime;
  280. if (MiniTimer < 0)
  281. {
  282. Mini = true;
  283. ManaReso.Get("C_MiniGame").TweenForCG();
  284. }
  285. }
  286. if (Auxiliary.AnyKeyUp)
  287. {
  288. OpTimer = 0;
  289. if (MainDepth == 0)
  290. {
  291. ManaReso.Get("C_Main").TweenForCG();
  292. }
  293. }
  294. else
  295. {
  296. OpTimer += Time.deltaTime;
  297. if (OpTimer >= OpTime)
  298. {
  299. OpTimer = 0;
  300. if (MainDepth == -1)
  301. {
  302. ManaReso.Get("C_Main").TweenBacCG();
  303. }
  304. }
  305. }
  306. }
  307. private void FixedUpdate()
  308. {
  309. if (ManaTutorial.TutorialA)
  310. {
  311. TutorialFixedUpdate();
  312. }
  313. else
  314. {
  315. RegularFixedUpdate();
  316. }
  317. }
  318. private void TutorialFixedUpdate()
  319. {
  320. }
  321. private void RegularFixedUpdate()
  322. {
  323. #region 技能
  324. for (int i = 0; i < UseList.Count; i++)
  325. {
  326. if (UseList[i].DoUse())
  327. {
  328. i--;
  329. }
  330. }
  331. for (int i = 0; i < CoolList.Count; i++)
  332. {
  333. if (CoolList[i].DoCool())
  334. {
  335. i--;
  336. }
  337. }
  338. #endregion
  339. #region 参观收入
  340. CircleTimer -= Time.deltaTime;
  341. if (CircleTimer < 0)
  342. {
  343. CircleTimer = CircleTime;
  344. NewPerson = Person * (1 + SkillPersonBuff) + SkillPerson;
  345. NewCoinPerson = CoinPerson + SkillCoinPerson;
  346. float temp = (NewPerson * NewCoinPerson * CircleTime) * (1 + SkillPlus);
  347. Coin += temp;
  348. if (MainDepth == -1)
  349. {
  350. ManaReso.GetHudText("+" + temp.ToString("0"), Color.white, 25, ManaReso.Get("C_PosTra"), ManaReso.Get("C_Main"), false);
  351. }
  352. ManaDebug.Log(string.Format("参观收益<color=red>{0: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));
  353. }
  354. #endregion
  355. }
  356. public override void Instantiate()
  357. {
  358. #region 生成技能条
  359. #region 读技能配置
  360. List<XmlAttributeCollection> attributeList = Data.GetSkillConfig();
  361. for (int i = 0; i < attributeList.Count; i++)
  362. {
  363. SkillRoot skillRoot;
  364. #region MyRegion
  365. if (attributeList[i].Count == 17)
  366. {
  367. skillRoot = new Pack(attributeList[i]);
  368. }
  369. else if (attributeList[i].Count == 23)
  370. {
  371. skillRoot = new Ability(attributeList[i]);
  372. }
  373. else if (attributeList[i].Count == 33)
  374. {
  375. if (string.IsNullOrEmpty(attributeList[i][4].Value))
  376. {
  377. skillRoot = new Skill(attributeList[i]);
  378. }
  379. else
  380. {
  381. skillRoot = new BigSkill(attributeList[i]);
  382. }
  383. }
  384. else
  385. {
  386. throw new Exception(attributeList[i].Count.ToString());
  387. }
  388. #endregion
  389. SkillDic.Add(skillRoot._Name, skillRoot);
  390. SkillList.Add(skillRoot);
  391. }
  392. SkillList.Sort(SkillRoot.Sort);
  393. #endregion
  394. for (int i = 0; i < SkillList.Count; i++)
  395. {
  396. if (SkillList[i].SkillTab != SkillTab.Null)
  397. {
  398. ManaReso.GetSkillItem(SkillList[i]);
  399. }
  400. }
  401. #endregion
  402. }
  403. public override void RegistValueA()
  404. {
  405. if (ManaReso.Get("B_SignIn").gameObject.activeSelf)
  406. {
  407. MainDepth = 1;
  408. }
  409. else
  410. {
  411. MainDepth = 0;
  412. }
  413. #region 读数据存档
  414. SignIndex = Data.GetPlayerInt("SignIndex");
  415. CircleTimer = Data.GetPlayerFloat("CircleTimer");
  416. List<double> dataList = Data.GetAchieveData();
  417. AD = dataList[0];
  418. Skill = dataList[1];
  419. Sign = dataList[2];
  420. Share = dataList[3];
  421. MiniGame = dataList[4];
  422. FlowerCoin = dataList[5];
  423. #endregion
  424. }
  425. public override void RegistValueC()
  426. {
  427. #region 读技能存档
  428. float elapse = (float) DateTime.Now.Subtract(DateTime.Parse(Data.PlayerNode.SelectSingleNode("QuitTime").Attributes[0].Value)).TotalSeconds;
  429. if (elapse > 43200)
  430. {
  431. elapse = 43200;
  432. }
  433. ManaDebug.Log(string.Format("离线时间<color=red>{0}</color>", elapse));
  434. List<SkillRoot> ffCoolList = new List<SkillRoot>();
  435. List<List<SkillRoot>> ffUseList = new List<List<SkillRoot>>();
  436. if (elapse > CircleTimer)
  437. {
  438. int ffCircle = 1 + Mathf.FloorToInt((elapse - CircleTimer)/CircleTime);
  439. ManaDebug.Log(string.Format("离线周期<color=red>{0}</color>", ffCircle));
  440. for (int i = 0; i < ffCircle; i++)
  441. {
  442. ffUseList.Add(new List<SkillRoot>());
  443. }
  444. }
  445. else
  446. {
  447. ManaDebug.Log(string.Format("离线周期<color=red>{0}</color>", 0));
  448. }
  449. List<XmlAttributeCollection> attributeList = Data.GetSkillList();
  450. for (int i = 0; i < attributeList.Count; i++)
  451. {
  452. SkillRoot skillRoot = SkillDic[attributeList[i][0].Value];
  453. skillRoot.RegistReference();
  454. skillRoot.RegistValue(elapse, ffUseList, attributeList[i]);
  455. }
  456. #endregion
  457. #region 读数据存档
  458. for (int i = 0; i < Data.GetPlayerInt("Slot"); i++)
  459. {
  460. ManaGarden.UnlockSlot();
  461. }
  462. Coin = Data.GetPlayerDouble("Coin");
  463. Level = Data.GetPlayerInt("Level");
  464. Diamond = Data.GetPlayerDouble("Diamond");
  465. MiniTimer = Data.GetPlayerFloat("MiniTimer");
  466. ManaDebug.Log(string.Format("<color=red>{0:0}</color>秒后激活小游戏", MiniTimer));
  467. #endregion
  468. #region 计算离线收入
  469. float collectCoin = 0;
  470. if (ffUseList.Count > 0)
  471. {
  472. for (int i = 0; i < ffUseList.Count; i++)
  473. {
  474. for (int j = 0; j < ffCoolList.Count; j++)
  475. {
  476. if (ffCoolList[j] is Skill)
  477. {
  478. if (i == 0)
  479. {
  480. ((Skill)ffCoolList[j]).CoolTimer -= CircleTimer;
  481. }
  482. else
  483. {
  484. ((Skill)ffCoolList[j]).CoolTimer -= CircleTime;
  485. }
  486. }
  487. }
  488. for (int j = 0; j < ffUseList[i].Count; j++)
  489. {
  490. ffUseList[i][j].Annul();
  491. ffCoolList.Add(ffUseList[i][j]);
  492. }
  493. NewPerson = Person * (1 + SkillPersonBuff) + SkillPerson;
  494. NewCoinPerson = CoinPerson + SkillCoinPerson;
  495. collectCoin += (NewPerson * NewCoinPerson * CircleTime) * (1 + SkillPlus);
  496. }
  497. CircleTimer = (elapse - CircleTimer)%CircleTime;
  498. for (int j = 0; j < ffCoolList.Count; j++)
  499. {
  500. if (ffCoolList[j] is Skill)
  501. {
  502. ((Skill) ffCoolList[j]).CoolTimer -= CircleTime - CircleTimer;
  503. }
  504. }
  505. Coin += collectCoin;
  506. ManaReso.SetText("Ba_IconLab", collectCoin.ToString("0"));
  507. }
  508. else
  509. {
  510. CircleTimer = CircleTimer - elapse;
  511. ManaReso.SetText("Ba_IconLab", "0");
  512. }
  513. #endregion
  514. }
  515. public static bool Pay(double amt, Current current)
  516. {
  517. if (Free)
  518. {
  519. return true;
  520. }
  521. amt = (long) amt;
  522. if (current == Current.Free)
  523. {
  524. return true;
  525. }
  526. else if (current == Current.AD)
  527. {
  528. return true;
  529. }
  530. else if (current == Current.Cash)
  531. {
  532. return true;
  533. }
  534. else if (current == Current.Coin)
  535. {
  536. if (Coin >= amt)
  537. {
  538. Coin -= amt;
  539. return true;
  540. }
  541. else
  542. {
  543. ManaDebug.Log("您没有足够的金币");
  544. return false;
  545. }
  546. }
  547. else if (current == Current.Diamond)
  548. {
  549. if (Diamond >= amt)
  550. {
  551. Diamond -= amt;
  552. return true;
  553. }
  554. else
  555. {
  556. ManaDebug.Log("您没有足够的钻石");
  557. return false;
  558. }
  559. }
  560. else
  561. {
  562. throw new Exception(current.ToString());
  563. }
  564. }
  565. }