ManaData.cs 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666
  1. using LitJson;
  2. using UnityEngine;
  3. using UnityEngine.UI;
  4. using UnityEngine.EventSystems;
  5. using System;
  6. using System.Xml;
  7. using System.Collections;
  8. using System.Collections.Generic;
  9. public class ManaData : Regist
  10. {
  11. #region 变量
  12. #region 成就
  13. public static double Elf
  14. {
  15. get { return Elf_; }
  16. set
  17. {
  18. Elf_ = value;
  19. ManaAchieve.UpdateStatus(AchieveType.ElfLevel, Elf_);
  20. }
  21. }
  22. public static double AD
  23. {
  24. get { return AD_; }
  25. set
  26. {
  27. AD_ = value;
  28. ManaAchieve.UpdateStatus(AchieveType.AdAmt, AD_);
  29. }
  30. }
  31. public static double Skill
  32. {
  33. get { return Skill_; }
  34. set
  35. {
  36. Skill_ = value;
  37. ManaAchieve.UpdateStatus(AchieveType.SkillAmt, Skill_);
  38. }
  39. }
  40. public static double SignAmt
  41. {
  42. get { return SignAmt_; }
  43. set
  44. {
  45. SignAmt_ = value;
  46. ManaAchieve.UpdateStatus(AchieveType.SignAmt, SignAmt_);
  47. }
  48. }
  49. public static double Share
  50. {
  51. get { return Share_; }
  52. set
  53. {
  54. Share_ = value;
  55. ManaAchieve.UpdateStatus(AchieveType.ShareAmt, Share_);
  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 MiniGameAmt
  68. {
  69. get { return MiniGameAmt_; }
  70. set
  71. {
  72. MiniGameAmt_ = value;
  73. ManaAchieve.UpdateStatus(AchieveType.MiniGameAmt, MiniGameAmt_);
  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. public static double TotalPerson
  86. {
  87. get { return TotalPerson_; }
  88. set
  89. {
  90. TotalPerson_ = value;
  91. ManaAchieve.UpdateStatus(AchieveType.TotalPerson, FlowerCoin_);
  92. }
  93. }
  94. private static double Elf_;
  95. private static double AD_;
  96. private static double Skill_;
  97. private static double SignAmt_;
  98. private static double Share_;
  99. private static double TotalCoin_;
  100. private static double MiniGameAmt_;
  101. private static double FlowerCoin_;
  102. private static double TotalPerson_;
  103. #endregion
  104. public static int Slot
  105. {
  106. get { return Slot_; }
  107. set
  108. {
  109. Slot_ = value;
  110. Garden.ValidPage = Mathf.Clamp(Mathf.CeilToInt(Slot_/7f), 1, 2);
  111. }
  112. }
  113. public static int Level
  114. {
  115. get { return Level_; }
  116. set
  117. {
  118. Level_ = value;
  119. ManaDebug.Log(string.Format("已升级 花园等级 : <color=red>{0}</color>", Level_));
  120. ManaAchieve.UpdateStatus(AchieveType.GardenLevel, Level_);
  121. if (TabBtnValid == false)
  122. {
  123. if (Level_ >= 20)
  124. {
  125. TabBtnValid = true;
  126. ManaReso.Get<Graphic>("F_Elf").material = null;
  127. ManaReso.Get<Graphic>("F_Store").material = null;
  128. ManaReso.Get<Graphic>("F_Magic").material = null;
  129. ManaReso.Get<Graphic>("F_ElfLab").material = null;
  130. ManaReso.Get<Graphic>("F_StoreLab").material = null;
  131. ManaReso.Get<Graphic>("F_MagicLab").material = null;
  132. ManaReso.Get<Button>("F_Elf").interactable = true;
  133. ManaReso.Get<Button>("F_Store").interactable = true;
  134. ManaReso.Get<Button>("F_Magic").interactable = true;
  135. }
  136. }
  137. for (int i = 0; i < SkillList.Count; i++)
  138. {
  139. SkillList[i].UpdateStatus();
  140. }
  141. if (ManaTutorial.TutorialB_ && !ManaTutorial.TutorialB)
  142. {
  143. if (Level_ >= 200)
  144. {
  145. ManaTutorial.TutorialB = true;
  146. ManaTutorial.PrepareStep10();
  147. }
  148. }
  149. }
  150. }
  151. public static bool Pause
  152. {
  153. get { return Pause_; }
  154. set
  155. {
  156. Pause_ = value;
  157. if (Pause_)
  158. {
  159. Time.timeScale = 0;
  160. ManaDebug.Log("<color=red>游戏暂停</color>");
  161. }
  162. else
  163. {
  164. Time.timeScale = 1;
  165. ManaDebug.Log("<color=red>游戏继续</color>");
  166. }
  167. }
  168. }
  169. public static float Person
  170. {
  171. get { return Person_; }
  172. set
  173. {
  174. Person_ = value;
  175. ManaReso.SetText("F_PersonLab", Person_.ToString("0"));
  176. }
  177. }
  178. public static float CoinPerson
  179. {
  180. get { return CoinPerson_; }
  181. set
  182. {
  183. CoinPerson_ = value;
  184. ManaReso.SetText("F_CoinPersonLab", CoinPerson_.ToString("0"));
  185. }
  186. }
  187. public static double Coin
  188. {
  189. get { return Coin_; }
  190. set
  191. {
  192. if (value - Coin_ > 0)
  193. {
  194. TotalCoin += value - Coin_;
  195. }
  196. Coin_ = value;
  197. ManaReso.SetText("F_CoinLab", Coin_.ToString("0"));
  198. ManaReso.SetText("C_CoinLab", Coin_.ToString("0"));
  199. ManaAchieve.UpdateStatus(AchieveType.CurrentCoin, Coin_);
  200. }
  201. }
  202. public static double Diamond
  203. {
  204. get { return Diamond_; }
  205. set
  206. {
  207. Diamond_ = value;
  208. ManaReso.SetText("F_DiamondLab", Diamond_.ToString("0"));
  209. }
  210. }
  211. private static int Slot_;
  212. private static int Level_;
  213. private static bool Pause_;
  214. private static float Person_;
  215. private static float CoinPerson_;
  216. private static double Coin_;
  217. private static double Diamond_;
  218. public static bool MiniValid;
  219. public static bool TabBtnValid;
  220. public static bool SkillBarValid;
  221. public static int MainDepth;
  222. public static float OpTime = 90;
  223. public static float OpTimer;
  224. public static float MiniTimer;
  225. public static float CircleTime = 10;
  226. public static float CircleTimer;
  227. public static float NewPerson;
  228. public static float NewCoinPerson;
  229. public static float SkillPlus;
  230. public static float SkillPerson;
  231. public static float SkillPersonBuff;
  232. public static float SkillCoinPerson;
  233. public static List<Skill> CoolList = new List<Skill>();
  234. public static List<Skill> UseList = new List<Skill>();
  235. public static List<SkillRoot> SkillList = new List<SkillRoot>();
  236. public static Dictionary<string, SkillRoot> SkillDic = new Dictionary<string, SkillRoot>();
  237. #endregion
  238. private void Update()
  239. {
  240. if (ManaTutorial.TutorialA)
  241. {
  242. return;
  243. }
  244. MiniThread();
  245. MainThread();
  246. }
  247. private void MiniThread()
  248. {
  249. if (Pause)
  250. {
  251. return;
  252. }
  253. if (MiniValid == false)
  254. {
  255. MiniTimer -= Time.deltaTime;
  256. if (MiniTimer < 0)
  257. {
  258. MiniValid = true;
  259. ManaReso.Get("C_MiniGame").TweenForCG();
  260. }
  261. }
  262. }
  263. private void MainThread()
  264. {
  265. if (Pause)
  266. {
  267. return;
  268. }
  269. MiniThread();
  270. if (Auxiliary.AnyKeyUp)
  271. {
  272. OpTimer = 0;
  273. if (MainDepth == 0)
  274. {
  275. ManaReso.Get("C_Main").TweenForCG();
  276. }
  277. }
  278. else
  279. {
  280. OpTimer += Time.deltaTime;
  281. if (OpTimer >= OpTime)
  282. {
  283. OpTimer = 0;
  284. if (MainDepth == -1)
  285. {
  286. ManaReso.Get("C_Main").TweenBacCG();
  287. }
  288. }
  289. }
  290. }
  291. private void FixedUpdate()
  292. {
  293. if (ManaTutorial.TutorialA)
  294. {
  295. return;
  296. }
  297. #region 技能
  298. for (int i = 0; i < UseList.Count; i++)
  299. {
  300. if (UseList[i].DoUse())
  301. {
  302. UseList.RemoveAt(i--);
  303. }
  304. }
  305. for (int i = 0; i < CoolList.Count; i++)
  306. {
  307. if (CoolList[i].DoCool())
  308. {
  309. CoolList.RemoveAt(i--);
  310. }
  311. }
  312. #endregion
  313. #region 参观收入
  314. CircleTimer -= Time.deltaTime;
  315. if (CircleTimer < 0)
  316. {
  317. CircleTimer = CircleTime;
  318. NewPerson = Person * (1 + SkillPersonBuff) + SkillPerson;
  319. NewCoinPerson = CoinPerson + SkillCoinPerson;
  320. TotalPerson += NewPerson;
  321. float temp = (NewPerson * NewCoinPerson * CircleTime) * (1 + SkillPlus);
  322. Coin += temp;
  323. ManaReso.Get("C_IncomeLab").TweenForGra();
  324. ManaReso.Get("C_IncomeLab").TweenForVec();
  325. ManaReso.SetText("C_IncomeLab", "+" + temp.ToString("0"));
  326. 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));
  327. }
  328. #endregion
  329. }
  330. public override void Instantiate()
  331. {
  332. #region 生成技能条
  333. #region 读技能配置
  334. List<XmlAttributeCollection> attributeList = Data.GetSkillConfig();
  335. for (int i = 0; i < attributeList.Count; i++)
  336. {
  337. SkillRoot skillRoot;
  338. #region MyRegion
  339. if (attributeList[i].Count == 17)
  340. {
  341. skillRoot = new Pack(attributeList[i]);
  342. }
  343. else if (attributeList[i].Count == 23)
  344. {
  345. skillRoot = new Ability(attributeList[i]);
  346. }
  347. else if (attributeList[i].Count == 33)
  348. {
  349. if (string.IsNullOrEmpty(attributeList[i][4].Value))
  350. {
  351. skillRoot = new Skill(attributeList[i]);
  352. }
  353. else
  354. {
  355. skillRoot = new BigSkill(attributeList[i]);
  356. }
  357. }
  358. else
  359. {
  360. throw new Exception(attributeList[i].Count.ToString());
  361. }
  362. #endregion
  363. SkillDic.Add(skillRoot.ID, skillRoot);
  364. SkillList.Add(skillRoot);
  365. }
  366. SkillList.Sort(SkillRoot.Sort);
  367. #endregion
  368. for (int i = 0; i < SkillList.Count; i++)
  369. {
  370. if (SkillList[i].SkillTab != SkillTab.Null)
  371. {
  372. ManaReso.GetSkillItem(SkillList[i]);
  373. }
  374. }
  375. #endregion
  376. }
  377. public override void RegistValueA()
  378. {
  379. if (ManaReso.Get("B_SignIn").gameObject.activeSelf)
  380. {
  381. MainDepth = 1;
  382. }
  383. else
  384. {
  385. MainDepth = 0;
  386. }
  387. #region 读数据存档
  388. CircleTimer = Data.GetPlayerFloat("CircleTimer");
  389. List<double> dataList = Data.GetAchieveData();
  390. AD = dataList[0];
  391. Skill = dataList[1];
  392. SignAmt = dataList[2];
  393. Share = dataList[3];
  394. MiniGameAmt = dataList[4];
  395. FlowerCoin = dataList[5];
  396. TotalPerson = dataList[6];
  397. #endregion
  398. }
  399. public override void RegistValueC()
  400. {
  401. #region 读技能存档
  402. float elapse = (float) DateTime.Now.Subtract(DateTime.Parse(Data.GetPlayerString("QuitTime"))).TotalSeconds;
  403. if (elapse > 43200)
  404. {
  405. elapse = 43200;
  406. }
  407. ManaDebug.Log(string.Format("离线时间<color=red>{0}</color>", elapse));
  408. List<Skill> coolList = new List<Skill>();
  409. List<List<Skill>> useList = new List<List<Skill>>();
  410. if (elapse > CircleTimer)
  411. {
  412. int circle = 1 + Mathf.FloorToInt((elapse - CircleTimer)/CircleTime);
  413. for (int i = 0; i < circle; i++)
  414. {
  415. useList.Add(new List<Skill>());
  416. }
  417. ManaDebug.Log(string.Format("离线周期<color=red>{0}</color>", circle));
  418. }
  419. else
  420. {
  421. ManaDebug.Log(string.Format("离线周期<color=red>{0}</color>", 0));
  422. }
  423. List<XmlAttributeCollection> attributeList = Data.GetSkillList();
  424. for (int i = 0; i < attributeList.Count; i++)
  425. {
  426. SkillRoot skillRoot = SkillDic[attributeList[i][0].Value];
  427. skillRoot.RegistReference();
  428. skillRoot.RegistValue(elapse, useList, attributeList[i]);
  429. }
  430. #endregion
  431. #region 读数据存档
  432. for (int i = 0; i < Data.GetPlayerInt("Slot"); i++)
  433. {
  434. ManaGarden.UnlockSlot();
  435. }
  436. Coin = Data.GetPlayerDouble("Coin");
  437. Level = Data.GetPlayerInt("Level");
  438. Diamond = Data.GetPlayerDouble("Diamond");
  439. MiniTimer = Data.GetPlayerFloat("MiniTimer");
  440. if (MiniTimer <= 0)
  441. {
  442. MiniValid = true;
  443. }
  444. else
  445. {
  446. MiniValid = false;
  447. }
  448. ManaDebug.Log(string.Format("<color=red>{0:0}</color>秒后激活小游戏", MiniTimer));
  449. #endregion
  450. #region 计算离线收入
  451. float coin = 0;
  452. if (useList.Count > 0)
  453. {
  454. for (int i = 0; i < useList.Count; i++)
  455. {
  456. for (int j = 0; j < coolList.Count; j++)
  457. {
  458. coolList[j].CoolTimer -= CircleTime;
  459. }
  460. for (int j = 0; j < useList[i].Count; j++)
  461. {
  462. useList[i][j].Annul();
  463. coolList.Add(useList[i][j]);
  464. }
  465. }
  466. NewPerson = Person * (1 + SkillPersonBuff) + SkillPerson;
  467. NewCoinPerson = CoinPerson + SkillCoinPerson;
  468. coin += (NewPerson * NewCoinPerson * CircleTime) * (1 + SkillPlus);
  469. CircleTimer = (elapse - CircleTimer)%CircleTime;
  470. for (int j = 0; j < coolList.Count; j++)
  471. {
  472. coolList[j].CoolTimer -= CircleTime - CircleTimer;
  473. }
  474. Coin += coin;
  475. ManaReso.SetText("Ba_IconLab", coin.ToString("0"));
  476. }
  477. else
  478. {
  479. CircleTimer = CircleTimer - elapse;
  480. ManaReso.SetText("Ba_IconLab", "0");
  481. }
  482. #endregion
  483. }
  484. public static bool Pay(double amt, Current current)
  485. {
  486. if (ManaTutorial.PayExempt)
  487. {
  488. return true;
  489. }
  490. amt = Auxiliary.ShrinkNumber(amt);
  491. if (current == Current.Free)
  492. {
  493. return true;
  494. }
  495. else if (current == Current.AD)
  496. {
  497. return true;
  498. }
  499. else if (current == Current.Cash)
  500. {
  501. return true;
  502. }
  503. else if (current == Current.Coin)
  504. {
  505. if (Coin >= amt)
  506. {
  507. Coin -= amt;
  508. return true;
  509. }
  510. else
  511. {
  512. Toast.Show(1.5f, Language.GetStr("Common", "ShortCoin"));
  513. return false;
  514. }
  515. }
  516. else if (current == Current.Diamond)
  517. {
  518. if (Diamond >= amt)
  519. {
  520. Diamond -= amt;
  521. return true;
  522. }
  523. else
  524. {
  525. Toast.Show(1.5f, Language.GetStr("Common", "ShortDiamond"));
  526. return false;
  527. }
  528. }
  529. else
  530. {
  531. throw new Exception(current.ToString());
  532. }
  533. }
  534. }