ManaVisit.cs 20 KB

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