VisitManager.cs 31 KB

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