ManaVisit.cs 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071
  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. HideTip ();
  151. ManaReso.SetActive("C_Visit", true);
  152. ManaReso.SetActive("C_Coin", true);
  153. ManaReso.SetActive("C_Group1", true);
  154. ManaReso.SetActive("C_Group2", true);
  155. ManaReso.SetActive("C_Return", false);
  156. ManaReso.SetActive("C_Garden", false);
  157. ManaGarden.MiniLock = true;
  158. #region Garden
  159. ManaGarden.RetriveFlowerAll();
  160. for (int i = 0; i < ManaGarden.PageList.Count; i++)
  161. {
  162. ManaReso.Save(ManaGarden.PageList[i]);
  163. }
  164. ManaGarden.PageList = new List<Transform>();
  165. ManaGarden.SlotList = new List<Slot>();
  166. ManaGarden.PageList = new List<Transform>();
  167. Garden.ResetPage();
  168. Garden.PagePos = new List<Vector3>();
  169. int pageAmt = 2;
  170. if (ManaGarden.Slot >= 7)
  171. {
  172. pageAmt = (ManaGarden.Slot - 7)/9 + 3;
  173. }
  174. for (int i = 0; i < pageAmt; i++)
  175. {
  176. ManaGarden.CreatePage();
  177. }
  178. for (int i = 0; i < ManaGarden.SlotList.Count; i++)
  179. {
  180. if (i < ManaGarden.Slot)
  181. {
  182. ManaGarden.SlotList[i].Lock = true;
  183. ManaGarden.SlotList[i].Available = true;
  184. }
  185. else
  186. {
  187. ManaGarden.SlotList[i].Lock = false;
  188. ManaGarden.SlotList[i].Available = false;
  189. }
  190. }
  191. List<KV<int, int>> plantList = ManaData.GetPlantList();
  192. for (int i = 0; i < plantList.Count; i++)
  193. {
  194. ManaGarden.PlantFlower(plantList[i].Key, plantList[i].Value);
  195. }
  196. #endregion
  197. #region Bird Tree Rainbow
  198. if (OriginBird)
  199. {
  200. ManaReso.Get("Bird0").GetTweenSr().InDestination = true;
  201. }
  202. else
  203. {
  204. ManaReso.Get("Bird0").GetTweenSr().InOrigin = true;
  205. }
  206. if (OriginTree)
  207. {
  208. ManaReso.Get("Tree1").GetTweenSr().InDestination = true;
  209. ManaReso.Get("Tree2").GetTweenSr().InDestination = true;
  210. }
  211. else
  212. {
  213. ManaReso.Get("Tree1").GetTweenSr().InOrigin = true;
  214. ManaReso.Get("Tree2").GetTweenSr().InOrigin = true;
  215. }
  216. if (OriginRainbow)
  217. {
  218. ManaReso.Get("Rainbow").GetTweenSr().InDestination = true;
  219. }
  220. else
  221. {
  222. ManaReso.Get("Rainbow").GetTweenSr().InOrigin = true;
  223. }
  224. #endregion
  225. #region Player
  226. ManaReso.Save(ManaPlayer.Player);
  227. ManaReso.TraDic.Remove("Player");
  228. ManaPlayer.Instance.GetPlayer();
  229. Garden.PlayerPos = new List<Vector3>();
  230. Garden.Player = ManaReso.Get("Player");
  231. Garden.PlayerPos.Add(ManaPlayer.Player.ChildDic["Pos1"].position);
  232. Garden.PlayerPos.Add(ManaPlayer.Player.ChildDic["Pos2"].position);
  233. #endregion
  234. ManaGarden.ElfList = new List<ElfType>(OriginElfList);
  235. InVisit = false;
  236. LoadComplete = false;
  237. TweenComplete = false;
  238. SetPlayerPraise();
  239. SetPlayerCommentPanel();
  240. SetPlayerRankPanel();
  241. SetPlayerNickName();
  242. }
  243. public static void EnterVisiteeGarden()
  244. {
  245. if (!LoadComplete || !TweenComplete)
  246. {
  247. return;
  248. }
  249. ManaReso.Get("I_BlackMask").TweenForCG();
  250. //Debug.Log(Document.OuterXml);
  251. SetVisiteePraise(Document);
  252. ShowTip ();
  253. Node = Document.SelectSingleNode("PlayerConfig");
  254. ManaReso.SetActive("C_Coin", false);
  255. ManaReso.SetActive("C_Group1", false);
  256. ManaReso.SetActive("C_Group2", false);
  257. ManaReso.SetActive("C_Garden", true);
  258. if (!InVisit)
  259. {
  260. ManaGarden.RetrieveAllStar();
  261. ManaGarden.RetrieveAllElf();
  262. ManaIAP.RetrieveADChest();
  263. ManaGarden.StarList = new List<Star>();
  264. }
  265. ManaReso.SetActive("C_Return", true);
  266. ManaGarden.MiniLock = false;
  267. #region Bird Tree Rainbow
  268. if (!InVisit)
  269. {
  270. if (ManaReso.Get("Bird0").gameObject.activeSelf)
  271. {
  272. OriginBird = true;
  273. }
  274. if (ManaReso.Get("Tree1").gameObject.activeSelf)
  275. {
  276. OriginTree = true;
  277. }
  278. if (ManaReso.Get("Rainbow").gameObject.activeSelf)
  279. {
  280. OriginRainbow = true;
  281. }
  282. }
  283. ManaReso.SetActive("Bird0", false);
  284. ManaReso.SetActive("Tree1", false);
  285. ManaReso.SetActive("Tree2", false);
  286. ManaReso.SetActive("Rainbow", false);
  287. #endregion
  288. #region Ability
  289. Slot = 1;
  290. if (!InVisit)
  291. {
  292. OriginElfList = new List<ElfType>(ManaGarden.ElfList);
  293. }
  294. ManaGarden.ElfList = new List<ElfType>();
  295. List<XmlAttributeCollection> attributeList = ManaData.GetSkillList(Node);
  296. for (int i = 0; i < attributeList.Count; i++)
  297. {
  298. if (!attributeList[i][0].Value.Contains("Ability"))
  299. {
  300. continue;
  301. }
  302. if (attributeList[i][0].Value == "Ability1")
  303. {
  304. Level = int.Parse(attributeList[i][3].Value);
  305. ManaReso.SetText("C_GardenLab", Language.GetStr("UI", "C_GardenLab") + Level);
  306. continue;
  307. }
  308. if (int.Parse(attributeList[i][3].Value) == 0)
  309. {
  310. continue;
  311. }
  312. if (attributeList[i][0].Value == "Ability2")
  313. {
  314. ManaReso.Get("Rainbow").GetTweenSr().InDestination = true;
  315. }
  316. else if (attributeList[i][0].Value == "Ability3")
  317. {
  318. ManaReso.Get("Tree1").GetTweenSr().InDestination = true;
  319. ManaReso.Get("Tree2").GetTweenSr().InDestination = true;
  320. }
  321. else if (attributeList[i][0].Value == "Ability4")
  322. {
  323. ManaReso.Get("Bird0").GetTweenSr().InDestination = true;
  324. }
  325. else if (attributeList[i][0].Value == "Ability5")
  326. {
  327. ManaGarden.ElfList.Add(ElfType.Bee_Yellow);
  328. }
  329. else if (attributeList[i][0].Value == "Ability6")
  330. {
  331. Slot++;
  332. ManaGarden.ElfList.Add(ElfType.Bee_Purple);
  333. }
  334. else if (attributeList[i][0].Value == "Ability7")
  335. {
  336. Slot++;
  337. ManaGarden.ElfList.Add(ElfType.Bee_Blue);
  338. }
  339. else if (attributeList[i][0].Value == "Ability8")
  340. {
  341. Slot++;
  342. ManaGarden.ElfList.Add(ElfType.Bee_Red);
  343. }
  344. else if (attributeList[i][0].Value == "Ability9")
  345. {
  346. Slot++;
  347. ManaGarden.ElfList.Add(ElfType.Bee_White);
  348. }
  349. else if (attributeList[i][0].Value == "Ability10")
  350. {
  351. Slot++;
  352. ManaGarden.ElfList.Add(ElfType.Butterfly_Yellow);
  353. }
  354. else if (attributeList[i][0].Value == "Ability11")
  355. {
  356. Slot++;
  357. ManaGarden.ElfList.Add(ElfType.Butterfly_Purple);
  358. }
  359. else if (attributeList[i][0].Value == "Ability12")
  360. {
  361. Slot++;
  362. ManaGarden.ElfList.Add(ElfType.Butterfly_Blue);
  363. }
  364. else if (attributeList[i][0].Value == "Ability13")
  365. {
  366. Slot++;
  367. ManaGarden.ElfList.Add(ElfType.Butterfly_Red);
  368. }
  369. else if (attributeList[i][0].Value == "Ability14")
  370. {
  371. Slot++;
  372. ManaGarden.ElfList.Add(ElfType.Butterfly_White);
  373. }
  374. else if (attributeList[i][0].Value == "Ability15")
  375. {
  376. Slot++;
  377. ManaGarden.ElfList.Add(ElfType.Dragonfly_Yellow);
  378. }
  379. else if (attributeList[i][0].Value == "Ability16")
  380. {
  381. Slot++;
  382. ManaGarden.ElfList.Add(ElfType.Dragonfly_Purple);
  383. }
  384. else if (attributeList[i][0].Value == "Ability17")
  385. {
  386. Slot++;
  387. ManaGarden.ElfList.Add(ElfType.Dragonfly_Blue);
  388. }
  389. else if (attributeList[i][0].Value == "Ability18")
  390. {
  391. Slot++;
  392. ManaGarden.ElfList.Add(ElfType.Dragonfly_Red);
  393. }
  394. else if (attributeList[i][0].Value == "Ability19")
  395. {
  396. Slot++;
  397. ManaGarden.ElfList.Add(ElfType.Dragonfly_White);
  398. }
  399. else if (attributeList[i][0].Value == "Ability20")
  400. {
  401. Slot++;
  402. ManaGarden.ElfList.Add(ElfType.Beetle_Yellow);
  403. }
  404. else if (attributeList[i][0].Value == "Ability21")
  405. {
  406. Slot++;
  407. ManaGarden.ElfList.Add(ElfType.Beetle_Purple);
  408. }
  409. else if (attributeList[i][0].Value == "Ability22")
  410. {
  411. Slot++;
  412. ManaGarden.ElfList.Add(ElfType.Beetle_Blue);
  413. }
  414. else if (attributeList[i][0].Value == "Ability23")
  415. {
  416. Slot++;
  417. ManaGarden.ElfList.Add(ElfType.Beetle_Red);
  418. }
  419. else if (attributeList[i][0].Value == "Ability24")
  420. {
  421. Slot++;
  422. ManaGarden.ElfList.Add(ElfType.Beetle_White);
  423. }
  424. }
  425. #endregion
  426. #region Garden
  427. if (!InVisit)
  428. {
  429. OriginPlantList = new List<Slot>(ManaGarden.PlantList);
  430. ManaData.SaveDress();
  431. ManaData.SavePlantList();
  432. }
  433. ManaGarden.RetriveFlowerAll();
  434. for (int i = 0; i < ManaGarden.PageList.Count; i++)
  435. {
  436. ManaReso.Save(ManaGarden.PageList[i]);
  437. }
  438. ManaGarden.PageList = new List<Transform>();
  439. ManaGarden.SlotList = new List<Slot>();
  440. ManaGarden.PageList = new List<Transform>();
  441. Garden.ResetPage();
  442. Garden.PagePos = new List<Vector3>();
  443. int pageAmt = 2;
  444. if (Slot >= 7)
  445. {
  446. pageAmt = (Slot - 7) / 9 + 3;
  447. }
  448. for (int i = 0; i < pageAmt; i++)
  449. {
  450. ManaGarden.CreatePage();
  451. }
  452. for (int i = 0; i < ManaGarden.SlotList.Count; i++)
  453. {
  454. if (i < Slot)
  455. {
  456. ManaGarden.SlotList[i].Lock = true;
  457. ManaGarden.SlotList[i].Available = true;
  458. }
  459. else
  460. {
  461. ManaGarden.SlotList[i].Lock = false;
  462. ManaGarden.SlotList[i].Available = false;
  463. }
  464. }
  465. List<KV<int, int>> plantList = ManaData.GetPlantList(Node);
  466. for (int i = 0; i < plantList.Count; i++)
  467. {
  468. ManaGarden.PlantFlower(plantList[i].Key, plantList[i].Value);
  469. }
  470. #endregion
  471. #region Player
  472. ManaReso.Save(ManaPlayer.Player);
  473. ManaReso.TraDic.Remove("Player");
  474. ManaPlayer.Instance.GetPlayer(Node).SetAllCollider(false);
  475. Garden.PlayerPos = new List<Vector3>();
  476. Garden.Player = ManaReso.Get("Player");
  477. Garden.PlayerPos.Add(ManaPlayer.Player.ChildDic["Pos1"].position);
  478. Garden.PlayerPos.Add(ManaPlayer.Player.ChildDic["Pos2"].position);
  479. #endregion
  480. #region Award
  481. if (Random.Range(0f,1f) <= AwardRate)
  482. {
  483. if (ManaGarden.PlantList.Count > 0)
  484. {
  485. ManaGarden.PlantList.Random()[0].Flower.Award = true;
  486. }
  487. }
  488. #endregion
  489. XmlNode nicknameNode = Document.SelectSingleNode("PlayerConfig").SelectSingleNode("NickName");
  490. if (nicknameNode == null || string.IsNullOrEmpty(nicknameNode.Attributes[0].Value))
  491. {
  492. SetVisiteeNickName(Language.GetStr("UI", "未命名"));
  493. }
  494. else
  495. {
  496. SetVisiteeNickName(nicknameNode.Attributes[0].Value);
  497. }
  498. InVisit = true;
  499. }
  500. public static void SetPlayerRankPanel()
  501. {
  502. ManaSocial.RecoverRankPanel();
  503. }
  504. public static void SetPlayerPraise()
  505. {
  506. ManaSocial.PraiseText.text = ManaServer.PraiseAmt.ToString();
  507. ManaSocial.PraiseBtn.interactable = false;
  508. ManaSocial.PraiseBtn.image.color = Color.white;
  509. }
  510. public static void SetVisiteePraise(XmlDocument document)
  511. {
  512. ManaSocial.PraiseText.text = VisiteePraise.ToString();
  513. if (document.SelectSingleNode("PlayerConfig").SelectSingleNode("SerialNumber") == null)
  514. {
  515. ManaSocial.EnablePraise();
  516. VisiteeSerialNumber = null;
  517. }
  518. else
  519. {
  520. VisiteeSerialNumber = document.SelectSingleNode("PlayerConfig").SelectSingleNode("SerialNumber").Attributes[0].Value;
  521. //Debug.Log(VisiteeSerialNumber);
  522. ManaServer.Target
  523. (
  524. ManaServer.SerialNumber,
  525. VisiteeSerialNumber,
  526. jsonData =>
  527. {
  528. if (jsonData["i"].ToString() == "0")
  529. {
  530. ManaSocial.EnablePraise();
  531. }
  532. else if (jsonData["i"].ToString() == "1")
  533. {
  534. ManaSocial.DisablePraise();
  535. }
  536. }
  537. );
  538. }
  539. }
  540. public static void SetPlayerCommentPanel()
  541. {
  542. if (ManaSocial.CommentRecordFlag)
  543. {
  544. ManaSocial.RecoverCommentPanel();
  545. }
  546. else
  547. {
  548. //ManaSocial.UpdatePage(true);
  549. }
  550. }
  551. public static void SetVisiteeCommentPanel()
  552. {
  553. ManaSocial.ClearComment();
  554. //ManaSocial.UpdatePage(false);
  555. }
  556. public static void SetPlayerNickName()
  557. {
  558. ManaReso.SetText("C_NickNameLab", ManaNickName.NickName);
  559. }
  560. public static void SetVisiteeNickName(string nickname)
  561. {
  562. ManaReso.SetText("C_NickNameLab", nickname);
  563. }
  564. public static void UpdateCost()
  565. {
  566. if (Complete)
  567. {
  568. Cost = Mathf.FloorToInt((float)Auxiliary.FmlParse(CostFml, "l", ManaCenter.Level.ToString()));
  569. }
  570. }
  571. public static void DataReverse()
  572. {
  573. if (InVisit)
  574. {
  575. VisitPlantList = new List<Slot>(ManaGarden.PlantList);
  576. ManaGarden.PlantList = OriginPlantList;
  577. }
  578. }
  579. public static void DataRecover()
  580. {
  581. if (InVisit)
  582. {
  583. ManaGarden.PlantList = VisitPlantList;
  584. }
  585. }
  586. public static void ShowTip()
  587. {
  588. ManaReso.SetActive ("C_Tip", true);
  589. ManaReso.Get<Text> ("C_TipLab").text = Language.GetStr ("Tip", "Tip" + Random.Range(1,10));
  590. }
  591. public static void HideTip()
  592. {
  593. ManaReso.SetActive ("C_Tip", false);
  594. }
  595. public static void Visit(ArchiveSource archiveSource, string info = null)
  596. {
  597. if (ManaCenter.SceneSwitchLock)
  598. {
  599. return;
  600. }
  601. ManaReso.SetActive("C_EnterPlazaRoom0", false);
  602. ManaCenter.Pay
  603. (
  604. "",
  605. Cost,
  606. Current.Coin,
  607. () =>
  608. {
  609. ManaReso.Get("I_BlackMask").GetTweenCG().Duration = 0.5f;
  610. LoadComplete = false;
  611. TweenComplete = false;
  612. GetArchive(archiveSource, info);
  613. ManaAudio.PlayClip(Clip.BubbleClip);
  614. ManaReso.SetActive("C_Return", false);
  615. TweenRoot tween;
  616. if (CoolTime != 0)
  617. {
  618. ManaReso.Get<Button>("C_Visit").interactable = false;
  619. tween = ManaReso.Get("C_VisitLab").StreamReForScale();
  620. tween.AddEventOnetime
  621. (
  622. EventType.ForwardFinish,
  623. () =>
  624. {
  625. ManaReso.Get<Button>("C_Visit").interactable = true;
  626. }
  627. );
  628. }
  629. tween = ManaReso.Get("I_BlackMask").TweenBacCG();
  630. tween.AddEventOnetime
  631. (
  632. EventType.BackwardFinish,
  633. () =>
  634. {
  635. TweenComplete = true;
  636. EnterVisiteeGarden();
  637. }
  638. );
  639. },
  640. StaticsManager.ItemID.参观花费,
  641. StaticsManager.ConsumeModule.Shop,
  642. false
  643. );
  644. }
  645. public static void GetArchive(ArchiveSource archiveSource, string info = null)
  646. {
  647. //LoadComplete = true;
  648. //XmlStr = Auxiliary.Instance.TextAsset.text;
  649. //VisiteePraise = 0;
  650. //Document = new XmlDocument();
  651. //Document.LoadXml(XmlStr);
  652. ////SetVisiteePraise(Document);
  653. ////SetVisiteeCommentPanel();
  654. //EnterVisiteeGarden();
  655. //Debug.Log(Document.OuterXml);
  656. //return;
  657. if (archiveSource == ArchiveSource.SerialNumber)
  658. {
  659. ManaServer.Other
  660. (
  661. info,
  662. data =>
  663. {
  664. //Debug.LogWarning(data.ToJson());
  665. PullArchiveCallback(data, ShowFailPanel, EnterVisiteeGarden);
  666. }
  667. );
  668. }
  669. else if (archiveSource == ArchiveSource.Random)
  670. {
  671. //Debug.Log($"新存档{UnusedDataList.Count} 已用存档{UsedDataList.Count}");
  672. if (UnusedDataList.Count > 0)
  673. {
  674. EnterVisiteeGarden(UnusedDataList[0].JsonData);
  675. UsedDataList.Add(UnusedDataList[0]);
  676. UnusedDataList.RemoveAt(0);
  677. }
  678. else if (UsedDataList.Count > 0)
  679. {
  680. EnterVisiteeGarden(UsedDataList.Random()[0].JsonData);
  681. }
  682. else
  683. {
  684. ShowFailPanel();
  685. }
  686. }
  687. //else
  688. //{
  689. // LoadComplete = true;
  690. // XmlStr = CreateArchive();
  691. // Document = new XmlDocument();
  692. // Document.LoadXml(XmlStr);
  693. // EnterVisiteeGarden();
  694. //}
  695. }
  696. public static void PullArchiveCallback(JsonData jsonData, Action failed, Action<JsonData> succeed)
  697. {
  698. if (jsonData.Inst_Object.ContainsKey("l"))
  699. {
  700. if (succeed != null)
  701. succeed.Invoke(jsonData);
  702. }
  703. else
  704. {
  705. if (failed != null)
  706. failed.Invoke();
  707. }
  708. }
  709. public static void SavePulledArchive(JsonData jsonData)
  710. {
  711. UnusedDataList.Add(new VisitData() {JsonData = jsonData});
  712. }
  713. public static void EnterVisiteeGarden(JsonData jsonData)
  714. {
  715. LoadComplete = true;
  716. XmlStr = jsonData["l"].ToString();
  717. VisiteePraise = int.Parse(jsonData["p"].ToString());
  718. Document = new XmlDocument();
  719. Document.LoadXml(XmlStr);
  720. SetVisiteeCommentPanel();
  721. EnterVisiteeGarden();
  722. }
  723. public static void ShowFailPanel()
  724. {
  725. Bubble.Show
  726. (
  727. Language.GetStr("UI", "C_VisitFail"),
  728. null,
  729. null,
  730. null,
  731. () =>
  732. {
  733. ManaReso.Get("I_BlackMask").TweenForCG();
  734. ManaReso.SetActive("C_EnterPlazaRoom0", true);
  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. }