ManaVisit.cs 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978
  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. Fake,
  11. Random,
  12. SerialNumber,
  13. }
  14. public class ManaVisit
  15. {
  16. #region 变量
  17. #region 配置
  18. public static int Cost
  19. {
  20. get { return Cost_; }
  21. set
  22. {
  23. Cost_ = value;
  24. ManaReso.Get<Text>("C_CostLab").text = "<(金币)>" + Cost;
  25. }
  26. }
  27. public static int Cost_;
  28. public static int CoolTime;
  29. public static float FancyRate;
  30. public static float AwardRate;
  31. public static float CreateRate;
  32. public static string CostFml;
  33. public static string AwardMinFml;
  34. public static string AwardMaxFml;
  35. #endregion
  36. public static bool InVisit;
  37. public static bool Complete;
  38. public static bool LoadComplete;
  39. public static bool TweenComplete;
  40. public static string XmlStr;
  41. public static int Slot;
  42. public static int Level;
  43. public static XmlNode Node;
  44. public static XmlDocument Document;
  45. public static int VisiteePraise;
  46. public static string VisiteeSerialNumber;
  47. public static bool OriginBird;
  48. public static bool OriginTree;
  49. public static bool OriginRainbow;
  50. public static List<Slot> VisitPlantList;
  51. public static List<Slot> OriginPlantList;
  52. public static List<ElfType> OriginElfList;
  53. #endregion
  54. public static void Initialize()
  55. {
  56. XmlAttributeCollection attribute = ManaData.GetVisitConfig();
  57. CostFml = attribute[5].Value;
  58. Cost = Mathf.FloorToInt((float)Auxiliary.FmlParse(CostFml, "l", ManaCenter.Level.ToString()));
  59. AwardMinFml = attribute[2].Value;
  60. AwardMaxFml = attribute[3].Value;
  61. CoolTime = int.Parse(attribute[4].Value);
  62. FancyRate = float.Parse(attribute[7].Value);
  63. AwardRate = float.Parse(attribute[1].Value);
  64. CreateRate = float.Parse(attribute[6].Value);
  65. #region 倒计时
  66. if (CoolTime != 0)
  67. {
  68. Text text = ManaReso.Get<Text>("C_VisitLab");
  69. List<float> delayList = new List<float>();
  70. List<float> durationList = new List<float>();
  71. List<VecPair> pairList = new List<VecPair>();
  72. List<UnityAction> actionList = new List<UnityAction>();
  73. Vector3 v1 = new Vector3(0.75f, 0.75f, 0.75f);
  74. Vector3 v2 = new Vector3(0.4f, 0.4f, 0.4f);
  75. Vector3 v3 = new Vector3(0, 0, 0);
  76. for (int i = 0; i < CoolTime - 1; i++)
  77. {
  78. delayList.Add(0.5f);
  79. delayList.Add(0);
  80. }
  81. delayList.Add(0.5f);
  82. for (int i = 0; i < CoolTime; i++)
  83. {
  84. durationList.Add(0.25f);
  85. durationList.Add(0.25f);
  86. pairList.Add(new VecPair(v1, v2));
  87. pairList.Add(new VecPair(v2, v3));
  88. var tempInt = i;
  89. actionList.Add
  90. (
  91. () =>
  92. {
  93. text.text = (CoolTime - tempInt).ToString();
  94. ManaAudio.PlayClip(Clip.BtnClip);
  95. }
  96. );
  97. actionList.Add(null);
  98. }
  99. TweenRoot tween = ManaReso.Get("C_VisitLab").CreateStreamScale
  100. (
  101. delayList,
  102. durationList,
  103. pairList,
  104. true,
  105. false,
  106. Curve.EaseOutQuad,
  107. false,
  108. actionList
  109. );
  110. tween.OnForwardFinish += () =>
  111. {
  112. ManaAudio.PlayClip(Clip.BubbleClip);
  113. };
  114. }
  115. #endregion
  116. Complete = true;
  117. }
  118. public static void Exit()
  119. {
  120. ManaReso.Get("I_BlackMask").TweenForCG();
  121. EnableChest();
  122. HideTip ();
  123. ManaReso.SetActive("C_Visit", true);
  124. ManaReso.SetActive("C_Coin", true);
  125. ManaReso.SetActive("C_Group1", true);
  126. ManaReso.SetActive("C_Group2", true);
  127. ManaReso.SetActive("C_Return", false);
  128. ManaReso.SetActive("C_Garden", false);
  129. ManaGarden.MiniLock = true;
  130. #region Garden
  131. ManaGarden.RetriveFlowerAll();
  132. for (int i = 0; i < ManaGarden.PageList.Count; i++)
  133. {
  134. ManaReso.Save(ManaGarden.PageList[i]);
  135. }
  136. ManaGarden.PageList = new List<Transform>();
  137. Garden.CurPage = 0;
  138. ManaGarden.SlotList = new List<Slot>();
  139. ManaGarden.PageList = new List<Transform>();
  140. Garden.ResetPage();
  141. Garden.PagePos = new List<Vector3>();
  142. int pageAmt = 2;
  143. if (ManaGarden.Slot >= 7)
  144. {
  145. pageAmt = (ManaGarden.Slot - 7)/9 + 3;
  146. }
  147. for (int i = 0; i < pageAmt; i++)
  148. {
  149. ManaGarden.CreatePage();
  150. }
  151. for (int i = 0; i < ManaGarden.SlotList.Count; i++)
  152. {
  153. if (i < ManaGarden.Slot)
  154. {
  155. ManaGarden.SlotList[i].Lock = true;
  156. ManaGarden.SlotList[i].Available = true;
  157. }
  158. else
  159. {
  160. ManaGarden.SlotList[i].Lock = false;
  161. ManaGarden.SlotList[i].Available = false;
  162. }
  163. }
  164. List<KV<int, int>> plantList = ManaData.GetPlantList();
  165. for (int i = 0; i < plantList.Count; i++)
  166. {
  167. ManaGarden.PlantFlower(plantList[i].Key, plantList[i].Value);
  168. }
  169. #endregion
  170. #region Bird Tree Rainbow
  171. if (OriginBird)
  172. {
  173. ManaReso.Get("Bird0").GetTweenSr().InDestination = true;
  174. }
  175. else
  176. {
  177. ManaReso.Get("Bird0").GetTweenSr().InOrigin = true;
  178. }
  179. if (OriginTree)
  180. {
  181. ManaReso.Get("Tree1").GetTweenSr().InDestination = true;
  182. ManaReso.Get("Tree2").GetTweenSr().InDestination = true;
  183. }
  184. else
  185. {
  186. ManaReso.Get("Tree1").GetTweenSr().InOrigin = true;
  187. ManaReso.Get("Tree2").GetTweenSr().InOrigin = true;
  188. }
  189. if (OriginRainbow)
  190. {
  191. ManaReso.Get("Rainbow").GetTweenSr().InDestination = true;
  192. }
  193. else
  194. {
  195. ManaReso.Get("Rainbow").GetTweenSr().InOrigin = true;
  196. }
  197. #endregion
  198. #region Player
  199. ManaReso.Save(ManaPlayer.Player);
  200. ManaReso.TraDic.Remove("Player");
  201. ManaPlayer.Instance.GetPlayer();
  202. Garden.PlayerPos = new List<Vector3>();
  203. Garden.Player = ManaReso.Get("Player");
  204. Garden.PlayerPos.Add(ManaPlayer.Player.ChildDic["Pos1"].position);
  205. Garden.PlayerPos.Add(ManaPlayer.Player.ChildDic["Pos2"].position);
  206. #endregion
  207. ManaGarden.ElfList = new List<ElfType>(OriginElfList);
  208. InVisit = false;
  209. LoadComplete = false;
  210. TweenComplete = 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. ManaSocial.PraiseBtn.interactable = false;
  486. ManaSocial.PraiseBtn.image.color = Color.white;
  487. }
  488. public static void SetVisiteePraise(XmlDocument document)
  489. {
  490. ManaSocial.PraiseText.text = VisiteePraise.ToString();
  491. if (document.SelectSingleNode("PlayerConfig").SelectSingleNode("SerialNumber") == null)
  492. {
  493. ManaSocial.EnablePraise();
  494. }
  495. else
  496. {
  497. VisiteeSerialNumber = document.SelectSingleNode("PlayerConfig").SelectSingleNode("SerialNumber").Attributes[0].Value;
  498. ManaServer.Target
  499. (
  500. ManaServer.SerialNumber,
  501. VisiteeSerialNumber,
  502. jsonData =>
  503. {
  504. if (jsonData["i"].ToString() == "0")
  505. {
  506. ManaSocial.EnablePraise();
  507. }
  508. else if (jsonData["i"].ToString() == "1")
  509. {
  510. ManaSocial.DisablePraise();
  511. }
  512. }
  513. );
  514. }
  515. }
  516. public static void SetPlayerComment()
  517. {
  518. if (ManaSocial.RecordFlag)
  519. {
  520. ManaSocial.Recover();
  521. }
  522. else
  523. {
  524. ManaSocial.UpdatePage(true);
  525. }
  526. }
  527. public static void SetVisiteeComment()
  528. {
  529. ManaSocial.UpdatePage(false);
  530. }
  531. public static void UpdateCost()
  532. {
  533. if (Complete)
  534. {
  535. Cost = Mathf.FloorToInt((float)Auxiliary.FmlParse(CostFml, "l", ManaCenter.Level.ToString()));
  536. }
  537. }
  538. public static void DataReverse()
  539. {
  540. if (InVisit)
  541. {
  542. VisitPlantList = new List<Slot>(ManaGarden.PlantList);
  543. ManaGarden.PlantList = OriginPlantList;
  544. }
  545. }
  546. public static void DataRecover()
  547. {
  548. if (InVisit)
  549. {
  550. ManaGarden.PlantList = VisitPlantList;
  551. }
  552. }
  553. public static void ShowTip()
  554. {
  555. ManaReso.SetActive ("C_Tip", true);
  556. ManaReso.Get<Text> ("C_TipLab").text = Language.GetStr ("Tip", "Tip" + Random.Range(1,10));
  557. }
  558. public static void HideTip()
  559. {
  560. ManaReso.SetActive ("C_Tip", false);
  561. }
  562. public static void Visit(ArchiveSource archiveSource, string info = null)
  563. {
  564. if (ManaCenter.SceneSwitchLock)
  565. {
  566. return;
  567. }
  568. ManaCenter.Pay
  569. (
  570. "",
  571. Cost,
  572. Current.Coin,
  573. () =>
  574. {
  575. ManaReso.Get("I_BlackMask").GetTweenCG().Duration = 0.5f;
  576. LoadComplete = false;
  577. TweenComplete = false;
  578. PullArchive(archiveSource, info);
  579. ManaAudio.PlayClip(Clip.BubbleClip);
  580. ManaReso.SetActive("C_Return", false);
  581. TweenRoot tween;
  582. if (CoolTime != 0)
  583. {
  584. ManaReso.Get<Button>("C_Visit").interactable = false;
  585. tween = ManaReso.Get("C_VisitLab").StreamReForScale();
  586. tween.AddEventOnetime
  587. (
  588. EventType.ForwardFinish,
  589. () =>
  590. {
  591. ManaReso.Get<Button>("C_Visit").interactable = true;
  592. }
  593. );
  594. }
  595. tween = ManaReso.Get("I_BlackMask").TweenBacCG();
  596. tween.AddEventOnetime
  597. (
  598. EventType.BackwardFinish,
  599. () =>
  600. {
  601. TweenComplete = true;
  602. Enter();
  603. }
  604. );
  605. },
  606. StaticsManager.ItemID.参观花费,
  607. StaticsManager.ConsumeModule.Shop,
  608. false
  609. );
  610. }
  611. public static void PullArchive(ArchiveSource archiveSource, string info = null)
  612. {
  613. //archiveSource = ArchiveSource.Fake;
  614. if (archiveSource == ArchiveSource.SerialNumber)
  615. {
  616. ManaServer.Other
  617. (
  618. info,
  619. PullArchiveCallback
  620. );
  621. }
  622. else if (archiveSource == ArchiveSource.Random)
  623. {
  624. ManaServer.RandomLoad
  625. (
  626. PullArchiveCallback
  627. );
  628. }
  629. else
  630. {
  631. LoadComplete = true;
  632. XmlStr = CreateArchive();
  633. Document = new XmlDocument();
  634. Document.LoadXml(XmlStr);
  635. Enter();
  636. }
  637. }
  638. public static void PullArchiveCallback(JsonData jsonData)
  639. {
  640. if (jsonData.Inst_Object.ContainsKey("l"))
  641. {
  642. LoadComplete = true;
  643. XmlStr = jsonData["l"].ToString();
  644. VisiteePraise = int.Parse(jsonData["p"].ToString());
  645. Document = new XmlDocument();
  646. Document.LoadXml(XmlStr);
  647. SetVisiteePraise(Document);
  648. SetVisiteeComment();
  649. Enter();
  650. }
  651. else
  652. {
  653. Bubble.Show
  654. (
  655. Language.GetStr("UI", "C_VisitFail"),
  656. null,
  657. null,
  658. null,
  659. () =>
  660. {
  661. ManaReso.Get("I_BlackMask").TweenForCG();
  662. },
  663. null,
  664. false
  665. );
  666. ManaCenter.AddCoin(Cost, StaticsManager.ItemID.获得金币, StaticsManager.ConsumeModule.VisitRefund);
  667. }
  668. }
  669. public static string CreateArchive()
  670. {
  671. XmlDocument doc = new XmlDocument();
  672. doc.LoadXml(ManaData.PlayerDoc.OuterXml); //以自己的存档做模板进行修改
  673. int newLevel = Random.Range(1, 450); //随机等级
  674. #region 根据等级确定有多少土地解锁
  675. int slot = 1; //解锁土地数量
  676. XmlNodeList nodeList = doc.SelectSingleNode("PlayerConfig").SelectSingleNode("SkillList").ChildNodes;
  677. for (int i = 0; i < nodeList.Count; i++)
  678. {
  679. SkillType type = nodeList[i].Attributes[1].Value.ToEnum<SkillType>();
  680. if (type == SkillType.Ability)
  681. {
  682. Ability ability = (Ability)ManaCenter.SkillDic[nodeList[i].Attributes[0].Value];
  683. int unlockLevel = ability.UnlockLv;
  684. if (newLevel >= unlockLevel)
  685. {
  686. if (ability.ID_ >= 6)
  687. {
  688. slot++;
  689. }
  690. nodeList[i].Attributes[2].Value = "Upgrade";
  691. nodeList[i].Attributes[3].Value = newLevel.ToString();
  692. }
  693. else
  694. {
  695. nodeList[i].Attributes[2].Value = "Lock";
  696. nodeList[i].Attributes[3].Value = "0";
  697. }
  698. }
  699. }
  700. #endregion
  701. #region 随机种一些花
  702. bool fancy = Random.Range(0f, 1f) < FancyRate; //fancy=True时 种的花比较多
  703. List<int> flowerList = new List<int>();
  704. for (int i = 1; i < 36; i++)
  705. {
  706. flowerList.Add(i);
  707. }
  708. int slotIndex = 0;
  709. string plantList = "";
  710. for (int i = 0; i < slot; i++)
  711. {
  712. if (fancy || Random.Range(0f, 1f) >= 0.35f)
  713. {
  714. int flowerID = slotIndex + 1;
  715. plantList += string.Format("{0},{1} ", flowerID, slotIndex);
  716. slotIndex++;
  717. }
  718. }
  719. plantList = plantList.TrimEnd(' ');
  720. doc.SelectSingleNode("PlayerConfig").SelectSingleNode("PlantList").Attributes[0].Value = plantList;
  721. #endregion
  722. #region 随机一套服装 等级越高拥有的服装越多 再随机选几件穿上
  723. XmlNode xmlNode = doc.SelectSingleNode("PlayerConfig").SelectSingleNode("DressData");
  724. xmlNode.Attributes[0].Value = "";
  725. xmlNode.Attributes[0].Value = ManaPlayer.CloseUnitDic[Random.Range(2, (int)Mathf.Lerp(2, 30, newLevel / 449f) + 1)].ArmatureName;
  726. xmlNode.Attributes[1].Value = ManaPlayer.CloseUnitDic[Random.Range(201, (int)Mathf.Lerp(201, 217, newLevel / 449f) + 1)].ArmatureName;
  727. xmlNode.Attributes[2].Value = ManaPlayer.CloseUnitDic[Random.Range(401, (int)Mathf.Lerp(401, 415, newLevel / 449f) + 1)].ArmatureName;
  728. xmlNode.Attributes[3].Value = ManaPlayer.CloseUnitDic[Random.Range(601, (int)Mathf.Lerp(601, 612, newLevel / 449f) + 1)].ArmatureName;
  729. xmlNode.Attributes[4].Value = ManaPlayer.CloseUnitDic[Random.Range(801, (int)Mathf.Lerp(801, 817, newLevel / 449f) + 1)].ArmatureName;
  730. xmlNode.Attributes[7].Value = ManaPlayer.CloseUnitDic[Random.Range(1001, (int)Mathf.Lerp(1001, 1003, newLevel / 449f) + 1)].ArmatureName;
  731. #region 随机选一套眼睛嘴巴
  732. float eyeMouseRate = Random.Range(0f, 1f);
  733. if (eyeMouseRate <= 0.33f)
  734. {
  735. xmlNode.Attributes[5].Value = "眼睛1";
  736. xmlNode.Attributes[6].Value = "嘴巴1";
  737. }
  738. else if (eyeMouseRate <= 0.66f)
  739. {
  740. xmlNode.Attributes[5].Value = "眼睛2";
  741. xmlNode.Attributes[6].Value = "嘴巴2";
  742. }
  743. else
  744. {
  745. xmlNode.Attributes[5].Value = "眼睛3";
  746. xmlNode.Attributes[6].Value = "嘴巴3";
  747. }
  748. #endregion
  749. #endregion
  750. return doc.OuterXml;
  751. }
  752. }