ManaVisit.cs 28 KB

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