ManaVisit.cs 27 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073
  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 ArchiveSource
  11. {
  12. Fake,
  13. Random,
  14. SerialNumber,
  15. }
  16. public class VisitData
  17. {
  18. public bool Praised;
  19. public JsonData JsonData;
  20. }
  21. public class ManaVisit : Regist
  22. {
  23. #region 变量
  24. #region 配置
  25. public static int Cost
  26. {
  27. get { return Cost_; }
  28. set
  29. {
  30. Cost_ = value;
  31. ManaReso.Get<Text>("C_CostLab").text = "<(金币)>" + Cost;
  32. }
  33. }
  34. public static int Cost_;
  35. public static int CoolTime;
  36. public static float FancyRate;
  37. public static float AwardRate;
  38. public static float CreateRate;
  39. public static string CostFml;
  40. public static string AwardMinFml;
  41. public static string AwardMaxFml;
  42. #endregion
  43. public static float PullTimer;
  44. public static List<VisitData> UsedDataList = new List<VisitData>();
  45. public static List<VisitData> UnusedDataList = new List<VisitData>();
  46. public static bool InVisit;
  47. public static bool Complete;
  48. public static bool LoadComplete;
  49. public static bool TweenComplete;
  50. public static string XmlStr;
  51. public static int Slot;
  52. public static int Level;
  53. public static XmlNode Node;
  54. public static XmlDocument Document;
  55. public static int VisiteePraise;
  56. public static string VisiteeSerialNumber;
  57. public static bool OriginBird;
  58. public static bool OriginTree;
  59. public static bool OriginRainbow;
  60. public static List<Slot> VisitPlantList;
  61. public static List<Slot> OriginPlantList;
  62. public static List<ElfType> OriginElfList;
  63. #endregion
  64. public void Update()
  65. {
  66. if (UnusedDataList.Count > 8)
  67. {
  68. return;
  69. }
  70. PullTimer += Time.deltaTime;
  71. if (PullTimer >= 0.5f)
  72. {
  73. PullTimer = 0;
  74. ManaServer.RandomLoad
  75. (
  76. data =>
  77. {
  78. PullArchiveCallback(data, null, SavePulledArchive);
  79. }
  80. );
  81. }
  82. }
  83. public static void Initialize()
  84. {
  85. XmlAttributeCollection attribute = ManaData.GetVisitConfig();
  86. CostFml = attribute[5].Value;
  87. Cost = Mathf.FloorToInt((float)Auxiliary.FmlParse(CostFml, "l", ManaCenter.Level.ToString()));
  88. AwardMinFml = attribute[2].Value;
  89. AwardMaxFml = attribute[3].Value;
  90. CoolTime = int.Parse(attribute[4].Value);
  91. FancyRate = float.Parse(attribute[7].Value);
  92. AwardRate = float.Parse(attribute[1].Value);
  93. CreateRate = float.Parse(attribute[6].Value);
  94. #region 倒计时
  95. if (CoolTime != 0)
  96. {
  97. Text text = ManaReso.Get<Text>("C_VisitLab");
  98. List<float> delayList = new List<float>();
  99. List<float> durationList = new List<float>();
  100. List<VecPair> pairList = new List<VecPair>();
  101. List<UnityAction> actionList = new List<UnityAction>();
  102. Vector3 v1 = new Vector3(0.75f, 0.75f, 0.75f);
  103. Vector3 v2 = new Vector3(0.4f, 0.4f, 0.4f);
  104. Vector3 v3 = new Vector3(0, 0, 0);
  105. for (int i = 0; i < CoolTime - 1; i++)
  106. {
  107. delayList.Add(0.5f);
  108. delayList.Add(0);
  109. }
  110. delayList.Add(0.5f);
  111. for (int i = 0; i < CoolTime; i++)
  112. {
  113. durationList.Add(0.25f);
  114. durationList.Add(0.25f);
  115. pairList.Add(new VecPair(v1, v2));
  116. pairList.Add(new VecPair(v2, v3));
  117. var tempInt = i;
  118. actionList.Add
  119. (
  120. () =>
  121. {
  122. text.text = (CoolTime - tempInt).ToString();
  123. ManaAudio.PlayClip(Clip.BtnClip);
  124. }
  125. );
  126. actionList.Add(null);
  127. }
  128. TweenRoot tween = ManaReso.Get("C_VisitLab").CreateStreamScale
  129. (
  130. delayList,
  131. durationList,
  132. pairList,
  133. true,
  134. false,
  135. Curve.EaseOutQuad,
  136. false,
  137. actionList
  138. );
  139. tween.OnForwardFinish += () =>
  140. {
  141. ManaAudio.PlayClip(Clip.BubbleClip);
  142. };
  143. }
  144. #endregion
  145. Complete = true;
  146. }
  147. public static void ExitVisiteeGarden()
  148. {
  149. ManaReso.Get("I_BlackMask").TweenForCG();
  150. EnableChest();
  151. HideTip ();
  152. ManaReso.SetActive("C_Visit", true);
  153. ManaReso.SetActive("C_Coin", true);
  154. ManaReso.SetActive("C_Group1", true);
  155. ManaReso.SetActive("C_Group2", true);
  156. ManaReso.SetActive("C_Return", false);
  157. ManaReso.SetActive("C_Garden", false);
  158. ManaGarden.MiniLock = true;
  159. #region Garden
  160. ManaGarden.RetriveFlowerAll();
  161. for (int i = 0; i < ManaGarden.PageList.Count; i++)
  162. {
  163. ManaReso.Save(ManaGarden.PageList[i]);
  164. }
  165. ManaGarden.PageList = new List<Transform>();
  166. Garden.CurPage = 0;
  167. ManaGarden.SlotList = new List<Slot>();
  168. ManaGarden.PageList = new List<Transform>();
  169. Garden.ResetPage();
  170. Garden.PagePos = new List<Vector3>();
  171. int pageAmt = 2;
  172. if (ManaGarden.Slot >= 7)
  173. {
  174. pageAmt = (ManaGarden.Slot - 7)/9 + 3;
  175. }
  176. for (int i = 0; i < pageAmt; i++)
  177. {
  178. ManaGarden.CreatePage();
  179. }
  180. for (int i = 0; i < ManaGarden.SlotList.Count; i++)
  181. {
  182. if (i < ManaGarden.Slot)
  183. {
  184. ManaGarden.SlotList[i].Lock = true;
  185. ManaGarden.SlotList[i].Available = true;
  186. }
  187. else
  188. {
  189. ManaGarden.SlotList[i].Lock = false;
  190. ManaGarden.SlotList[i].Available = false;
  191. }
  192. }
  193. List<KV<int, int>> plantList = ManaData.GetPlantList();
  194. for (int i = 0; i < plantList.Count; i++)
  195. {
  196. ManaGarden.PlantFlower(plantList[i].Key, plantList[i].Value);
  197. }
  198. #endregion
  199. #region Bird Tree Rainbow
  200. if (OriginBird)
  201. {
  202. ManaReso.Get("Bird0").GetTweenSr().InDestination = true;
  203. }
  204. else
  205. {
  206. ManaReso.Get("Bird0").GetTweenSr().InOrigin = true;
  207. }
  208. if (OriginTree)
  209. {
  210. ManaReso.Get("Tree1").GetTweenSr().InDestination = true;
  211. ManaReso.Get("Tree2").GetTweenSr().InDestination = true;
  212. }
  213. else
  214. {
  215. ManaReso.Get("Tree1").GetTweenSr().InOrigin = true;
  216. ManaReso.Get("Tree2").GetTweenSr().InOrigin = true;
  217. }
  218. if (OriginRainbow)
  219. {
  220. ManaReso.Get("Rainbow").GetTweenSr().InDestination = true;
  221. }
  222. else
  223. {
  224. ManaReso.Get("Rainbow").GetTweenSr().InOrigin = true;
  225. }
  226. #endregion
  227. #region Player
  228. ManaReso.Save(ManaPlayer.Player);
  229. ManaReso.TraDic.Remove("Player");
  230. ManaPlayer.Instance.GetPlayer();
  231. Garden.PlayerPos = new List<Vector3>();
  232. Garden.Player = ManaReso.Get("Player");
  233. Garden.PlayerPos.Add(ManaPlayer.Player.ChildDic["Pos1"].position);
  234. Garden.PlayerPos.Add(ManaPlayer.Player.ChildDic["Pos2"].position);
  235. #endregion
  236. ManaGarden.ElfList = new List<ElfType>(OriginElfList);
  237. InVisit = false;
  238. LoadComplete = false;
  239. TweenComplete = false;
  240. SetPlayerPraise();
  241. SetPlayerCommentPanel();
  242. SetPlayerRankPanel();
  243. }
  244. public static void EnterVisiteeGarden()
  245. {
  246. if (!LoadComplete || !TweenComplete)
  247. {
  248. return;
  249. }
  250. ManaReso.Get("I_BlackMask").TweenForCG();
  251. DisableChest();
  252. ShowTip ();
  253. Node = Document.SelectSingleNode("PlayerConfig");
  254. ManaReso.SetActive("C_Coin", false);
  255. ManaReso.SetActive("C_Group1", false);
  256. ManaReso.SetActive("C_Group2", false);
  257. ManaReso.SetActive("C_Garden", true);
  258. if (!InVisit)
  259. {
  260. for (int i = 0; i < ManaGarden.StarList.Count; i++)
  261. {
  262. ManaReso.Save(ManaGarden.StarList[i]);
  263. }
  264. ManaGarden.StarList = new List<Star>();
  265. }
  266. ManaReso.SetActive("C_Return", true);
  267. ManaGarden.MiniLock = false;
  268. #region Bird Tree Rainbow
  269. if (!InVisit)
  270. {
  271. if (ManaReso.Get("Bird0").gameObject.activeSelf)
  272. {
  273. OriginBird = true;
  274. }
  275. if (ManaReso.Get("Tree1").gameObject.activeSelf)
  276. {
  277. OriginTree = true;
  278. }
  279. if (ManaReso.Get("Rainbow").gameObject.activeSelf)
  280. {
  281. OriginRainbow = true;
  282. }
  283. }
  284. ManaReso.SetActive("Bird0", false);
  285. ManaReso.SetActive("Tree1", false);
  286. ManaReso.SetActive("Tree2", false);
  287. ManaReso.SetActive("Rainbow", false);
  288. #endregion
  289. #region Ability
  290. Slot = 1;
  291. if (!InVisit)
  292. {
  293. OriginElfList = new List<ElfType>(ManaGarden.ElfList);
  294. }
  295. ManaGarden.ElfList = new List<ElfType>();
  296. List<XmlAttributeCollection> attributeList = ManaData.GetSkillList(Node);
  297. for (int i = 0; i < attributeList.Count; i++)
  298. {
  299. if (!attributeList[i][0].Value.Contains("Ability"))
  300. {
  301. continue;
  302. }
  303. if (attributeList[i][0].Value == "Ability1")
  304. {
  305. Level = int.Parse(attributeList[i][3].Value);
  306. ManaReso.SetText("C_GardenLab", Language.GetStr("UI", "C_GardenLab") + Level);
  307. continue;
  308. }
  309. if (int.Parse(attributeList[i][3].Value) == 0)
  310. {
  311. continue;
  312. }
  313. if (attributeList[i][0].Value == "Ability2")
  314. {
  315. ManaReso.Get("Rainbow").GetTweenSr().InDestination = true;
  316. }
  317. else if (attributeList[i][0].Value == "Ability3")
  318. {
  319. ManaReso.Get("Tree1").GetTweenSr().InDestination = true;
  320. ManaReso.Get("Tree2").GetTweenSr().InDestination = true;
  321. }
  322. else if (attributeList[i][0].Value == "Ability4")
  323. {
  324. ManaReso.Get("Bird0").GetTweenSr().InDestination = true;
  325. }
  326. else if (attributeList[i][0].Value == "Ability5")
  327. {
  328. ManaGarden.ElfList.Add(ElfType.Bee_Yellow);
  329. }
  330. else if (attributeList[i][0].Value == "Ability6")
  331. {
  332. Slot++;
  333. ManaGarden.ElfList.Add(ElfType.Bee_Purple);
  334. }
  335. else if (attributeList[i][0].Value == "Ability7")
  336. {
  337. Slot++;
  338. ManaGarden.ElfList.Add(ElfType.Bee_Blue);
  339. }
  340. else if (attributeList[i][0].Value == "Ability8")
  341. {
  342. Slot++;
  343. ManaGarden.ElfList.Add(ElfType.Bee_Red);
  344. }
  345. else if (attributeList[i][0].Value == "Ability9")
  346. {
  347. Slot++;
  348. ManaGarden.ElfList.Add(ElfType.Bee_White);
  349. }
  350. else if (attributeList[i][0].Value == "Ability10")
  351. {
  352. Slot++;
  353. ManaGarden.ElfList.Add(ElfType.Butterfly_Yellow);
  354. }
  355. else if (attributeList[i][0].Value == "Ability11")
  356. {
  357. Slot++;
  358. ManaGarden.ElfList.Add(ElfType.Butterfly_Purple);
  359. }
  360. else if (attributeList[i][0].Value == "Ability12")
  361. {
  362. Slot++;
  363. ManaGarden.ElfList.Add(ElfType.Butterfly_Blue);
  364. }
  365. else if (attributeList[i][0].Value == "Ability13")
  366. {
  367. Slot++;
  368. ManaGarden.ElfList.Add(ElfType.Butterfly_Red);
  369. }
  370. else if (attributeList[i][0].Value == "Ability14")
  371. {
  372. Slot++;
  373. ManaGarden.ElfList.Add(ElfType.Butterfly_White);
  374. }
  375. else if (attributeList[i][0].Value == "Ability15")
  376. {
  377. Slot++;
  378. ManaGarden.ElfList.Add(ElfType.Dragonfly_Yellow);
  379. }
  380. else if (attributeList[i][0].Value == "Ability16")
  381. {
  382. Slot++;
  383. ManaGarden.ElfList.Add(ElfType.Dragonfly_Purple);
  384. }
  385. else if (attributeList[i][0].Value == "Ability17")
  386. {
  387. Slot++;
  388. ManaGarden.ElfList.Add(ElfType.Dragonfly_Blue);
  389. }
  390. else if (attributeList[i][0].Value == "Ability18")
  391. {
  392. Slot++;
  393. ManaGarden.ElfList.Add(ElfType.Dragonfly_Red);
  394. }
  395. else if (attributeList[i][0].Value == "Ability19")
  396. {
  397. Slot++;
  398. ManaGarden.ElfList.Add(ElfType.Dragonfly_White);
  399. }
  400. else if (attributeList[i][0].Value == "Ability20")
  401. {
  402. Slot++;
  403. ManaGarden.ElfList.Add(ElfType.Beetle_Yellow);
  404. }
  405. else if (attributeList[i][0].Value == "Ability21")
  406. {
  407. Slot++;
  408. ManaGarden.ElfList.Add(ElfType.Beetle_Purple);
  409. }
  410. else if (attributeList[i][0].Value == "Ability22")
  411. {
  412. Slot++;
  413. ManaGarden.ElfList.Add(ElfType.Beetle_Blue);
  414. }
  415. else if (attributeList[i][0].Value == "Ability23")
  416. {
  417. Slot++;
  418. ManaGarden.ElfList.Add(ElfType.Beetle_Red);
  419. }
  420. else if (attributeList[i][0].Value == "Ability24")
  421. {
  422. Slot++;
  423. ManaGarden.ElfList.Add(ElfType.Beetle_White);
  424. }
  425. }
  426. #endregion
  427. #region Garden
  428. if (!InVisit)
  429. {
  430. OriginPlantList = new List<Slot>(ManaGarden.PlantList);
  431. ManaData.SaveDress();
  432. ManaData.SavePlantList();
  433. }
  434. ManaGarden.RetriveFlowerAll();
  435. for (int i = 0; i < ManaGarden.PageList.Count; i++)
  436. {
  437. ManaReso.Save(ManaGarden.PageList[i]);
  438. }
  439. ManaGarden.PageList = new List<Transform>();
  440. Garden.CurPage = 0;
  441. ManaGarden.SlotList = new List<Slot>();
  442. ManaGarden.PageList = new List<Transform>();
  443. Garden.ResetPage();
  444. Garden.PagePos = new List<Vector3>();
  445. int pageAmt = 2;
  446. if (Slot >= 7)
  447. {
  448. pageAmt = (Slot - 7) / 9 + 3;
  449. }
  450. for (int i = 0; i < pageAmt; i++)
  451. {
  452. ManaGarden.CreatePage();
  453. }
  454. for (int i = 0; i < ManaGarden.SlotList.Count; i++)
  455. {
  456. if (i < Slot)
  457. {
  458. ManaGarden.SlotList[i].Lock = true;
  459. ManaGarden.SlotList[i].Available = true;
  460. }
  461. else
  462. {
  463. ManaGarden.SlotList[i].Lock = false;
  464. ManaGarden.SlotList[i].Available = false;
  465. }
  466. }
  467. List<KV<int, int>> plantList = ManaData.GetPlantList(Node);
  468. for (int i = 0; i < plantList.Count; i++)
  469. {
  470. ManaGarden.PlantFlower(plantList[i].Key, plantList[i].Value);
  471. }
  472. #endregion
  473. #region Player
  474. ManaReso.Save(ManaPlayer.Player);
  475. ManaReso.TraDic.Remove("Player");
  476. ManaPlayer.Instance.GetPlayer(Node).SetAllCollider(false);
  477. Garden.PlayerPos = new List<Vector3>();
  478. Garden.Player = ManaReso.Get("Player");
  479. Garden.PlayerPos.Add(ManaPlayer.Player.ChildDic["Pos1"].position);
  480. Garden.PlayerPos.Add(ManaPlayer.Player.ChildDic["Pos2"].position);
  481. #endregion
  482. #region Award
  483. if (ManaTutorial.TutorialC || Random.Range(0f,1f) <= AwardRate)
  484. {
  485. if (ManaTutorial.TutorialC)
  486. {
  487. ManaTutorial.EndC();
  488. }
  489. if (ManaGarden.PlantList.Count > 0)
  490. {
  491. ManaGarden.PlantList.Random()[0].Flower.Award = true;
  492. }
  493. }
  494. #endregion
  495. InVisit = true;
  496. }
  497. public static void SetPlayerRankPanel()
  498. {
  499. ManaSocial.RecoverRankPanel();
  500. }
  501. public static void EnableChest()
  502. {
  503. for (int i = 0; i < ManaIAP.ChestList.Count; i++)
  504. {
  505. ManaIAP.ChestList[i].SetActive(true);
  506. }
  507. }
  508. public static void DisableChest()
  509. {
  510. for (int i = 0; i < ManaIAP.ChestList.Count; i++)
  511. {
  512. ManaIAP.ChestList[i].SetActive(false);
  513. }
  514. }
  515. public static void SetPlayerPraise()
  516. {
  517. ManaSocial.PraiseText.text = ManaServer.PraiseAmt.ToString();
  518. ManaSocial.PraiseBtn.interactable = false;
  519. ManaSocial.PraiseBtn.image.color = Color.white;
  520. }
  521. public static void SetVisiteePraise(XmlDocument document)
  522. {
  523. ManaSocial.PraiseText.text = VisiteePraise.ToString();
  524. if (document.SelectSingleNode("PlayerConfig").SelectSingleNode("SerialNumber") == null)
  525. {
  526. ManaSocial.EnablePraise();
  527. VisiteeSerialNumber = null;
  528. }
  529. else
  530. {
  531. VisiteeSerialNumber = document.SelectSingleNode("PlayerConfig").SelectSingleNode("SerialNumber").Attributes[0].Value;
  532. ManaServer.Target
  533. (
  534. ManaServer.SerialNumber,
  535. VisiteeSerialNumber,
  536. jsonData =>
  537. {
  538. if (jsonData["i"].ToString() == "0")
  539. {
  540. ManaSocial.EnablePraise();
  541. }
  542. else if (jsonData["i"].ToString() == "1")
  543. {
  544. ManaSocial.DisablePraise();
  545. }
  546. }
  547. );
  548. }
  549. }
  550. public static void SetPlayerCommentPanel()
  551. {
  552. if (ManaSocial.CommentRecordFlag)
  553. {
  554. ManaSocial.RecoverCommentPanel();
  555. }
  556. else
  557. {
  558. ManaSocial.UpdatePage(true);
  559. }
  560. }
  561. public static void SetVisiteeCommentPanel()
  562. {
  563. ManaSocial.ClearComment();
  564. ManaSocial.UpdatePage(false);
  565. }
  566. public static void UpdateCost()
  567. {
  568. if (Complete)
  569. {
  570. Cost = Mathf.FloorToInt((float)Auxiliary.FmlParse(CostFml, "l", ManaCenter.Level.ToString()));
  571. }
  572. }
  573. public static void DataReverse()
  574. {
  575. if (InVisit)
  576. {
  577. VisitPlantList = new List<Slot>(ManaGarden.PlantList);
  578. ManaGarden.PlantList = OriginPlantList;
  579. }
  580. }
  581. public static void DataRecover()
  582. {
  583. if (InVisit)
  584. {
  585. ManaGarden.PlantList = VisitPlantList;
  586. }
  587. }
  588. public static void ShowTip()
  589. {
  590. ManaReso.SetActive ("C_Tip", true);
  591. ManaReso.Get<Text> ("C_TipLab").text = Language.GetStr ("Tip", "Tip" + Random.Range(1,10));
  592. }
  593. public static void HideTip()
  594. {
  595. ManaReso.SetActive ("C_Tip", false);
  596. }
  597. public static void Visit(ArchiveSource archiveSource, string info = null)
  598. {
  599. if (ManaCenter.SceneSwitchLock)
  600. {
  601. return;
  602. }
  603. ManaCenter.Pay
  604. (
  605. "",
  606. Cost,
  607. Current.Coin,
  608. () =>
  609. {
  610. ManaReso.Get("I_BlackMask").GetTweenCG().Duration = 0.5f;
  611. LoadComplete = false;
  612. TweenComplete = false;
  613. GetArchive(archiveSource, info);
  614. ManaAudio.PlayClip(Clip.BubbleClip);
  615. ManaReso.SetActive("C_Return", false);
  616. TweenRoot tween;
  617. if (CoolTime != 0)
  618. {
  619. ManaReso.Get<Button>("C_Visit").interactable = false;
  620. tween = ManaReso.Get("C_VisitLab").StreamReForScale();
  621. tween.AddEventOnetime
  622. (
  623. EventType.ForwardFinish,
  624. () =>
  625. {
  626. ManaReso.Get<Button>("C_Visit").interactable = true;
  627. }
  628. );
  629. }
  630. tween = ManaReso.Get("I_BlackMask").TweenBacCG();
  631. tween.AddEventOnetime
  632. (
  633. EventType.BackwardFinish,
  634. () =>
  635. {
  636. TweenComplete = true;
  637. EnterVisiteeGarden();
  638. }
  639. );
  640. },
  641. StaticsManager.ItemID.参观花费,
  642. StaticsManager.ConsumeModule.Shop,
  643. false
  644. );
  645. }
  646. public static void GetArchive(ArchiveSource archiveSource, string info = null)
  647. {
  648. //LoadComplete = true;
  649. //XmlStr = Auxiliary.Instance.TextAsset.text;
  650. //VisiteePraise = 0;
  651. //Document = new XmlDocument();
  652. //Document.LoadXml(XmlStr);
  653. ////SetVisiteePraise(Document);
  654. ////SetVisiteeCommentPanel();
  655. //EnterVisiteeGarden();
  656. //Debug.Log(Document.OuterXml);
  657. //return;
  658. if (archiveSource == ArchiveSource.SerialNumber)
  659. {
  660. ManaServer.Other
  661. (
  662. info,
  663. data =>
  664. {
  665. PullArchiveCallback(data, ShowFailPanel, EnterVisiteeGarden);
  666. }
  667. );
  668. }
  669. else if (archiveSource == ArchiveSource.Random)
  670. {
  671. //Debug.Log($"新存档{UnusedDataList.Count} 已用存档{UsedDataList.Count}");
  672. if (UnusedDataList.Count > 0)
  673. {
  674. EnterVisiteeGarden(UnusedDataList[0].JsonData);
  675. UsedDataList.Add(UnusedDataList[0]);
  676. UnusedDataList.RemoveAt(0);
  677. }
  678. else if (UsedDataList.Count > 0)
  679. {
  680. EnterVisiteeGarden(UsedDataList.Random()[0].JsonData);
  681. }
  682. else
  683. {
  684. ShowFailPanel();
  685. }
  686. }
  687. else
  688. {
  689. LoadComplete = true;
  690. XmlStr = CreateArchive();
  691. Document = new XmlDocument();
  692. Document.LoadXml(XmlStr);
  693. EnterVisiteeGarden();
  694. }
  695. }
  696. public static void PullArchiveCallback(JsonData jsonData, Action failed, Action<JsonData> succeed)
  697. {
  698. if (jsonData.Inst_Object.ContainsKey("l"))
  699. {
  700. if (succeed != null)
  701. succeed.Invoke(jsonData);
  702. }
  703. else
  704. {
  705. if (failed != null)
  706. failed.Invoke();
  707. }
  708. }
  709. public static void SavePulledArchive(JsonData jsonData)
  710. {
  711. UnusedDataList.Add(new VisitData() {JsonData = jsonData});
  712. }
  713. public static void EnterVisiteeGarden(JsonData jsonData)
  714. {
  715. LoadComplete = true;
  716. XmlStr = jsonData["l"].ToString();
  717. VisiteePraise = int.Parse(jsonData["p"].ToString());
  718. Document = new XmlDocument();
  719. Document.LoadXml(XmlStr);
  720. SetVisiteePraise(Document);
  721. SetVisiteeCommentPanel();
  722. EnterVisiteeGarden();
  723. }
  724. public static void ShowFailPanel()
  725. {
  726. Bubble.Show
  727. (
  728. Language.GetStr("UI", "C_VisitFail"),
  729. null,
  730. null,
  731. null,
  732. () =>
  733. {
  734. ManaReso.Get("I_BlackMask").TweenForCG();
  735. },
  736. null,
  737. false
  738. );
  739. ManaCenter.AddCoin(Cost, StaticsManager.ItemID.获得金币, StaticsManager.ConsumeModule.VisitRefund);
  740. }
  741. public static string CreateArchive()
  742. {
  743. XmlDocument doc = new XmlDocument();
  744. doc.LoadXml(ManaData.PlayerDoc.OuterXml); //以自己的存档做模板进行修改
  745. int newLevel = Random.Range(1, 450); //随机等级
  746. #region 根据等级确定有多少土地解锁
  747. int slot = 1; //解锁土地数量
  748. XmlNodeList nodeList = doc.SelectSingleNode("PlayerConfig").SelectSingleNode("SkillList").ChildNodes;
  749. for (int i = 0; i < nodeList.Count; i++)
  750. {
  751. SkillType type = nodeList[i].Attributes[1].Value.ToEnum<SkillType>();
  752. if (type == SkillType.Ability)
  753. {
  754. Ability ability = (Ability)ManaCenter.SkillDic[nodeList[i].Attributes[0].Value];
  755. int unlockLevel = ability.UnlockLv;
  756. if (newLevel >= unlockLevel)
  757. {
  758. if (ability.ID_ >= 6)
  759. {
  760. slot++;
  761. }
  762. nodeList[i].Attributes[2].Value = "Upgrade";
  763. nodeList[i].Attributes[3].Value = newLevel.ToString();
  764. }
  765. else
  766. {
  767. nodeList[i].Attributes[2].Value = "Lock";
  768. nodeList[i].Attributes[3].Value = "0";
  769. }
  770. }
  771. }
  772. #endregion
  773. #region 随机种一些花
  774. bool fancy = Random.Range(0f, 1f) < FancyRate; //fancy=True时 种的花比较多
  775. List<int> flowerList = new List<int>();
  776. for (int i = 1; i < 36; i++)
  777. {
  778. flowerList.Add(i);
  779. }
  780. int slotIndex = 0;
  781. string plantList = "";
  782. for (int i = 0; i < slot; i++)
  783. {
  784. if (fancy || Random.Range(0f, 1f) >= 0.35f)
  785. {
  786. int flowerID = slotIndex + 1;
  787. plantList += string.Format("{0},{1} ", flowerID, slotIndex);
  788. slotIndex++;
  789. }
  790. }
  791. plantList = plantList.TrimEnd(' ');
  792. doc.SelectSingleNode("PlayerConfig").SelectSingleNode("PlantList").Attributes[0].Value = plantList;
  793. #endregion
  794. #region 随机一套服装 等级越高拥有的服装越多 再随机选几件穿上
  795. XmlNode xmlNode = doc.SelectSingleNode("PlayerConfig").SelectSingleNode("DressData");
  796. xmlNode.Attributes[0].Value = "";
  797. xmlNode.Attributes[0].Value = ManaPlayer.CloseUnitDic[Random.Range(2, (int)Mathf.Lerp(2, 30, newLevel / 449f) + 1)].ArmatureName;
  798. xmlNode.Attributes[1].Value = ManaPlayer.CloseUnitDic[Random.Range(201, (int)Mathf.Lerp(201, 217, newLevel / 449f) + 1)].ArmatureName;
  799. xmlNode.Attributes[2].Value = ManaPlayer.CloseUnitDic[Random.Range(401, (int)Mathf.Lerp(401, 415, newLevel / 449f) + 1)].ArmatureName;
  800. xmlNode.Attributes[3].Value = ManaPlayer.CloseUnitDic[Random.Range(601, (int)Mathf.Lerp(601, 612, newLevel / 449f) + 1)].ArmatureName;
  801. xmlNode.Attributes[4].Value = ManaPlayer.CloseUnitDic[Random.Range(801, (int)Mathf.Lerp(801, 817, newLevel / 449f) + 1)].ArmatureName;
  802. xmlNode.Attributes[7].Value = ManaPlayer.CloseUnitDic[Random.Range(1001, (int)Mathf.Lerp(1001, 1003, newLevel / 449f) + 1)].ArmatureName;
  803. #region 随机选一套眼睛嘴巴
  804. float eyeMouseRate = Random.Range(0f, 1f);
  805. if (eyeMouseRate <= 0.33f)
  806. {
  807. xmlNode.Attributes[5].Value = "眼睛1";
  808. xmlNode.Attributes[6].Value = "嘴巴1";
  809. }
  810. else if (eyeMouseRate <= 0.66f)
  811. {
  812. xmlNode.Attributes[5].Value = "眼睛2";
  813. xmlNode.Attributes[6].Value = "嘴巴2";
  814. }
  815. else
  816. {
  817. xmlNode.Attributes[5].Value = "眼睛3";
  818. xmlNode.Attributes[6].Value = "嘴巴3";
  819. }
  820. #endregion
  821. #endregion
  822. return doc.OuterXml;
  823. }
  824. }