VisitManager.cs 33 KB

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