ManaVisit.cs 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728
  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 string Player;
  39. public static XmlNode Node;
  40. public static XmlDocument Document;
  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<ObjType> 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. tweenRoot.AddEventOnetime
  116. (
  117. EventType.ForwardFinish,
  118. () =>
  119. {
  120. ManaPlayer.Player.SetAllCollider(true);
  121. }
  122. );
  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. for (int i = 0; i < ManaGarden.Slot / 7 + 2; i++)
  142. {
  143. ManaGarden.CreatePage();
  144. }
  145. for (int i = 0; i < ManaGarden.SlotList.Count; i++)
  146. {
  147. if (i < ManaGarden.Slot)
  148. {
  149. ManaGarden.SlotList[i].Lock = true;
  150. ManaGarden.SlotList[i].Available = true;
  151. }
  152. else
  153. {
  154. ManaGarden.SlotList[i].Lock = false;
  155. ManaGarden.SlotList[i].Available = false;
  156. }
  157. }
  158. List<KV<int, int>> plantList = ManaData.GetPlantList();
  159. for (int i = 0; i < plantList.Count; i++)
  160. {
  161. ManaGarden.PlantFlower(plantList[i].Key, plantList[i].Value);
  162. }
  163. #endregion
  164. #region Bird Tree Rainbow
  165. if (OriginBird)
  166. {
  167. ManaReso.Get("Bird0").GetTweenSr().InDestination = true;
  168. }
  169. else
  170. {
  171. ManaReso.Get("Bird0").GetTweenSr().InOrigin = true;
  172. }
  173. if (OriginTree)
  174. {
  175. ManaReso.Get("Tree1").GetTweenSr().InDestination = true;
  176. ManaReso.Get("Tree2").GetTweenSr().InDestination = true;
  177. }
  178. else
  179. {
  180. ManaReso.Get("Tree1").GetTweenSr().InOrigin = true;
  181. ManaReso.Get("Tree2").GetTweenSr().InOrigin = true;
  182. }
  183. if (OriginRainbow)
  184. {
  185. ManaReso.Get("Rainbow").GetTweenSr().InDestination = true;
  186. }
  187. else
  188. {
  189. ManaReso.Get("Rainbow").GetTweenSr().InOrigin = true;
  190. }
  191. #endregion
  192. #region Player
  193. ManaReso.Save(ManaPlayer.Player);
  194. ManaReso.TraDic.Remove("Player");
  195. ManaPlayer.Instance.GetPlayer();
  196. Garden.PlayerPos = new List<Vector3>();
  197. Garden.Player = ManaReso.Get("Player");
  198. Garden.PlayerPos.Add(ManaPlayer.Player.ChildDic["Pos1"].position);
  199. Garden.PlayerPos.Add(ManaPlayer.Player.ChildDic["Pos2"].position);
  200. #endregion
  201. ManaGarden.ElfList = new List<ObjType>(OriginElfList);
  202. InVisit = false;
  203. }
  204. public static void Enter()
  205. {
  206. if (!LoadComplete || !TweenComplete)
  207. {
  208. return;
  209. }
  210. ManaReso.Get("I_BlackMask").TweenForCG();
  211. Document = new XmlDocument();
  212. Document.LoadXml(XmlStr);
  213. Node = Document.SelectSingleNode("PlayerConfig");
  214. XmlNode tempNode = Node.SelectSingleNode("Player");
  215. if (tempNode == null)
  216. {
  217. Player = null;
  218. tempNode = Node;
  219. }
  220. else
  221. {
  222. Player = Node.SelectSingleNode("Player").Attributes[0].Value;
  223. tempNode = null;
  224. }
  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<ObjType>(ManaGarden.ElfList);
  265. }
  266. ManaGarden.ElfList = new List<ObjType>();
  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(ObjType.BeeYellow);
  300. }
  301. else if (attributeList[i][0].Value == "Ability6")
  302. {
  303. Slot++;
  304. ManaGarden.ElfList.Add(ObjType.BeePurple);
  305. }
  306. else if (attributeList[i][0].Value == "Ability7")
  307. {
  308. Slot++;
  309. ManaGarden.ElfList.Add(ObjType.BeeBlue);
  310. }
  311. else if (attributeList[i][0].Value == "Ability8")
  312. {
  313. Slot++;
  314. ManaGarden.ElfList.Add(ObjType.BeeRed);
  315. }
  316. else if (attributeList[i][0].Value == "Ability9")
  317. {
  318. Slot++;
  319. ManaGarden.ElfList.Add(ObjType.BeeWhite);
  320. }
  321. else if (attributeList[i][0].Value == "Ability10")
  322. {
  323. Slot++;
  324. ManaGarden.ElfList.Add(ObjType.ButterflyYellow);
  325. }
  326. else if (attributeList[i][0].Value == "Ability11")
  327. {
  328. Slot++;
  329. ManaGarden.ElfList.Add(ObjType.ButterflyPurple);
  330. }
  331. else if (attributeList[i][0].Value == "Ability12")
  332. {
  333. Slot++;
  334. ManaGarden.ElfList.Add(ObjType.ButterflyBlue);
  335. }
  336. else if (attributeList[i][0].Value == "Ability13")
  337. {
  338. Slot++;
  339. ManaGarden.ElfList.Add(ObjType.ButterflyRed);
  340. }
  341. else if (attributeList[i][0].Value == "Ability14")
  342. {
  343. Slot++;
  344. ManaGarden.ElfList.Add(ObjType.ButterflyWhite);
  345. }
  346. }
  347. #endregion
  348. #region Garden
  349. if (!InVisit)
  350. {
  351. OriginPlantList = new List<Slot>(ManaGarden.PlantList);
  352. ManaData.SavePlantList();
  353. }
  354. ManaGarden.RetriveFlowerAll();
  355. for (int i = 0; i < ManaGarden.PageList.Count; i++)
  356. {
  357. ManaReso.Save(ManaGarden.PageList[i]);
  358. }
  359. ManaGarden.PageList = new List<Transform>();
  360. Garden.CurPage = 0;
  361. ManaGarden.SlotList = new List<Slot>();
  362. ManaGarden.PageList = new List<Transform>();
  363. Garden.ResetPage();
  364. for (int i = 0; i < Slot/7 + 2; i++)
  365. {
  366. ManaGarden.CreatePage();
  367. }
  368. for (int i = 0; i < ManaGarden.SlotList.Count; i++)
  369. {
  370. if (i < Slot)
  371. {
  372. ManaGarden.SlotList[i].Lock = true;
  373. ManaGarden.SlotList[i].Available = true;
  374. }
  375. else
  376. {
  377. ManaGarden.SlotList[i].Lock = false;
  378. ManaGarden.SlotList[i].Available = false;
  379. }
  380. }
  381. List<KV<int, int>> plantList = ManaData.GetPlantList(Node);
  382. for (int i = 0; i < plantList.Count; i++)
  383. {
  384. ManaGarden.PlantFlower(plantList[i].Key, plantList[i].Value);
  385. }
  386. #endregion
  387. #region Player
  388. ManaReso.Save(ManaPlayer.Player);
  389. ManaReso.TraDic.Remove("Player");
  390. ManaPlayer.Instance.GetPlayer(Player, tempNode).SetAllCollider(false);
  391. Garden.PlayerPos = new List<Vector3>();
  392. Garden.Player = ManaReso.Get("Player");
  393. Garden.PlayerPos.Add(ManaPlayer.Player.ChildDic["Pos1"].position);
  394. Garden.PlayerPos.Add(ManaPlayer.Player.ChildDic["Pos2"].position);
  395. #endregion
  396. #region Award
  397. if (ManaTutorial.TutorialC || Random.Range(0f,1f) <= AwardRate)
  398. {
  399. if (ManaTutorial.TutorialC)
  400. {
  401. ManaTutorial.EndC();
  402. }
  403. if (ManaGarden.PlantList.Count > 0)
  404. {
  405. ManaGarden.PlantList.Random().Flower.Award = true;
  406. }
  407. }
  408. #endregion
  409. InVisit = true;
  410. }
  411. public static void UpdateCost()
  412. {
  413. if (Complete)
  414. {
  415. Cost = Mathf.FloorToInt((float)Auxiliary.FmlParse(CostFml, "l", ManaCenter.Level.ToString()));
  416. }
  417. }
  418. public static void DataReverse()
  419. {
  420. if (InVisit)
  421. {
  422. VisitPlantList = new List<Slot>(ManaGarden.PlantList);
  423. ManaGarden.PlantList = OriginPlantList;
  424. }
  425. }
  426. public static void DataRecover()
  427. {
  428. if (InVisit)
  429. {
  430. ManaGarden.PlantList = VisitPlantList;
  431. }
  432. }
  433. public static void GetArchive()
  434. {
  435. if (Random.Range(0f, 1f) <= CreateRate)
  436. {
  437. LoadComplete = true;
  438. XmlStr = WriteArchive();
  439. Enter();
  440. }
  441. else
  442. {
  443. ManaServer.RandomLoad
  444. (
  445. (jsonData) =>
  446. {
  447. LoadComplete = true;
  448. if (jsonData.Inst_Object.ContainsKey("l"))
  449. {
  450. XmlStr = jsonData["l"].ToString();
  451. }
  452. else
  453. {
  454. LoadComplete = true;
  455. XmlStr = WriteArchive();
  456. }
  457. Enter();
  458. }
  459. );
  460. }
  461. }
  462. public static string WriteArchive()
  463. {
  464. XmlDocument doc = new XmlDocument();
  465. doc.LoadXml(ManaData.PlayerDoc.OuterXml);
  466. bool fancy;
  467. if (Random.Range(0f, 1f) < FancyRate)
  468. {
  469. fancy = true;
  470. }
  471. else
  472. {
  473. fancy = false;
  474. }
  475. int slot = 1;
  476. int newLevel = Random.Range(1, 300);
  477. XmlNodeList nodeList = doc.SelectSingleNode("PlayerConfig").SelectSingleNode("SkillList").ChildNodes;
  478. for (int i = 0; i < nodeList.Count; i++)
  479. {
  480. SkillType type = nodeList[i].Attributes[1].Value.ToEnum<SkillType>();
  481. if (type == SkillType.Ability)
  482. {
  483. Ability ability = (Ability) ManaCenter.SkillDic[nodeList[i].Attributes[0].Value];
  484. int unlockLevel = ability.UnlockLv;
  485. if (newLevel >= unlockLevel)
  486. {
  487. if (ability.ID_ >= 6)
  488. {
  489. slot++;
  490. }
  491. nodeList[i].Attributes[2].Value = "Upgrade";
  492. nodeList[i].Attributes[3].Value = newLevel.ToString();
  493. }
  494. else
  495. {
  496. nodeList[i].Attributes[2].Value = "Lock";
  497. nodeList[i].Attributes[3].Value = "0";
  498. }
  499. }
  500. }
  501. List<int> flowerList = new List<int>();
  502. for (int i = 2; i < 28; i++)
  503. {
  504. flowerList.Add(i);
  505. }
  506. int slotIndex = 0;
  507. string plantList = "";
  508. for (int i = 0; i < slot; i++)
  509. {
  510. if (fancy || Random.Range(0f, 1f) >= 0.35f)
  511. {
  512. int flowerID = slotIndex + 1;
  513. plantList += string.Format("{0},{1} ", flowerID, slotIndex);
  514. slotIndex++;
  515. }
  516. }
  517. plantList = plantList.TrimEnd(' ');
  518. doc.SelectSingleNode("PlayerConfig").SelectSingleNode("PlantList").Attributes[0].Value = plantList;
  519. XmlNode xmlNode = doc.SelectSingleNode("PlayerConfig").SelectSingleNode("DressData");
  520. xmlNode.Attributes[0].Value = "";
  521. float rate = Random.Range(0f, 1f);
  522. if (rate < 0.33f)
  523. {
  524. xmlNode.Attributes[0].Value = "脑壳1";
  525. xmlNode.Attributes[1].Value = "裙子1";
  526. xmlNode.Attributes[2].Value = "鞋子1";
  527. xmlNode.Attributes[3].Value = "头饰品1";
  528. xmlNode.Attributes[4].Value = "上衣1";
  529. xmlNode.Attributes[5].Value = "眼睛1";
  530. xmlNode.Attributes[6].Value = "嘴巴1";
  531. }
  532. else if (rate < 0.66f)
  533. {
  534. xmlNode.Attributes[0].Value = "脑壳2";
  535. xmlNode.Attributes[1].Value = "裙子2";
  536. xmlNode.Attributes[2].Value = "鞋子2";
  537. xmlNode.Attributes[3].Value = "头饰品2";
  538. xmlNode.Attributes[4].Value = "上衣2";
  539. xmlNode.Attributes[5].Value = "眼睛2";
  540. xmlNode.Attributes[6].Value = "嘴巴2";
  541. }
  542. else
  543. {
  544. xmlNode.Attributes[0].Value = "脑壳3";
  545. xmlNode.Attributes[1].Value = "裙子3";
  546. xmlNode.Attributes[2].Value = "鞋子3";
  547. xmlNode.Attributes[3].Value = "头饰品3";
  548. xmlNode.Attributes[4].Value = "上衣3";
  549. xmlNode.Attributes[5].Value = "眼睛3";
  550. xmlNode.Attributes[6].Value = "嘴巴3";
  551. }
  552. return doc.OuterXml;
  553. }
  554. }