ManaVisit.cs 27 KB

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