ManaVisit.cs 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681
  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 Bird;
  31. public static bool Tree;
  32. public static bool Rainbow;
  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));
  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 (Bird)
  145. {
  146. ManaReso.Get("Bird0").GetTweenSr().InDestination = true;
  147. }
  148. else
  149. {
  150. ManaReso.Get("Bird0").GetTweenSr().InOrigin = true;
  151. }
  152. if (Tree)
  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 (Rainbow)
  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. Bird = true;
  209. }
  210. if (ManaReso.Get("Tree1").gameObject.activeSelf)
  211. {
  212. Tree = true;
  213. }
  214. if (ManaReso.Get("Rainbow").gameObject.activeSelf)
  215. {
  216. Rainbow = 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. ManaData.SavePlantList();
  229. OriginElfList = new List<ObjType>(ManaGarden.ElfList);
  230. }
  231. ManaGarden.ElfList = new List<ObjType>();
  232. List<XmlAttributeCollection> attributeList = ManaData.GetSkillList(Node);
  233. for (int i = 0; i < attributeList.Count; i++)
  234. {
  235. if (!attributeList[i][0].Value.Contains("Ability"))
  236. {
  237. continue;
  238. }
  239. if (attributeList[i][0].Value == "Ability1")
  240. {
  241. Level = int.Parse(attributeList[i][3].Value);
  242. ManaReso.SetText("C_GardenLab", Language.GetStr("UI", "C_GardenLab") + Level);
  243. continue;
  244. }
  245. if (int.Parse(attributeList[i][3].Value) == 0)
  246. {
  247. continue;
  248. }
  249. if (attributeList[i][0].Value == "Ability2")
  250. {
  251. ManaReso.Get("Rainbow").GetTweenSr().InDestination = true;
  252. }
  253. else if (attributeList[i][0].Value == "Ability3")
  254. {
  255. ManaReso.Get("Tree1").GetTweenSr().InDestination = true;
  256. ManaReso.Get("Tree2").GetTweenSr().InDestination = true;
  257. }
  258. else if (attributeList[i][0].Value == "Ability4")
  259. {
  260. ManaReso.Get("Bird0").GetTweenSr().InDestination = true;
  261. }
  262. else if (attributeList[i][0].Value == "Ability5")
  263. {
  264. ManaGarden.ElfList.Add(ObjType.BeeYellow);
  265. }
  266. else if (attributeList[i][0].Value == "Ability6")
  267. {
  268. Slot++;
  269. ManaGarden.ElfList.Add(ObjType.BeePurple);
  270. }
  271. else if (attributeList[i][0].Value == "Ability7")
  272. {
  273. Slot++;
  274. ManaGarden.ElfList.Add(ObjType.BeeBlue);
  275. }
  276. else if (attributeList[i][0].Value == "Ability8")
  277. {
  278. Slot++;
  279. ManaGarden.ElfList.Add(ObjType.BeeRed);
  280. }
  281. else if (attributeList[i][0].Value == "Ability9")
  282. {
  283. Slot++;
  284. ManaGarden.ElfList.Add(ObjType.BeeWhite);
  285. }
  286. else if (attributeList[i][0].Value == "Ability10")
  287. {
  288. Slot++;
  289. ManaGarden.ElfList.Add(ObjType.ButterflyYellow);
  290. }
  291. else if (attributeList[i][0].Value == "Ability11")
  292. {
  293. Slot++;
  294. ManaGarden.ElfList.Add(ObjType.ButterflyPurple);
  295. }
  296. else if (attributeList[i][0].Value == "Ability12")
  297. {
  298. Slot++;
  299. ManaGarden.ElfList.Add(ObjType.ButterflyBlue);
  300. }
  301. else if (attributeList[i][0].Value == "Ability13")
  302. {
  303. Slot++;
  304. ManaGarden.ElfList.Add(ObjType.ButterflyRed);
  305. }
  306. else if (attributeList[i][0].Value == "Ability14")
  307. {
  308. Slot++;
  309. ManaGarden.ElfList.Add(ObjType.ButterflyWhite);
  310. }
  311. }
  312. #endregion
  313. #region Garden
  314. if (!InVisit)
  315. {
  316. OriginPlantList = new List<Slot>(ManaGarden.PlantList);
  317. ManaData.SavePlantList();
  318. }
  319. ManaGarden.RetriveFlowerAll();
  320. for (int i = 0; i < ManaGarden.PageList.Count; i++)
  321. {
  322. ManaReso.Save(ManaGarden.PageList[i]);
  323. }
  324. ManaGarden.PageList = new List<Transform>();
  325. Garden.CurPage = 0;
  326. ManaGarden.SlotList = new List<Slot>();
  327. ManaGarden.PageList = new List<Transform>();
  328. Garden.ResetPage();
  329. for (int i = 0; i < Slot/7 + 2; i++)
  330. {
  331. ManaGarden.CreatePage();
  332. }
  333. for (int i = 0; i < ManaGarden.SlotList.Count; i++)
  334. {
  335. if (i < Slot)
  336. {
  337. ManaGarden.SlotList[i].Lock = true;
  338. ManaGarden.SlotList[i].Available = true;
  339. }
  340. else
  341. {
  342. ManaGarden.SlotList[i].Lock = false;
  343. ManaGarden.SlotList[i].Available = false;
  344. }
  345. }
  346. List<KV<int, int>> plantList = ManaData.GetPlantList(Node);
  347. for (int i = 0; i < plantList.Count; i++)
  348. {
  349. ManaGarden.PlantFlower(plantList[i].Key, plantList[i].Value);
  350. }
  351. #endregion
  352. #region Player
  353. ManaReso.Save(ManaPlayer.Player);
  354. ManaReso.TraDic.Remove("Player");
  355. ManaPlayer.Instance.GetPlayer(Player);
  356. Garden.PlayerPos = new List<Vector3>();
  357. Garden.Player = ManaReso.Get("Player");
  358. Garden.PlayerPos.Add(ManaPlayer.Player.ChildDic["Pos1"].position);
  359. Garden.PlayerPos.Add(ManaPlayer.Player.ChildDic["Pos2"].position);
  360. #endregion
  361. #region Award
  362. if (Random.Range(0f,1f) <= AwardRate)
  363. {
  364. if (ManaGarden.PlantList.Count > 0)
  365. {
  366. ManaGarden.PlantList.Random().Flower.Award = true;
  367. }
  368. }
  369. #endregion
  370. InVisit = true;
  371. }
  372. public static void DataReverse()
  373. {
  374. if (InVisit)
  375. {
  376. VisitPlantList = new List<Slot>(ManaGarden.PlantList);
  377. ManaGarden.PlantList = OriginPlantList;
  378. }
  379. }
  380. public static void DataRecover()
  381. {
  382. if (InVisit)
  383. {
  384. ManaGarden.PlantList = VisitPlantList;
  385. }
  386. }
  387. public static void GetArchive()
  388. {
  389. //ManaServer.Download
  390. //(
  391. // "ytcy9g",
  392. // (jsonData) =>
  393. // {
  394. // LoadComplete = true;
  395. // XmlStr = jsonData["l"].ToString();
  396. // Enter();
  397. // }
  398. //);
  399. if (Random.Range(0f, 1f) <= CreateRate)
  400. {
  401. XmlDocument document = new XmlDocument();
  402. document.LoadXml(ManaData.PlayerDoc.OuterXml);
  403. WriteArchive(document);
  404. LoadComplete = true;
  405. XmlStr = document.OuterXml;
  406. Enter();
  407. }
  408. else
  409. {
  410. ManaServer.RandomLoad
  411. (
  412. (jsonData) =>
  413. {
  414. LoadComplete = true;
  415. XmlStr = jsonData["l"].ToString();
  416. Enter();
  417. }
  418. );
  419. }
  420. }
  421. public static void WriteArchive(XmlDocument doc)
  422. {
  423. bool fancy;
  424. if (Random.Range(0f, 1f) < FancyRate)
  425. {
  426. fancy = true;
  427. }
  428. else
  429. {
  430. fancy = false;
  431. }
  432. int slot = 1;
  433. int newLevel = Random.Range(1, 300);
  434. XmlNodeList nodeList = doc.SelectSingleNode("PlayerConfig").SelectSingleNode("SkillList").ChildNodes;
  435. for (int i = 0; i < nodeList.Count; i++)
  436. {
  437. SkillType type = nodeList[i].Attributes[1].Value.ToEnum<SkillType>();
  438. if (type == SkillType.Ability)
  439. {
  440. Ability ability = (Ability) ManaCenter.SkillDic[nodeList[i].Attributes[0].Value];
  441. int unlockLevel = ability.UnlockLv;
  442. if (newLevel >= unlockLevel)
  443. {
  444. if (ability.ID_ >= 6)
  445. {
  446. slot++;
  447. }
  448. nodeList[i].Attributes[2].Value = "Upgrade";
  449. nodeList[i].Attributes[3].Value = newLevel.ToString();
  450. }
  451. else
  452. {
  453. nodeList[i].Attributes[2].Value = "Lock";
  454. nodeList[i].Attributes[3].Value = "0";
  455. }
  456. }
  457. }
  458. List<int> flowerList = new List<int>();
  459. for (int i = 2; i < 21; i++)
  460. {
  461. flowerList.Add(i);
  462. }
  463. for (int i = 27; i >= 21; i--)
  464. {
  465. flowerList.Add(i);
  466. }
  467. if (!fancy)
  468. {
  469. slot = Mathf.CeilToInt(slot/2f);
  470. }
  471. int slotIndex = 0;
  472. string plantList = "";
  473. for (int i = 0; i < slot; i++)
  474. {
  475. if (fancy || Random.Range(0f, 1f) >= 0.25f)
  476. {
  477. int flowerID;
  478. if (i == 0)
  479. {
  480. flowerID = 1;
  481. }
  482. else if (i < 8)
  483. {
  484. flowerID = flowerList.Last(i - 1, true);
  485. }
  486. else
  487. {
  488. if (fancy)
  489. {
  490. flowerID = flowerList.Random(true);
  491. }
  492. else
  493. {
  494. break;
  495. }
  496. }
  497. plantList += string.Format("{0},{1} ", flowerID, slotIndex);
  498. slotIndex++;
  499. }
  500. }
  501. plantList = plantList.TrimEnd(' ');
  502. doc.SelectSingleNode("PlayerConfig").SelectSingleNode("PlantList").Attributes[0].Value = plantList;
  503. float rate = Random.Range(0f, 1f);
  504. if (rate < 0.33f)
  505. {
  506. doc.SelectSingleNode("PlayerConfig").SelectSingleNode("Player").Attributes[0].Value = "PlayerPink";
  507. }
  508. else if (rate < 0.66f)
  509. {
  510. doc.SelectSingleNode("PlayerConfig").SelectSingleNode("Player").Attributes[0].Value = "PlayerBlond";
  511. }
  512. else
  513. {
  514. doc.SelectSingleNode("PlayerConfig").SelectSingleNode("Player").Attributes[0].Value = "PlayerBrown";
  515. }
  516. }
  517. }