ManaVisit.cs 25 KB

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