ManaData.cs 27 KB

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