ManaData.cs 28 KB

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