ManaVisit.cs 25 KB

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