ManaData.cs 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654
  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.Elf, Elf_);
  20. }
  21. }
  22. public static double AD
  23. {
  24. get { return AD_; }
  25. set
  26. {
  27. AD_ = value;
  28. ManaAchieve.UpdateStatus(AchieveType.AD, AD_);
  29. }
  30. }
  31. public static double Skill
  32. {
  33. get { return Skill_; }
  34. set
  35. {
  36. Skill_ = value;
  37. ManaAchieve.UpdateStatus(AchieveType.Skill, Skill_);
  38. }
  39. }
  40. public static double SignAmt
  41. {
  42. get { return SignAmt_; }
  43. set
  44. {
  45. SignAmt_ = value;
  46. ManaAchieve.UpdateStatus(AchieveType.Sign, SignAmt_);
  47. }
  48. }
  49. public static double Share
  50. {
  51. get { return Share_; }
  52. set
  53. {
  54. Share_ = value;
  55. ManaAchieve.UpdateStatus(AchieveType.Share, 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.MiniGame, 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. private static double Elf_;
  86. private static double AD_;
  87. private static double Skill_;
  88. private static double SignAmt_;
  89. private static double Share_;
  90. private static double TotalCoin_;
  91. private static double MiniGameAmt_;
  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. ManaAchieve.UpdateStatus(AchieveType.Garden, Level_);
  111. if (TabBtnValid == false)
  112. {
  113. if (Level_ >= 20)
  114. {
  115. TabBtnValid = true;
  116. ManaReso.Get<Graphic>("F_Elf").material = null;
  117. ManaReso.Get<Graphic>("F_Store").material = null;
  118. ManaReso.Get<Graphic>("F_Magic").material = null;
  119. ManaReso.Get<Graphic>("F_ElfLab").material = null;
  120. ManaReso.Get<Graphic>("F_StoreLab").material = null;
  121. ManaReso.Get<Graphic>("F_MagicLab").material = null;
  122. ManaReso.Get<Button>("F_Elf").interactable = true;
  123. ManaReso.Get<Button>("F_Store").interactable = true;
  124. ManaReso.Get<Button>("F_Magic").interactable = true;
  125. }
  126. }
  127. for (int i = 0; i < SkillList.Count; i++)
  128. {
  129. SkillList[i].UpdateStatus();
  130. }
  131. if (ManaTutorial.TutorialB_ && !ManaTutorial.TutorialB)
  132. {
  133. if (Level_ >= 200)
  134. {
  135. ManaTutorial.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 bool MiniValid;
  210. public static bool TabBtnValid;
  211. public static bool SkillBarValid;
  212. public static int MainDepth;
  213. public static float OpTime = 90;
  214. public static float OpTimer;
  215. public static float MiniTimer;
  216. public static float CircleTime = 10;
  217. public static float CircleTimer;
  218. public static float NewPerson;
  219. public static float NewCoinPerson;
  220. public static float SkillPlus;
  221. public static float SkillPerson;
  222. public static float SkillPersonBuff;
  223. public static float SkillCoinPerson;
  224. public static List<Skill> CoolList = new List<Skill>();
  225. public static List<Skill> UseList = new List<Skill>();
  226. public static List<SkillRoot> SkillList = new List<SkillRoot>();
  227. public static Dictionary<string, SkillRoot> SkillDic = new Dictionary<string, SkillRoot>();
  228. #endregion
  229. private void Update()
  230. {
  231. if (ManaTutorial.TutorialA)
  232. {
  233. return;
  234. }
  235. MiniThread();
  236. MainThread();
  237. }
  238. private void MiniThread()
  239. {
  240. if (Pause)
  241. {
  242. return;
  243. }
  244. if (MiniValid == false)
  245. {
  246. MiniTimer -= Time.deltaTime;
  247. if (MiniTimer < 0)
  248. {
  249. MiniValid = true;
  250. ManaReso.Get("C_MiniGame").TweenForCG();
  251. }
  252. }
  253. }
  254. private void MainThread()
  255. {
  256. if (Pause)
  257. {
  258. return;
  259. }
  260. MiniThread();
  261. if (Auxiliary.AnyKeyUp)
  262. {
  263. OpTimer = 0;
  264. if (MainDepth == 0)
  265. {
  266. ManaReso.Get("C_Main").TweenForCG();
  267. }
  268. }
  269. else
  270. {
  271. OpTimer += Time.deltaTime;
  272. if (OpTimer >= OpTime)
  273. {
  274. OpTimer = 0;
  275. if (MainDepth == -1)
  276. {
  277. ManaReso.Get("C_Main").TweenBacCG();
  278. }
  279. }
  280. }
  281. }
  282. private void FixedUpdate()
  283. {
  284. if (ManaTutorial.TutorialA)
  285. {
  286. return;
  287. }
  288. #region 技能
  289. for (int i = 0; i < UseList.Count; i++)
  290. {
  291. if (UseList[i].DoUse())
  292. {
  293. UseList.RemoveAt(i--);
  294. }
  295. }
  296. for (int i = 0; i < CoolList.Count; i++)
  297. {
  298. if (CoolList[i].DoCool())
  299. {
  300. CoolList.RemoveAt(i--);
  301. }
  302. }
  303. #endregion
  304. #region 参观收入
  305. CircleTimer -= Time.deltaTime;
  306. if (CircleTimer < 0)
  307. {
  308. CircleTimer = CircleTime;
  309. NewPerson = Person * (1 + SkillPersonBuff) + SkillPerson;
  310. NewCoinPerson = CoinPerson + SkillCoinPerson;
  311. float temp = (NewPerson * NewCoinPerson * CircleTime) * (1 + SkillPlus);
  312. Coin += temp;
  313. ManaReso.Get("C_IncomeLab").TweenForGra();
  314. ManaReso.Get("C_IncomeLab").TweenForVec();
  315. ManaReso.SetText("C_IncomeLab", "+" + temp.ToString("0"));
  316. 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));
  317. }
  318. #endregion
  319. }
  320. public override void Instantiate()
  321. {
  322. #region 生成技能条
  323. #region 读技能配置
  324. List<XmlAttributeCollection> attributeList = Data.GetSkillConfig();
  325. for (int i = 0; i < attributeList.Count; i++)
  326. {
  327. SkillRoot skillRoot;
  328. #region MyRegion
  329. if (attributeList[i].Count == 17)
  330. {
  331. skillRoot = new Pack(attributeList[i]);
  332. }
  333. else if (attributeList[i].Count == 23)
  334. {
  335. skillRoot = new Ability(attributeList[i]);
  336. }
  337. else if (attributeList[i].Count == 33)
  338. {
  339. if (string.IsNullOrEmpty(attributeList[i][4].Value))
  340. {
  341. skillRoot = new Skill(attributeList[i]);
  342. }
  343. else
  344. {
  345. skillRoot = new BigSkill(attributeList[i]);
  346. }
  347. }
  348. else
  349. {
  350. throw new Exception(attributeList[i].Count.ToString());
  351. }
  352. #endregion
  353. SkillDic.Add(skillRoot.ID, skillRoot);
  354. SkillList.Add(skillRoot);
  355. }
  356. SkillList.Sort(SkillRoot.Sort);
  357. #endregion
  358. for (int i = 0; i < SkillList.Count; i++)
  359. {
  360. if (SkillList[i].SkillTab != SkillTab.Null)
  361. {
  362. ManaReso.GetSkillItem(SkillList[i]);
  363. }
  364. }
  365. #endregion
  366. }
  367. public override void RegistValueA()
  368. {
  369. if (ManaReso.Get("B_SignIn").gameObject.activeSelf)
  370. {
  371. MainDepth = 1;
  372. }
  373. else
  374. {
  375. MainDepth = 0;
  376. }
  377. #region 读数据存档
  378. CircleTimer = Data.GetPlayerFloat("CircleTimer");
  379. List<double> dataList = Data.GetAchieveData();
  380. AD = dataList[0];
  381. Skill = dataList[1];
  382. SignAmt = dataList[2];
  383. Share = dataList[3];
  384. MiniGameAmt = dataList[4];
  385. FlowerCoin = dataList[5];
  386. #endregion
  387. }
  388. public override void RegistValueC()
  389. {
  390. #region 读技能存档
  391. float elapse = (float) DateTime.Now.Subtract(DateTime.Parse(Data.GetPlayerString("QuitTime"))).TotalSeconds;
  392. if (elapse > 43200)
  393. {
  394. elapse = 43200;
  395. }
  396. ManaDebug.Log(string.Format("离线时间<color=red>{0}</color>", elapse));
  397. List<Skill> coolList = new List<Skill>();
  398. List<List<Skill>> useList = new List<List<Skill>>();
  399. if (elapse > CircleTimer)
  400. {
  401. int circle = 1 + Mathf.FloorToInt((elapse - CircleTimer)/CircleTime);
  402. for (int i = 0; i < circle; i++)
  403. {
  404. useList.Add(new List<Skill>());
  405. }
  406. ManaDebug.Log(string.Format("离线周期<color=red>{0}</color>", circle));
  407. }
  408. else
  409. {
  410. ManaDebug.Log(string.Format("离线周期<color=red>{0}</color>", 0));
  411. }
  412. List<XmlAttributeCollection> attributeList = Data.GetSkillList();
  413. for (int i = 0; i < attributeList.Count; i++)
  414. {
  415. SkillRoot skillRoot = SkillDic[attributeList[i][0].Value];
  416. skillRoot.RegistReference();
  417. skillRoot.RegistValue(elapse, useList, attributeList[i]);
  418. }
  419. #endregion
  420. #region 读数据存档
  421. for (int i = 0; i < Data.GetPlayerInt("Slot"); i++)
  422. {
  423. ManaGarden.UnlockSlot();
  424. }
  425. Coin = Data.GetPlayerDouble("Coin");
  426. Level = Data.GetPlayerInt("Level");
  427. Diamond = Data.GetPlayerDouble("Diamond");
  428. MiniTimer = Data.GetPlayerFloat("MiniTimer");
  429. if (MiniTimer <= 0)
  430. {
  431. MiniValid = true;
  432. }
  433. else
  434. {
  435. MiniValid = false;
  436. }
  437. ManaDebug.Log(string.Format("<color=red>{0:0}</color>秒后激活小游戏", MiniTimer));
  438. #endregion
  439. #region 计算离线收入
  440. float coin = 0;
  441. if (useList.Count > 0)
  442. {
  443. for (int i = 0; i < useList.Count; i++)
  444. {
  445. for (int j = 0; j < coolList.Count; j++)
  446. {
  447. coolList[j].CoolTimer -= CircleTime;
  448. }
  449. for (int j = 0; j < useList[i].Count; j++)
  450. {
  451. useList[i][j].Annul();
  452. coolList.Add(useList[i][j]);
  453. }
  454. }
  455. NewPerson = Person * (1 + SkillPersonBuff) + SkillPerson;
  456. NewCoinPerson = CoinPerson + SkillCoinPerson;
  457. coin += (NewPerson * NewCoinPerson * CircleTime) * (1 + SkillPlus);
  458. CircleTimer = (elapse - CircleTimer)%CircleTime;
  459. for (int j = 0; j < coolList.Count; j++)
  460. {
  461. coolList[j].CoolTimer -= CircleTime - CircleTimer;
  462. }
  463. Coin += coin;
  464. ManaReso.SetText("Ba_IconLab", coin.ToString("0"));
  465. }
  466. else
  467. {
  468. CircleTimer = CircleTimer - elapse;
  469. ManaReso.SetText("Ba_IconLab", "0");
  470. }
  471. #endregion
  472. }
  473. public static bool Pay(double amt, Current current)
  474. {
  475. if (ManaTutorial.PayExempt)
  476. {
  477. return true;
  478. }
  479. amt = (long) amt;
  480. if (current == Current.Free)
  481. {
  482. return true;
  483. }
  484. else if (current == Current.AD)
  485. {
  486. return true;
  487. }
  488. else if (current == Current.Cash)
  489. {
  490. return true;
  491. }
  492. else if (current == Current.Coin)
  493. {
  494. if (Coin >= amt)
  495. {
  496. Coin -= amt;
  497. return true;
  498. }
  499. else
  500. {
  501. Toast.Show(1.5f, Language.GetStr("Common", "ShortCoin"));
  502. return false;
  503. }
  504. }
  505. else if (current == Current.Diamond)
  506. {
  507. if (Diamond >= amt)
  508. {
  509. Diamond -= amt;
  510. return true;
  511. }
  512. else
  513. {
  514. Toast.Show(1.5f, Language.GetStr("Common", "ShortDiamond"));
  515. return false;
  516. }
  517. }
  518. else
  519. {
  520. throw new Exception(current.ToString());
  521. }
  522. }
  523. }