VisitManager.cs 37 KB

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