VisitManager.cs 29 KB

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