ManaCenter.cs 33 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264
  1. using LitJson;
  2. using UnityEngine;
  3. using UnityEngine.UI;
  4. using UnityEngine.Events;
  5. using UnityEngine.Analytics;
  6. using UnityEngine.EventSystems;
  7. using System;
  8. using System.Xml;
  9. using System.Collections;
  10. using System.Collections.Generic;
  11. public class ManaCenter : Regist
  12. {
  13. #region 变量
  14. #region 成就
  15. public static double AdAmt
  16. {
  17. get { return AdAmt_; }
  18. set
  19. {
  20. AdAmt_ = value;
  21. ManaAchieve.UpdateStatus(AchieveType.AdAmt, AdAmt_);
  22. }
  23. }
  24. public static double SkillAmt
  25. {
  26. get { return SkillAmt_; }
  27. set
  28. {
  29. SkillAmt_ = value;
  30. ManaAchieve.UpdateStatus(AchieveType.SkillAmt, SkillAmt_);
  31. }
  32. }
  33. public static double SignAmt
  34. {
  35. get { return SignAmt_; }
  36. set
  37. {
  38. SignAmt_ = value;
  39. ManaAchieve.UpdateStatus(AchieveType.SignAmt, SignAmt_);
  40. }
  41. }
  42. public static double CloseAmt
  43. {
  44. get { return CloseAmt_; }
  45. set
  46. {
  47. CloseAmt_ = value;
  48. ManaAchieve.UpdateStatus(AchieveType.CloseAmt, CloseAmt_);
  49. }
  50. }
  51. public static double ShareAmt
  52. {
  53. get { return ShareAmt_; }
  54. set
  55. {
  56. ShareAmt_ = value;
  57. ManaAchieve.UpdateStatus(AchieveType.ShareAmt, ShareAmt_);
  58. }
  59. }
  60. public static double MiniGameAmt
  61. {
  62. get { return MiniGameAmt_; }
  63. set
  64. {
  65. MiniGameAmt_ = value;
  66. ManaAchieve.UpdateStatus(AchieveType.MiniGameAmt, MiniGameAmt_);
  67. }
  68. }
  69. public static double ElfLevel
  70. {
  71. get { return ElfLevel_; }
  72. set
  73. {
  74. ElfLevel_ = value;
  75. ManaAchieve.UpdateStatus(AchieveType.ElfLevel, ElfLevel_);
  76. }
  77. }
  78. public static double TotalCoin
  79. {
  80. get { return TotalCoin_; }
  81. set
  82. {
  83. TotalCoin_ = value;
  84. ManaAchieve.UpdateStatus(AchieveType.TotalCoin, TotalCoin_);
  85. }
  86. }
  87. public static double FlowerCoin
  88. {
  89. get { return FlowerCoin_; }
  90. set
  91. {
  92. FlowerCoin_ = value;
  93. ManaAchieve.UpdateStatus(AchieveType.FlowerCoin, FlowerCoin_);
  94. }
  95. }
  96. public static double TotalPerson
  97. {
  98. get { return TotalPerson_; }
  99. set
  100. {
  101. TotalPerson_ = value;
  102. ManaAchieve.UpdateStatus(AchieveType.TotalPerson, TotalPerson_);
  103. }
  104. }
  105. public static double CostDiamond
  106. {
  107. get { return CostDiamond_; }
  108. set
  109. {
  110. CostDiamond_ = value;
  111. ManaAchieve.UpdateStatus(AchieveType.CostDiamond, CostDiamond_);
  112. }
  113. }
  114. public static double CreateRoomAmt
  115. {
  116. get { return CreateRoomAmt_; }
  117. set
  118. {
  119. CreateRoomAmt_ = value;
  120. ManaAchieve.UpdateStatus(AchieveType.CreateRoomAmt, CreateRoomAmt_);
  121. }
  122. }
  123. public static double CreateChestAmt
  124. {
  125. get { return CreateChestAmt_; }
  126. set
  127. {
  128. CreateChestAmt_ = value;
  129. ManaAchieve.UpdateStatus(AchieveType.CreateChestAmt, CreateChestAmt_);
  130. }
  131. }
  132. public static double CreateLuckyChestAmt
  133. {
  134. get { return CreateLuckyChestAmt_; }
  135. set
  136. {
  137. CreateLuckyChestAmt_ = value;
  138. ManaAchieve.UpdateStatus(AchieveType.CreateLuckyChestAmt, CreateLuckyChestAmt_);
  139. }
  140. }
  141. public static double CreateGuessColorChestAmt
  142. {
  143. get { return CreateGuessColorChestAmt_; }
  144. set
  145. {
  146. CreateGuessColorChestAmt_ = value;
  147. ManaAchieve.UpdateStatus(AchieveType.CreateGuessColorChestAmt, CreateGuessColorChestAmt_);
  148. }
  149. }
  150. public static double CreateGuessNumberChestAmt
  151. {
  152. get { return CreateGuessNumberChestAmt_; }
  153. set
  154. {
  155. CreateGuessNumberChestAmt_ = value;
  156. ManaAchieve.UpdateStatus(AchieveType.CreateGuessNumberChestAmt, CreateGuessNumberChestAmt_);
  157. }
  158. }
  159. public static double GetChestAwardAmt
  160. {
  161. get { return GetChestAwardAmt_; }
  162. set
  163. {
  164. GetChestAwardAmt_ = value;
  165. ManaAchieve.UpdateStatus(AchieveType.GetChestAwardAmt, GetChestAwardAmt_);
  166. }
  167. }
  168. private static double AdAmt_;
  169. private static double SkillAmt_;
  170. private static double SignAmt_;
  171. private static double CloseAmt_;
  172. private static double ShareAmt_;
  173. private static double MiniGameAmt_;
  174. private static double ElfLevel_;
  175. private static double TotalCoin_;
  176. private static double FlowerCoin_;
  177. private static double TotalPerson_;
  178. private static double CostDiamond_;
  179. private static double CreateRoomAmt_;
  180. private static double CreateChestAmt_;
  181. private static double CreateLuckyChestAmt_;
  182. private static double CreateGuessColorChestAmt_;
  183. private static double CreateGuessNumberChestAmt_;
  184. private static double GetChestAwardAmt_;
  185. #endregion
  186. public static Action OnLevelChange;
  187. public static int Level
  188. {
  189. get { return Level_; }
  190. set
  191. {
  192. Level_ = value;
  193. if (!Complete)
  194. {
  195. return;
  196. }
  197. ManaVisit.UpdateCost();
  198. if (OnLevelChange != null)
  199. {
  200. OnLevelChange.Invoke();
  201. }
  202. ManaAchieve.UpdateStatus(AchieveType.GardenLevel, Level_);
  203. for (int i = 0; i < SkillList.Count; i++)
  204. {
  205. SkillList[i].UpdateStatus();
  206. }
  207. foreach (var kv in ManaPlayer.CloseUnitDic)
  208. {
  209. kv.Value.OnLevelChange();
  210. }
  211. if (Level_ >= 18) //小游戏B
  212. {
  213. if (ManaTutorial.TutorialB_)
  214. {
  215. ManaTutorial.TutorialB = true;
  216. }
  217. }
  218. if (Level < 13)
  219. {
  220. ManaReso.Get<Image>("C_DressRoom").material = Lib.GrayMat;
  221. }
  222. else
  223. {
  224. ManaReso.Get<Image>("C_DressRoom").material = null;
  225. }
  226. if (ManaGarden.MyFlower >= 2 && Level_ >= 22) //小游戏C
  227. {
  228. if (ManaTutorial.TutorialE_)
  229. {
  230. ManaTutorial.EnterE1();
  231. }
  232. }
  233. if (Level_ >= 8)
  234. {
  235. if (ManaTutorial.TutorialC_)
  236. {
  237. ManaTutorial.EnterC1();
  238. return;
  239. }
  240. else
  241. {
  242. ManaReso.SetActive("C_Visit", true);
  243. }
  244. }
  245. if (Level_ >= 13)
  246. {
  247. if (ManaTutorial.TutorialD_)
  248. {
  249. ManaTutorial.EnterD1();
  250. return;
  251. }
  252. }
  253. if (Level_ >= 28)
  254. {
  255. if (ManaTutorial.TutorialPlazaRoom_)
  256. {
  257. ManaTutorial.EnterPlazaRoom();
  258. return;
  259. }
  260. else
  261. {
  262. ManaReso.SetActive("C_EnterPlazaRoom", true);
  263. }
  264. }
  265. }
  266. }
  267. public static float Person
  268. {
  269. get { return Person_; }
  270. set
  271. {
  272. Person_ = value;
  273. ManaReso.SetText("F_PersonLab", (60*(Person_ * (1 + SkillPersonBuff_) + SkillPerson_)).ToString("0"));
  274. }
  275. }
  276. public static float SkillPerson
  277. {
  278. get { return SkillPerson_; }
  279. set
  280. {
  281. SkillPerson_ = value;
  282. TweenOutline tween = ManaReso.Get("F_PersonLab").GetTweenOutline();
  283. if (SkillPerson_.Equal(0))
  284. {
  285. tween.Pause();
  286. tween.Target.enabled = false;
  287. }
  288. else
  289. {
  290. if (tween.InPause)
  291. {
  292. tween.Resume();
  293. tween.Target.enabled = true;
  294. }
  295. else
  296. {
  297. tween.StartForward();
  298. }
  299. }
  300. ManaReso.SetText("F_PersonLab", (60*(Person_ * (1 + SkillPersonBuff_) + SkillPerson_)).ToString("0"));
  301. }
  302. }
  303. public static float CoinPerson
  304. {
  305. get { return CoinPerson_; }
  306. set
  307. {
  308. CoinPerson_ = value;
  309. ManaReso.SetText("F_CoinPersonLab", (CoinPerson_ + SkillCoinPerson_).ToString("0"));
  310. }
  311. }
  312. public static float SkillPersonBuff
  313. {
  314. get { return SkillPersonBuff_; }
  315. set
  316. {
  317. SkillPersonBuff_ = value;
  318. ManaReso.SetText("F_PersonLab", (60 * (Person_ * (1 + SkillPersonBuff_) + SkillPerson_)).ToString("0"));
  319. }
  320. }
  321. public static float SkillCoinPerson
  322. {
  323. get { return SkillCoinPerson_; }
  324. set
  325. {
  326. SkillCoinPerson_ = value;
  327. TweenOutline tween = ManaReso.Get("F_CoinPersonLab").GetTweenOutline();
  328. if (SkillCoinPerson_.Equal(0))
  329. {
  330. tween.Pause();
  331. tween.Target.enabled = false;
  332. }
  333. else
  334. {
  335. if (tween.InPause)
  336. {
  337. tween.Resume();
  338. tween.Target.enabled = true;
  339. }
  340. else
  341. {
  342. tween.StartForward();
  343. }
  344. }
  345. ManaReso.SetText("F_CoinPersonLab", (CoinPerson_ + SkillCoinPerson_).ToString("0"));
  346. }
  347. }
  348. private static int Level_;
  349. private static bool Pause_;
  350. private static float Person_;
  351. private static float CoinPerson_;
  352. public static double Coin
  353. {
  354. get { return Coin_; }
  355. set
  356. {
  357. Coin_ = value;
  358. ManaReso.SetText("F_CoinLab", Auxiliary.ShrinkNumberStr(Coin_));
  359. ManaReso.SetText("C_CoinLab", Auxiliary.ShrinkNumberStr(Coin_));
  360. ManaReso.SetText("P_CoinLab", Auxiliary.ShrinkNumberStr(Coin_));
  361. ManaAchieve.UpdateStatus(AchieveType.CurrentCoin, Coin_);
  362. }
  363. }
  364. public static double Diamond
  365. {
  366. get { return Diamond_; }
  367. set
  368. {
  369. Diamond_ = value;
  370. ManaReso.SetText("F_DiamondLab", Auxiliary.ShrinkNumberStr(Diamond_));
  371. ManaReso.SetText("P_DiamondLab", Auxiliary.ShrinkNumberStr(Diamond_));
  372. }
  373. }
  374. public static double Coin_;
  375. public static double Diamond_;
  376. public static bool MiniLock;
  377. public static bool SaveLock;
  378. public static bool LoginLock;
  379. public static bool OfflineLock;
  380. public static bool ReactiveLock;
  381. public static bool DownloadLock;
  382. public static bool SceneSwitchLock;
  383. public static bool Complete;
  384. public static bool FirstFrame = true;
  385. public static bool Background;
  386. public static float Elapse;
  387. public static float CircleTime = 10;
  388. public static float OpTimer;
  389. public static float MiniTimer;
  390. public static float SaveTimer;
  391. public static float LoginTimer;
  392. public static float CircleTimer;
  393. public static float NewPerson;
  394. public static float NewCoinPerson;
  395. public static string OfflineFml;
  396. public static double MaxCoin;
  397. public static double MaxTime;
  398. public static float SkillPlus;
  399. public static float SkillPerson_;
  400. public static float SkillPersonBuff_;
  401. public static float SkillCoinPerson_;
  402. public static DateTime QuitTime;
  403. public static ManaCenter Instance;
  404. public static List<Skill> UseList = new List<Skill>();
  405. public static List<Skill> CoolList = new List<Skill>();
  406. public static List<Skill> TempCoolList = new List<Skill>();
  407. public static List<List<Skill>> TempUseList = new List<List<Skill>>();
  408. public static List<SkillRoot> SkillList = new List<SkillRoot>();
  409. public static Dictionary<string, SkillRoot> SkillDic = new Dictionary<string, SkillRoot>();
  410. #endregion
  411. private void Update()
  412. {
  413. LoginThread();
  414. if (ManaTutorial.TutorialA)
  415. {
  416. return;
  417. }
  418. OpThread();
  419. SkillThread();
  420. MiniThread();
  421. SaveThread();
  422. CircleThread();
  423. }
  424. public static void AddCoin(double amt, StaticsManager.ItemID itemId, StaticsManager.ConsumeModule consumeModule)
  425. {
  426. Coin += amt;
  427. if (amt > 0)
  428. {
  429. TotalCoin += amt;
  430. StaticsManager.GetInstance().RewardItem(itemId, StaticsManager.ItemType.金币, amt.ToString("0"), consumeModule);
  431. }
  432. }
  433. public static void AddDiamond(double amt, StaticsManager.ItemID itemId, StaticsManager.ConsumeModule consumeModule)
  434. {
  435. Diamond += amt;
  436. if (amt > 0)
  437. {
  438. StaticsManager.GetInstance().RewardItem(itemId, StaticsManager.ItemType.钻石, amt.ToString("0"), consumeModule);
  439. }
  440. }
  441. private void OpThread()
  442. {
  443. if (Auxiliary.AnyKeyUp)
  444. {
  445. OpTimer = 0;
  446. ManaReso.Get("C_Group").TweenForCG();
  447. }
  448. else
  449. {
  450. OpTimer += Time.deltaTime;
  451. if (OpTimer >= 60)
  452. {
  453. OpTimer = 0;
  454. ManaReso.Get("C_Group").TweenBacCG();
  455. }
  456. }
  457. }
  458. private void SkillThread()
  459. {
  460. for (int i = 0; i < UseList.Count; i++)
  461. {
  462. if (UseList[i].DoUse())
  463. {
  464. UseList.RemoveAt(i--);
  465. }
  466. }
  467. for (int i = 0; i < CoolList.Count; i++)
  468. {
  469. if (CoolList[i].DoCool())
  470. {
  471. CoolList.RemoveAt(i--);
  472. }
  473. }
  474. }
  475. private void MiniThread()
  476. {
  477. if (!MiniLock)
  478. {
  479. MiniTimer -= Time.deltaTime;
  480. ManaReso.SetText("C_MiniGameLab", Mathf.CeilToInt(MiniTimer).ToString());
  481. if (MiniTimer < 0)
  482. {
  483. MiniLock = true;
  484. ManaReso.Get("C_MiniGame").TweenBacRect();
  485. ManaReso.SetText("C_MiniGameLab", "");
  486. StaticsManager.GetInstance().RewardItem(StaticsManager.ItemID.获得小游戏, StaticsManager.ItemType.小游戏, "1", StaticsManager.ConsumeModule.None);
  487. }
  488. }
  489. }
  490. private void SaveThread()
  491. {
  492. if (DownloadLock)
  493. {
  494. return;
  495. }
  496. SaveTimer += Time.deltaTime;
  497. if (SaveTimer >= 60)
  498. {
  499. SaveTimer = 0;
  500. ManaServer.Save();
  501. }
  502. }
  503. private void LoginThread()
  504. {
  505. LoginTimer += Time.deltaTime;
  506. if (LoginTimer >= 10)
  507. {
  508. LoginTimer = 0;
  509. ManaServer.Login();
  510. StaticsManager.GetInstance().Online();
  511. }
  512. }
  513. private void CircleThread()
  514. {
  515. CircleTimer -= Time.deltaTime;
  516. if (CircleTimer < 0)
  517. {
  518. CircleTimer = CircleTime;
  519. NewPerson = Person * (1 + SkillPersonBuff) + SkillPerson;
  520. NewCoinPerson = CoinPerson + SkillCoinPerson;
  521. TotalPerson += NewPerson * CircleTime;
  522. float temp = (NewPerson * NewCoinPerson * CircleTime) * (1 + SkillPlus);
  523. AddCoin(temp, StaticsManager.ItemID.获得金币, StaticsManager.ConsumeModule.Income);
  524. ManaReso.Get("C_IncomeLab").TweenReForGra();
  525. ManaReso.Get("C_IncomeLab").TweenReForVec();
  526. ManaReso.SetText("C_IncomeLab", "+" + Auxiliary.ShrinkNumberStr(temp, 0));
  527. //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));
  528. }
  529. }
  530. public override void Reactive()
  531. {
  532. foreach (var kv in SkillDic)
  533. {
  534. kv.Value.Reactive();
  535. }
  536. RegistSkill(false);
  537. RegistIncome();
  538. ManaSign.ShowOfflinePanel();
  539. }
  540. public override void Instantiate()
  541. {
  542. #region 生成技能条
  543. #region 读技能配置
  544. List<XmlAttributeCollection> attributeList = ManaData.GetSkillConfig();
  545. for (int i = 0; i < attributeList.Count; i++)
  546. {
  547. SkillRoot skillRoot;
  548. #region MyRegion
  549. if (attributeList[i].Count == 18)
  550. {
  551. skillRoot = new Pack(attributeList[i]);
  552. }
  553. else if (attributeList[i].Count == 24)
  554. {
  555. skillRoot = new Ability(attributeList[i]);
  556. }
  557. else if (attributeList[i].Count == 34)
  558. {
  559. if (string.IsNullOrEmpty(attributeList[i][4].Value))
  560. {
  561. skillRoot = new Skill(attributeList[i]);
  562. }
  563. else
  564. {
  565. skillRoot = new BigSkill(attributeList[i]);
  566. }
  567. }
  568. else
  569. {
  570. throw new Exception(attributeList[i].Count.ToString());
  571. }
  572. #endregion
  573. SkillDic.Add(skillRoot.ID, skillRoot);
  574. SkillList.Add(skillRoot);
  575. }
  576. SkillList.Sort(SkillRoot.Sort);
  577. #endregion
  578. for (int i = 0; i < SkillList.Count; i++)
  579. {
  580. if (SkillList[i].SkillTab != SkillTab.Null)
  581. {
  582. ManaReso.GetSkillItem(SkillList[i]);
  583. }
  584. }
  585. #endregion
  586. }
  587. public override void RegistValueA()
  588. {
  589. ManaReso.Get<Graphic>("F_Elf").material = ManaReso.Load<Material>("GrayMat", Folder.UI);
  590. ManaReso.Get<Graphic>("F_Store").material = ManaReso.Load<Material>("GrayMat", Folder.UI);
  591. ManaReso.Get<Graphic>("F_Magic").material = ManaReso.Load<Material>("GrayMat", Folder.UI);
  592. ManaReso.Get<Graphic>("F_ElfLab").material = ManaReso.Load<Material>("GrayMat", Folder.UI);
  593. ManaReso.Get<Graphic>("F_StoreLab").material = ManaReso.Load<Material>("GrayMat", Folder.UI);
  594. ManaReso.Get<Graphic>("F_MagicLab").material = ManaReso.Load<Material>("GrayMat", Folder.UI);
  595. ManaReso.Get<Button>("F_Elf").interactable = false;
  596. ManaReso.Get<Button>("F_Store").interactable = false;
  597. ManaReso.Get<Button>("F_Magic").interactable = false;
  598. List<XmlAttributeCollection> attributeList = ManaData.GetSkillList();
  599. for (int i = 0; i < attributeList.Count; i++)
  600. {
  601. SkillRoot skillRoot = SkillDic[attributeList[i][0].Value];
  602. if (!(skillRoot is Skill))
  603. {
  604. skillRoot.RegistReference();
  605. skillRoot.RegistValue(true, Elapse, TempUseList, attributeList[i]);
  606. }
  607. }
  608. }
  609. public override void RegistValueB()
  610. {
  611. Instance = this;
  612. Coin = ManaData.GetPlayerDouble("Coin");
  613. Diamond = ManaData.GetPlayerDouble("Diamond");
  614. MiniTimer = ManaData.GetPlayerFloat("MiniTimer");
  615. CircleTimer = ManaData.GetPlayerFloat("CircleTimer");
  616. if (MiniTimer > 0)
  617. {
  618. ManaReso.Get("C_MiniGame").TweenForRect();
  619. }
  620. else
  621. {
  622. MiniLock = true;
  623. }
  624. ManaServer.ID = ManaData.GetPlayerString("ID");
  625. ManaServer.SerialNumber = ManaData.GetPlayerString("SerialNumber");
  626. List<string> offlineList = ManaData.GetOfflineConfig();
  627. MaxCoin = Auxiliary.LongParse(offlineList[1], 999999999999999999);
  628. MaxTime = Auxiliary.LongParse(offlineList[2], 999999999999999999);
  629. OfflineFml = offlineList[0];
  630. List<double> dataList = ManaData.GetAchieveData();
  631. AdAmt = dataList[0];
  632. ElfLevel = dataList[4];
  633. SkillAmt = dataList[1];
  634. SignAmt = dataList[2];
  635. ShareAmt = dataList[3];
  636. FlowerCoin = dataList[6];
  637. TotalPerson = dataList[7];
  638. CostDiamond = dataList[8];
  639. MiniGameAmt = dataList[5];
  640. CreateRoomAmt = dataList[9];
  641. CreateChestAmt = dataList[10];
  642. CreateLuckyChestAmt = dataList[11];
  643. CreateGuessColorChestAmt = dataList[12];
  644. CreateGuessNumberChestAmt = dataList[13];
  645. GetChestAwardAmt = dataList[14];
  646. }
  647. public static void RegistSkill(bool firstRegist)
  648. {
  649. OfflineLock = false;
  650. ManaReso.SetActive("Ba_Lab2", false);
  651. if (ManaServer.Connect && ManaData.GetPlayerBool("QuitFlag"))
  652. {
  653. QuitTime = DateTime.Parse(ManaData.GetPlayerString("QuitTime"));
  654. Elapse = (float)ManaServer.Time.Subtract(QuitTime).TotalSeconds;
  655. MiniTimer -= Elapse;
  656. //ManaDebug.Log(string.Format("离线时间<color=red>{0}</color>", Elapse));
  657. if (Elapse <= 120)
  658. {
  659. Elapse = 0;
  660. }
  661. else
  662. {
  663. OfflineLock = true;
  664. }
  665. if (Elapse > MaxTime)
  666. {
  667. Elapse = (long)MaxTime;
  668. ManaReso.SetText("Ba_Lab2", Language.GetStr("UI", "Ba_Lab2"));
  669. ManaReso.SetActive("Ba_Lab2", true);
  670. }
  671. }
  672. TempUseList = new List<List<Skill>>();
  673. TempCoolList = new List<Skill>();
  674. if (Elapse > CircleTimer)
  675. {
  676. int circle = 1 + Mathf.FloorToInt((Elapse - CircleTimer) / CircleTime);
  677. for (int i = 0; i < circle; i++)
  678. {
  679. TempUseList.Add(new List<Skill>());
  680. }
  681. //ManaDebug.Log(string.Format("离线周期<color=red>{0}</color>", circle));
  682. }
  683. List<XmlAttributeCollection> attributeList = ManaData.GetSkillList();
  684. for (int i = 0; i < attributeList.Count; i++)
  685. {
  686. SkillRoot skillRoot = SkillDic[attributeList[i][0].Value];
  687. if (skillRoot is Skill)
  688. {
  689. skillRoot.RegistReference();
  690. skillRoot.RegistValue(firstRegist, Elapse, TempUseList, attributeList[i]);
  691. }
  692. }
  693. }
  694. public static void RegistIncome()
  695. {
  696. double coin = 0;
  697. for (int i = 0; i < TempUseList.Count; i++)
  698. {
  699. for (int j = 0; j < TempCoolList.Count; j++)
  700. {
  701. TempCoolList[j].CoolTimer -= CircleTime;
  702. }
  703. for (int j = 0; j < TempUseList[i].Count; j++)
  704. {
  705. TempUseList[i][j].AnnulA();
  706. TempCoolList.Add(TempUseList[i][j]);
  707. }
  708. NewPerson = Person*(1 + SkillPersonBuff_) + SkillPerson;
  709. NewCoinPerson = CoinPerson + SkillCoinPerson;
  710. TotalPerson += NewPerson*CircleTime;
  711. coin += (NewPerson*NewCoinPerson*CircleTime)*(1 + SkillPlus);
  712. }
  713. CircleTimer = (Elapse - CircleTimer)%CircleTime;
  714. for (int j = 0; j < TempCoolList.Count; j++)
  715. {
  716. TempCoolList[j].CoolTimer -= CircleTime - CircleTimer;
  717. }
  718. coin = (long) Auxiliary.FmlParse(OfflineFml, "c", coin.ToString());
  719. if (coin > MaxCoin)
  720. {
  721. coin = MaxCoin;
  722. ManaReso.SetText("Ba_Lab2", Language.GetStr("UI", "Ba_Lab2"));
  723. ManaReso.SetActive("Ba_Lab2", true);
  724. }
  725. AddCoin(coin, StaticsManager.ItemID.获得金币, StaticsManager.ConsumeModule.Income);
  726. ManaReso.SetText("Ba_IconLab", Auxiliary.ShrinkNumberStr(coin));
  727. }
  728. public static void SwitchLanguage()
  729. {
  730. Coin = Coin;
  731. AddDiamond(0, StaticsManager.ItemID.None, StaticsManager.ConsumeModule.None);
  732. }
  733. public static void Pay(string id, double amt, Current current, UnityAction succeedCallback, StaticsManager.ItemID itemId, StaticsManager.ConsumeModule consumeModule, bool navigate = true, bool useBubbleTweenNavigate = true, UnityAction navigateCall = null)
  734. {
  735. if (ManaTutorial.PayExempt)
  736. {
  737. succeedCallback.Invoke();
  738. return;
  739. }
  740. amt = Auxiliary.ShrinkNumber(amt);
  741. if (current == Current.Free)
  742. {
  743. succeedCallback.Invoke();
  744. }
  745. else if (current == Current.AD)
  746. {
  747. ManaIAP.PlayAD(succeedCallback);
  748. }
  749. else if (current == Current.Cash)
  750. {
  751. ManaIAP.Purchase(id);
  752. }
  753. else if (current == Current.Coin)
  754. {
  755. #region MyRegion
  756. if (Coin >= amt)
  757. {
  758. Coin -= amt;
  759. succeedCallback.Invoke();
  760. StaticsManager.GetInstance().UseItem(itemId, StaticsManager.ItemType.金币, "1", consumeModule);
  761. }
  762. else
  763. {
  764. ManaReso.Get("Fe_Info").TweenBacCG();
  765. if (navigate)
  766. {
  767. Bubble.Show
  768. (
  769. Language.GetStr("Common", "ShortCoin"),
  770. Language.GetStr("Common", "NavigateCoin"),
  771. null,
  772. ManaReso.LoadSprite("金币", Folder.UI),
  773. () =>
  774. {
  775. navigateCall.SafeInvoke();
  776. if (useBubbleTweenNavigate)
  777. {
  778. TweenRoot tween = ManaReso.Get("K_Bubble0").GetTweenScale();
  779. tween.AddEventOnetime
  780. (
  781. EventType.BackwardFinish,
  782. () =>
  783. {
  784. ManaUI.NavigateBuyCoin();
  785. }
  786. );
  787. }
  788. else
  789. {
  790. TweenRoot tween = ManaReso.Get("F_Manage0").GetTweenVec();
  791. tween.AddEventOnetime
  792. (
  793. EventType.ForwardFinish,
  794. () =>
  795. {
  796. ManaUI.NavigateBuyCoin();
  797. }
  798. );
  799. }
  800. }
  801. );
  802. }
  803. else
  804. {
  805. Bubble.Show
  806. (
  807. Language.GetStr("Common", "ShortCoin"),
  808. null,
  809. null,
  810. ManaReso.LoadSprite("金币", Folder.UI)
  811. );
  812. }
  813. }
  814. #endregion
  815. }
  816. else if (current == Current.Diamond)
  817. {
  818. #region MyRegion
  819. if (Diamond >= amt)
  820. {
  821. Diamond -= amt;
  822. CostDiamond += amt;
  823. succeedCallback.Invoke();
  824. StaticsManager.GetInstance().PurchaseItem(itemId, StaticsManager.ItemType.钻石, "1", amt.ToString("0"), consumeModule);
  825. }
  826. else
  827. {
  828. ManaReso.Get("Fe_Info").TweenBacCG();
  829. if (navigate)
  830. {
  831. Bubble.Show
  832. (
  833. Language.GetStr("Common", "ShortDiamond"),
  834. Language.GetStr("Common", "NavigateDiamond"),
  835. null,
  836. ManaReso.LoadSprite("钻石", Folder.UI),
  837. () =>
  838. {
  839. navigateCall.SafeInvoke();
  840. if (useBubbleTweenNavigate)
  841. {
  842. TweenRoot tween = ManaReso.Get("K_Bubble0").GetTweenScale();
  843. tween.AddEventOnetime
  844. (
  845. EventType.BackwardFinish,
  846. () =>
  847. {
  848. ManaUI.NavigateBuyDiamond();
  849. }
  850. );
  851. }
  852. else
  853. {
  854. TweenRoot tween = ManaReso.Get("F_Manage0").GetTweenVec();
  855. tween.AddEventOnetime
  856. (
  857. EventType.ForwardFinish,
  858. () =>
  859. {
  860. ManaUI.NavigateBuyDiamond();
  861. }
  862. );
  863. }
  864. }
  865. );
  866. }
  867. else
  868. {
  869. Bubble.Show
  870. (
  871. Language.GetStr("Common", "ShortDiamond"),
  872. null,
  873. null,
  874. ManaReso.LoadSprite("钻石", Folder.UI)
  875. );
  876. }
  877. }
  878. #endregion
  879. }
  880. else
  881. {
  882. throw new Exception(current.ToString());
  883. }
  884. }
  885. public static void LoginCallbackInitial(JsonData jsonData)
  886. {
  887. if (!Initializer.Complete || !ManaServer.Complete || Complete)
  888. {
  889. return;
  890. }
  891. ManaServer.PackTypeRequest();
  892. if (ManaServer.Connect)
  893. {
  894. if (ManaData.GetPlayerString("ID") == "Default")
  895. {
  896. ManaServer.ID = ManaServer.JsonData["o"].ToString();
  897. ManaReso.SetText("L_UserLab", ManaServer.ID);
  898. }
  899. if (ManaData.GetPlayerString("SerialNumber") == "Default")
  900. {
  901. ManaServer.SerialNumber = ManaServer.JsonData["i"].ToString();
  902. }
  903. }
  904. //ManaSocial.UpdatePage(true);
  905. RegistSkill(true);
  906. RegistIncome();
  907. ManaSign.ShowOfflinePanel();
  908. Analytics.SetUserId(ManaServer.ID);
  909. Complete = true;
  910. Level = Level;
  911. }
  912. public static void LoginCallbackReactive(JsonData jsonData)
  913. {
  914. LoginLock = false;
  915. for (int i = 0; i < Initializer.RegistList.Count; i++)
  916. {
  917. Initializer.RegistList[i].Reactive();
  918. }
  919. }
  920. public static void Download(string id)
  921. {
  922. ManaReso.SetText("La_Lab", "连接中");
  923. ManaReso.SetActive("La_Lab", true);
  924. ManaReso.SetActive("La_Mask", true);
  925. ManaServer.DownloadByID(id, DownloadCallback);
  926. }
  927. public static void DownloadCallback(JsonData jsonData)
  928. {
  929. if (jsonData.Inst_Object.Keys.Contains("l"))
  930. {
  931. ManaReso.Get("La_Info").TweenBacCG();
  932. ManaReso.SetText("La_Lab", Language.GetStr("UI", "La_Lab0"));
  933. ManaData.PlayerDoc.LoadXml(jsonData["l"].ToString());
  934. ManaData.PlayerNode = ManaData.PlayerDoc.SelectSingleNode("PlayerConfig");
  935. ManaReso.SetText("L_UserLab", ManaData.GetPlayerString("ID"));
  936. ManaServer.ID = ManaData.GetPlayerString("ID");
  937. ManaServer.SerialNumber = ManaData.GetPlayerString("SerialNumber");
  938. Bubble.Show(null, Language.GetStr("UI", "La_Lab0"), null, null, () => { Application.Quit(); }, null, false);
  939. SaveLock = true;
  940. DownloadLock = true;
  941. ManaData.SaveXml();
  942. PlayerPrefs.SetString(Lib.ConfigPrefs, "");
  943. }
  944. else
  945. {
  946. ManaReso.SetText("La_Lab", Language.GetStr("UI", "La_Lab1"));
  947. ManaReso.SetActive("La_Mask", false);
  948. }
  949. }
  950. public void OnApplicationQuit()
  951. {
  952. if (!SaveLock)
  953. {
  954. ManaVisit.DataReverse();
  955. ManaData.SavePlayerConfig();
  956. ManaData.SaveXml();
  957. }
  958. }
  959. public void OnApplicationPause(bool pause)
  960. {
  961. if (pause)
  962. {
  963. Background = true;
  964. if (DownloadLock)
  965. {
  966. return;
  967. }
  968. ManaVisit.DataReverse();
  969. ManaData.SavePlayerConfig();
  970. ManaData.SaveXml();
  971. }
  972. else
  973. {
  974. StaticsManager.GetInstance().StartSession();
  975. Background = false;
  976. if (FirstFrame)
  977. {
  978. FirstFrame = false;
  979. }
  980. else
  981. {
  982. if (ManaTutorial.TutorialA)
  983. {
  984. return;
  985. }
  986. if (!Initializer.Complete)
  987. {
  988. return;
  989. }
  990. if (DownloadLock)
  991. {
  992. return;
  993. }
  994. ManaVisit.DataRecover();
  995. if (LoginLock)
  996. {
  997. return;
  998. }
  999. if (ReactiveLock)
  1000. {
  1001. ReactiveLock = false;
  1002. return;
  1003. }
  1004. LoginLock = true;
  1005. ManaServer.Login(LoginCallbackReactive);
  1006. ManaServer.MailRequest();
  1007. }
  1008. }
  1009. }
  1010. }