VisitManager.cs 34 KB

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