ManaVisit.cs 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571
  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 Visit;
  22. public static bool LoadFinish;
  23. public static bool TweenFinish;
  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 = Data.GetVisitConfig();
  41. Cost = Mathf.FloorToInt((float)Auxiliary.FmlParse(attribute[5].Value, "l", ManaData.Level.ToString()));
  42. AwardMin = Mathf.CeilToInt((float) Auxiliary.FmlParse(attribute[2].Value));
  43. AwardMax = Mathf.CeilToInt((float)Auxiliary.FmlParse(attribute[3].Value, "l", ManaData.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. actionList.Add
  81. (
  82. () =>
  83. {
  84. ManaAudio.PlayClip(Clip.BubbleClip);
  85. }
  86. );
  87. ManaReso.Get("C_VisitLab").CreateStreamScale
  88. (
  89. delayList,
  90. durationList,
  91. pairList,
  92. true,
  93. false,
  94. Curve.EaseOutQuad,
  95. false,
  96. actionList
  97. );
  98. }
  99. #endregion
  100. }
  101. public static void Exit()
  102. {
  103. ManaReso.Get("I_BlackMask").TweenForCG();
  104. ManaReso.SetActive("C_Visit", true);
  105. ManaReso.SetActive("C_Coin", true);
  106. ManaReso.SetActive("C_Group1", true);
  107. ManaReso.SetActive("C_Group2", true);
  108. ManaReso.SetActive("C_Return", false);
  109. ManaReso.SetActive("C_Garden", false);
  110. ManaGarden.AwardValid = true;
  111. #region Garden
  112. ManaGarden.RetriveFlowerAll();
  113. for (int i = 0; i < ManaGarden.PageList.Count; i++)
  114. {
  115. ManaReso.Save(ManaGarden.PageList[i]);
  116. }
  117. ManaGarden.PageList = new List<Transform>();
  118. Garden.CurPage = 0;
  119. ManaGarden.SlotList = new List<Slot>();
  120. ManaGarden.PageList = new List<Transform>();
  121. Garden.Garden2.position = Garden.GardenPos2[0];
  122. Garden.Garden3.position = Garden.GardenPos3[0];
  123. Garden.Garden4.position = Garden.GardenPos4[0];
  124. Garden.GardenPage.position = Garden.PagePos[0];
  125. for (int i = 0; i < ManaGarden.SlotAmt / 7 + 2; i++)
  126. {
  127. ManaGarden.CreatePage();
  128. }
  129. for (int i = 0; i < ManaGarden.SlotList.Count; i++)
  130. {
  131. if (i < ManaGarden.SlotAmt)
  132. {
  133. ManaGarden.SlotList[i].Valid = true;
  134. ManaGarden.SlotList[i].Available = true;
  135. }
  136. else
  137. {
  138. ManaGarden.SlotList[i].Valid = false;
  139. ManaGarden.SlotList[i].Available = false;
  140. }
  141. }
  142. List<KV<int, int>> plantList = Data.GetPlantList();
  143. for (int i = 0; i < plantList.Count; i++)
  144. {
  145. ManaGarden.PlantFlower(plantList[i].Key, plantList[i].Value);
  146. }
  147. #endregion
  148. #region Bird Tree Rainbow
  149. if (Bird)
  150. {
  151. ManaReso.Get("Bird0").GetTweenSr().InDestination = true;
  152. }
  153. else
  154. {
  155. ManaReso.Get("Bird0").GetTweenSr().InOrigin = true;
  156. }
  157. if (Tree)
  158. {
  159. ManaReso.Get("Tree1").GetTweenSr().InDestination = true;
  160. ManaReso.Get("Tree2").GetTweenSr().InDestination = true;
  161. }
  162. else
  163. {
  164. ManaReso.Get("Tree1").GetTweenSr().InOrigin = true;
  165. ManaReso.Get("Tree2").GetTweenSr().InOrigin = true;
  166. }
  167. if (Rainbow)
  168. {
  169. ManaReso.Get("Rainbow").GetTweenSr().InDestination = true;
  170. }
  171. else
  172. {
  173. ManaReso.Get("Rainbow").GetTweenSr().InOrigin = true;
  174. }
  175. #endregion
  176. #region Player
  177. ManaReso.Save(ManaPlayer.Player);
  178. ManaReso.TraDic.Remove("Player");
  179. ManaPlayer.Instance.GetPlayer();
  180. Garden.PlayerPos = new List<Vector3>();
  181. Garden.Player = ManaReso.Get("Player");
  182. Garden.PlayerPos.Add(ManaPlayer.Player.ChildDic["Pos1"].position);
  183. Garden.PlayerPos.Add(ManaPlayer.Player.ChildDic["Pos2"].position);
  184. #endregion
  185. ManaGarden.ElfList = new List<ObjType>(OriginElfList);
  186. Visit = false;
  187. }
  188. public static void Enter()
  189. {
  190. if (!LoadFinish || !TweenFinish)
  191. {
  192. return;
  193. }
  194. ManaReso.Get("I_BlackMask").TweenForCG();
  195. Document = new XmlDocument();
  196. Document.LoadXml(XmlStr);
  197. Node = Document.SelectSingleNode("PlayerConfig");
  198. Slot = int.Parse(Node.SelectSingleNode("Slot").Attributes[0].Value);
  199. Level = int.Parse(Node.SelectSingleNode("Level").Attributes[0].Value);
  200. Player = Node.SelectSingleNode("Player").Attributes[0].Value;
  201. ManaReso.SetText("C_GardenLab", Language.GetStr("UI", "C_GardenLab") + Level);
  202. ManaReso.SetActive("C_Coin", false);
  203. ManaReso.SetActive("C_Group1", false);
  204. ManaReso.SetActive("C_Group2", false);
  205. ManaReso.SetActive("C_Garden", true);
  206. if (!ManaTutorial.TutorialC)
  207. {
  208. ManaReso.SetActive("C_Return", true);
  209. }
  210. ManaGarden.AwardValid = false;
  211. #region Bird Tree Rainbow
  212. if (!Visit)
  213. {
  214. if (ManaReso.Get("Bird0").gameObject.activeSelf)
  215. {
  216. Bird = true;
  217. }
  218. if (ManaReso.Get("Tree1").gameObject.activeSelf)
  219. {
  220. Tree = true;
  221. }
  222. if (ManaReso.Get("Rainbow").gameObject.activeSelf)
  223. {
  224. Rainbow = true;
  225. }
  226. }
  227. ManaReso.SetActive("Bird0", false);
  228. ManaReso.SetActive("Tree1", false);
  229. ManaReso.SetActive("Tree2", false);
  230. ManaReso.SetActive("Rainbow", false);
  231. #endregion
  232. #region Ability
  233. if (!Visit)
  234. {
  235. Data.SavePlantList();
  236. OriginElfList = new List<ObjType>(ManaGarden.ElfList);
  237. }
  238. ManaGarden.ElfList = new List<ObjType>();
  239. List<XmlAttributeCollection> attributeList = Data.GetSkillList(Node);
  240. for (int i = 0; i < attributeList.Count; i++)
  241. {
  242. if (!attributeList[i][0].Value.Contains("Ability"))
  243. {
  244. continue;
  245. }
  246. if (int.Parse(attributeList[i][3].Value) == 0)
  247. {
  248. continue;
  249. }
  250. if (attributeList[i][0].Value == "Ability2")
  251. {
  252. ManaReso.Get("Rainbow").GetTweenSr().InDestination = true;
  253. }
  254. else if (attributeList[i][0].Value == "Ability3")
  255. {
  256. ManaReso.Get("Tree1").GetTweenSr().InDestination = true;
  257. ManaReso.Get("Tree2").GetTweenSr().InDestination = true;
  258. }
  259. else if (attributeList[i][0].Value == "Ability4")
  260. {
  261. ManaReso.Get("Bird0").GetTweenSr().InDestination = true;
  262. }
  263. else if (attributeList[i][0].Value == "Ability5")
  264. {
  265. ManaGarden.ElfList.Add(ObjType.BeeYellow);
  266. }
  267. else if (attributeList[i][0].Value == "Ability6")
  268. {
  269. Slot++;
  270. ManaGarden.ElfList.Add(ObjType.BeePurple);
  271. }
  272. else if (attributeList[i][0].Value == "Ability7")
  273. {
  274. Slot++;
  275. ManaGarden.ElfList.Add(ObjType.BeeBlue);
  276. }
  277. else if (attributeList[i][0].Value == "Ability8")
  278. {
  279. Slot++;
  280. ManaGarden.ElfList.Add(ObjType.BeeRed);
  281. }
  282. else if (attributeList[i][0].Value == "Ability9")
  283. {
  284. Slot++;
  285. ManaGarden.ElfList.Add(ObjType.BeeWhite);
  286. }
  287. else if (attributeList[i][0].Value == "Ability10")
  288. {
  289. Slot++;
  290. ManaGarden.ElfList.Add(ObjType.ButterflyYellow);
  291. }
  292. else if (attributeList[i][0].Value == "Ability11")
  293. {
  294. Slot++;
  295. ManaGarden.ElfList.Add(ObjType.ButterflyPurple);
  296. }
  297. else if (attributeList[i][0].Value == "Ability12")
  298. {
  299. Slot++;
  300. ManaGarden.ElfList.Add(ObjType.ButterflyBlue);
  301. }
  302. else if (attributeList[i][0].Value == "Ability13")
  303. {
  304. Slot++;
  305. ManaGarden.ElfList.Add(ObjType.ButterflyRed);
  306. }
  307. else if (attributeList[i][0].Value == "Ability14")
  308. {
  309. Slot++;
  310. ManaGarden.ElfList.Add(ObjType.ButterflyWhite);
  311. }
  312. }
  313. #endregion
  314. #region Garden
  315. OriginPlantList = new List<Slot>(ManaGarden.PlantList);
  316. ManaGarden.RetriveFlowerAll();
  317. for (int i = 0; i < ManaGarden.PageList.Count; i++)
  318. {
  319. ManaReso.Save(ManaGarden.PageList[i]);
  320. }
  321. ManaGarden.PageList = new List<Transform>();
  322. Garden.CurPage = 0;
  323. ManaGarden.SlotList = new List<Slot>();
  324. ManaGarden.PageList = new List<Transform>();
  325. for (int i = 0; i < Slot/7 + 2; i++)
  326. {
  327. ManaGarden.CreatePage();
  328. }
  329. for (int i = 0; i < ManaGarden.SlotList.Count; i++)
  330. {
  331. if (i < Slot)
  332. {
  333. ManaGarden.SlotList[i].Valid = true;
  334. ManaGarden.SlotList[i].Available = true;
  335. }
  336. else
  337. {
  338. ManaGarden.SlotList[i].Valid = false;
  339. ManaGarden.SlotList[i].Available = false;
  340. }
  341. }
  342. List<KV<int, int>> plantList = Data.GetPlantList(Node);
  343. Debug.Log("Count" + ManaGarden.PlantList.Count);
  344. for (int i = 0; i < plantList.Count; i++)
  345. {
  346. Debug.Log("Plant : " + plantList[i].Key + " " + plantList[i].Value);
  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. ManaGarden.PlantList.Random().Flower.Award = true;
  363. }
  364. #endregion
  365. Visit = true;
  366. }
  367. public static void DataReverse()
  368. {
  369. if (Visit)
  370. {
  371. VisitPlantList = new List<Slot>(ManaGarden.PlantList);
  372. ManaGarden.PlantList = OriginPlantList;
  373. }
  374. }
  375. public static void DataRecover()
  376. {
  377. if (Visit)
  378. {
  379. ManaGarden.PlantList = VisitPlantList;
  380. }
  381. }
  382. public static void GetArchive()
  383. {
  384. ManaServer.Load
  385. (
  386. "hsoiv1",
  387. (jsonData) =>
  388. {
  389. LoadFinish = true;
  390. XmlStr = jsonData["l"].ToString();
  391. Enter();
  392. }
  393. );
  394. //if (Random.Range(0f, 1f) <= CreatePosi)
  395. //{
  396. // XmlDocument document = new XmlDocument();
  397. // document.LoadXml(Data.PlayerDoc.OuterXml);
  398. // document.SelectSingleNode("Level").Value = ((int) Mathf.Lerp(LevelMin, LevelMax, Random.Range(0f, 1f))).ToString();
  399. // #region 生成技能数据
  400. // List<int> intList = new List<int>() {19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31};
  401. // int tempInt = (int)Mathf.Lerp(6, 12, Random.Range(0f, 1f));
  402. // XmlNodeList nodeList = document.SelectNodes("Skill");
  403. // for (int i = 0; i < tempInt; i++)
  404. // {
  405. // nodeList[intList.Random(true)].Attributes[3].Value = "1";
  406. // }
  407. // for (int i = 0; i < intList.Count; i++)
  408. // {
  409. // nodeList[intList.Random(true)].Attributes[3].Value = "0";
  410. // }
  411. // #endregion
  412. // LoadFinish = true;
  413. // XmlStr = document.OuterXml;
  414. // Enter();
  415. //}
  416. //else
  417. //{
  418. // ManaServer.Load
  419. // (
  420. // "hsoiv1",
  421. // (jsonData) =>
  422. // {
  423. // LoadFinish = true;
  424. // XmlStr = jsonData.ToJson();
  425. // Enter();
  426. // }
  427. // );
  428. //}
  429. }
  430. }