ManaVisit.cs 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074
  1. using LitJson;
  2. using UnityEngine;
  3. using UnityEngine.UI;
  4. using UnityEngine.Events;
  5. using System;
  6. using System.Xml;
  7. using System.Collections;
  8. using System.Collections.Generic;
  9. using Random = UnityEngine.Random;
  10. public enum ArchiveSource
  11. {
  12. Fake,
  13. Random,
  14. SerialNumber,
  15. }
  16. public class VisitData
  17. {
  18. public bool Praised;
  19. public JsonData JsonData;
  20. }
  21. public class ManaVisit : Regist
  22. {
  23. #region 变量
  24. #region 配置
  25. public static int Cost
  26. {
  27. get { return Cost_; }
  28. set
  29. {
  30. Cost_ = value;
  31. ManaReso.Get<Text>("C_CostLab").text = "<(金币)>" + Cost;
  32. }
  33. }
  34. public static int Cost_;
  35. public static int CoolTime;
  36. public static float FancyRate;
  37. public static float AwardRate;
  38. public static float CreateRate;
  39. public static string CostFml;
  40. public static string AwardMinFml;
  41. public static string AwardMaxFml;
  42. #endregion
  43. public static float PullTimer;
  44. public static List<VisitData> UsedDataList = new List<VisitData>();
  45. public static List<VisitData> UnusedDataList = new List<VisitData>();
  46. public static bool InVisit;
  47. public static bool Complete;
  48. public static bool LoadComplete;
  49. public static bool TweenComplete;
  50. public static string XmlStr;
  51. public static int Slot;
  52. public static int Level;
  53. public static XmlNode Node;
  54. public static XmlDocument Document;
  55. public static int VisiteePraise;
  56. public static string VisiteeSerialNumber;
  57. public static bool OriginBird;
  58. public static bool OriginTree;
  59. public static bool OriginRainbow;
  60. public static List<Slot> VisitPlantList;
  61. public static List<Slot> OriginPlantList;
  62. public static List<ElfType> OriginElfList;
  63. #endregion
  64. public void Update()
  65. {
  66. if (UnusedDataList.Count > 8)
  67. {
  68. return;
  69. }
  70. PullTimer += Time.deltaTime;
  71. if (PullTimer >= 0.5f)
  72. {
  73. PullTimer = 0;
  74. ManaServer.RandomLoad
  75. (
  76. data =>
  77. {
  78. PullArchiveCallback(data, null, SavePulledArchive);
  79. }
  80. );
  81. }
  82. }
  83. public static void Initialize()
  84. {
  85. XmlAttributeCollection attribute = ManaData.GetVisitConfig();
  86. CostFml = attribute[5].Value;
  87. Cost = Mathf.FloorToInt((float)Auxiliary.FmlParse(CostFml, "l", ManaCenter.Level.ToString()));
  88. AwardMinFml = attribute[2].Value;
  89. AwardMaxFml = attribute[3].Value;
  90. CoolTime = int.Parse(attribute[4].Value);
  91. FancyRate = float.Parse(attribute[7].Value);
  92. AwardRate = float.Parse(attribute[1].Value);
  93. CreateRate = float.Parse(attribute[6].Value);
  94. #region 倒计时
  95. if (CoolTime != 0)
  96. {
  97. Text text = ManaReso.Get<Text>("C_VisitLab");
  98. List<float> delayList = new List<float>();
  99. List<float> durationList = new List<float>();
  100. List<VecPair> pairList = new List<VecPair>();
  101. List<UnityAction> actionList = new List<UnityAction>();
  102. Vector3 v1 = new Vector3(0.75f, 0.75f, 0.75f);
  103. Vector3 v2 = new Vector3(0.4f, 0.4f, 0.4f);
  104. Vector3 v3 = new Vector3(0, 0, 0);
  105. for (int i = 0; i < CoolTime - 1; i++)
  106. {
  107. delayList.Add(0.5f);
  108. delayList.Add(0);
  109. }
  110. delayList.Add(0.5f);
  111. for (int i = 0; i < CoolTime; i++)
  112. {
  113. durationList.Add(0.25f);
  114. durationList.Add(0.25f);
  115. pairList.Add(new VecPair(v1, v2));
  116. pairList.Add(new VecPair(v2, v3));
  117. var tempInt = i;
  118. actionList.Add
  119. (
  120. () =>
  121. {
  122. text.text = (CoolTime - tempInt).ToString();
  123. ManaAudio.PlayClip(Clip.BtnClip);
  124. }
  125. );
  126. actionList.Add(null);
  127. }
  128. TweenRoot tween = ManaReso.Get("C_VisitLab").CreateStreamScale
  129. (
  130. delayList,
  131. durationList,
  132. pairList,
  133. true,
  134. false,
  135. Curve.EaseOutQuad,
  136. false,
  137. actionList
  138. );
  139. tween.OnForwardFinish += () =>
  140. {
  141. ManaAudio.PlayClip(Clip.BubbleClip);
  142. };
  143. }
  144. #endregion
  145. Complete = true;
  146. }
  147. public static void ExitVisiteeGarden()
  148. {
  149. ManaReso.Get("I_BlackMask").TweenForCG();
  150. EnableChest();
  151. HideTip ();
  152. ManaReso.SetActive("C_Visit", true);
  153. ManaReso.SetActive("C_Coin", true);
  154. ManaReso.SetActive("C_Group1", true);
  155. ManaReso.SetActive("C_Group2", true);
  156. ManaReso.SetActive("C_Return", false);
  157. ManaReso.SetActive("C_Garden", false);
  158. ManaGarden.MiniLock = true;
  159. #region Garden
  160. ManaGarden.RetriveFlowerAll();
  161. for (int i = 0; i < ManaGarden.PageList.Count; i++)
  162. {
  163. ManaReso.Save(ManaGarden.PageList[i]);
  164. }
  165. ManaGarden.PageList = new List<Transform>();
  166. Garden.CurPage = 0;
  167. ManaGarden.SlotList = new List<Slot>();
  168. ManaGarden.PageList = new List<Transform>();
  169. Garden.ResetPage();
  170. Garden.PagePos = new List<Vector3>();
  171. int pageAmt = 2;
  172. if (ManaGarden.Slot >= 7)
  173. {
  174. pageAmt = (ManaGarden.Slot - 7)/9 + 3;
  175. }
  176. for (int i = 0; i < pageAmt; i++)
  177. {
  178. ManaGarden.CreatePage();
  179. }
  180. for (int i = 0; i < ManaGarden.SlotList.Count; i++)
  181. {
  182. if (i < ManaGarden.Slot)
  183. {
  184. ManaGarden.SlotList[i].Lock = true;
  185. ManaGarden.SlotList[i].Available = true;
  186. }
  187. else
  188. {
  189. ManaGarden.SlotList[i].Lock = false;
  190. ManaGarden.SlotList[i].Available = false;
  191. }
  192. }
  193. List<KV<int, int>> plantList = ManaData.GetPlantList();
  194. for (int i = 0; i < plantList.Count; i++)
  195. {
  196. ManaGarden.PlantFlower(plantList[i].Key, plantList[i].Value);
  197. }
  198. #endregion
  199. #region Bird Tree Rainbow
  200. if (OriginBird)
  201. {
  202. ManaReso.Get("Bird0").GetTweenSr().InDestination = true;
  203. }
  204. else
  205. {
  206. ManaReso.Get("Bird0").GetTweenSr().InOrigin = true;
  207. }
  208. if (OriginTree)
  209. {
  210. ManaReso.Get("Tree1").GetTweenSr().InDestination = true;
  211. ManaReso.Get("Tree2").GetTweenSr().InDestination = true;
  212. }
  213. else
  214. {
  215. ManaReso.Get("Tree1").GetTweenSr().InOrigin = true;
  216. ManaReso.Get("Tree2").GetTweenSr().InOrigin = true;
  217. }
  218. if (OriginRainbow)
  219. {
  220. ManaReso.Get("Rainbow").GetTweenSr().InDestination = true;
  221. }
  222. else
  223. {
  224. ManaReso.Get("Rainbow").GetTweenSr().InOrigin = true;
  225. }
  226. #endregion
  227. #region Player
  228. ManaReso.Save(ManaPlayer.Player);
  229. ManaReso.TraDic.Remove("Player");
  230. ManaPlayer.Instance.GetPlayer();
  231. Garden.PlayerPos = new List<Vector3>();
  232. Garden.Player = ManaReso.Get("Player");
  233. Garden.PlayerPos.Add(ManaPlayer.Player.ChildDic["Pos1"].position);
  234. Garden.PlayerPos.Add(ManaPlayer.Player.ChildDic["Pos2"].position);
  235. #endregion
  236. ManaGarden.ElfList = new List<ElfType>(OriginElfList);
  237. InVisit = false;
  238. LoadComplete = false;
  239. TweenComplete = false;
  240. SetPlayerPraise();
  241. SetPlayerCommentPanel();
  242. SetPlayerRankPanel();
  243. }
  244. public static void EnterVisiteeGarden()
  245. {
  246. if (!LoadComplete || !TweenComplete)
  247. {
  248. return;
  249. }
  250. ManaReso.Get("I_BlackMask").TweenForCG();
  251. SetVisiteePraise(Document);
  252. DisableChest();
  253. ShowTip ();
  254. Node = Document.SelectSingleNode("PlayerConfig");
  255. ManaReso.SetActive("C_Coin", false);
  256. ManaReso.SetActive("C_Group1", false);
  257. ManaReso.SetActive("C_Group2", false);
  258. ManaReso.SetActive("C_Garden", true);
  259. if (!InVisit)
  260. {
  261. for (int i = 0; i < ManaGarden.StarList.Count; i++)
  262. {
  263. ManaReso.Save(ManaGarden.StarList[i]);
  264. }
  265. ManaGarden.StarList = new List<Star>();
  266. }
  267. ManaReso.SetActive("C_Return", true);
  268. ManaGarden.MiniLock = false;
  269. #region Bird Tree Rainbow
  270. if (!InVisit)
  271. {
  272. if (ManaReso.Get("Bird0").gameObject.activeSelf)
  273. {
  274. OriginBird = true;
  275. }
  276. if (ManaReso.Get("Tree1").gameObject.activeSelf)
  277. {
  278. OriginTree = true;
  279. }
  280. if (ManaReso.Get("Rainbow").gameObject.activeSelf)
  281. {
  282. OriginRainbow = true;
  283. }
  284. }
  285. ManaReso.SetActive("Bird0", false);
  286. ManaReso.SetActive("Tree1", false);
  287. ManaReso.SetActive("Tree2", false);
  288. ManaReso.SetActive("Rainbow", false);
  289. #endregion
  290. #region Ability
  291. Slot = 1;
  292. if (!InVisit)
  293. {
  294. OriginElfList = new List<ElfType>(ManaGarden.ElfList);
  295. }
  296. ManaGarden.ElfList = new List<ElfType>();
  297. List<XmlAttributeCollection> attributeList = ManaData.GetSkillList(Node);
  298. for (int i = 0; i < attributeList.Count; i++)
  299. {
  300. if (!attributeList[i][0].Value.Contains("Ability"))
  301. {
  302. continue;
  303. }
  304. if (attributeList[i][0].Value == "Ability1")
  305. {
  306. Level = int.Parse(attributeList[i][3].Value);
  307. ManaReso.SetText("C_GardenLab", Language.GetStr("UI", "C_GardenLab") + Level);
  308. continue;
  309. }
  310. if (int.Parse(attributeList[i][3].Value) == 0)
  311. {
  312. continue;
  313. }
  314. if (attributeList[i][0].Value == "Ability2")
  315. {
  316. ManaReso.Get("Rainbow").GetTweenSr().InDestination = true;
  317. }
  318. else if (attributeList[i][0].Value == "Ability3")
  319. {
  320. ManaReso.Get("Tree1").GetTweenSr().InDestination = true;
  321. ManaReso.Get("Tree2").GetTweenSr().InDestination = true;
  322. }
  323. else if (attributeList[i][0].Value == "Ability4")
  324. {
  325. ManaReso.Get("Bird0").GetTweenSr().InDestination = true;
  326. }
  327. else if (attributeList[i][0].Value == "Ability5")
  328. {
  329. ManaGarden.ElfList.Add(ElfType.Bee_Yellow);
  330. }
  331. else if (attributeList[i][0].Value == "Ability6")
  332. {
  333. Slot++;
  334. ManaGarden.ElfList.Add(ElfType.Bee_Purple);
  335. }
  336. else if (attributeList[i][0].Value == "Ability7")
  337. {
  338. Slot++;
  339. ManaGarden.ElfList.Add(ElfType.Bee_Blue);
  340. }
  341. else if (attributeList[i][0].Value == "Ability8")
  342. {
  343. Slot++;
  344. ManaGarden.ElfList.Add(ElfType.Bee_Red);
  345. }
  346. else if (attributeList[i][0].Value == "Ability9")
  347. {
  348. Slot++;
  349. ManaGarden.ElfList.Add(ElfType.Bee_White);
  350. }
  351. else if (attributeList[i][0].Value == "Ability10")
  352. {
  353. Slot++;
  354. ManaGarden.ElfList.Add(ElfType.Butterfly_Yellow);
  355. }
  356. else if (attributeList[i][0].Value == "Ability11")
  357. {
  358. Slot++;
  359. ManaGarden.ElfList.Add(ElfType.Butterfly_Purple);
  360. }
  361. else if (attributeList[i][0].Value == "Ability12")
  362. {
  363. Slot++;
  364. ManaGarden.ElfList.Add(ElfType.Butterfly_Blue);
  365. }
  366. else if (attributeList[i][0].Value == "Ability13")
  367. {
  368. Slot++;
  369. ManaGarden.ElfList.Add(ElfType.Butterfly_Red);
  370. }
  371. else if (attributeList[i][0].Value == "Ability14")
  372. {
  373. Slot++;
  374. ManaGarden.ElfList.Add(ElfType.Butterfly_White);
  375. }
  376. else if (attributeList[i][0].Value == "Ability15")
  377. {
  378. Slot++;
  379. ManaGarden.ElfList.Add(ElfType.Dragonfly_Yellow);
  380. }
  381. else if (attributeList[i][0].Value == "Ability16")
  382. {
  383. Slot++;
  384. ManaGarden.ElfList.Add(ElfType.Dragonfly_Purple);
  385. }
  386. else if (attributeList[i][0].Value == "Ability17")
  387. {
  388. Slot++;
  389. ManaGarden.ElfList.Add(ElfType.Dragonfly_Blue);
  390. }
  391. else if (attributeList[i][0].Value == "Ability18")
  392. {
  393. Slot++;
  394. ManaGarden.ElfList.Add(ElfType.Dragonfly_Red);
  395. }
  396. else if (attributeList[i][0].Value == "Ability19")
  397. {
  398. Slot++;
  399. ManaGarden.ElfList.Add(ElfType.Dragonfly_White);
  400. }
  401. else if (attributeList[i][0].Value == "Ability20")
  402. {
  403. Slot++;
  404. ManaGarden.ElfList.Add(ElfType.Beetle_Yellow);
  405. }
  406. else if (attributeList[i][0].Value == "Ability21")
  407. {
  408. Slot++;
  409. ManaGarden.ElfList.Add(ElfType.Beetle_Purple);
  410. }
  411. else if (attributeList[i][0].Value == "Ability22")
  412. {
  413. Slot++;
  414. ManaGarden.ElfList.Add(ElfType.Beetle_Blue);
  415. }
  416. else if (attributeList[i][0].Value == "Ability23")
  417. {
  418. Slot++;
  419. ManaGarden.ElfList.Add(ElfType.Beetle_Red);
  420. }
  421. else if (attributeList[i][0].Value == "Ability24")
  422. {
  423. Slot++;
  424. ManaGarden.ElfList.Add(ElfType.Beetle_White);
  425. }
  426. }
  427. #endregion
  428. #region Garden
  429. if (!InVisit)
  430. {
  431. OriginPlantList = new List<Slot>(ManaGarden.PlantList);
  432. ManaData.SaveDress();
  433. ManaData.SavePlantList();
  434. }
  435. ManaGarden.RetriveFlowerAll();
  436. for (int i = 0; i < ManaGarden.PageList.Count; i++)
  437. {
  438. ManaReso.Save(ManaGarden.PageList[i]);
  439. }
  440. ManaGarden.PageList = new List<Transform>();
  441. Garden.CurPage = 0;
  442. ManaGarden.SlotList = new List<Slot>();
  443. ManaGarden.PageList = new List<Transform>();
  444. Garden.ResetPage();
  445. Garden.PagePos = new List<Vector3>();
  446. int pageAmt = 2;
  447. if (Slot >= 7)
  448. {
  449. pageAmt = (Slot - 7) / 9 + 3;
  450. }
  451. for (int i = 0; i < pageAmt; i++)
  452. {
  453. ManaGarden.CreatePage();
  454. }
  455. for (int i = 0; i < ManaGarden.SlotList.Count; i++)
  456. {
  457. if (i < Slot)
  458. {
  459. ManaGarden.SlotList[i].Lock = true;
  460. ManaGarden.SlotList[i].Available = true;
  461. }
  462. else
  463. {
  464. ManaGarden.SlotList[i].Lock = false;
  465. ManaGarden.SlotList[i].Available = false;
  466. }
  467. }
  468. List<KV<int, int>> plantList = ManaData.GetPlantList(Node);
  469. for (int i = 0; i < plantList.Count; i++)
  470. {
  471. ManaGarden.PlantFlower(plantList[i].Key, plantList[i].Value);
  472. }
  473. #endregion
  474. #region Player
  475. ManaReso.Save(ManaPlayer.Player);
  476. ManaReso.TraDic.Remove("Player");
  477. ManaPlayer.Instance.GetPlayer(Node).SetAllCollider(false);
  478. Garden.PlayerPos = new List<Vector3>();
  479. Garden.Player = ManaReso.Get("Player");
  480. Garden.PlayerPos.Add(ManaPlayer.Player.ChildDic["Pos1"].position);
  481. Garden.PlayerPos.Add(ManaPlayer.Player.ChildDic["Pos2"].position);
  482. #endregion
  483. #region Award
  484. if (ManaTutorial.TutorialC || Random.Range(0f,1f) <= AwardRate)
  485. {
  486. if (ManaTutorial.TutorialC)
  487. {
  488. ManaTutorial.EndC();
  489. }
  490. if (ManaGarden.PlantList.Count > 0)
  491. {
  492. ManaGarden.PlantList.Random()[0].Flower.Award = true;
  493. }
  494. }
  495. #endregion
  496. InVisit = true;
  497. }
  498. public static void SetPlayerRankPanel()
  499. {
  500. ManaSocial.RecoverRankPanel();
  501. }
  502. public static void EnableChest()
  503. {
  504. for (int i = 0; i < ManaIAP.ChestList.Count; i++)
  505. {
  506. ManaIAP.ChestList[i].SetActive(true);
  507. }
  508. }
  509. public static void DisableChest()
  510. {
  511. for (int i = 0; i < ManaIAP.ChestList.Count; i++)
  512. {
  513. ManaIAP.ChestList[i].SetActive(false);
  514. }
  515. }
  516. public static void SetPlayerPraise()
  517. {
  518. ManaSocial.PraiseText.text = ManaServer.PraiseAmt.ToString();
  519. ManaSocial.PraiseBtn.interactable = false;
  520. ManaSocial.PraiseBtn.image.color = Color.white;
  521. }
  522. public static void SetVisiteePraise(XmlDocument document)
  523. {
  524. ManaSocial.PraiseText.text = VisiteePraise.ToString();
  525. if (document.SelectSingleNode("PlayerConfig").SelectSingleNode("SerialNumber") == null)
  526. {
  527. ManaSocial.EnablePraise();
  528. VisiteeSerialNumber = null;
  529. }
  530. else
  531. {
  532. VisiteeSerialNumber = document.SelectSingleNode("PlayerConfig").SelectSingleNode("SerialNumber").Attributes[0].Value;
  533. ManaServer.Target
  534. (
  535. ManaServer.SerialNumber,
  536. VisiteeSerialNumber,
  537. jsonData =>
  538. {
  539. if (jsonData["i"].ToString() == "0")
  540. {
  541. ManaSocial.EnablePraise();
  542. }
  543. else if (jsonData["i"].ToString() == "1")
  544. {
  545. ManaSocial.DisablePraise();
  546. }
  547. }
  548. );
  549. }
  550. }
  551. public static void SetPlayerCommentPanel()
  552. {
  553. if (ManaSocial.CommentRecordFlag)
  554. {
  555. ManaSocial.RecoverCommentPanel();
  556. }
  557. else
  558. {
  559. ManaSocial.UpdatePage(true);
  560. }
  561. }
  562. public static void SetVisiteeCommentPanel()
  563. {
  564. ManaSocial.ClearComment();
  565. ManaSocial.UpdatePage(false);
  566. }
  567. public static void UpdateCost()
  568. {
  569. if (Complete)
  570. {
  571. Cost = Mathf.FloorToInt((float)Auxiliary.FmlParse(CostFml, "l", ManaCenter.Level.ToString()));
  572. }
  573. }
  574. public static void DataReverse()
  575. {
  576. if (InVisit)
  577. {
  578. VisitPlantList = new List<Slot>(ManaGarden.PlantList);
  579. ManaGarden.PlantList = OriginPlantList;
  580. }
  581. }
  582. public static void DataRecover()
  583. {
  584. if (InVisit)
  585. {
  586. ManaGarden.PlantList = VisitPlantList;
  587. }
  588. }
  589. public static void ShowTip()
  590. {
  591. ManaReso.SetActive ("C_Tip", true);
  592. ManaReso.Get<Text> ("C_TipLab").text = Language.GetStr ("Tip", "Tip" + Random.Range(1,10));
  593. }
  594. public static void HideTip()
  595. {
  596. ManaReso.SetActive ("C_Tip", false);
  597. }
  598. public static void Visit(ArchiveSource archiveSource, string info = null)
  599. {
  600. if (ManaCenter.SceneSwitchLock)
  601. {
  602. return;
  603. }
  604. ManaCenter.Pay
  605. (
  606. "",
  607. Cost,
  608. Current.Coin,
  609. () =>
  610. {
  611. ManaReso.Get("I_BlackMask").GetTweenCG().Duration = 0.5f;
  612. LoadComplete = false;
  613. TweenComplete = false;
  614. GetArchive(archiveSource, info);
  615. ManaAudio.PlayClip(Clip.BubbleClip);
  616. ManaReso.SetActive("C_Return", false);
  617. TweenRoot tween;
  618. if (CoolTime != 0)
  619. {
  620. ManaReso.Get<Button>("C_Visit").interactable = false;
  621. tween = ManaReso.Get("C_VisitLab").StreamReForScale();
  622. tween.AddEventOnetime
  623. (
  624. EventType.ForwardFinish,
  625. () =>
  626. {
  627. ManaReso.Get<Button>("C_Visit").interactable = true;
  628. }
  629. );
  630. }
  631. tween = ManaReso.Get("I_BlackMask").TweenBacCG();
  632. tween.AddEventOnetime
  633. (
  634. EventType.BackwardFinish,
  635. () =>
  636. {
  637. TweenComplete = true;
  638. EnterVisiteeGarden();
  639. }
  640. );
  641. },
  642. StaticsManager.ItemID.参观花费,
  643. StaticsManager.ConsumeModule.Shop,
  644. false
  645. );
  646. }
  647. public static void GetArchive(ArchiveSource archiveSource, string info = null)
  648. {
  649. //LoadComplete = true;
  650. //XmlStr = Auxiliary.Instance.TextAsset.text;
  651. //VisiteePraise = 0;
  652. //Document = new XmlDocument();
  653. //Document.LoadXml(XmlStr);
  654. ////SetVisiteePraise(Document);
  655. ////SetVisiteeCommentPanel();
  656. //EnterVisiteeGarden();
  657. //Debug.Log(Document.OuterXml);
  658. //return;
  659. if (archiveSource == ArchiveSource.SerialNumber)
  660. {
  661. ManaServer.Other
  662. (
  663. info,
  664. data =>
  665. {
  666. PullArchiveCallback(data, ShowFailPanel, EnterVisiteeGarden);
  667. }
  668. );
  669. }
  670. else if (archiveSource == ArchiveSource.Random)
  671. {
  672. //Debug.Log($"新存档{UnusedDataList.Count} 已用存档{UsedDataList.Count}");
  673. if (UnusedDataList.Count > 0)
  674. {
  675. EnterVisiteeGarden(UnusedDataList[0].JsonData);
  676. UsedDataList.Add(UnusedDataList[0]);
  677. UnusedDataList.RemoveAt(0);
  678. }
  679. else if (UsedDataList.Count > 0)
  680. {
  681. EnterVisiteeGarden(UsedDataList.Random()[0].JsonData);
  682. }
  683. else
  684. {
  685. ShowFailPanel();
  686. }
  687. }
  688. //else
  689. //{
  690. // LoadComplete = true;
  691. // XmlStr = CreateArchive();
  692. // Document = new XmlDocument();
  693. // Document.LoadXml(XmlStr);
  694. // EnterVisiteeGarden();
  695. //}
  696. }
  697. public static void PullArchiveCallback(JsonData jsonData, Action failed, Action<JsonData> succeed)
  698. {
  699. if (jsonData.Inst_Object.ContainsKey("l"))
  700. {
  701. if (succeed != null)
  702. succeed.Invoke(jsonData);
  703. }
  704. else
  705. {
  706. if (failed != null)
  707. failed.Invoke();
  708. }
  709. }
  710. public static void SavePulledArchive(JsonData jsonData)
  711. {
  712. UnusedDataList.Add(new VisitData() {JsonData = jsonData});
  713. }
  714. public static void EnterVisiteeGarden(JsonData jsonData)
  715. {
  716. LoadComplete = true;
  717. XmlStr = jsonData["l"].ToString();
  718. VisiteePraise = int.Parse(jsonData["p"].ToString());
  719. Document = new XmlDocument();
  720. Document.LoadXml(XmlStr);
  721. SetVisiteeCommentPanel();
  722. EnterVisiteeGarden();
  723. }
  724. public static void ShowFailPanel()
  725. {
  726. Bubble.Show
  727. (
  728. Language.GetStr("UI", "C_VisitFail"),
  729. null,
  730. null,
  731. null,
  732. () =>
  733. {
  734. ManaReso.Get("I_BlackMask").TweenForCG();
  735. },
  736. null,
  737. false
  738. );
  739. ManaCenter.AddCoin(Cost, StaticsManager.ItemID.获得金币, StaticsManager.ConsumeModule.VisitRefund);
  740. }
  741. public static string CreateArchive()
  742. {
  743. XmlDocument doc = new XmlDocument();
  744. doc.LoadXml(ManaData.PlayerDoc.OuterXml); //以自己的存档做模板进行修改
  745. int newLevel = Random.Range(1, 450); //随机等级
  746. #region 根据等级确定有多少土地解锁
  747. int slot = 1; //解锁土地数量
  748. XmlNodeList nodeList = doc.SelectSingleNode("PlayerConfig").SelectSingleNode("SkillList").ChildNodes;
  749. for (int i = 0; i < nodeList.Count; i++)
  750. {
  751. SkillType type = nodeList[i].Attributes[1].Value.ToEnum<SkillType>();
  752. if (type == SkillType.Ability)
  753. {
  754. Ability ability = (Ability)ManaCenter.SkillDic[nodeList[i].Attributes[0].Value];
  755. int unlockLevel = ability.UnlockLv;
  756. if (newLevel >= unlockLevel)
  757. {
  758. if (ability.ID_ >= 6)
  759. {
  760. slot++;
  761. }
  762. nodeList[i].Attributes[2].Value = "Upgrade";
  763. nodeList[i].Attributes[3].Value = newLevel.ToString();
  764. }
  765. else
  766. {
  767. nodeList[i].Attributes[2].Value = "Lock";
  768. nodeList[i].Attributes[3].Value = "0";
  769. }
  770. }
  771. }
  772. #endregion
  773. #region 随机种一些花
  774. bool fancy = Random.Range(0f, 1f) < FancyRate; //fancy=True时 种的花比较多
  775. List<int> flowerList = new List<int>();
  776. for (int i = 1; i < 36; i++)
  777. {
  778. flowerList.Add(i);
  779. }
  780. int slotIndex = 0;
  781. string plantList = "";
  782. for (int i = 0; i < slot; i++)
  783. {
  784. if (fancy || Random.Range(0f, 1f) >= 0.35f)
  785. {
  786. int flowerID = slotIndex + 1;
  787. plantList += string.Format("{0},{1} ", flowerID, slotIndex);
  788. slotIndex++;
  789. }
  790. }
  791. plantList = plantList.TrimEnd(' ');
  792. doc.SelectSingleNode("PlayerConfig").SelectSingleNode("PlantList").Attributes[0].Value = plantList;
  793. #endregion
  794. #region 随机一套服装 等级越高拥有的服装越多 再随机选几件穿上
  795. XmlNode xmlNode = doc.SelectSingleNode("PlayerConfig").SelectSingleNode("DressData");
  796. xmlNode.Attributes[0].Value = "";
  797. xmlNode.Attributes[0].Value = ManaPlayer.CloseUnitDic[Random.Range(2, (int)Mathf.Lerp(2, 30, newLevel / 449f) + 1)].ArmatureName;
  798. xmlNode.Attributes[1].Value = ManaPlayer.CloseUnitDic[Random.Range(201, (int)Mathf.Lerp(201, 217, newLevel / 449f) + 1)].ArmatureName;
  799. xmlNode.Attributes[2].Value = ManaPlayer.CloseUnitDic[Random.Range(401, (int)Mathf.Lerp(401, 415, newLevel / 449f) + 1)].ArmatureName;
  800. xmlNode.Attributes[3].Value = ManaPlayer.CloseUnitDic[Random.Range(601, (int)Mathf.Lerp(601, 612, newLevel / 449f) + 1)].ArmatureName;
  801. xmlNode.Attributes[4].Value = ManaPlayer.CloseUnitDic[Random.Range(801, (int)Mathf.Lerp(801, 817, newLevel / 449f) + 1)].ArmatureName;
  802. xmlNode.Attributes[7].Value = ManaPlayer.CloseUnitDic[Random.Range(1001, (int)Mathf.Lerp(1001, 1003, newLevel / 449f) + 1)].ArmatureName;
  803. #region 随机选一套眼睛嘴巴
  804. float eyeMouseRate = Random.Range(0f, 1f);
  805. if (eyeMouseRate <= 0.33f)
  806. {
  807. xmlNode.Attributes[5].Value = "眼睛1";
  808. xmlNode.Attributes[6].Value = "嘴巴1";
  809. }
  810. else if (eyeMouseRate <= 0.66f)
  811. {
  812. xmlNode.Attributes[5].Value = "眼睛2";
  813. xmlNode.Attributes[6].Value = "嘴巴2";
  814. }
  815. else
  816. {
  817. xmlNode.Attributes[5].Value = "眼睛3";
  818. xmlNode.Attributes[6].Value = "嘴巴3";
  819. }
  820. #endregion
  821. #endregion
  822. return doc.OuterXml;
  823. }
  824. }