ManaVisit.cs 17 KB

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