VisitManager.cs 33 KB

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