VisitManager.cs 32 KB

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