ManaData.cs 15 KB

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