ManaVisit.cs 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706
  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 int AwardMin;
  24. public static int AwardMax;
  25. public static float FancyRate;
  26. public static float AwardRate;
  27. public static float CreateRate;
  28. public static string CostFml;
  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. AwardMin = Mathf.CeilToInt((float) Auxiliary.FmlParse(attribute[2].Value, "l", ManaCenter.Level.ToString()));
  54. AwardMax = Mathf.CeilToInt((float) Auxiliary.FmlParse(attribute[3].Value, "l", ManaCenter.Level.ToString()));
  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. ManaReso.Get("I_BlackMask").TweenForCG();
  115. ManaReso.SetActive("C_Visit", true);
  116. ManaReso.SetActive("C_Coin", true);
  117. ManaReso.SetActive("C_Group1", true);
  118. ManaReso.SetActive("C_Group2", true);
  119. ManaReso.SetActive("C_Return", false);
  120. ManaReso.SetActive("C_Garden", false);
  121. ManaGarden.AwardLock = true;
  122. #region Garden
  123. ManaGarden.RetriveFlowerAll();
  124. for (int i = 0; i < ManaGarden.PageList.Count; i++)
  125. {
  126. ManaReso.Save(ManaGarden.PageList[i]);
  127. }
  128. ManaGarden.PageList = new List<Transform>();
  129. Garden.CurPage = 0;
  130. ManaGarden.SlotList = new List<Slot>();
  131. ManaGarden.PageList = new List<Transform>();
  132. Garden.ResetPage();
  133. for (int i = 0; i < ManaGarden.Slot / 7 + 2; i++)
  134. {
  135. ManaGarden.CreatePage();
  136. }
  137. for (int i = 0; i < ManaGarden.SlotList.Count; i++)
  138. {
  139. if (i < ManaGarden.Slot)
  140. {
  141. ManaGarden.SlotList[i].Lock = true;
  142. ManaGarden.SlotList[i].Available = true;
  143. }
  144. else
  145. {
  146. ManaGarden.SlotList[i].Lock = false;
  147. ManaGarden.SlotList[i].Available = false;
  148. }
  149. }
  150. List<KV<int, int>> plantList = ManaData.GetPlantList();
  151. for (int i = 0; i < plantList.Count; i++)
  152. {
  153. ManaGarden.PlantFlower(plantList[i].Key, plantList[i].Value);
  154. }
  155. #endregion
  156. #region Bird Tree Rainbow
  157. if (OriginBird)
  158. {
  159. ManaReso.Get("Bird0").GetTweenSr().InDestination = true;
  160. }
  161. else
  162. {
  163. ManaReso.Get("Bird0").GetTweenSr().InOrigin = true;
  164. }
  165. if (OriginTree)
  166. {
  167. ManaReso.Get("Tree1").GetTweenSr().InDestination = true;
  168. ManaReso.Get("Tree2").GetTweenSr().InDestination = true;
  169. }
  170. else
  171. {
  172. ManaReso.Get("Tree1").GetTweenSr().InOrigin = true;
  173. ManaReso.Get("Tree2").GetTweenSr().InOrigin = true;
  174. }
  175. if (OriginRainbow)
  176. {
  177. ManaReso.Get("Rainbow").GetTweenSr().InDestination = true;
  178. }
  179. else
  180. {
  181. ManaReso.Get("Rainbow").GetTweenSr().InOrigin = true;
  182. }
  183. #endregion
  184. #region Player
  185. ManaReso.Save(ManaPlayer.Player);
  186. ManaReso.TraDic.Remove("Player");
  187. ManaPlayer.Instance.GetPlayer();
  188. Garden.PlayerPos = new List<Vector3>();
  189. Garden.Player = ManaReso.Get("Player");
  190. Garden.PlayerPos.Add(ManaPlayer.Player.ChildDic["Pos1"].position);
  191. Garden.PlayerPos.Add(ManaPlayer.Player.ChildDic["Pos2"].position);
  192. #endregion
  193. ManaGarden.ElfList = new List<ObjType>(OriginElfList);
  194. InVisit = false;
  195. }
  196. public static void Enter()
  197. {
  198. if (!LoadComplete || !TweenComplete)
  199. {
  200. return;
  201. }
  202. ManaReso.Get("I_BlackMask").TweenForCG();
  203. Document = new XmlDocument();
  204. Document.LoadXml(XmlStr);
  205. Node = Document.SelectSingleNode("PlayerConfig");
  206. Player = Node.SelectSingleNode("Player").Attributes[0].Value;
  207. ManaReso.SetActive("C_Coin", false);
  208. ManaReso.SetActive("C_Group1", false);
  209. ManaReso.SetActive("C_Group2", false);
  210. ManaReso.SetActive("C_Garden", true);
  211. if (!ManaTutorial.TutorialC)
  212. {
  213. ManaReso.SetActive("C_Return", true);
  214. }
  215. ManaGarden.AwardLock = false;
  216. #region Bird Tree Rainbow
  217. if (!InVisit)
  218. {
  219. if (ManaReso.Get("Bird0").gameObject.activeSelf)
  220. {
  221. OriginBird = true;
  222. }
  223. if (ManaReso.Get("Tree1").gameObject.activeSelf)
  224. {
  225. OriginTree = true;
  226. }
  227. if (ManaReso.Get("Rainbow").gameObject.activeSelf)
  228. {
  229. OriginRainbow = true;
  230. }
  231. }
  232. ManaReso.SetActive("Bird0", false);
  233. ManaReso.SetActive("Tree1", false);
  234. ManaReso.SetActive("Tree2", false);
  235. ManaReso.SetActive("Rainbow", false);
  236. #endregion
  237. #region Ability
  238. Slot = 1;
  239. if (!InVisit)
  240. {
  241. OriginElfList = new List<ObjType>(ManaGarden.ElfList);
  242. }
  243. ManaGarden.ElfList = new List<ObjType>();
  244. List<XmlAttributeCollection> attributeList = ManaData.GetSkillList(Node);
  245. for (int i = 0; i < attributeList.Count; i++)
  246. {
  247. if (!attributeList[i][0].Value.Contains("Ability"))
  248. {
  249. continue;
  250. }
  251. if (attributeList[i][0].Value == "Ability1")
  252. {
  253. Level = int.Parse(attributeList[i][3].Value);
  254. ManaReso.SetText("C_GardenLab", Language.GetStr("UI", "C_GardenLab") + Level);
  255. continue;
  256. }
  257. if (int.Parse(attributeList[i][3].Value) == 0)
  258. {
  259. continue;
  260. }
  261. if (attributeList[i][0].Value == "Ability2")
  262. {
  263. ManaReso.Get("Rainbow").GetTweenSr().InDestination = true;
  264. }
  265. else if (attributeList[i][0].Value == "Ability3")
  266. {
  267. ManaReso.Get("Tree1").GetTweenSr().InDestination = true;
  268. ManaReso.Get("Tree2").GetTweenSr().InDestination = true;
  269. }
  270. else if (attributeList[i][0].Value == "Ability4")
  271. {
  272. ManaReso.Get("Bird0").GetTweenSr().InDestination = true;
  273. }
  274. else if (attributeList[i][0].Value == "Ability5")
  275. {
  276. ManaGarden.ElfList.Add(ObjType.BeeYellow);
  277. }
  278. else if (attributeList[i][0].Value == "Ability6")
  279. {
  280. Slot++;
  281. ManaGarden.ElfList.Add(ObjType.BeePurple);
  282. }
  283. else if (attributeList[i][0].Value == "Ability7")
  284. {
  285. Slot++;
  286. ManaGarden.ElfList.Add(ObjType.BeeBlue);
  287. }
  288. else if (attributeList[i][0].Value == "Ability8")
  289. {
  290. Slot++;
  291. ManaGarden.ElfList.Add(ObjType.BeeRed);
  292. }
  293. else if (attributeList[i][0].Value == "Ability9")
  294. {
  295. Slot++;
  296. ManaGarden.ElfList.Add(ObjType.BeeWhite);
  297. }
  298. else if (attributeList[i][0].Value == "Ability10")
  299. {
  300. Slot++;
  301. ManaGarden.ElfList.Add(ObjType.ButterflyYellow);
  302. }
  303. else if (attributeList[i][0].Value == "Ability11")
  304. {
  305. Slot++;
  306. ManaGarden.ElfList.Add(ObjType.ButterflyPurple);
  307. }
  308. else if (attributeList[i][0].Value == "Ability12")
  309. {
  310. Slot++;
  311. ManaGarden.ElfList.Add(ObjType.ButterflyBlue);
  312. }
  313. else if (attributeList[i][0].Value == "Ability13")
  314. {
  315. Slot++;
  316. ManaGarden.ElfList.Add(ObjType.ButterflyRed);
  317. }
  318. else if (attributeList[i][0].Value == "Ability14")
  319. {
  320. Slot++;
  321. ManaGarden.ElfList.Add(ObjType.ButterflyWhite);
  322. }
  323. }
  324. #endregion
  325. #region Garden
  326. if (!InVisit)
  327. {
  328. OriginPlantList = new List<Slot>(ManaGarden.PlantList);
  329. ManaData.SavePlantList();
  330. }
  331. ManaGarden.RetriveFlowerAll();
  332. for (int i = 0; i < ManaGarden.PageList.Count; i++)
  333. {
  334. ManaReso.Save(ManaGarden.PageList[i]);
  335. }
  336. ManaGarden.PageList = new List<Transform>();
  337. Garden.CurPage = 0;
  338. ManaGarden.SlotList = new List<Slot>();
  339. ManaGarden.PageList = new List<Transform>();
  340. Garden.ResetPage();
  341. for (int i = 0; i < Slot/7 + 2; i++)
  342. {
  343. ManaGarden.CreatePage();
  344. }
  345. for (int i = 0; i < ManaGarden.SlotList.Count; i++)
  346. {
  347. if (i < Slot)
  348. {
  349. ManaGarden.SlotList[i].Lock = true;
  350. ManaGarden.SlotList[i].Available = true;
  351. }
  352. else
  353. {
  354. ManaGarden.SlotList[i].Lock = false;
  355. ManaGarden.SlotList[i].Available = false;
  356. }
  357. }
  358. List<KV<int, int>> plantList = ManaData.GetPlantList(Node);
  359. for (int i = 0; i < plantList.Count; i++)
  360. {
  361. ManaGarden.PlantFlower(plantList[i].Key, plantList[i].Value);
  362. }
  363. #endregion
  364. #region Player
  365. ManaReso.Save(ManaPlayer.Player);
  366. ManaReso.TraDic.Remove("Player");
  367. ManaPlayer.Instance.GetPlayer(Player);
  368. Garden.PlayerPos = new List<Vector3>();
  369. Garden.Player = ManaReso.Get("Player");
  370. Garden.PlayerPos.Add(ManaPlayer.Player.ChildDic["Pos1"].position);
  371. Garden.PlayerPos.Add(ManaPlayer.Player.ChildDic["Pos2"].position);
  372. #endregion
  373. #region Award
  374. if (Random.Range(0f,1f) <= AwardRate)
  375. {
  376. if (ManaGarden.PlantList.Count > 0)
  377. {
  378. ManaGarden.PlantList.Random().Flower.Award = true;
  379. }
  380. }
  381. #endregion
  382. InVisit = true;
  383. }
  384. public static void UpdateCost()
  385. {
  386. if (Complete)
  387. {
  388. Cost = Mathf.FloorToInt((float)Auxiliary.FmlParse(CostFml, "l", ManaCenter.Level.ToString()));
  389. }
  390. }
  391. public static void DataReverse()
  392. {
  393. if (InVisit)
  394. {
  395. VisitPlantList = new List<Slot>(ManaGarden.PlantList);
  396. ManaGarden.PlantList = OriginPlantList;
  397. }
  398. }
  399. public static void DataRecover()
  400. {
  401. if (InVisit)
  402. {
  403. ManaGarden.PlantList = VisitPlantList;
  404. }
  405. }
  406. public static void GetArchive()
  407. {
  408. //ManaServer.Download
  409. //(
  410. // "ytcy9g",
  411. // (jsonData) =>
  412. // {
  413. // LoadComplete = true;
  414. // XmlStr = jsonData["l"].ToString();
  415. // Enter();
  416. // }
  417. //);
  418. if (Random.Range(0f, 1f) <= CreateRate)
  419. {
  420. XmlDocument document = new XmlDocument();
  421. document.LoadXml(ManaData.PlayerDoc.OuterXml);
  422. WriteArchive(document);
  423. LoadComplete = true;
  424. XmlStr = document.OuterXml;
  425. Enter();
  426. }
  427. else
  428. {
  429. ManaServer.RandomLoad
  430. (
  431. (jsonData) =>
  432. {
  433. LoadComplete = true;
  434. XmlStr = jsonData["l"].ToString();
  435. Enter();
  436. }
  437. );
  438. }
  439. }
  440. public static void WriteArchive(XmlDocument doc)
  441. {
  442. bool fancy;
  443. if (Random.Range(0f, 1f) < FancyRate)
  444. {
  445. fancy = true;
  446. }
  447. else
  448. {
  449. fancy = false;
  450. }
  451. int slot = 1;
  452. int newLevel = Random.Range(1, 300);
  453. XmlNodeList nodeList = doc.SelectSingleNode("PlayerConfig").SelectSingleNode("SkillList").ChildNodes;
  454. for (int i = 0; i < nodeList.Count; i++)
  455. {
  456. SkillType type = nodeList[i].Attributes[1].Value.ToEnum<SkillType>();
  457. if (type == SkillType.Ability)
  458. {
  459. Ability ability = (Ability) ManaCenter.SkillDic[nodeList[i].Attributes[0].Value];
  460. int unlockLevel = ability.UnlockLv;
  461. if (newLevel >= unlockLevel)
  462. {
  463. if (ability.ID_ >= 6)
  464. {
  465. slot++;
  466. }
  467. nodeList[i].Attributes[2].Value = "Upgrade";
  468. nodeList[i].Attributes[3].Value = newLevel.ToString();
  469. }
  470. else
  471. {
  472. nodeList[i].Attributes[2].Value = "Lock";
  473. nodeList[i].Attributes[3].Value = "0";
  474. }
  475. }
  476. }
  477. List<int> flowerList = new List<int>();
  478. for (int i = 2; i < 21; i++)
  479. {
  480. flowerList.Add(i);
  481. }
  482. for (int i = 27; i >= 21; i--)
  483. {
  484. flowerList.Add(i);
  485. }
  486. if (!fancy)
  487. {
  488. slot = Mathf.CeilToInt(slot/2f);
  489. }
  490. int slotIndex = 0;
  491. string plantList = "";
  492. for (int i = 0; i < slot; i++)
  493. {
  494. if (fancy || Random.Range(0f, 1f) >= 0.25f)
  495. {
  496. int flowerID;
  497. if (i == 0)
  498. {
  499. flowerID = 1;
  500. }
  501. else if (i < 8)
  502. {
  503. flowerID = flowerList.Last(i - 1, true);
  504. }
  505. else
  506. {
  507. if (fancy)
  508. {
  509. flowerID = flowerList.Random(true);
  510. }
  511. else
  512. {
  513. break;
  514. }
  515. }
  516. plantList += string.Format("{0},{1} ", flowerID, slotIndex);
  517. slotIndex++;
  518. }
  519. }
  520. plantList = plantList.TrimEnd(' ');
  521. doc.SelectSingleNode("PlayerConfig").SelectSingleNode("PlantList").Attributes[0].Value = plantList;
  522. float rate = Random.Range(0f, 1f);
  523. if (rate < 0.33f)
  524. {
  525. doc.SelectSingleNode("PlayerConfig").SelectSingleNode("Player").Attributes[0].Value = "PlayerPink";
  526. }
  527. else if (rate < 0.66f)
  528. {
  529. doc.SelectSingleNode("PlayerConfig").SelectSingleNode("Player").Attributes[0].Value = "PlayerBlond";
  530. }
  531. else
  532. {
  533. doc.SelectSingleNode("PlayerConfig").SelectSingleNode("Player").Attributes[0].Value = "PlayerBrown";
  534. }
  535. }
  536. }