VisitManager.cs 33 KB

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