ManaData.cs 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681
  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 && !TutorialValidB)
  132. {
  133. if (Level_ >= 200)
  134. {
  135. TutorialValidB = 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 Free;
  210. public static bool MiniValid;
  211. public static bool TabBtnValid;
  212. public static bool SkillBarValid;
  213. public static bool TutorialValidB;
  214. public static int MainDepth;
  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. public static List<SkillRoot> SkillList = new List<SkillRoot>();
  229. public static Dictionary<string, SkillRoot> SkillDic = new Dictionary<string, SkillRoot>();
  230. #endregion
  231. private void Update()
  232. {
  233. if (ManaTutorial.TutorialA)
  234. {
  235. TutorialUpdate();
  236. }
  237. else
  238. {
  239. RegularUpdate();
  240. }
  241. }
  242. private void TutorialUpdate()
  243. {
  244. }
  245. private void RegularUpdate()
  246. {
  247. MiniThread();
  248. MainThread();
  249. }
  250. private void MiniThread()
  251. {
  252. if (Pause)
  253. {
  254. return;
  255. }
  256. if (MiniValid == false)
  257. {
  258. MiniTimer -= Time.deltaTime;
  259. if (MiniTimer < 0)
  260. {
  261. MiniValid = false;
  262. ManaReso.Get("C_MiniGame").TweenForCG();
  263. }
  264. }
  265. }
  266. private void MainThread()
  267. {
  268. if (Pause)
  269. {
  270. return;
  271. }
  272. MiniThread();
  273. if (Auxiliary.AnyKeyUp)
  274. {
  275. OpTimer = 0;
  276. if (MainDepth == 0)
  277. {
  278. ManaReso.Get("C_Main").TweenForCG();
  279. }
  280. }
  281. else
  282. {
  283. OpTimer += Time.deltaTime;
  284. if (OpTimer >= OpTime)
  285. {
  286. OpTimer = 0;
  287. if (MainDepth == -1)
  288. {
  289. ManaReso.Get("C_Main").TweenBacCG();
  290. }
  291. }
  292. }
  293. }
  294. private void FixedUpdate()
  295. {
  296. if (ManaTutorial.TutorialA)
  297. {
  298. TutorialFixedUpdate();
  299. }
  300. else
  301. {
  302. RegularFixedUpdate();
  303. }
  304. }
  305. private void TutorialFixedUpdate()
  306. {
  307. }
  308. private void RegularFixedUpdate()
  309. {
  310. #region 技能
  311. for (int i = 0; i < UseList.Count; i++)
  312. {
  313. if (UseList[i].DoUse())
  314. {
  315. i--;
  316. }
  317. }
  318. for (int i = 0; i < CoolList.Count; i++)
  319. {
  320. if (CoolList[i].DoCool())
  321. {
  322. i--;
  323. }
  324. }
  325. #endregion
  326. #region 参观收入
  327. CircleTimer -= Time.deltaTime;
  328. if (CircleTimer < 0)
  329. {
  330. CircleTimer = CircleTime;
  331. NewPerson = Person * (1 + SkillPersonBuff) + SkillPerson;
  332. NewCoinPerson = CoinPerson + SkillCoinPerson;
  333. float temp = (NewPerson * NewCoinPerson * CircleTime) * (1 + SkillPlus);
  334. Coin += temp;
  335. if (MainDepth == -1)
  336. {
  337. ManaReso.GetHudText("+" + temp.ToString("0"), Color.white, 25, ManaReso.Get("C_PosTra"), ManaReso.Get("C_Main"), false);
  338. }
  339. 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));
  340. }
  341. #endregion
  342. }
  343. public override void Instantiate()
  344. {
  345. #region 生成技能条
  346. #region 读技能配置
  347. List<XmlAttributeCollection> attributeList = Data.GetSkillConfig();
  348. for (int i = 0; i < attributeList.Count; i++)
  349. {
  350. SkillRoot skillRoot;
  351. #region MyRegion
  352. if (attributeList[i].Count == 17)
  353. {
  354. skillRoot = new Pack(attributeList[i]);
  355. }
  356. else if (attributeList[i].Count == 23)
  357. {
  358. skillRoot = new Ability(attributeList[i]);
  359. }
  360. else if (attributeList[i].Count == 33)
  361. {
  362. if (string.IsNullOrEmpty(attributeList[i][4].Value))
  363. {
  364. skillRoot = new Skill(attributeList[i]);
  365. }
  366. else
  367. {
  368. skillRoot = new BigSkill(attributeList[i]);
  369. }
  370. }
  371. else
  372. {
  373. throw new Exception(attributeList[i].Count.ToString());
  374. }
  375. #endregion
  376. SkillDic.Add(skillRoot.ID, skillRoot);
  377. SkillList.Add(skillRoot);
  378. }
  379. SkillList.Sort(SkillRoot.Sort);
  380. #endregion
  381. for (int i = 0; i < SkillList.Count; i++)
  382. {
  383. if (SkillList[i].SkillTab != SkillTab.Null)
  384. {
  385. ManaReso.GetSkillItem(SkillList[i]);
  386. }
  387. }
  388. #endregion
  389. }
  390. public override void RegistValueA()
  391. {
  392. if (ManaReso.Get("B_SignIn").gameObject.activeSelf)
  393. {
  394. MainDepth = 1;
  395. }
  396. else
  397. {
  398. MainDepth = 0;
  399. }
  400. #region 读数据存档
  401. CircleTimer = Data.GetPlayerFloat("CircleTimer");
  402. List<double> dataList = Data.GetAchieveData();
  403. AD = dataList[0];
  404. Skill = dataList[1];
  405. SignAmt = dataList[2];
  406. Share = dataList[3];
  407. MiniGameAmt = dataList[4];
  408. FlowerCoin = dataList[5];
  409. #endregion
  410. }
  411. public override void RegistValueC()
  412. {
  413. #region 读技能存档
  414. float elapse = (float) DateTime.Now.Subtract(DateTime.Parse(Data.GetPlayerString("QuitTime"))).TotalSeconds;
  415. if (elapse > 43200)
  416. {
  417. elapse = 43200;
  418. }
  419. ManaDebug.Log(string.Format("离线时间<color=red>{0}</color>", elapse));
  420. List<Skill> coolList = new List<Skill>();
  421. List<List<Skill>> useList = new List<List<Skill>>();
  422. if (elapse > CircleTimer)
  423. {
  424. int circle = 1 + Mathf.FloorToInt((elapse - CircleTimer)/CircleTime);
  425. for (int i = 0; i < circle; i++)
  426. {
  427. useList.Add(new List<Skill>());
  428. }
  429. ManaDebug.Log(string.Format("离线周期<color=red>{0}</color>", circle));
  430. }
  431. else
  432. {
  433. ManaDebug.Log(string.Format("离线周期<color=red>{0}</color>", 0));
  434. }
  435. List<XmlAttributeCollection> attributeList = Data.GetSkillList();
  436. for (int i = 0; i < attributeList.Count; i++)
  437. {
  438. SkillRoot skillRoot = SkillDic[attributeList[i][0].Value];
  439. skillRoot.RegistReference();
  440. skillRoot.RegistValue(elapse, useList, attributeList[i]);
  441. }
  442. #endregion
  443. #region 读数据存档
  444. for (int i = 0; i < Data.GetPlayerInt("Slot"); i++)
  445. {
  446. ManaGarden.UnlockSlot();
  447. }
  448. Coin = Data.GetPlayerDouble("Coin");
  449. Level = Data.GetPlayerInt("Level");
  450. Diamond = Data.GetPlayerDouble("Diamond");
  451. MiniTimer = Data.GetPlayerFloat("MiniTimer");
  452. if (MiniTimer <= 0)
  453. {
  454. MiniValid = true;
  455. }
  456. else
  457. {
  458. MiniValid = false;
  459. }
  460. ManaDebug.Log(string.Format("<color=red>{0:0}</color>秒后激活小游戏", MiniTimer));
  461. #endregion
  462. #region 计算离线收入
  463. float coin = 0;
  464. if (useList.Count > 0)
  465. {
  466. for (int i = 0; i < useList.Count; i++)
  467. {
  468. for (int j = 0; j < coolList.Count; j++)
  469. {
  470. coolList[j].CoolTimer -= CircleTime;
  471. }
  472. for (int j = 0; j < useList[i].Count; j++)
  473. {
  474. useList[i][j].Annul();
  475. coolList.Add(useList[i][j]);
  476. }
  477. }
  478. NewPerson = Person * (1 + SkillPersonBuff) + SkillPerson;
  479. NewCoinPerson = CoinPerson + SkillCoinPerson;
  480. coin += (NewPerson * NewCoinPerson * CircleTime) * (1 + SkillPlus);
  481. CircleTimer = (elapse - CircleTimer)%CircleTime;
  482. for (int j = 0; j < coolList.Count; j++)
  483. {
  484. coolList[j].CoolTimer -= CircleTime - CircleTimer;
  485. }
  486. Coin += coin;
  487. ManaReso.SetText("Ba_IconLab", coin.ToString("0"));
  488. }
  489. else
  490. {
  491. CircleTimer = CircleTimer - elapse;
  492. ManaReso.SetText("Ba_IconLab", "0");
  493. }
  494. #endregion
  495. }
  496. public static bool Pay(double amt, Current current)
  497. {
  498. if (Free)
  499. {
  500. return true;
  501. }
  502. amt = (long) amt;
  503. if (current == Current.Free)
  504. {
  505. return true;
  506. }
  507. else if (current == Current.AD)
  508. {
  509. return true;
  510. }
  511. else if (current == Current.Cash)
  512. {
  513. return true;
  514. }
  515. else if (current == Current.Coin)
  516. {
  517. if (Coin >= amt)
  518. {
  519. Coin -= amt;
  520. return true;
  521. }
  522. else
  523. {
  524. ManaDebug.Log("您没有足够的金币");
  525. return false;
  526. }
  527. }
  528. else if (current == Current.Diamond)
  529. {
  530. if (Diamond >= amt)
  531. {
  532. Diamond -= amt;
  533. return true;
  534. }
  535. else
  536. {
  537. ManaDebug.Log("您没有足够的钻石");
  538. return false;
  539. }
  540. }
  541. else
  542. {
  543. throw new Exception(current.ToString());
  544. }
  545. }
  546. }