VisitManager.cs 32 KB

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