ManaData.cs 28 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090
  1. using LitJson;
  2. using UnityEngine;
  3. using UnityEngine.UI;
  4. using UnityEngine.Events;
  5. using UnityEngine.EventSystems;
  6. using System;
  7. using System.Xml;
  8. using System.Collections;
  9. using System.Collections.Generic;
  10. public class ManaData : Regist
  11. {
  12. #region 变量
  13. #region 成就
  14. public static double TotalPerson
  15. {
  16. get { return TotalPerson_; }
  17. set
  18. {
  19. TotalPerson_ = value;
  20. ManaAchieve.UpdateStatus(AchieveType.TotalPerson, TotalPerson_);
  21. }
  22. }
  23. public static double ElfLevel
  24. {
  25. get { return ElfLevel_; }
  26. set
  27. {
  28. ElfLevel_ = value;
  29. ManaAchieve.UpdateStatus(AchieveType.ElfLevel, ElfLevel_);
  30. }
  31. }
  32. public static double AdAmt
  33. {
  34. get { return AdAmt_; }
  35. set
  36. {
  37. AdAmt_ = value;
  38. ManaAchieve.UpdateStatus(AchieveType.AdAmt, AdAmt_);
  39. }
  40. }
  41. public static double SkillAmt
  42. {
  43. get { return SkillAmt_; }
  44. set
  45. {
  46. SkillAmt_ = value;
  47. ManaAchieve.UpdateStatus(AchieveType.SkillAmt, SkillAmt_);
  48. }
  49. }
  50. public static double SignAmt
  51. {
  52. get { return SignAmt_; }
  53. set
  54. {
  55. SignAmt_ = value;
  56. ManaAchieve.UpdateStatus(AchieveType.SignAmt, SignAmt_);
  57. }
  58. }
  59. public static double ShareAmt
  60. {
  61. get { return ShareAmt_; }
  62. set
  63. {
  64. ShareAmt_ = value;
  65. ManaAchieve.UpdateStatus(AchieveType.ShareAmt, ShareAmt_);
  66. }
  67. }
  68. public static double TotalCoin
  69. {
  70. get { return TotalCoin_; }
  71. set
  72. {
  73. TotalCoin_ = value;
  74. ManaAchieve.UpdateStatus(AchieveType.TotalCoin, TotalCoin_);
  75. }
  76. }
  77. public static double MiniGameAmt
  78. {
  79. get { return MiniGameAmt_; }
  80. set
  81. {
  82. MiniGameAmt_ = value;
  83. ManaAchieve.UpdateStatus(AchieveType.MiniGameAmt, MiniGameAmt_);
  84. }
  85. }
  86. public static double FlowerCoin
  87. {
  88. get { return FlowerCoin_; }
  89. set
  90. {
  91. FlowerCoin_ = value;
  92. ManaAchieve.UpdateStatus(AchieveType.FlowerCoin, FlowerCoin_);
  93. }
  94. }
  95. private static double TotalPerson_;
  96. private static double ElfLevel_;
  97. private static double AdAmt_;
  98. private static double SkillAmt_;
  99. private static double SignAmt_;
  100. private static double ShareAmt_;
  101. private static double MiniGameAmt_;
  102. private static double TotalCoin_;
  103. private static double FlowerCoin_;
  104. #endregion
  105. public static int Level
  106. {
  107. get { return Level_; }
  108. set
  109. {
  110. Level_ = value;
  111. ManaDebug.Log(string.Format("已升级 花园等级 : <color=red>{0}</color>", Level_));
  112. ManaAchieve.UpdateStatus(AchieveType.GardenLevel, Level_);
  113. for (int i = 0; i < SkillList.Count; i++)
  114. {
  115. SkillList[i].UpdateStatus();
  116. }
  117. if (TabBtnValid == false)
  118. {
  119. if (Level_ >= 1)
  120. {
  121. TabBtnValid = true;
  122. ManaReso.Get<Graphic>("F_Elf").material = null;
  123. ManaReso.Get<Graphic>("F_Store").material = null;
  124. ManaReso.Get<Graphic>("F_Magic").material = null;
  125. ManaReso.Get<Graphic>("F_ElfLab").material = null;
  126. ManaReso.Get<Graphic>("F_StoreLab").material = null;
  127. ManaReso.Get<Graphic>("F_MagicLab").material = null;
  128. ManaReso.Get<Button>("F_Elf").interactable = true;
  129. ManaReso.Get<Button>("F_Store").interactable = true;
  130. ManaReso.Get<Button>("F_Magic").interactable = true;
  131. }
  132. }
  133. if (Level_ >= 20)
  134. {
  135. if (ManaTutorial.TutorialC_)
  136. {
  137. ManaTutorial.PrepareStepC1();
  138. }
  139. else
  140. {
  141. ManaReso.SetActive("C_Visit", true);
  142. }
  143. }
  144. //if (Level_ >= 200)
  145. //{
  146. // if (ManaTutorial.TutorialB_)
  147. // {
  148. // ManaTutorial.TutorialB = true;
  149. // ManaTutorial.PrepareStepB1();
  150. // }
  151. //}
  152. }
  153. }
  154. public static bool Pause
  155. {
  156. get { return Pause_; }
  157. set
  158. {
  159. Pause_ = value;
  160. if (Pause_)
  161. {
  162. Time.timeScale = 0;
  163. ManaDebug.Log("<color=red>游戏暂停</color>");
  164. }
  165. else
  166. {
  167. Time.timeScale = 1;
  168. ManaDebug.Log("<color=red>游戏继续</color>");
  169. }
  170. }
  171. }
  172. public static float Person
  173. {
  174. get { return Person_; }
  175. set
  176. {
  177. Person_ = value;
  178. ManaReso.SetText("F_PersonLab", Mathf.FloorToInt(60*(Person_ + SkillPerson_)).ToString());
  179. }
  180. }
  181. public static float SkillPerson
  182. {
  183. get { return SkillPerson_; }
  184. set
  185. {
  186. SkillPerson_ = value;
  187. if (SkillPerson_.Equal(0))
  188. {
  189. ManaReso.Get<Outline>("F_PersonLab").enabled = false;
  190. }
  191. else
  192. {
  193. ManaReso.Get("F_PersonLab").TweenReForOutline();
  194. }
  195. ManaReso.SetText("F_PersonLab", Mathf.FloorToInt(60*(Person_ + SkillPerson_)).ToString());
  196. }
  197. }
  198. public static float CoinPerson
  199. {
  200. get { return CoinPerson_; }
  201. set
  202. {
  203. CoinPerson_ = value;
  204. ManaReso.SetText("F_CoinPersonLab", Mathf.FloorToInt(CoinPerson_ + SkillCoinPerson_).ToString());
  205. }
  206. }
  207. public static float SkillCoinPerson
  208. {
  209. get { return SkillCoinPerson_; }
  210. set
  211. {
  212. SkillCoinPerson_ = value;
  213. if (SkillCoinPerson_.Equal(0))
  214. {
  215. ManaReso.Get<Outline>("F_CoinPersonLab").enabled = false;
  216. }
  217. else
  218. {
  219. ManaReso.Get("F_CoinPersonLab").TweenReForOutline();
  220. }
  221. ManaReso.SetText("F_CoinPersonLab", Mathf.FloorToInt(CoinPerson_ + SkillCoinPerson_).ToString());
  222. }
  223. }
  224. public static double Coin
  225. {
  226. get { return Coin_; }
  227. set
  228. {
  229. if (value - Coin_ > 0)
  230. {
  231. TotalCoin += value - Coin_;
  232. }
  233. Coin_ = value;
  234. ManaReso.SetText("F_CoinLab", Auxiliary.ShrinkNumberStr(Coin_, 0));
  235. ManaReso.SetText("C_CoinLab", Auxiliary.ShrinkNumberStr(Coin_, 0));
  236. ManaAchieve.UpdateStatus(AchieveType.CurrentCoin, Coin_);
  237. }
  238. }
  239. public static double Diamond
  240. {
  241. get { return Diamond_; }
  242. set
  243. {
  244. Diamond_ = value;
  245. ManaReso.SetText("F_DiamondLab", Auxiliary.ShrinkNumberStr(Diamond_, 0));
  246. }
  247. }
  248. private static int Level_;
  249. private static bool Pause_;
  250. private static float Person_;
  251. private static float CoinPerson_;
  252. private static double Coin_;
  253. private static double Diamond_;
  254. public static int MainDepth;
  255. public static bool Reset;
  256. public static bool MiniValid;
  257. public static bool FirstFrame = true;
  258. public static bool OfflineValid;
  259. public static bool TabBtnValid;
  260. public static bool ReactiveRequest;
  261. public static bool InitiateComplete;
  262. public static float Elapse;
  263. public static float OpTimer;
  264. public static float MiniTimer;
  265. public static float SaveTimer;
  266. public static float LoginTimer;
  267. public static float CircleTime = 10;
  268. public static float CircleTimer;
  269. public static float NewPerson;
  270. public static float NewCoinPerson;
  271. public static string OfflineFml;
  272. public static double MaxCoin;
  273. public static double MaxTime;
  274. public static float SkillPlus;
  275. public static float SkillPerson_;
  276. public static float SkillPersonBuff;
  277. public static float SkillCoinPerson_;
  278. public static DateTime QuitTime;
  279. public static ManaData Instance;
  280. public static List<Skill> UseList = new List<Skill>();
  281. public static List<Skill> CoolList = new List<Skill>();
  282. public static List<Skill> FFCoolList = new List<Skill>();
  283. public static List<SkillRoot> SkillList = new List<SkillRoot>();
  284. public static List<List<Skill>> FFUseList = new List<List<Skill>>();
  285. public static Dictionary<string, SkillRoot> SkillDic = new Dictionary<string, SkillRoot>();
  286. #endregion
  287. private void Update()
  288. {
  289. if (ManaTutorial.TutorialA)
  290. {
  291. return;
  292. }
  293. OperateThread();
  294. }
  295. private void FixedUpdate()
  296. {
  297. if (ManaTutorial.TutorialA)
  298. {
  299. LoginThread();
  300. return;
  301. }
  302. SkillThread();
  303. MiniThread();
  304. MiniThread();
  305. SaveThread();
  306. LoginThread();
  307. IncomeThread();
  308. }
  309. private void SkillThread()
  310. {
  311. for (int i = 0; i < UseList.Count; i++)
  312. {
  313. if (UseList[i].DoUse())
  314. {
  315. UseList.RemoveAt(i--);
  316. }
  317. }
  318. for (int i = 0; i < CoolList.Count; i++)
  319. {
  320. if (CoolList[i].DoCool())
  321. {
  322. CoolList.RemoveAt(i--);
  323. }
  324. }
  325. }
  326. private void MiniThread()
  327. {
  328. if (Pause)
  329. {
  330. return;
  331. }
  332. if (MiniValid == false)
  333. {
  334. MiniTimer -= Time.deltaTime;
  335. if (MiniTimer < 0)
  336. {
  337. MiniValid = true;
  338. ManaReso.Get("C_MiniGame").TweenForCG();
  339. }
  340. }
  341. }
  342. private void SaveThread()
  343. {
  344. SaveTimer += Time.fixedDeltaTime;
  345. if (SaveTimer >= 60)
  346. {
  347. SaveTimer = 0;
  348. ManaServer.Save();
  349. }
  350. }
  351. private void LoginThread()
  352. {
  353. LoginTimer += Time.fixedDeltaTime;
  354. if (LoginTimer >= 10)
  355. {
  356. LoginTimer = 0;
  357. ManaServer.Login();
  358. }
  359. }
  360. private void IncomeThread()
  361. {
  362. CircleTimer -= Time.deltaTime;
  363. if (CircleTimer < 0)
  364. {
  365. CircleTimer = CircleTime;
  366. NewPerson = Person * (1 + SkillPersonBuff) + SkillPerson;
  367. NewCoinPerson = CoinPerson + SkillCoinPerson;
  368. TotalPerson += NewPerson * CircleTime;
  369. float temp = (NewPerson * NewCoinPerson * CircleTime) * (1 + SkillPlus);
  370. Coin += temp;
  371. ManaReso.Get("C_IncomeLab").TweenForGra();
  372. ManaReso.Get("C_IncomeLab").TweenForVec();
  373. ManaReso.SetText("C_IncomeLab", "+" + temp.ToString("0"));
  374. 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));
  375. }
  376. }
  377. private void OperateThread()
  378. {
  379. if (Pause)
  380. {
  381. return;
  382. }
  383. if (Auxiliary.AnyKeyUp)
  384. {
  385. OpTimer = 0;
  386. if (MainDepth == 0)
  387. {
  388. ManaReso.Get("C_Group").TweenConForCG();
  389. }
  390. }
  391. else
  392. {
  393. OpTimer += Time.deltaTime;
  394. if (OpTimer >= 60)
  395. {
  396. OpTimer = 0;
  397. if (MainDepth == -1)
  398. {
  399. ManaReso.Get("C_Group").TweenConBacCG();
  400. }
  401. }
  402. }
  403. }
  404. public static void Reload()
  405. {
  406. Reset = false;
  407. TabBtnValid = false;
  408. Person = 0;
  409. CoinPerson = 0;
  410. SkillPlus = 0;
  411. SkillPerson = 0;
  412. SkillPersonBuff = 0;
  413. SkillCoinPerson = 0;
  414. SaveTimer = 0;
  415. UseList = new List<Skill>();
  416. CoolList = new List<Skill>();
  417. Instance.RegistValueB();
  418. ManaTutorial.TutorialB_ = Data.GetPlayerBool("TutorialB");
  419. ManaTutorial.TutorialIndexB = Data.GetPlayerInt("TutorialIndexB");
  420. for (int i = 0; i < SkillList.Count; i++)
  421. {
  422. Ability ability = SkillList[i] as Ability;
  423. if (ability != null)
  424. {
  425. ability.ValidSlot = true;
  426. }
  427. }
  428. RegistSkill();
  429. RegistIncome();
  430. if (ManaServer.Connect)
  431. {
  432. if (!ManaTutorial.TutorialA && !ManaTutorial.TutorialB)
  433. {
  434. ManaReso.Get("B_SignIn").TweenConForCG();
  435. }
  436. }
  437. }
  438. public override void Reactive()
  439. {
  440. foreach (var kv in SkillDic)
  441. {
  442. kv.Value.Reactive();
  443. }
  444. RegistSkill();
  445. RegistIncome();
  446. if (OfflineValid)
  447. {
  448. if (!ManaTutorial.TutorialA && !ManaTutorial.TutorialB)
  449. {
  450. ManaReso.Get("C_Group").TweenConBacCG();
  451. ManaReso.Get("B_SignIn").TweenConForCG();
  452. ManaReso.Get("Ba_Notice").TweenConForCG();
  453. }
  454. }
  455. }
  456. public override void Instantiate()
  457. {
  458. #region 生成技能条
  459. #region 读技能配置
  460. List<XmlAttributeCollection> attributeList = Data.GetSkillConfig();
  461. for (int i = 0; i < attributeList.Count; i++)
  462. {
  463. SkillRoot skillRoot;
  464. #region MyRegion
  465. if (attributeList[i].Count == 17)
  466. {
  467. skillRoot = new Pack(attributeList[i]);
  468. }
  469. else if (attributeList[i].Count == 23)
  470. {
  471. skillRoot = new Ability(attributeList[i]);
  472. }
  473. else if (attributeList[i].Count == 33)
  474. {
  475. if (string.IsNullOrEmpty(attributeList[i][4].Value))
  476. {
  477. skillRoot = new Skill(attributeList[i]);
  478. }
  479. else
  480. {
  481. skillRoot = new BigSkill(attributeList[i]);
  482. }
  483. }
  484. else
  485. {
  486. throw new Exception(attributeList[i].Count.ToString());
  487. }
  488. #endregion
  489. SkillDic.Add(skillRoot.ID, skillRoot);
  490. SkillList.Add(skillRoot);
  491. }
  492. SkillList.Sort(SkillRoot.Sort);
  493. #endregion
  494. for (int i = 0; i < SkillList.Count; i++)
  495. {
  496. if (SkillList[i].SkillTab != SkillTab.Null)
  497. {
  498. ManaReso.GetSkillItem(SkillList[i]);
  499. }
  500. }
  501. #endregion
  502. }
  503. public override void RegistValueB()
  504. {
  505. Instance = this;
  506. ManaReso.Get<Graphic>("F_Elf").material = ManaReso.Load<Material>("GrayMat", Folder.Effect);
  507. ManaReso.Get<Graphic>("F_Store").material = ManaReso.Load<Material>("GrayMat", Folder.Effect);
  508. ManaReso.Get<Graphic>("F_Magic").material = ManaReso.Load<Material>("GrayMat", Folder.Effect);
  509. ManaReso.Get<Graphic>("F_ElfLab").material = ManaReso.Load<Material>("GrayMat", Folder.Effect);
  510. ManaReso.Get<Graphic>("F_StoreLab").material = ManaReso.Load<Material>("GrayMat", Folder.Effect);
  511. ManaReso.Get<Graphic>("F_MagicLab").material = ManaReso.Load<Material>("GrayMat", Folder.Effect);
  512. ManaReso.Get<Button>("F_Elf").interactable = false;
  513. ManaReso.Get<Button>("F_Store").interactable = false;
  514. ManaReso.Get<Button>("F_Magic").interactable = false;
  515. Coin = Data.GetPlayerDouble("Coin");
  516. Diamond = Data.GetPlayerDouble("Diamond");
  517. MiniTimer = Data.GetPlayerFloat("MiniTimer");
  518. CircleTimer = Data.GetPlayerFloat("CircleTimer");
  519. ManaServer.ID = Data.GetPlayerString("ID");
  520. ManaDebug.Log(string.Format("<color=red>{0:0}</color>秒后激活小游戏", MiniTimer));
  521. List<string> offlineList = Data.GetOfflineConfig();
  522. MaxCoin = Auxiliary.LongParse(offlineList[2], 999999999999999999);
  523. MaxTime = Auxiliary.LongParse(offlineList[1], 999999999999999999);
  524. OfflineFml = offlineList[0];
  525. List<double> dataList = Data.GetAchieveData();
  526. AdAmt = dataList[0];
  527. ElfLevel = dataList[4];
  528. SkillAmt = dataList[1];
  529. SignAmt = dataList[2];
  530. ShareAmt = dataList[3];
  531. FlowerCoin = dataList[6];
  532. TotalPerson = dataList[7];
  533. MiniGameAmt = dataList[5];
  534. }
  535. public static void RegistSkill()
  536. {
  537. OfflineValid = false;
  538. if (ManaServer.Connect && Data.GetPlayerBool("QuitFlag"))
  539. {
  540. QuitTime = DateTime.Parse(Data.GetPlayerString("QuitTime"));
  541. Elapse = (float)ManaServer.Time.Subtract(QuitTime).TotalSeconds;
  542. ManaDebug.Log(string.Format("真实离线时间<color=red>{0}</color>", Elapse));
  543. if (Elapse <= 120)
  544. {
  545. Elapse = 0;
  546. }
  547. else
  548. {
  549. OfflineValid = true;
  550. }
  551. if (Elapse > MaxTime)
  552. {
  553. Elapse = (long)MaxTime;
  554. }
  555. }
  556. ManaDebug.Log(string.Format("计算离线时间<color=red>{0}</color>", Elapse));
  557. FFUseList = new List<List<Skill>>();
  558. FFCoolList = new List<Skill>();
  559. if (Elapse > CircleTimer)
  560. {
  561. int circle = 1 + Mathf.FloorToInt((Elapse - CircleTimer) / CircleTime);
  562. for (int i = 0; i < circle; i++)
  563. {
  564. FFUseList.Add(new List<Skill>());
  565. }
  566. ManaDebug.Log(string.Format("离线周期<color=red>{0}</color>", circle));
  567. }
  568. else
  569. {
  570. ManaDebug.Log(string.Format("离线周期<color=red>{0}</color>", 0));
  571. }
  572. List<XmlAttributeCollection> attributeList = Data.GetSkillList();
  573. for (int i = 0; i < attributeList.Count; i++)
  574. {
  575. SkillRoot skillRoot = SkillDic[attributeList[i][0].Value];
  576. skillRoot.RegistReference();
  577. skillRoot.RegistValue(Elapse, FFUseList, attributeList[i]);
  578. }
  579. Level = Data.GetPlayerInt("Level");
  580. }
  581. public static void RegistIncome()
  582. {
  583. double coin = 0;
  584. if (FFUseList.Count > 0)
  585. {
  586. for (int i = 0; i < FFUseList.Count; i++)
  587. {
  588. for (int j = 0; j < FFCoolList.Count; j++)
  589. {
  590. FFCoolList[j].CoolTimer -= CircleTime;
  591. }
  592. for (int j = 0; j < FFUseList[i].Count; j++)
  593. {
  594. FFUseList[i][j].Annul();
  595. FFCoolList.Add(FFUseList[i][j]);
  596. }
  597. NewPerson = Person * (1 + SkillPersonBuff) + SkillPerson;
  598. NewCoinPerson = CoinPerson + SkillCoinPerson;
  599. TotalPerson += NewPerson * CircleTime;
  600. coin += (NewPerson * NewCoinPerson * CircleTime) * (1 + SkillPlus);
  601. }
  602. CircleTimer = (Elapse - CircleTimer) % CircleTime;
  603. for (int j = 0; j < FFCoolList.Count; j++)
  604. {
  605. FFCoolList[j].CoolTimer -= CircleTime - CircleTimer;
  606. }
  607. coin = (long) Auxiliary.FmlParse(OfflineFml, "c", coin.ToString());
  608. if (coin > MaxCoin)
  609. {
  610. coin = MaxCoin;
  611. }
  612. Coin += coin;
  613. ManaReso.SetText("Ba_IconLab", coin.ToString("0"));
  614. }
  615. else
  616. {
  617. CircleTimer = CircleTimer - Elapse;
  618. ManaReso.SetText("Ba_IconLab", "0");
  619. }
  620. }
  621. public static void SwitchLanguage()
  622. {
  623. Coin = Coin;
  624. Diamond = Diamond;
  625. }
  626. public static void Pay(string id, double amt, Current current, UnityAction callback, bool navigate = true)
  627. {
  628. if (ManaTutorial.PayExempt)
  629. {
  630. callback.Invoke();
  631. return;
  632. }
  633. amt = Auxiliary.ShrinkNumber(amt);
  634. if (current == Current.Free)
  635. {
  636. callback.Invoke();
  637. }
  638. else if (current == Current.AD)
  639. {
  640. ManaIAP.PlayAd(callback);
  641. }
  642. else if (current == Current.Cash)
  643. {
  644. ManaIAP.Purchase(id);
  645. }
  646. else if (current == Current.Coin)
  647. {
  648. #region MyRegion
  649. if (Coin >= amt)
  650. {
  651. Coin -= amt;
  652. callback.Invoke();
  653. }
  654. else
  655. {
  656. ManaReso.Get("Fe_Info").TweenBacCG();
  657. if (navigate)
  658. {
  659. Bubble.Show
  660. (
  661. Language.GetStr("Common", "ShortCoin"),
  662. Language.GetStr("Common", "NavigateCoin"),
  663. ManaReso.LoadSprite("金币"),
  664. () =>
  665. {
  666. Tween tween = ManaReso.Get("K_Bubble0").GetTweenScale();
  667. tween.AddEventOnetime
  668. (
  669. EventType.BackwardFinish,
  670. () =>
  671. {
  672. ManaReso.Get<Button>("F_Magic").onClick.Invoke();
  673. Auxiliary.Instance.DelayCall
  674. (
  675. () =>
  676. {
  677. int index = ManaReso.Get("Fb_Grid").childCount - 1;
  678. ManaReso.Get<ScrollRect>("Fb_Scrr").Locate(index, 0.25f, Curve.EaseOutQuad, LocatePos.Down);
  679. },
  680. 1
  681. );
  682. }
  683. );
  684. }
  685. );
  686. }
  687. else
  688. {
  689. Bubble.Show
  690. (
  691. Language.GetStr("Common", "ShortCoin"),
  692. null,
  693. ManaReso.LoadSprite("金币")
  694. );
  695. }
  696. }
  697. #endregion
  698. }
  699. else if (current == Current.Diamond)
  700. {
  701. #region MyRegion
  702. if (Diamond >= amt)
  703. {
  704. Diamond -= amt;
  705. callback.Invoke();
  706. }
  707. else
  708. {
  709. ManaReso.Get("Fe_Info").TweenBacCG();
  710. if (navigate)
  711. {
  712. Bubble.Show
  713. (
  714. Language.GetStr("Common", "ShortDiamond"),
  715. Language.GetStr("Common", "NavigateDiamond"),
  716. ManaReso.LoadSprite("钻石"),
  717. () =>
  718. {
  719. Tween tween = ManaReso.Get("K_Bubble0").GetTweenScale();
  720. tween.AddEventOnetime
  721. (
  722. EventType.BackwardFinish,
  723. () =>
  724. {
  725. ManaReso.Get<Button>("F_Store").onClick.Invoke();
  726. Auxiliary.Instance.DelayCall
  727. (
  728. () =>
  729. {
  730. int index = ManaReso.Get("Fc_Grid").childCount - 1;
  731. ManaReso.Get<ScrollRect>("Fc_Scrr").Locate(index, 0.25f, Curve.EaseOutQuad, LocatePos.Down);
  732. },
  733. 1
  734. );
  735. }
  736. );
  737. }
  738. );
  739. }
  740. else
  741. {
  742. Bubble.Show
  743. (
  744. Language.GetStr("Common", "ShortDiamond"),
  745. null,
  746. ManaReso.LoadSprite("钻石")
  747. );
  748. }
  749. }
  750. #endregion
  751. }
  752. else
  753. {
  754. throw new Exception(current.ToString());
  755. }
  756. }
  757. public static void LoginCallbackInitial(JsonData jsonData)
  758. {
  759. if (!Initializer.LoadComplete || !ManaServer.LoginComplete)
  760. {
  761. return;
  762. }
  763. if (ManaServer.Connect)
  764. {
  765. if (Data.GetPlayerString("ID") == "Default")
  766. {
  767. ManaServer.ID = ManaServer.JsonData["o"].ToString();
  768. ManaReso.SetText("L_UserLab", ManaServer.ID);
  769. }
  770. }
  771. RegistSkill();
  772. RegistIncome();
  773. if (OfflineValid)
  774. {
  775. if (!ManaTutorial.TutorialA)
  776. {
  777. ManaReso.Get("B_SignIn").TweenConForCG();
  778. ManaReso.Get("Ba_Notice").TweenConForCG();
  779. }
  780. }
  781. else
  782. {
  783. if (!ManaTutorial.TutorialA)
  784. {
  785. int daySpan = ManaServer.Time.Day - ManaSign.SignTime.Day;
  786. int yearSpan = ManaServer.Time.Year - ManaSign.SignTime.Year;
  787. int monthSpan = ManaServer.Time.Month - ManaSign.SignTime.Month;
  788. if (daySpan >= 1 || yearSpan >= 1 || monthSpan >= 1)
  789. {
  790. ManaReso.Get("B_SignIn").TweenConForCG();
  791. ManaReso.Get("Bb_SignIn").TweenConForCG();
  792. }
  793. }
  794. }
  795. InitiateComplete = true;
  796. Level = Level;
  797. }
  798. public static void LoginCallbackReactive(JsonData jsonData)
  799. {
  800. ReactiveRequest = false;
  801. for (int i = 0; i < Initializer.RegistList.Count; i++)
  802. {
  803. Initializer.RegistList[i].Reactive();
  804. }
  805. }
  806. public static void DownloadArchive()
  807. {
  808. ManaReso.SetText("La_Lab", "连接中");
  809. ManaReso.SetActive("La_Lab", true);
  810. ManaReso.SetActive("La_Mask", true);
  811. string id = ManaReso.Get<InputField>("La_InputField").text;
  812. ManaServer.Load(id, DownloadCallback);
  813. }
  814. public static void DownloadCallback(JsonData jsonData)
  815. {
  816. if (jsonData.Inst_Object.Keys.Contains("l"))
  817. {
  818. ManaReso.SetActive("La_Mask", false);
  819. ManaReso.SetText("La_Lab", Language.GetStr("UI", "La_Lab0"));
  820. int version = Data.GetPlayerInt("Version");
  821. Data.PlayerDoc.LoadXml(jsonData["l"].ToString());
  822. Data.PlayerNode = Data.PlayerDoc.SelectSingleNode("PlayerConfig");
  823. Data.SavePlayerInt("Version", version);
  824. ManaReso.SetText("L_UserLab", Data.GetPlayerString("ID"));
  825. ManaServer.ID = Data.GetPlayerString("ID");
  826. ManaMiniGame.MiniGameIndex = Data.GetPlayerInt("MiniGameIndex");
  827. Garden.Reload();
  828. ManaGarden.Reload();
  829. Reload();
  830. ManaAchieve.Reload();
  831. ManaPlayer.Reload();
  832. ManaSign.Reload();
  833. ManaReso.Get("La_Info").TweenBacCG();
  834. }
  835. else
  836. {
  837. ManaReso.SetText("La_Lab", Language.GetStr("UI", "La_Lab1"));
  838. ManaReso.SetActive("La_Mask", false);
  839. }
  840. }
  841. public void OnApplicationQuit()
  842. {
  843. if (Initializer.LoadComplete && !Reset)
  844. {
  845. Data.SavePlayerConfig();
  846. Data.SaveXml();
  847. }
  848. }
  849. public void OnApplicationPause(bool pause)
  850. {
  851. if (pause)
  852. {
  853. Data.SavePlayerConfig();
  854. Data.SaveXml();
  855. }
  856. else
  857. {
  858. if (FirstFrame)
  859. {
  860. FirstFrame = false;
  861. }
  862. else
  863. {
  864. if (!Initializer.LoadComplete)
  865. {
  866. return;
  867. }
  868. ManaVisit.DataRecover();
  869. if (ReactiveRequest)
  870. {
  871. return;
  872. }
  873. ReactiveRequest = true;
  874. ManaServer.Login(LoginCallbackReactive);
  875. }
  876. }
  877. }
  878. }