ManaVisit.cs 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590
  1. using UnityEngine;
  2. using System.Xml;
  3. using System.Collections;
  4. using System.Collections.Generic;
  5. using LitJson;
  6. using UnityEngine.Events;
  7. using UnityEngine.UI;
  8. public class ManaVisit
  9. {
  10. #region 变量
  11. #region 配置
  12. public static int Cost;
  13. public static int LevelMin;
  14. public static int LevelMax;
  15. public static int CoolTime;
  16. public static int AwardMin;
  17. public static int AwardMax;
  18. public static float AwardRate;
  19. public static float CreateRate;
  20. #endregion
  21. public static bool InVisit;
  22. public static bool LoadComplete;
  23. public static bool TweenComplete;
  24. public static string XmlStr;
  25. public static int Slot;
  26. public static int Level;
  27. public static int PageAmt;
  28. public static string Player;
  29. public static XmlNode Node;
  30. public static XmlDocument Document;
  31. public static bool Bird;
  32. public static bool Tree;
  33. public static bool Rainbow;
  34. public static List<Slot> VisitPlantList;
  35. public static List<Slot> OriginPlantList;
  36. public static List<ObjType> OriginElfList;
  37. #endregion
  38. public static void Initialize()
  39. {
  40. XmlAttributeCollection attribute = ManaData.GetVisitConfig();
  41. Cost = Mathf.FloorToInt((float)Auxiliary.FmlParse(attribute[5].Value, "l", ManaCenter.Level.ToString()));
  42. AwardMin = Mathf.CeilToInt((float) Auxiliary.FmlParse(attribute[2].Value));
  43. AwardMax = Mathf.CeilToInt((float)Auxiliary.FmlParse(attribute[3].Value, "l", ManaCenter.Level.ToString()));
  44. CoolTime = int.Parse(attribute[4].Value);
  45. AwardRate = float.Parse(attribute[1].Value);
  46. #region 倒计时
  47. if (CoolTime != 0)
  48. {
  49. Text text = ManaReso.Get<Text>("C_VisitLab");
  50. List<float> delayList = new List<float>();
  51. List<float> durationList = new List<float>();
  52. List<VecPair> pairList = new List<VecPair>();
  53. List<UnityAction> actionList = new List<UnityAction>();
  54. Vector3 v1 = new Vector3(0.75f, 0.75f, 0.75f);
  55. Vector3 v2 = new Vector3(0.4f, 0.4f, 0.4f);
  56. Vector3 v3 = new Vector3(0, 0, 0);
  57. for (int i = 0; i < CoolTime - 1; i++)
  58. {
  59. delayList.Add(0.5f);
  60. delayList.Add(0);
  61. }
  62. delayList.Add(0.5f);
  63. for (int i = 0; i < CoolTime; i++)
  64. {
  65. durationList.Add(0.25f);
  66. durationList.Add(0.25f);
  67. pairList.Add(new VecPair(v1, v2));
  68. pairList.Add(new VecPair(v2, v3));
  69. var tempInt = i;
  70. actionList.Add
  71. (
  72. () =>
  73. {
  74. text.text = (CoolTime - tempInt).ToString();
  75. ManaAudio.PlayClip(Clip.BtnClip);
  76. }
  77. );
  78. actionList.Add(null);
  79. }
  80. TweenRoot tween = ManaReso.Get("C_VisitLab").CreateStreamScale
  81. (
  82. delayList,
  83. durationList,
  84. pairList,
  85. true,
  86. false,
  87. Curve.EaseOutQuad,
  88. false,
  89. actionList
  90. );
  91. tween.OnForwardFinish += () =>
  92. {
  93. ManaAudio.PlayClip(Clip.BubbleClip);
  94. };
  95. }
  96. #endregion
  97. }
  98. public static void Exit()
  99. {
  100. ManaReso.Get("I_BlackMask").TweenForCG();
  101. ManaReso.SetActive("C_Visit", true);
  102. ManaReso.SetActive("C_Coin", true);
  103. ManaReso.SetActive("C_Group1", true);
  104. ManaReso.SetActive("C_Group2", true);
  105. ManaReso.SetActive("C_Return", false);
  106. ManaReso.SetActive("C_Garden", false);
  107. ManaGarden.AwardValid = true;
  108. #region Garden
  109. ManaGarden.RetriveFlowerAll();
  110. for (int i = 0; i < ManaGarden.PageList.Count; i++)
  111. {
  112. ManaReso.Save(ManaGarden.PageList[i]);
  113. }
  114. ManaGarden.PageList = new List<Transform>();
  115. Garden.CurPage = 0;
  116. ManaGarden.SlotList = new List<Slot>();
  117. ManaGarden.PageList = new List<Transform>();
  118. Garden.ResetPage();
  119. for (int i = 0; i < ManaGarden.SlotAmt / 7 + 2; i++)
  120. {
  121. ManaGarden.CreatePage();
  122. }
  123. for (int i = 0; i < ManaGarden.SlotList.Count; i++)
  124. {
  125. if (i < ManaGarden.SlotAmt)
  126. {
  127. ManaGarden.SlotList[i].Valid = true;
  128. ManaGarden.SlotList[i].Available = true;
  129. }
  130. else
  131. {
  132. ManaGarden.SlotList[i].Valid = false;
  133. ManaGarden.SlotList[i].Available = false;
  134. }
  135. }
  136. List<KV<int, int>> plantList = ManaData.GetPlantList();
  137. for (int i = 0; i < plantList.Count; i++)
  138. {
  139. ManaGarden.PlantFlower(plantList[i].Key, plantList[i].Value);
  140. }
  141. #endregion
  142. #region Bird Tree Rainbow
  143. if (Bird)
  144. {
  145. ManaReso.Get("Bird0").GetTweenSr().InDestination = true;
  146. }
  147. else
  148. {
  149. ManaReso.Get("Bird0").GetTweenSr().InOrigin = true;
  150. }
  151. if (Tree)
  152. {
  153. ManaReso.Get("Tree1").GetTweenSr().InDestination = true;
  154. ManaReso.Get("Tree2").GetTweenSr().InDestination = true;
  155. }
  156. else
  157. {
  158. ManaReso.Get("Tree1").GetTweenSr().InOrigin = true;
  159. ManaReso.Get("Tree2").GetTweenSr().InOrigin = true;
  160. }
  161. if (Rainbow)
  162. {
  163. ManaReso.Get("Rainbow").GetTweenSr().InDestination = true;
  164. }
  165. else
  166. {
  167. ManaReso.Get("Rainbow").GetTweenSr().InOrigin = true;
  168. }
  169. #endregion
  170. #region Player
  171. ManaReso.Save(ManaPlayer.Player);
  172. ManaReso.TraDic.Remove("Player");
  173. ManaPlayer.Instance.GetPlayer();
  174. Garden.PlayerPos = new List<Vector3>();
  175. Garden.Player = ManaReso.Get("Player");
  176. Garden.PlayerPos.Add(ManaPlayer.Player.ChildDic["Pos1"].position);
  177. Garden.PlayerPos.Add(ManaPlayer.Player.ChildDic["Pos2"].position);
  178. #endregion
  179. ManaGarden.ElfList = new List<ObjType>(OriginElfList);
  180. InVisit = false;
  181. }
  182. public static void Enter()
  183. {
  184. if (!LoadComplete || !TweenComplete)
  185. {
  186. return;
  187. }
  188. ManaReso.Get("I_BlackMask").TweenForCG();
  189. Document = new XmlDocument();
  190. Document.LoadXml(XmlStr);
  191. Node = Document.SelectSingleNode("PlayerConfig");
  192. Player = Node.SelectSingleNode("Player").Attributes[0].Value;
  193. ManaReso.SetActive("C_Coin", false);
  194. ManaReso.SetActive("C_Group1", false);
  195. ManaReso.SetActive("C_Group2", false);
  196. ManaReso.SetActive("C_Garden", true);
  197. if (!ManaTutorial.TutorialC)
  198. {
  199. ManaReso.SetActive("C_Return", true);
  200. }
  201. ManaGarden.AwardValid = false;
  202. #region Bird Tree Rainbow
  203. if (!InVisit)
  204. {
  205. if (ManaReso.Get("Bird0").gameObject.activeSelf)
  206. {
  207. Bird = true;
  208. }
  209. if (ManaReso.Get("Tree1").gameObject.activeSelf)
  210. {
  211. Tree = true;
  212. }
  213. if (ManaReso.Get("Rainbow").gameObject.activeSelf)
  214. {
  215. Rainbow = true;
  216. }
  217. }
  218. ManaReso.SetActive("Bird0", false);
  219. ManaReso.SetActive("Tree1", false);
  220. ManaReso.SetActive("Tree2", false);
  221. ManaReso.SetActive("Rainbow", false);
  222. #endregion
  223. #region Ability
  224. Slot = 1;
  225. if (!InVisit)
  226. {
  227. ManaData.SavePlantList();
  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. }
  317. ManaGarden.RetriveFlowerAll();
  318. for (int i = 0; i < ManaGarden.PageList.Count; i++)
  319. {
  320. ManaReso.Save(ManaGarden.PageList[i]);
  321. }
  322. ManaGarden.PageList = new List<Transform>();
  323. Garden.CurPage = 0;
  324. ManaGarden.SlotList = new List<Slot>();
  325. ManaGarden.PageList = new List<Transform>();
  326. Garden.ResetPage();
  327. for (int i = 0; i < Slot/7 + 2; i++)
  328. {
  329. ManaGarden.CreatePage();
  330. }
  331. for (int i = 0; i < ManaGarden.SlotList.Count; i++)
  332. {
  333. if (i < Slot)
  334. {
  335. ManaGarden.SlotList[i].Valid = true;
  336. ManaGarden.SlotList[i].Available = true;
  337. }
  338. else
  339. {
  340. ManaGarden.SlotList[i].Valid = false;
  341. ManaGarden.SlotList[i].Available = false;
  342. }
  343. }
  344. List<KV<int, int>> plantList = ManaData.GetPlantList(Node);
  345. for (int i = 0; i < plantList.Count; i++)
  346. {
  347. ManaGarden.PlantFlower(plantList[i].Key, plantList[i].Value);
  348. }
  349. #endregion
  350. #region Player
  351. ManaReso.Save(ManaPlayer.Player);
  352. ManaReso.TraDic.Remove("Player");
  353. ManaPlayer.Instance.GetPlayer(Player);
  354. Garden.PlayerPos = new List<Vector3>();
  355. Garden.Player = ManaReso.Get("Player");
  356. Garden.PlayerPos.Add(ManaPlayer.Player.ChildDic["Pos1"].position);
  357. Garden.PlayerPos.Add(ManaPlayer.Player.ChildDic["Pos2"].position);
  358. #endregion
  359. #region Award
  360. if (Random.Range(0f,1f) <= AwardRate)
  361. {
  362. if (ManaGarden.PlantList.Count > 0)
  363. {
  364. ManaGarden.PlantList.Random().Flower.Award = true;
  365. }
  366. }
  367. #endregion
  368. InVisit = true;
  369. }
  370. public static void DataReverse()
  371. {
  372. if (InVisit)
  373. {
  374. VisitPlantList = new List<Slot>(ManaGarden.PlantList);
  375. ManaGarden.PlantList = OriginPlantList;
  376. }
  377. }
  378. public static void DataRecover()
  379. {
  380. if (InVisit)
  381. {
  382. ManaGarden.PlantList = VisitPlantList;
  383. }
  384. }
  385. public static void GetArchive()
  386. {
  387. ManaServer.Download
  388. (
  389. "ytcy9g",
  390. (jsonData) =>
  391. {
  392. LoadComplete = true;
  393. XmlStr = jsonData["l"].ToString();
  394. Enter();
  395. }
  396. );
  397. //ManaServer.Random
  398. //(
  399. // (jsonData) =>
  400. // {
  401. // LoadComplete = true;
  402. // XmlStr = jsonData["l"].ToString();
  403. // Enter();
  404. // }
  405. //);
  406. //if (Random.Range(0f, 1f) <= CreatePosi)
  407. //{
  408. // XmlDocument document = new XmlDocument();
  409. // document.LoadXml(ManaData.PlayerDoc.OuterXml);
  410. // document.SelectSingleNode("Level").Value = ((int) Mathf.Lerp(LevelMin, LevelMax, Random.Range(0f, 1f))).ToString();
  411. // #region 生成技能数据
  412. // List<int> intList = new List<int>() {19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31};
  413. // int tempInt = (int)Mathf.Lerp(6, 12, Random.Range(0f, 1f));
  414. // XmlNodeList nodeList = document.SelectNodes("Skill");
  415. // for (int i = 0; i < tempInt; i++)
  416. // {
  417. // nodeList[intList.Random(true)].Attributes[3].Value = "1";
  418. // }
  419. // for (int i = 0; i < intList.Count; i++)
  420. // {
  421. // nodeList[intList.Random(true)].Attributes[3].Value = "0";
  422. // }
  423. // #endregion
  424. // LoadFinish = true;
  425. // XmlStr = document.OuterXml;
  426. // Enter();
  427. //}
  428. //else
  429. //{
  430. // ManaServer.Load
  431. // (
  432. // "hsoiv1",
  433. // (jsonData) =>
  434. // {
  435. // LoadFinish = true;
  436. // XmlStr = jsonData.ToJson();
  437. // Enter();
  438. // }
  439. // );
  440. //}
  441. }
  442. }