ManaVisit.cs 28 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070
  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. HideTip ();
  151. ManaReso.SetActive("C_Visit", true);
  152. ManaReso.SetActive("C_Coin", true);
  153. ManaReso.SetActive("C_Group1", true);
  154. ManaReso.SetActive("C_Group2", true);
  155. ManaReso.Get<Button>("C_NickNameBK").interactable = 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. ManaUI.SetEnterGameLabel();
  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. SetPlayerNickName();
  244. }
  245. public static void EnterVisiteeGarden()
  246. {
  247. if (!LoadComplete || !TweenComplete)
  248. {
  249. return;
  250. }
  251. ManaReso.Get("I_BlackMask").TweenForCG();
  252. //Debug.Log(Document.OuterXml);
  253. SetVisiteePraise(Document);
  254. ShowTip ();
  255. Node = Document.SelectSingleNode("PlayerConfig");
  256. ManaReso.SetActive("C_Coin", false);
  257. ManaReso.SetActive("C_Group1", false);
  258. ManaReso.SetActive("C_Group2", false);
  259. ManaReso.Get<Button>("C_NickNameBK").interactable = false;
  260. ManaReso.SetActive("C_Garden", true);
  261. if (!InVisit)
  262. {
  263. ManaGarden.RetrieveAllStar();
  264. ManaGarden.RetrieveAllElf();
  265. ManaIAP.RetrieveADChest();
  266. ManaGarden.StarList = new List<Star>();
  267. }
  268. ManaReso.SetActive("C_Return", true);
  269. ManaGarden.MiniLock = false;
  270. #region Bird Tree Rainbow
  271. if (!InVisit)
  272. {
  273. if (ManaReso.Get("Bird0").gameObject.activeSelf)
  274. {
  275. OriginBird = true;
  276. }
  277. if (ManaReso.Get("Tree1").gameObject.activeSelf)
  278. {
  279. OriginTree = true;
  280. }
  281. if (ManaReso.Get("Rainbow").gameObject.activeSelf)
  282. {
  283. OriginRainbow = true;
  284. }
  285. }
  286. ManaReso.SetActive("Bird0", false);
  287. ManaReso.SetActive("Tree1", false);
  288. ManaReso.SetActive("Tree2", false);
  289. ManaReso.SetActive("Rainbow", false);
  290. #endregion
  291. #region Ability
  292. Slot = 1;
  293. if (!InVisit)
  294. {
  295. OriginElfList = new List<ElfType>(ManaGarden.ElfList);
  296. }
  297. ManaGarden.ElfList = new List<ElfType>();
  298. List<XmlAttributeCollection> attributeList = ManaData.GetSkillList(Node);
  299. for (int i = 0; i < attributeList.Count; i++)
  300. {
  301. if (!attributeList[i][0].Value.Contains("Ability"))
  302. {
  303. continue;
  304. }
  305. if (attributeList[i][0].Value == "Ability1")
  306. {
  307. Level = int.Parse(attributeList[i][3].Value);
  308. ManaReso.SetText("C_GardenLab", Language.GetStr("UI", "C_GardenLab") + Level);
  309. continue;
  310. }
  311. if (int.Parse(attributeList[i][3].Value) == 0)
  312. {
  313. continue;
  314. }
  315. if (attributeList[i][0].Value == "Ability2")
  316. {
  317. ManaReso.Get("Rainbow").GetTweenSr().InDestination = true;
  318. }
  319. else if (attributeList[i][0].Value == "Ability3")
  320. {
  321. ManaReso.Get("Tree1").GetTweenSr().InDestination = true;
  322. ManaReso.Get("Tree2").GetTweenSr().InDestination = true;
  323. }
  324. else if (attributeList[i][0].Value == "Ability4")
  325. {
  326. ManaReso.Get("Bird0").GetTweenSr().InDestination = true;
  327. }
  328. else if (attributeList[i][0].Value == "Ability5")
  329. {
  330. ManaGarden.ElfList.Add(ElfType.Bee_Yellow);
  331. }
  332. else if (attributeList[i][0].Value == "Ability6")
  333. {
  334. Slot++;
  335. ManaGarden.ElfList.Add(ElfType.Bee_Purple);
  336. }
  337. else if (attributeList[i][0].Value == "Ability7")
  338. {
  339. Slot++;
  340. ManaGarden.ElfList.Add(ElfType.Bee_Blue);
  341. }
  342. else if (attributeList[i][0].Value == "Ability8")
  343. {
  344. Slot++;
  345. ManaGarden.ElfList.Add(ElfType.Bee_Red);
  346. }
  347. else if (attributeList[i][0].Value == "Ability9")
  348. {
  349. Slot++;
  350. ManaGarden.ElfList.Add(ElfType.Bee_White);
  351. }
  352. else if (attributeList[i][0].Value == "Ability10")
  353. {
  354. Slot++;
  355. ManaGarden.ElfList.Add(ElfType.Butterfly_Yellow);
  356. }
  357. else if (attributeList[i][0].Value == "Ability11")
  358. {
  359. Slot++;
  360. ManaGarden.ElfList.Add(ElfType.Butterfly_Purple);
  361. }
  362. else if (attributeList[i][0].Value == "Ability12")
  363. {
  364. Slot++;
  365. ManaGarden.ElfList.Add(ElfType.Butterfly_Blue);
  366. }
  367. else if (attributeList[i][0].Value == "Ability13")
  368. {
  369. Slot++;
  370. ManaGarden.ElfList.Add(ElfType.Butterfly_Red);
  371. }
  372. else if (attributeList[i][0].Value == "Ability14")
  373. {
  374. Slot++;
  375. ManaGarden.ElfList.Add(ElfType.Butterfly_White);
  376. }
  377. else if (attributeList[i][0].Value == "Ability15")
  378. {
  379. Slot++;
  380. ManaGarden.ElfList.Add(ElfType.Dragonfly_Yellow);
  381. }
  382. else if (attributeList[i][0].Value == "Ability16")
  383. {
  384. Slot++;
  385. ManaGarden.ElfList.Add(ElfType.Dragonfly_Purple);
  386. }
  387. else if (attributeList[i][0].Value == "Ability17")
  388. {
  389. Slot++;
  390. ManaGarden.ElfList.Add(ElfType.Dragonfly_Blue);
  391. }
  392. else if (attributeList[i][0].Value == "Ability18")
  393. {
  394. Slot++;
  395. ManaGarden.ElfList.Add(ElfType.Dragonfly_Red);
  396. }
  397. else if (attributeList[i][0].Value == "Ability19")
  398. {
  399. Slot++;
  400. ManaGarden.ElfList.Add(ElfType.Dragonfly_White);
  401. }
  402. else if (attributeList[i][0].Value == "Ability20")
  403. {
  404. Slot++;
  405. ManaGarden.ElfList.Add(ElfType.Beetle_Yellow);
  406. }
  407. else if (attributeList[i][0].Value == "Ability21")
  408. {
  409. Slot++;
  410. ManaGarden.ElfList.Add(ElfType.Beetle_Purple);
  411. }
  412. else if (attributeList[i][0].Value == "Ability22")
  413. {
  414. Slot++;
  415. ManaGarden.ElfList.Add(ElfType.Beetle_Blue);
  416. }
  417. else if (attributeList[i][0].Value == "Ability23")
  418. {
  419. Slot++;
  420. ManaGarden.ElfList.Add(ElfType.Beetle_Red);
  421. }
  422. else if (attributeList[i][0].Value == "Ability24")
  423. {
  424. Slot++;
  425. ManaGarden.ElfList.Add(ElfType.Beetle_White);
  426. }
  427. }
  428. #endregion
  429. #region Garden
  430. if (!InVisit)
  431. {
  432. OriginPlantList = new List<Slot>(ManaGarden.PlantList);
  433. ManaData.SaveDress();
  434. ManaData.SavePlantList();
  435. }
  436. ManaGarden.RetriveFlowerAll();
  437. for (int i = 0; i < ManaGarden.PageList.Count; i++)
  438. {
  439. ManaReso.Save(ManaGarden.PageList[i]);
  440. }
  441. ManaGarden.PageList = new List<Transform>();
  442. ManaGarden.SlotList = new List<Slot>();
  443. ManaGarden.PageList = new List<Transform>();
  444. Garden.ResetPage();
  445. Garden.PagePos = new List<Vector3>();
  446. int pageAmt = 2;
  447. if (Slot >= 7)
  448. {
  449. pageAmt = (Slot - 7) / 9 + 3;
  450. }
  451. for (int i = 0; i < pageAmt; i++)
  452. {
  453. ManaGarden.CreatePage();
  454. }
  455. for (int i = 0; i < ManaGarden.SlotList.Count; i++)
  456. {
  457. if (i < Slot)
  458. {
  459. ManaGarden.SlotList[i].Lock = true;
  460. ManaGarden.SlotList[i].Available = true;
  461. }
  462. else
  463. {
  464. ManaGarden.SlotList[i].Lock = false;
  465. ManaGarden.SlotList[i].Available = false;
  466. }
  467. }
  468. List<KV<int, int>> plantList = ManaData.GetPlantList(Node);
  469. for (int i = 0; i < plantList.Count; i++)
  470. {
  471. ManaGarden.PlantFlower(plantList[i].Key, plantList[i].Value);
  472. }
  473. #endregion
  474. #region Player
  475. ManaReso.Save(ManaPlayer.Player);
  476. ManaReso.TraDic.Remove("Player");
  477. ManaPlayer.Instance.GetPlayer(Node).SetAllCollider(false);
  478. Garden.PlayerPos = new List<Vector3>();
  479. Garden.Player = ManaReso.Get("Player");
  480. Garden.PlayerPos.Add(ManaPlayer.Player.ChildDic["Pos1"].position);
  481. Garden.PlayerPos.Add(ManaPlayer.Player.ChildDic["Pos2"].position);
  482. #endregion
  483. #region Award
  484. if (Random.Range(0f,1f) <= AwardRate)
  485. {
  486. if (ManaGarden.PlantList.Count > 0)
  487. {
  488. ManaGarden.PlantList.Random()[0].Flower.Award = true;
  489. }
  490. }
  491. #endregion
  492. XmlNode nicknameNode = Document.SelectSingleNode("PlayerConfig").SelectSingleNode("NickName");
  493. if (nicknameNode == null || string.IsNullOrEmpty(nicknameNode.Attributes[0].Value))
  494. {
  495. SetVisiteeNickName(Language.GetStr("UI", "未命名"));
  496. }
  497. else
  498. {
  499. SetVisiteeNickName(nicknameNode.Attributes[0].Value);
  500. }
  501. InVisit = true;
  502. }
  503. public static void SetPlayerRankPanel()
  504. {
  505. ManaSocial.RecoverRankPanel();
  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. //Debug.Log(VisiteeSerialNumber);
  517. ManaServer.Target
  518. (
  519. ManaServer.SerialNumber,
  520. VisiteeSerialNumber,
  521. jsonData =>
  522. {
  523. if (jsonData["i"].ToString() == "0")
  524. {
  525. ManaSocial.EnablePraise();
  526. }
  527. else if (jsonData["i"].ToString() == "1")
  528. {
  529. ManaSocial.DisablePraise();
  530. }
  531. }
  532. );
  533. }
  534. public static void SetPlayerCommentPanel()
  535. {
  536. if (ManaSocial.CommentRecordFlag)
  537. {
  538. ManaSocial.RecoverCommentPanel();
  539. }
  540. else
  541. {
  542. //ManaSocial.UpdatePage(true);
  543. }
  544. }
  545. public static void SetVisiteeCommentPanel()
  546. {
  547. ManaSocial.ClearComment();
  548. //ManaSocial.UpdatePage(false);
  549. }
  550. public static void SetPlayerNickName()
  551. {
  552. ManaReso.SetText("C_NickNameLab", ManaNickName.NickName);
  553. }
  554. public static void SetVisiteeNickName(string nickname)
  555. {
  556. ManaReso.SetText("C_NickNameLab", nickname);
  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. ManaReso.SetActive("C_EnterPlazaRoom0", false);
  596. ManaCenter.Pay
  597. (
  598. "",
  599. Cost,
  600. Current.Coin,
  601. () =>
  602. {
  603. ManaReso.Get("I_BlackMask").GetTweenCG().Duration = 0.5f;
  604. LoadComplete = false;
  605. TweenComplete = false;
  606. GetArchive(archiveSource, info);
  607. ManaAudio.PlayClip(Clip.BubbleClip);
  608. ManaReso.SetActive("C_Return", false);
  609. TweenRoot tween;
  610. if (CoolTime != 0)
  611. {
  612. ManaReso.Get<Button>("C_Visit").interactable = false;
  613. tween = ManaReso.Get("C_VisitLab").StreamReForScale();
  614. tween.AddEventOnetime
  615. (
  616. EventType.ForwardFinish,
  617. () =>
  618. {
  619. ManaReso.Get<Button>("C_Visit").interactable = true;
  620. }
  621. );
  622. }
  623. tween = ManaReso.Get("I_BlackMask").TweenBacCG();
  624. tween.AddEventOnetime
  625. (
  626. EventType.BackwardFinish,
  627. () =>
  628. {
  629. TweenComplete = true;
  630. EnterVisiteeGarden();
  631. }
  632. );
  633. },
  634. StaticsManager.ItemID.参观花费,
  635. StaticsManager.ConsumeModule.Shop,
  636. false
  637. );
  638. }
  639. public static void GetArchive(ArchiveSource archiveSource, string info = null)
  640. {
  641. //LoadComplete = true;
  642. //XmlStr = Auxiliary.Instance.TextAsset.text;
  643. //VisiteePraise = 0;
  644. //Document = new XmlDocument();
  645. //Document.LoadXml(XmlStr);
  646. ////SetVisiteePraise(Document);
  647. ////SetVisiteeCommentPanel();
  648. //EnterVisiteeGarden();
  649. //Debug.Log(Document.OuterXml);
  650. //return;
  651. if (archiveSource == ArchiveSource.SerialNumber)
  652. {
  653. ManaServer.Other
  654. (
  655. info,
  656. data =>
  657. {
  658. //Debug.LogWarning(data.ToJson());
  659. VisiteeSerialNumber = info;
  660. PullArchiveCallback(data, ShowFailPanel, EnterVisiteeGarden);
  661. }
  662. );
  663. }
  664. else if (archiveSource == ArchiveSource.Random)
  665. {
  666. //Debug.Log($"新存档{UnusedDataList.Count} 已用存档{UsedDataList.Count}");
  667. if (UnusedDataList.Count > 0)
  668. {
  669. EnterVisiteeGarden(UnusedDataList[0].JsonData);
  670. UsedDataList.Add(UnusedDataList[0]);
  671. UnusedDataList.RemoveAt(0);
  672. }
  673. else if (UsedDataList.Count > 0)
  674. {
  675. EnterVisiteeGarden(UsedDataList.Random()[0].JsonData);
  676. }
  677. else
  678. {
  679. ShowFailPanel();
  680. }
  681. }
  682. //else
  683. //{
  684. // LoadComplete = true;
  685. // XmlStr = CreateArchive();
  686. // Document = new XmlDocument();
  687. // Document.LoadXml(XmlStr);
  688. // EnterVisiteeGarden();
  689. //}
  690. }
  691. public static void PullArchiveCallback(JsonData jsonData, Action failed, Action<JsonData> succeed)
  692. {
  693. if (jsonData.Inst_Object.ContainsKey("l"))
  694. {
  695. if (succeed != null)
  696. succeed.Invoke(jsonData);
  697. }
  698. else
  699. {
  700. if (failed != null)
  701. failed.Invoke();
  702. }
  703. }
  704. public static void SavePulledArchive(JsonData jsonData)
  705. {
  706. UnusedDataList.Add(new VisitData() {JsonData = jsonData});
  707. }
  708. public static void EnterVisiteeGarden(JsonData jsonData)
  709. {
  710. LoadComplete = true;
  711. //Debug.Log(jsonData.ToJson());
  712. XmlStr = jsonData["l"].ToString();
  713. VisiteePraise = int.Parse(jsonData["p"].ToString());
  714. if (jsonData.Inst_Object.ContainsKey("i"))
  715. {
  716. VisiteeSerialNumber = jsonData["i"].ToString();
  717. }
  718. Document = new XmlDocument();
  719. Document.LoadXml(XmlStr);
  720. SetVisiteeCommentPanel();
  721. EnterVisiteeGarden();
  722. }
  723. public static void ShowFailPanel()
  724. {
  725. Bubble.Show
  726. (
  727. Language.GetStr("UI", "C_VisitFail"),
  728. null,
  729. null,
  730. null,
  731. () =>
  732. {
  733. ManaReso.Get("I_BlackMask").TweenForCG();
  734. ManaReso.SetActive("C_EnterPlazaRoom0", true);
  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. }