ManaVisit.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443
  1. using UnityEngine;
  2. using System.Xml;
  3. using System.Collections;
  4. using System.Collections.Generic;
  5. using LitJson;
  6. public class ManaVisit
  7. {
  8. #region 变量
  9. #region 配置
  10. public static int LevelMin;
  11. public static int LevelMax;
  12. public static float CreatePosi;
  13. #endregion
  14. public static bool Visit;
  15. public static bool LoadFinish;
  16. public static bool TweenFinish;
  17. public static string XmlStr;
  18. public static int Slot;
  19. public static int Level;
  20. public static int PageAmt;
  21. public static string Player;
  22. public static XmlNode Node;
  23. public static XmlDocument Document;
  24. public static bool Bird;
  25. public static bool Tree;
  26. public static bool Rainbow;
  27. public static List<Slot> VisitPlantList;
  28. public static List<Slot> OriginPlantList;
  29. public static List<ObjType> OriginElfList;
  30. #endregion
  31. public void Regist()
  32. {
  33. CreatePosi = 0.75f;
  34. }
  35. public static void Exit()
  36. {
  37. ManaReso.Get("I_BlackMask").TweenForCG();
  38. ManaReso.SetActive("C_Return", false);
  39. #region Garden
  40. ManaGarden.RetriveFlowerAll();
  41. for (int i = 0; i < ManaGarden.PageList.Count; i++)
  42. {
  43. ManaReso.Save(ManaGarden.PageList[i]);
  44. }
  45. Garden.CurPage = 0;
  46. ManaGarden.SlotList = new List<Slot>();
  47. ManaGarden.PageList = new List<Transform>();
  48. for (int i = 0; i < ManaGarden.SlotAmt / 7 + 2; i++)
  49. {
  50. ManaGarden.CreatePage();
  51. }
  52. for (int i = 0; i < ManaGarden.SlotList.Count; i++)
  53. {
  54. if (i < ManaGarden.SlotAmt)
  55. {
  56. ManaGarden.SlotList[i].Valid = true;
  57. }
  58. else
  59. {
  60. ManaGarden.SlotList[i].Valid = false;
  61. }
  62. }
  63. List<KV<int, int>> plantList = Data.GetPlantList();
  64. for (int i = 0; i < plantList.Count; i++)
  65. {
  66. ManaGarden.PlantFlower(plantList[i].Key, plantList[i].Value);
  67. }
  68. #endregion
  69. #region Bird Tree Rainbow
  70. if (Bird)
  71. {
  72. ManaReso.Get("Bird0").GetTweenSr().InDestination = true;
  73. }
  74. else
  75. {
  76. ManaReso.Get("Bird0").GetTweenSr().InOrigin = true;
  77. }
  78. if (Tree)
  79. {
  80. ManaReso.Get("Tree1").GetTweenSr().InDestination = true;
  81. ManaReso.Get("Tree2").GetTweenSr().InDestination = true;
  82. }
  83. else
  84. {
  85. ManaReso.Get("Tree1").GetTweenSr().InOrigin = true;
  86. ManaReso.Get("Tree2").GetTweenSr().InOrigin = true;
  87. }
  88. if (Rainbow)
  89. {
  90. ManaReso.Get("Rainbow").GetTweenSr().InDestination = true;
  91. }
  92. else
  93. {
  94. ManaReso.Get("Rainbow").GetTweenSr().InOrigin = true;
  95. }
  96. #endregion
  97. #region Player
  98. ManaReso.Save(ManaPlayer.Player);
  99. ManaReso.TraDic.Remove("Player");
  100. ManaPlayer.Instance.GetPlayer();
  101. Garden.PlayerPos = new List<Vector3>();
  102. Garden.Player = ManaReso.Get("Player");
  103. Garden.PlayerPos.Add(ManaPlayer.Player.ChildDic["Pos1"].position);
  104. Garden.PlayerPos.Add(ManaPlayer.Player.ChildDic["Pos2"].position);
  105. #endregion
  106. ManaGarden.ElfList = new List<ObjType>(OriginElfList);
  107. Visit = false;
  108. }
  109. public static void Enter()
  110. {
  111. if (!LoadFinish || !TweenFinish)
  112. {
  113. return;
  114. }
  115. ManaReso.Get("I_BlackMask").TweenForCG();
  116. ManaReso.SetActive("C_Return", true);
  117. Document = new XmlDocument();
  118. Document.LoadXml(XmlStr);
  119. Node = Document.SelectSingleNode("PlayerConfig");
  120. Slot = int.Parse(Node.SelectSingleNode("Slot").Attributes[0].Value);
  121. Level = int.Parse(Node.SelectSingleNode("Level").Attributes[0].Value);
  122. Player = Node.SelectSingleNode("Player").Attributes[0].Value;
  123. #region Bird Tree Rainbow
  124. if (!Visit)
  125. {
  126. if (ManaReso.Get("Bird").gameObject.activeSelf)
  127. {
  128. Bird = true;
  129. }
  130. if (ManaReso.Get("Tree1").gameObject.activeSelf)
  131. {
  132. Tree = true;
  133. }
  134. if (ManaReso.Get("Rainbow").gameObject.activeSelf)
  135. {
  136. Rainbow = true;
  137. }
  138. }
  139. ManaReso.SetActive("Bird0", false);
  140. ManaReso.SetActive("Tree1", false);
  141. ManaReso.SetActive("Tree2", false);
  142. ManaReso.SetActive("Rainbow", false);
  143. #endregion
  144. #region Ability
  145. if (!Visit)
  146. {
  147. Data.SavePlantList();
  148. OriginElfList = new List<ObjType>(ManaGarden.ElfList);
  149. }
  150. ManaGarden.ElfList = new List<ObjType>();
  151. List<XmlAttributeCollection> attributeList = Data.GetSkillList(Node);
  152. for (int i = 0; i < attributeList.Count; i++)
  153. {
  154. if (!attributeList[i][0].Value.Contains("Ability"))
  155. {
  156. continue;
  157. }
  158. if (int.Parse(attributeList[i][3].Value) == 0)
  159. {
  160. continue;
  161. }
  162. if (attributeList[i][0].Value == "Ability2")
  163. {
  164. ManaReso.Get("Rainbow").GetTweenSr().InDestination = true;
  165. }
  166. else if (attributeList[i][0].Value == "Ability3")
  167. {
  168. ManaReso.Get("Tree1").GetTweenSr().InDestination = true;
  169. ManaReso.Get("Tree2").GetTweenSr().InDestination = true;
  170. }
  171. else if (attributeList[i][0].Value == "Ability4")
  172. {
  173. ManaReso.Get("Bird0").GetTweenSr().InDestination = true;
  174. }
  175. else if (attributeList[i][0].Value == "Ability5")
  176. {
  177. ManaGarden.ElfList.Add(ObjType.BeeYellow);
  178. }
  179. else if (attributeList[i][0].Value == "Ability6")
  180. {
  181. Slot++;
  182. ManaGarden.ElfList.Add(ObjType.BeePurple);
  183. }
  184. else if (attributeList[i][0].Value == "Ability7")
  185. {
  186. Slot++;
  187. ManaGarden.ElfList.Add(ObjType.BeeBlue);
  188. }
  189. else if (attributeList[i][0].Value == "Ability8")
  190. {
  191. Slot++;
  192. ManaGarden.ElfList.Add(ObjType.BeeRed);
  193. }
  194. else if (attributeList[i][0].Value == "Ability9")
  195. {
  196. Slot++;
  197. ManaGarden.ElfList.Add(ObjType.BeeWhite);
  198. }
  199. else if (attributeList[i][0].Value == "Ability10")
  200. {
  201. Slot++;
  202. ManaGarden.ElfList.Add(ObjType.ButterflyYellow);
  203. }
  204. else if (attributeList[i][0].Value == "Ability11")
  205. {
  206. Slot++;
  207. ManaGarden.ElfList.Add(ObjType.ButterflyPurple);
  208. }
  209. else if (attributeList[i][0].Value == "Ability12")
  210. {
  211. Slot++;
  212. ManaGarden.ElfList.Add(ObjType.ButterflyBlue);
  213. }
  214. else if (attributeList[i][0].Value == "Ability13")
  215. {
  216. Slot++;
  217. ManaGarden.ElfList.Add(ObjType.ButterflyRed);
  218. }
  219. else if (attributeList[i][0].Value == "Ability14")
  220. {
  221. Slot++;
  222. ManaGarden.ElfList.Add(ObjType.ButterflyWhite);
  223. }
  224. }
  225. #endregion
  226. #region Garden
  227. OriginPlantList = new List<Slot>(ManaGarden.PlantList);
  228. ManaGarden.RetriveFlowerAll();
  229. for (int i = 0; i < ManaGarden.PageList.Count; i++)
  230. {
  231. ManaReso.Save(ManaGarden.PageList[i]);
  232. }
  233. Garden.CurPage = 0;
  234. ManaGarden.SlotList = new List<Slot>();
  235. ManaGarden.PageList = new List<Transform>();
  236. for (int i = 0; i < Slot/7 + 2; i++)
  237. {
  238. ManaGarden.CreatePage();
  239. }
  240. for (int i = 0; i < ManaGarden.SlotList.Count; i++)
  241. {
  242. if (i < Slot)
  243. {
  244. ManaGarden.SlotList[i].Valid = true;
  245. }
  246. else
  247. {
  248. ManaGarden.SlotList[i].Valid = false;
  249. }
  250. }
  251. List<KV<int, int>> plantList = Data.GetPlantList(Node);
  252. for (int i = 0; i < plantList.Count; i++)
  253. {
  254. ManaGarden.PlantFlower(plantList[i].Key, plantList[i].Value);
  255. }
  256. #endregion
  257. #region Player
  258. ManaReso.Save(ManaPlayer.Player);
  259. ManaReso.TraDic.Remove("Player");
  260. ManaPlayer.Instance.GetPlayer(Player);
  261. Garden.PlayerPos = new List<Vector3>();
  262. Garden.Player = ManaReso.Get("Player");
  263. Garden.PlayerPos.Add(ManaPlayer.Player.ChildDic["Pos1"].position);
  264. Garden.PlayerPos.Add(ManaPlayer.Player.ChildDic["Pos2"].position);
  265. #endregion
  266. Visit = true;
  267. }
  268. public static void DataReverse()
  269. {
  270. if (Visit)
  271. {
  272. VisitPlantList = new List<Slot>(ManaGarden.PlantList);
  273. ManaGarden.PlantList = OriginPlantList;
  274. }
  275. }
  276. public static void DataRecover()
  277. {
  278. if (Visit)
  279. {
  280. ManaGarden.PlantList = VisitPlantList;
  281. }
  282. }
  283. public static void GetArchive()
  284. {
  285. ManaServer.Load
  286. (
  287. "hsoiv1",
  288. (jsonData) =>
  289. {
  290. LoadFinish = true;
  291. XmlStr = jsonData["l"].ToString();
  292. Enter();
  293. }
  294. );
  295. //if (Random.Range(0f, 1f) <= CreatePosi)
  296. //{
  297. // XmlDocument document = new XmlDocument();
  298. // document.LoadXml(Data.PlayerDoc.OuterXml);
  299. // document.SelectSingleNode("Level").Value = ((int) Mathf.Lerp(LevelMin, LevelMax, Random.Range(0f, 1f))).ToString();
  300. // #region 生成技能数据
  301. // List<int> intList = new List<int>() {19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31};
  302. // int tempInt = (int)Mathf.Lerp(6, 12, Random.Range(0f, 1f));
  303. // XmlNodeList nodeList = document.SelectNodes("Skill");
  304. // for (int i = 0; i < tempInt; i++)
  305. // {
  306. // nodeList[intList.Random(true)].Attributes[3].Value = "1";
  307. // }
  308. // for (int i = 0; i < intList.Count; i++)
  309. // {
  310. // nodeList[intList.Random(true)].Attributes[3].Value = "0";
  311. // }
  312. // #endregion
  313. // LoadFinish = true;
  314. // XmlStr = document.OuterXml;
  315. // Enter();
  316. //}
  317. //else
  318. //{
  319. // ManaServer.Load
  320. // (
  321. // "hsoiv1",
  322. // (jsonData) =>
  323. // {
  324. // LoadFinish = true;
  325. // XmlStr = jsonData.ToJson();
  326. // Enter();
  327. // }
  328. // );
  329. //}
  330. }
  331. }