VisitManager.cs 33 KB

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