VisitManager.cs 33 KB

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