ManaVisit.cs 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777
  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 int PageAmt;
  38. public static XmlNode Node;
  39. public static XmlDocument Document;
  40. public static bool OriginBird;
  41. public static bool OriginTree;
  42. public static bool OriginRainbow;
  43. public static List<Slot> VisitPlantList;
  44. public static List<Slot> OriginPlantList;
  45. public static List<ElfType> OriginElfList;
  46. #endregion
  47. public static void Initialize()
  48. {
  49. XmlAttributeCollection attribute = ManaData.GetVisitConfig();
  50. CostFml = attribute[5].Value;
  51. Cost = Mathf.FloorToInt((float)Auxiliary.FmlParse(CostFml, "l", ManaCenter.Level.ToString()));
  52. AwardMinFml = attribute[2].Value;
  53. AwardMaxFml = attribute[3].Value;
  54. CoolTime = int.Parse(attribute[4].Value);
  55. FancyRate = float.Parse(attribute[7].Value);
  56. AwardRate = float.Parse(attribute[1].Value);
  57. CreateRate = float.Parse(attribute[6].Value);
  58. #region 倒计时
  59. if (CoolTime != 0)
  60. {
  61. Text text = ManaReso.Get<Text>("C_VisitLab");
  62. List<float> delayList = new List<float>();
  63. List<float> durationList = new List<float>();
  64. List<VecPair> pairList = new List<VecPair>();
  65. List<UnityAction> actionList = new List<UnityAction>();
  66. Vector3 v1 = new Vector3(0.75f, 0.75f, 0.75f);
  67. Vector3 v2 = new Vector3(0.4f, 0.4f, 0.4f);
  68. Vector3 v3 = new Vector3(0, 0, 0);
  69. for (int i = 0; i < CoolTime - 1; i++)
  70. {
  71. delayList.Add(0.5f);
  72. delayList.Add(0);
  73. }
  74. delayList.Add(0.5f);
  75. for (int i = 0; i < CoolTime; i++)
  76. {
  77. durationList.Add(0.25f);
  78. durationList.Add(0.25f);
  79. pairList.Add(new VecPair(v1, v2));
  80. pairList.Add(new VecPair(v2, v3));
  81. var tempInt = i;
  82. actionList.Add
  83. (
  84. () =>
  85. {
  86. text.text = (CoolTime - tempInt).ToString();
  87. ManaAudio.PlayClip(Clip.BtnClip);
  88. }
  89. );
  90. actionList.Add(null);
  91. }
  92. TweenRoot tween = ManaReso.Get("C_VisitLab").CreateStreamScale
  93. (
  94. delayList,
  95. durationList,
  96. pairList,
  97. true,
  98. false,
  99. Curve.EaseOutQuad,
  100. false,
  101. actionList
  102. );
  103. tween.OnForwardFinish += () =>
  104. {
  105. ManaAudio.PlayClip(Clip.BubbleClip);
  106. };
  107. }
  108. #endregion
  109. Complete = true;
  110. }
  111. public static void Exit()
  112. {
  113. TweenRoot tweenRoot = ManaReso.Get("I_BlackMask").TweenForCG();
  114. tweenRoot.AddEventOnetime
  115. (
  116. EventType.ForwardFinish,
  117. () =>
  118. {
  119. ManaPlayer.Player.SetAllCollider(true);
  120. }
  121. );
  122. ManaReso.SetActive("C_Visit", true);
  123. ManaReso.SetActive("C_Coin", true);
  124. ManaReso.SetActive("C_Group1", true);
  125. ManaReso.SetActive("C_Group2", true);
  126. ManaReso.SetActive("C_Return", false);
  127. ManaReso.SetActive("C_Garden", false);
  128. ManaGarden.MiniLock = true;
  129. #region Garden
  130. ManaGarden.RetriveFlowerAll();
  131. for (int i = 0; i < ManaGarden.PageList.Count; i++)
  132. {
  133. ManaReso.Save(ManaGarden.PageList[i]);
  134. }
  135. ManaGarden.PageList = new List<Transform>();
  136. Garden.CurPage = 0;
  137. ManaGarden.SlotList = new List<Slot>();
  138. ManaGarden.PageList = new List<Transform>();
  139. Garden.ResetPage();
  140. for (int i = 0; i < ManaGarden.Slot / 7 + 2; i++)
  141. {
  142. ManaGarden.CreatePage();
  143. }
  144. for (int i = 0; i < ManaGarden.SlotList.Count; i++)
  145. {
  146. if (i < ManaGarden.Slot)
  147. {
  148. ManaGarden.SlotList[i].Lock = true;
  149. ManaGarden.SlotList[i].Available = true;
  150. }
  151. else
  152. {
  153. ManaGarden.SlotList[i].Lock = false;
  154. ManaGarden.SlotList[i].Available = false;
  155. }
  156. }
  157. List<KV<int, int>> plantList = ManaData.GetPlantList();
  158. for (int i = 0; i < plantList.Count; i++)
  159. {
  160. ManaGarden.PlantFlower(plantList[i].Key, plantList[i].Value);
  161. }
  162. #endregion
  163. #region Bird Tree Rainbow
  164. if (OriginBird)
  165. {
  166. ManaReso.Get("Bird0").GetTweenSr().InDestination = true;
  167. }
  168. else
  169. {
  170. ManaReso.Get("Bird0").GetTweenSr().InOrigin = true;
  171. }
  172. if (OriginTree)
  173. {
  174. ManaReso.Get("Tree1").GetTweenSr().InDestination = true;
  175. ManaReso.Get("Tree2").GetTweenSr().InDestination = true;
  176. }
  177. else
  178. {
  179. ManaReso.Get("Tree1").GetTweenSr().InOrigin = true;
  180. ManaReso.Get("Tree2").GetTweenSr().InOrigin = true;
  181. }
  182. if (OriginRainbow)
  183. {
  184. ManaReso.Get("Rainbow").GetTweenSr().InDestination = true;
  185. }
  186. else
  187. {
  188. ManaReso.Get("Rainbow").GetTweenSr().InOrigin = true;
  189. }
  190. #endregion
  191. #region Player
  192. ManaReso.Save(ManaPlayer.Player);
  193. ManaReso.TraDic.Remove("Player");
  194. ManaPlayer.Instance.GetPlayer();
  195. Garden.PlayerPos = new List<Vector3>();
  196. Garden.Player = ManaReso.Get("Player");
  197. Garden.PlayerPos.Add(ManaPlayer.Player.ChildDic["Pos1"].position);
  198. Garden.PlayerPos.Add(ManaPlayer.Player.ChildDic["Pos2"].position);
  199. #endregion
  200. ManaGarden.ElfList = new List<ElfType>(OriginElfList);
  201. InVisit = false;
  202. }
  203. public static void Enter()
  204. {
  205. if (!LoadComplete || !TweenComplete)
  206. {
  207. return;
  208. }
  209. ManaReso.Get("I_BlackMask").TweenForCG();
  210. Document = new XmlDocument();
  211. Document.LoadXml(XmlStr);
  212. Node = Document.SelectSingleNode("PlayerConfig");
  213. ManaReso.SetActive("C_Coin", false);
  214. ManaReso.SetActive("C_Group1", false);
  215. ManaReso.SetActive("C_Group2", false);
  216. ManaReso.SetActive("C_Garden", true);
  217. if (!InVisit)
  218. {
  219. for (int i = 0; i < ManaGarden.StarList.Count; i++)
  220. {
  221. ManaReso.Save(ManaGarden.StarList[i]);
  222. }
  223. ManaGarden.StarList = new List<Star>();
  224. }
  225. ManaReso.SetActive("C_Return", true);
  226. ManaGarden.MiniLock = false;
  227. #region Bird Tree Rainbow
  228. if (!InVisit)
  229. {
  230. if (ManaReso.Get("Bird0").gameObject.activeSelf)
  231. {
  232. OriginBird = true;
  233. }
  234. if (ManaReso.Get("Tree1").gameObject.activeSelf)
  235. {
  236. OriginTree = true;
  237. }
  238. if (ManaReso.Get("Rainbow").gameObject.activeSelf)
  239. {
  240. OriginRainbow = true;
  241. }
  242. }
  243. ManaReso.SetActive("Bird0", false);
  244. ManaReso.SetActive("Tree1", false);
  245. ManaReso.SetActive("Tree2", false);
  246. ManaReso.SetActive("Rainbow", false);
  247. #endregion
  248. #region Ability
  249. Slot = 1;
  250. if (!InVisit)
  251. {
  252. OriginElfList = new List<ElfType>(ManaGarden.ElfList);
  253. }
  254. ManaGarden.ElfList = new List<ElfType>();
  255. List<XmlAttributeCollection> attributeList = ManaData.GetSkillList(Node);
  256. for (int i = 0; i < attributeList.Count; i++)
  257. {
  258. if (!attributeList[i][0].Value.Contains("Ability"))
  259. {
  260. continue;
  261. }
  262. if (attributeList[i][0].Value == "Ability1")
  263. {
  264. Level = int.Parse(attributeList[i][3].Value);
  265. ManaReso.SetText("C_GardenLab", Language.GetStr("UI", "C_GardenLab") + Level);
  266. continue;
  267. }
  268. if (int.Parse(attributeList[i][3].Value) == 0)
  269. {
  270. continue;
  271. }
  272. if (attributeList[i][0].Value == "Ability2")
  273. {
  274. ManaReso.Get("Rainbow").GetTweenSr().InDestination = true;
  275. }
  276. else if (attributeList[i][0].Value == "Ability3")
  277. {
  278. ManaReso.Get("Tree1").GetTweenSr().InDestination = true;
  279. ManaReso.Get("Tree2").GetTweenSr().InDestination = true;
  280. }
  281. else if (attributeList[i][0].Value == "Ability4")
  282. {
  283. ManaReso.Get("Bird0").GetTweenSr().InDestination = true;
  284. }
  285. else if (attributeList[i][0].Value == "Ability5")
  286. {
  287. ManaGarden.ElfList.Add(ElfType.Bee_Yellow);
  288. }
  289. else if (attributeList[i][0].Value == "Ability6")
  290. {
  291. Slot++;
  292. ManaGarden.ElfList.Add(ElfType.Bee_Purple);
  293. }
  294. else if (attributeList[i][0].Value == "Ability7")
  295. {
  296. Slot++;
  297. ManaGarden.ElfList.Add(ElfType.Bee_Blue);
  298. }
  299. else if (attributeList[i][0].Value == "Ability8")
  300. {
  301. Slot++;
  302. ManaGarden.ElfList.Add(ElfType.Bee_Red);
  303. }
  304. else if (attributeList[i][0].Value == "Ability9")
  305. {
  306. Slot++;
  307. ManaGarden.ElfList.Add(ElfType.Bee_White);
  308. }
  309. else if (attributeList[i][0].Value == "Ability10")
  310. {
  311. Slot++;
  312. ManaGarden.ElfList.Add(ElfType.Butterfly_Yellow);
  313. }
  314. else if (attributeList[i][0].Value == "Ability11")
  315. {
  316. Slot++;
  317. ManaGarden.ElfList.Add(ElfType.Butterfly_Purple);
  318. }
  319. else if (attributeList[i][0].Value == "Ability12")
  320. {
  321. Slot++;
  322. ManaGarden.ElfList.Add(ElfType.Butterfly_Blue);
  323. }
  324. else if (attributeList[i][0].Value == "Ability13")
  325. {
  326. Slot++;
  327. ManaGarden.ElfList.Add(ElfType.Butterfly_Red);
  328. }
  329. else if (attributeList[i][0].Value == "Ability14")
  330. {
  331. Slot++;
  332. ManaGarden.ElfList.Add(ElfType.Butterfly_White);
  333. }
  334. else if (attributeList[i][0].Value == "Ability15")
  335. {
  336. Slot++;
  337. ManaGarden.ElfList.Add(ElfType.Dragonfly_Yellow);
  338. }
  339. else if (attributeList[i][0].Value == "Ability16")
  340. {
  341. Slot++;
  342. ManaGarden.ElfList.Add(ElfType.Dragonfly_Purple);
  343. }
  344. else if (attributeList[i][0].Value == "Ability17")
  345. {
  346. Slot++;
  347. ManaGarden.ElfList.Add(ElfType.Dragonfly_Blue);
  348. }
  349. else if (attributeList[i][0].Value == "Ability18")
  350. {
  351. Slot++;
  352. ManaGarden.ElfList.Add(ElfType.Dragonfly_Red);
  353. }
  354. else if (attributeList[i][0].Value == "Ability19")
  355. {
  356. Slot++;
  357. ManaGarden.ElfList.Add(ElfType.Dragonfly_White);
  358. }
  359. else if (attributeList[i][0].Value == "Ability20")
  360. {
  361. Slot++;
  362. ManaGarden.ElfList.Add(ElfType.Beetle_Yellow);
  363. }
  364. else if (attributeList[i][0].Value == "Ability21")
  365. {
  366. Slot++;
  367. ManaGarden.ElfList.Add(ElfType.Beetle_Purple);
  368. }
  369. else if (attributeList[i][0].Value == "Ability22")
  370. {
  371. Slot++;
  372. ManaGarden.ElfList.Add(ElfType.Beetle_Blue);
  373. }
  374. else if (attributeList[i][0].Value == "Ability23")
  375. {
  376. Slot++;
  377. ManaGarden.ElfList.Add(ElfType.Beetle_Red);
  378. }
  379. else if (attributeList[i][0].Value == "Ability24")
  380. {
  381. Slot++;
  382. ManaGarden.ElfList.Add(ElfType.Beetle_White);
  383. }
  384. }
  385. #endregion
  386. #region Garden
  387. if (!InVisit)
  388. {
  389. OriginPlantList = new List<Slot>(ManaGarden.PlantList);
  390. ManaData.SaveDress();
  391. ManaData.SavePlantList();
  392. }
  393. ManaGarden.RetriveFlowerAll();
  394. for (int i = 0; i < ManaGarden.PageList.Count; i++)
  395. {
  396. ManaReso.Save(ManaGarden.PageList[i]);
  397. }
  398. ManaGarden.PageList = new List<Transform>();
  399. Garden.CurPage = 0;
  400. ManaGarden.SlotList = new List<Slot>();
  401. ManaGarden.PageList = new List<Transform>();
  402. Garden.ResetPage();
  403. for (int i = 0; i < Slot/7 + 2; i++)
  404. {
  405. ManaGarden.CreatePage();
  406. }
  407. for (int i = 0; i < ManaGarden.SlotList.Count; i++)
  408. {
  409. if (i < Slot)
  410. {
  411. ManaGarden.SlotList[i].Lock = true;
  412. ManaGarden.SlotList[i].Available = true;
  413. }
  414. else
  415. {
  416. ManaGarden.SlotList[i].Lock = false;
  417. ManaGarden.SlotList[i].Available = false;
  418. }
  419. }
  420. List<KV<int, int>> plantList = ManaData.GetPlantList(Node);
  421. for (int i = 0; i < plantList.Count; i++)
  422. {
  423. ManaGarden.PlantFlower(plantList[i].Key, plantList[i].Value);
  424. }
  425. #endregion
  426. #region Player
  427. ManaReso.Save(ManaPlayer.Player);
  428. ManaReso.TraDic.Remove("Player");
  429. ManaPlayer.Instance.GetPlayer(Node).SetAllCollider(false);
  430. Garden.PlayerPos = new List<Vector3>();
  431. Garden.Player = ManaReso.Get("Player");
  432. Garden.PlayerPos.Add(ManaPlayer.Player.ChildDic["Pos1"].position);
  433. Garden.PlayerPos.Add(ManaPlayer.Player.ChildDic["Pos2"].position);
  434. #endregion
  435. #region Award
  436. if (ManaTutorial.TutorialC || Random.Range(0f,1f) <= AwardRate)
  437. {
  438. if (ManaTutorial.TutorialC)
  439. {
  440. ManaTutorial.EndC();
  441. }
  442. if (ManaGarden.PlantList.Count > 0)
  443. {
  444. ManaGarden.PlantList.Random()[0].Flower.Award = true;
  445. }
  446. }
  447. #endregion
  448. InVisit = true;
  449. }
  450. public static void UpdateCost()
  451. {
  452. if (Complete)
  453. {
  454. Cost = Mathf.FloorToInt((float)Auxiliary.FmlParse(CostFml, "l", ManaCenter.Level.ToString()));
  455. }
  456. }
  457. public static void DataReverse()
  458. {
  459. if (InVisit)
  460. {
  461. VisitPlantList = new List<Slot>(ManaGarden.PlantList);
  462. ManaGarden.PlantList = OriginPlantList;
  463. }
  464. }
  465. public static void DataRecover()
  466. {
  467. if (InVisit)
  468. {
  469. ManaGarden.PlantList = VisitPlantList;
  470. }
  471. }
  472. public static void GetArchive()
  473. {
  474. if (Random.Range(0f, 1f) <= CreateRate)
  475. {
  476. LoadComplete = true;
  477. XmlStr = WriteArchive();
  478. Enter();
  479. }
  480. else
  481. {
  482. ManaServer.RandomLoad
  483. (
  484. (jsonData) =>
  485. {
  486. LoadComplete = true;
  487. if (jsonData.Inst_Object.ContainsKey("l"))
  488. {
  489. XmlStr = jsonData["l"].ToString();
  490. }
  491. else
  492. {
  493. LoadComplete = true;
  494. XmlStr = WriteArchive();
  495. }
  496. Enter();
  497. }
  498. );
  499. }
  500. }
  501. public static string WriteArchive()
  502. {
  503. XmlDocument doc = new XmlDocument();
  504. doc.LoadXml(ManaData.PlayerDoc.OuterXml);
  505. bool fancy;
  506. if (Random.Range(0f, 1f) < FancyRate)
  507. {
  508. fancy = true;
  509. }
  510. else
  511. {
  512. fancy = false;
  513. }
  514. int slot = 1;
  515. int newLevel = Random.Range(1, 300);
  516. XmlNodeList nodeList = doc.SelectSingleNode("PlayerConfig").SelectSingleNode("SkillList").ChildNodes;
  517. for (int i = 0; i < nodeList.Count; i++)
  518. {
  519. SkillType type = nodeList[i].Attributes[1].Value.ToEnum<SkillType>();
  520. if (type == SkillType.Ability)
  521. {
  522. Ability ability = (Ability) ManaCenter.SkillDic[nodeList[i].Attributes[0].Value];
  523. int unlockLevel = ability.UnlockLv;
  524. if (newLevel >= unlockLevel)
  525. {
  526. if (ability.ID_ >= 6)
  527. {
  528. slot++;
  529. }
  530. nodeList[i].Attributes[2].Value = "Upgrade";
  531. nodeList[i].Attributes[3].Value = newLevel.ToString();
  532. }
  533. else
  534. {
  535. nodeList[i].Attributes[2].Value = "Lock";
  536. nodeList[i].Attributes[3].Value = "0";
  537. }
  538. }
  539. }
  540. List<int> flowerList = new List<int>();
  541. for (int i = 2; i < 28; i++)
  542. {
  543. flowerList.Add(i);
  544. }
  545. int slotIndex = 0;
  546. string plantList = "";
  547. for (int i = 0; i < slot; i++)
  548. {
  549. if (fancy || Random.Range(0f, 1f) >= 0.35f)
  550. {
  551. int flowerID = slotIndex + 1;
  552. plantList += string.Format("{0},{1} ", flowerID, slotIndex);
  553. slotIndex++;
  554. }
  555. }
  556. plantList = plantList.TrimEnd(' ');
  557. doc.SelectSingleNode("PlayerConfig").SelectSingleNode("PlantList").Attributes[0].Value = plantList;
  558. XmlNode xmlNode = doc.SelectSingleNode("PlayerConfig").SelectSingleNode("DressData");
  559. xmlNode.Attributes[0].Value = "";
  560. float rate = Random.Range(0f, 1f);
  561. if (rate < 0.33f)
  562. {
  563. xmlNode.Attributes[0].Value = "脑壳1";
  564. xmlNode.Attributes[1].Value = "裙子1";
  565. xmlNode.Attributes[2].Value = "鞋子1";
  566. xmlNode.Attributes[3].Value = "头饰品1";
  567. xmlNode.Attributes[4].Value = "上衣1";
  568. xmlNode.Attributes[5].Value = "眼睛1";
  569. xmlNode.Attributes[6].Value = "嘴巴1";
  570. xmlNode.Attributes[7].Value = "Empty";
  571. }
  572. else if (rate < 0.66f)
  573. {
  574. xmlNode.Attributes[0].Value = "脑壳2";
  575. xmlNode.Attributes[1].Value = "裙子2";
  576. xmlNode.Attributes[2].Value = "鞋子2";
  577. xmlNode.Attributes[3].Value = "头饰品2";
  578. xmlNode.Attributes[4].Value = "上衣2";
  579. xmlNode.Attributes[5].Value = "眼睛2";
  580. xmlNode.Attributes[6].Value = "嘴巴2";
  581. xmlNode.Attributes[7].Value = "Empty";
  582. }
  583. else
  584. {
  585. xmlNode.Attributes[0].Value = "脑壳3";
  586. xmlNode.Attributes[1].Value = "裙子3";
  587. xmlNode.Attributes[2].Value = "鞋子3";
  588. xmlNode.Attributes[3].Value = "头饰品3";
  589. xmlNode.Attributes[4].Value = "上衣3";
  590. xmlNode.Attributes[5].Value = "眼睛3";
  591. xmlNode.Attributes[6].Value = "嘴巴3";
  592. xmlNode.Attributes[7].Value = "Empty";
  593. }
  594. return doc.OuterXml;
  595. }
  596. }