Data.cs 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568
  1. using UnityEngine;
  2. using System;
  3. using System.IO;
  4. using System.Xml;
  5. using System.Text;
  6. using System.Collections;
  7. using System.Collections.Generic;
  8. public class Data
  9. {
  10. #region
  11. public static XmlNode PlayerNode
  12. {
  13. get
  14. {
  15. if (_PlayerNode == null)
  16. {
  17. _PlayerNode = PlayerDoc.SelectSingleNode("PlayerConfig");
  18. }
  19. return _PlayerNode;
  20. }
  21. set { _PlayerNode = value; }
  22. }
  23. public static XmlDocument PlayerDoc
  24. {
  25. get
  26. {
  27. if (_PlayerDoc == null)
  28. {
  29. int version = 0;
  30. int nativeVersion = 0;
  31. XmlNode temoNode;
  32. XmlDocument tempDoc1;
  33. XmlDocument tempDoc2;
  34. FileInfo fileInfo = new FileInfo(Application.persistentDataPath + "/PlayerConfig.xml");
  35. if (fileInfo.Exists)
  36. {
  37. StreamReader sr = new StreamReader(Application.persistentDataPath + "/PlayerConfig.xml");
  38. tempDoc1 = new XmlDocument();
  39. tempDoc1.LoadXml(sr.ReadToEnd());
  40. sr.Close();
  41. TextAsset textAsset = Bundle.Config.LoadAsset<TextAsset>("PlayerConfig");
  42. tempDoc2 = new XmlDocument();
  43. tempDoc2.LoadXml(textAsset.text);
  44. version = int.Parse(tempDoc2.SelectSingleNode("PlayerConfig").SelectSingleNode("Version").Attributes[0].Value);
  45. temoNode = tempDoc1.SelectSingleNode("PlayerConfig").SelectSingleNode("Version");
  46. if (temoNode == null)
  47. {
  48. StreamWriter sw = new StreamWriter(Application.persistentDataPath + "/PlayerConfig.xml");
  49. sw.Write(tempDoc2.OuterXml);
  50. sw.Close();
  51. _PlayerDoc = tempDoc2;
  52. }
  53. else
  54. {
  55. nativeVersion = int.Parse(temoNode.Attributes[0].Value);
  56. if (nativeVersion != version)
  57. {
  58. StreamWriter sw = new StreamWriter(Application.persistentDataPath + "/PlayerConfig.xml");
  59. sw.Write(tempDoc2.OuterXml);
  60. sw.Close();
  61. _PlayerDoc = tempDoc2;
  62. }
  63. else
  64. {
  65. _PlayerDoc = tempDoc1;
  66. }
  67. }
  68. }
  69. else
  70. {
  71. TextAsset textAsset = Bundle.Config.LoadAsset<TextAsset>("PlayerConfig");
  72. tempDoc2 = new XmlDocument();
  73. tempDoc2.LoadXml(textAsset.text);
  74. StreamWriter sw = new StreamWriter(Application.persistentDataPath + "/PlayerConfig.xml");
  75. sw.Write(tempDoc2.OuterXml);
  76. sw.Close();
  77. _PlayerDoc = tempDoc2;
  78. _PlayerDoc.SelectSingleNode("PlayerConfig").SelectSingleNode("QuitTime").Attributes[0].Value = DateTime.Now.ToString();
  79. }
  80. }
  81. return _PlayerDoc;
  82. }
  83. set { _PlayerDoc = value; }
  84. }
  85. private static XmlNode _PlayerNode;
  86. private static XmlDocument _PlayerDoc;
  87. #endregion
  88. private static void SaveSkillList()
  89. {
  90. XmlNode xmlNode;
  91. XmlAttribute xmlAttribute;
  92. xmlNode = PlayerNode.SelectSingleNode("SkillList");
  93. xmlNode.RemoveAll();
  94. for (int i = 0; i < ManaData.SkillList.Count; i++)
  95. {
  96. if (ManaData.SkillList[i].SkillType == SkillType.Skill)
  97. {
  98. #region Skill
  99. Skill skill = (Skill)ManaData.SkillList[i];
  100. xmlNode = xmlNode.AppendChild(PlayerDoc.CreateNode(XmlNodeType.Element, skill.Name, ""));
  101. xmlAttribute = xmlNode.Attributes.Append(PlayerDoc.CreateAttribute("SkillType"));
  102. xmlAttribute.Value = skill.SkillType.ToString();
  103. xmlAttribute = xmlNode.Attributes.Append(PlayerDoc.CreateAttribute("ItemStatus"));
  104. xmlAttribute.Value = skill.ItemStatus.ToString();
  105. xmlAttribute = xmlNode.Attributes.Append(PlayerDoc.CreateAttribute("Level"));
  106. xmlAttribute.Value = skill.Level.ToString();
  107. xmlAttribute = xmlNode.Attributes.Append(PlayerDoc.CreateAttribute("CdTimer"));
  108. xmlAttribute.Value = skill.CoolTimer.ToString();
  109. xmlAttribute = xmlNode.Attributes.Append(PlayerDoc.CreateAttribute("EffectTimer"));
  110. xmlAttribute.Value = skill.UseTimer.ToString();
  111. xmlNode = PlayerNode.SelectSingleNode("SkillList");
  112. #endregion
  113. }
  114. else if (ManaData.SkillList[i].SkillType == SkillType.Pack)
  115. {
  116. #region Pack
  117. Pack pack = (Pack)ManaData.SkillList[i];
  118. xmlNode = xmlNode.AppendChild(PlayerDoc.CreateNode(XmlNodeType.Element, "礼包", ""));
  119. xmlAttribute = xmlNode.Attributes.Append(PlayerDoc.CreateAttribute("SkillType"));
  120. xmlAttribute.Value = pack.SkillType.ToString();
  121. xmlAttribute = xmlNode.Attributes.Append(PlayerDoc.CreateAttribute("Name"));
  122. xmlAttribute.Value = pack.Name;
  123. xmlAttribute = xmlNode.Attributes.Append(PlayerDoc.CreateAttribute("ItemStatus"));
  124. xmlAttribute.Value = pack.ItemStatus.ToString();
  125. xmlAttribute = xmlNode.Attributes.Append(PlayerDoc.CreateAttribute("Level"));
  126. xmlAttribute.Value = pack.Level.ToString();
  127. xmlNode = PlayerNode.SelectSingleNode("SkillList");
  128. #endregion
  129. }
  130. else if (ManaData.SkillList[i].SkillType == SkillType.Ability)
  131. {
  132. #region Ability
  133. Ability ability = (Ability)ManaData.SkillList[i];
  134. xmlNode = xmlNode.AppendChild(PlayerDoc.CreateNode(XmlNodeType.Element, ability.Name, ""));
  135. xmlAttribute = xmlNode.Attributes.Append(PlayerDoc.CreateAttribute("SkillType"));
  136. xmlAttribute.Value = ability.SkillType.ToString();
  137. xmlAttribute = xmlNode.Attributes.Append(PlayerDoc.CreateAttribute("ItemStatus"));
  138. xmlAttribute.Value = ability.ItemStatus.ToString();
  139. xmlAttribute = xmlNode.Attributes.Append(PlayerDoc.CreateAttribute("Level"));
  140. xmlAttribute.Value = ability.Level.ToString();
  141. xmlNode = PlayerNode.SelectSingleNode("SkillList");
  142. #endregion
  143. }
  144. else if (ManaData.SkillList[i].SkillType == SkillType.BigSkill)
  145. {
  146. #region BigSkill
  147. BigSkill bigSkill = (BigSkill)ManaData.SkillList[i];
  148. xmlNode = xmlNode.AppendChild(PlayerDoc.CreateNode(XmlNodeType.Element, bigSkill.Name, ""));
  149. xmlAttribute = xmlNode.Attributes.Append(PlayerDoc.CreateAttribute("SkillType"));
  150. xmlAttribute.Value = bigSkill.SkillType.ToString();
  151. xmlAttribute = xmlNode.Attributes.Append(PlayerDoc.CreateAttribute("ItemStatus"));
  152. xmlAttribute.Value = bigSkill.ItemStatus.ToString();
  153. xmlAttribute = xmlNode.Attributes.Append(PlayerDoc.CreateAttribute("BarStatus"));
  154. xmlAttribute.Value = bigSkill.BarStatus.ToString();
  155. xmlAttribute = xmlNode.Attributes.Append(PlayerDoc.CreateAttribute("Level"));
  156. xmlAttribute.Value = bigSkill.Level.ToString();
  157. xmlAttribute = xmlNode.Attributes.Append(PlayerDoc.CreateAttribute("CdTimer"));
  158. xmlAttribute.Value = bigSkill.CoolTimer.ToString();
  159. xmlAttribute = xmlNode.Attributes.Append(PlayerDoc.CreateAttribute("EffectTimer"));
  160. xmlAttribute.Value = bigSkill.UseTimer.ToString();
  161. xmlNode = PlayerNode.SelectSingleNode("SkillList");
  162. #endregion
  163. }
  164. }
  165. }
  166. private static void SavePlantList()
  167. {
  168. XmlAttributeCollection attributes = PlayerNode.SelectSingleNode("PlantList").Attributes;
  169. attributes.RemoveAll();
  170. for (int i = 0; i < ManaGarden.PlantList.Count; i++)
  171. {
  172. attributes.Append(PlayerDoc.CreateAttribute(ManaGarden.PlantList[i].name));
  173. attributes[i].Value = ManaGarden.PlantList[i].Flower.FlowerInfo.Id.ToString();
  174. }
  175. }
  176. private static void SaveCommon()
  177. {
  178. PlayerNode.SelectSingleNode("Sign").Attributes[0].Value = ManaData.Sign.ToString();
  179. PlayerNode.SelectSingleNode("Coin").Attributes[0].Value = ManaData.Coin.ToString("0");
  180. PlayerNode.SelectSingleNode("Level").Attributes[0].Value = ManaData.Level.ToString();
  181. PlayerNode.SelectSingleNode("Person").Attributes[0].Value = ManaData.Person.ToString();
  182. PlayerNode.SelectSingleNode("Diamond").Attributes[0].Value = ManaData.Diamond.ToString();
  183. PlayerNode.SelectSingleNode("QuitTime").Attributes[0].Value = DateTime.Now.ToString();
  184. PlayerNode.SelectSingleNode("CoinPerson").Attributes[0].Value = ManaData.CoinPerson.ToString();
  185. PlayerNode.SelectSingleNode("MiniTimer").Attributes[0].Value = ManaData.MiniTimer.ToString();
  186. PlayerNode.SelectSingleNode("CircleTimer").Attributes[0].Value = ManaData.CircleTimer.ToString();
  187. }
  188. private static void SaveFlowerList()
  189. {
  190. XmlAttributeCollection attributes = PlayerNode.SelectSingleNode("FlowerList").Attributes;
  191. attributes[0].RemoveAll();
  192. XmlAttribute xmlAttribute = attributes.Append(PlayerDoc.CreateAttribute("ID"));
  193. for (int i = 0; i < ManaGarden.FlowerInfoList.Count; i++)
  194. {
  195. if (ManaGarden.FlowerInfoList[i].Unlock)
  196. {
  197. xmlAttribute.Value += ManaGarden.FlowerInfoList[i].Id - 1 + " ";
  198. }
  199. }
  200. xmlAttribute.Value = xmlAttribute.Value.Trim(' ');
  201. }
  202. public static void SavePlayerConfig()
  203. {
  204. SaveSkillList();
  205. SavePlantList();
  206. SaveCommon();
  207. SaveFlowerList();
  208. StreamWriter sw = new StreamWriter(Application.persistentDataPath + "/PlayerConfig.xml");
  209. sw.Write(PlayerDoc.OuterXml);
  210. sw.Close();
  211. }
  212. private static void ResetSkillList()
  213. {
  214. XmlNode xmlNode;
  215. XmlAttribute xmlAttribute;
  216. xmlNode = PlayerNode.SelectSingleNode("SkillList");
  217. xmlNode.RemoveAll();
  218. for (int i = 0; i < ManaData.SkillList.Count; i++)
  219. {
  220. if (ManaData.SkillList[i].SkillType == SkillType.Skill)
  221. {
  222. #region Skill
  223. Skill skill = (Skill)ManaData.SkillList[i];
  224. xmlNode = xmlNode.AppendChild(PlayerDoc.CreateNode(XmlNodeType.Element, skill.Name, ""));
  225. xmlAttribute = xmlNode.Attributes.Append(PlayerDoc.CreateAttribute("SkillType"));
  226. xmlAttribute.Value = skill.SkillType.ToString();
  227. xmlAttribute = xmlNode.Attributes.Append(PlayerDoc.CreateAttribute("ItemStatus"));
  228. xmlAttribute.Value = SkillStatus.Lock.ToString();
  229. xmlAttribute = xmlNode.Attributes.Append(PlayerDoc.CreateAttribute("Level"));
  230. xmlAttribute.Value = 0.ToString();
  231. xmlAttribute = xmlNode.Attributes.Append(PlayerDoc.CreateAttribute("CdTimer"));
  232. xmlAttribute.Value = 0.ToString();
  233. xmlAttribute = xmlNode.Attributes.Append(PlayerDoc.CreateAttribute("EffectTimer"));
  234. xmlAttribute.Value = 0.ToString();
  235. xmlNode = PlayerNode.SelectSingleNode("SkillList");
  236. #endregion
  237. }
  238. else if (ManaData.SkillList[i].SkillType == SkillType.Pack)
  239. {
  240. #region Pack
  241. Pack pack = (Pack)ManaData.SkillList[i];
  242. xmlNode = xmlNode.AppendChild(PlayerDoc.CreateNode(XmlNodeType.Element, "礼包", ""));
  243. xmlAttribute = xmlNode.Attributes.Append(PlayerDoc.CreateAttribute("SkillType"));
  244. xmlAttribute.Value = pack.SkillType.ToString();
  245. xmlAttribute = xmlNode.Attributes.Append(PlayerDoc.CreateAttribute("Name"));
  246. xmlAttribute.Value = pack.Name;
  247. xmlAttribute = xmlNode.Attributes.Append(PlayerDoc.CreateAttribute("ItemStatus"));
  248. xmlAttribute.Value = SkillStatus.Lock.ToString();
  249. xmlAttribute = xmlNode.Attributes.Append(PlayerDoc.CreateAttribute("Level"));
  250. xmlAttribute.Value = 0.ToString();
  251. xmlNode = PlayerNode.SelectSingleNode("SkillList");
  252. #endregion
  253. }
  254. else if (ManaData.SkillList[i].SkillType == SkillType.Ability)
  255. {
  256. #region Ability
  257. Ability ability = (Ability)ManaData.SkillList[i];
  258. xmlNode = xmlNode.AppendChild(PlayerDoc.CreateNode(XmlNodeType.Element, ability.Name, ""));
  259. xmlAttribute = xmlNode.Attributes.Append(PlayerDoc.CreateAttribute("SkillType"));
  260. xmlAttribute.Value = ability.SkillType.ToString();
  261. xmlAttribute = xmlNode.Attributes.Append(PlayerDoc.CreateAttribute("ItemStatus"));
  262. xmlAttribute.Value = SkillStatus.Lock.ToString();
  263. xmlAttribute = xmlNode.Attributes.Append(PlayerDoc.CreateAttribute("Level"));
  264. xmlAttribute.Value = 0.ToString();
  265. xmlNode = PlayerNode.SelectSingleNode("SkillList");
  266. #endregion
  267. }
  268. else if (ManaData.SkillList[i].SkillType == SkillType.BigSkill)
  269. {
  270. #region BigSkill
  271. BigSkill bigSkill = (BigSkill)ManaData.SkillList[i];
  272. xmlNode = xmlNode.AppendChild(PlayerDoc.CreateNode(XmlNodeType.Element, bigSkill.Name, ""));
  273. xmlAttribute = xmlNode.Attributes.Append(PlayerDoc.CreateAttribute("SkillType"));
  274. xmlAttribute.Value = bigSkill.SkillType.ToString();
  275. xmlAttribute = xmlNode.Attributes.Append(PlayerDoc.CreateAttribute("ItemStatus"));
  276. xmlAttribute.Value = SkillStatus.Lock.ToString();
  277. xmlAttribute = xmlNode.Attributes.Append(PlayerDoc.CreateAttribute("BarStatus"));
  278. xmlAttribute.Value = SkillStatus.Buy.ToString();
  279. xmlAttribute = xmlNode.Attributes.Append(PlayerDoc.CreateAttribute("Level"));
  280. xmlAttribute.Value = 0.ToString();
  281. xmlAttribute = xmlNode.Attributes.Append(PlayerDoc.CreateAttribute("CdTimer"));
  282. xmlAttribute.Value = 0.ToString();
  283. xmlAttribute = xmlNode.Attributes.Append(PlayerDoc.CreateAttribute("EffectTimer"));
  284. xmlAttribute.Value = 0.ToString();
  285. xmlNode = PlayerNode.SelectSingleNode("SkillList");
  286. #endregion
  287. }
  288. }
  289. }
  290. private static void ResetPlantList()
  291. {
  292. XmlNode xmlNode = PlayerNode.SelectSingleNode("PlantList");
  293. xmlNode.RemoveAll();
  294. XmlAttribute xmlAttribute = xmlNode.Attributes.Append(PlayerDoc.CreateAttribute("SlotA1"));
  295. xmlAttribute.Value = 0.ToString();
  296. xmlAttribute = xmlNode.Attributes.Append(PlayerDoc.CreateAttribute("SlotA2"));
  297. xmlAttribute.Value = 1.ToString();
  298. xmlAttribute = xmlNode.Attributes.Append(PlayerDoc.CreateAttribute("SlotA3"));
  299. xmlAttribute.Value = 2.ToString();
  300. xmlAttribute = xmlNode.Attributes.Append(PlayerDoc.CreateAttribute("SlotA4"));
  301. xmlAttribute.Value = 3.ToString();
  302. xmlAttribute = xmlNode.Attributes.Append(PlayerDoc.CreateAttribute("SlotA5"));
  303. xmlAttribute.Value = 4.ToString();
  304. xmlAttribute = xmlNode.Attributes.Append(PlayerDoc.CreateAttribute("SlotA6"));
  305. xmlAttribute.Value = 5.ToString();
  306. xmlAttribute = xmlNode.Attributes.Append(PlayerDoc.CreateAttribute("SlotA7"));
  307. xmlAttribute.Value = 6.ToString();
  308. }
  309. private static void ResetCommon()
  310. {
  311. PlayerNode.SelectSingleNode("Slot").Attributes[0].Value = "7";
  312. PlayerNode.SelectSingleNode("Sign").Attributes[0].Value = "0";
  313. PlayerNode.SelectSingleNode("Coin").Attributes[0].Value = "0";
  314. PlayerNode.SelectSingleNode("Level").Attributes[0].Value = "0";
  315. PlayerNode.SelectSingleNode("Person").Attributes[0].Value = "0";
  316. PlayerNode.SelectSingleNode("Diamond").Attributes[0].Value = "0";
  317. PlayerNode.SelectSingleNode("QuitTime").Attributes[0].Value = DateTime.Now.ToString();
  318. PlayerNode.SelectSingleNode("CoinPerson").Attributes[0].Value = "0";
  319. PlayerNode.SelectSingleNode("MiniTimer").Attributes[0].Value = "0";
  320. PlayerNode.SelectSingleNode("CircleTimer").Attributes[0].Value = "10";
  321. }
  322. private static void ResetFlowerList()
  323. {
  324. XmlAttributeCollection attributes = PlayerNode.SelectSingleNode("FlowerList").Attributes;
  325. attributes[0].RemoveAll();
  326. XmlAttribute xmlAttribute = attributes.Append(PlayerDoc.CreateAttribute("ID"));
  327. xmlAttribute.Value = "0 1 2 3 4 5 6 7 8 9";
  328. }
  329. public static void ResetPlayerConfig()
  330. {
  331. ResetSkillList();
  332. ResetPlantList();
  333. ResetCommon();
  334. ResetFlowerList();
  335. StreamWriter sw = new StreamWriter(Application.persistentDataPath + "/PlayerConfig.xml");
  336. sw.Write(PlayerDoc.OuterXml);
  337. sw.Close();
  338. }
  339. public static XmlAttributeCollection GetAwardConfig()
  340. {
  341. TextAsset textAsset;
  342. XmlDocument xmlDoc = new XmlDocument();
  343. textAsset = Bundle.Config.LoadAsset<TextAsset>("award_config");
  344. xmlDoc.LoadXml(textAsset.text);
  345. XmlNode xmlNode = xmlDoc.SelectSingleNode("data").SelectSingleNode("item");
  346. return xmlNode.Attributes;
  347. }
  348. public static List<XmlAttributeCollection> GetSkillConfig()
  349. {
  350. TextAsset textAsset;
  351. XmlDocument xmlDoc = new XmlDocument();
  352. List<XmlNodeList> xmlNodeLists = new List<XmlNodeList>();
  353. List<XmlAttributeCollection> attributesList = new List<XmlAttributeCollection>();
  354. textAsset = Bundle.Config.LoadAsset<TextAsset>("pack_config");
  355. xmlDoc.LoadXml(textAsset.text);
  356. xmlNodeLists.Add(xmlDoc.SelectSingleNode("data").SelectNodes("item"));
  357. textAsset = Bundle.Config.LoadAsset<TextAsset>("skill_config");
  358. xmlDoc.LoadXml(textAsset.text);
  359. xmlNodeLists.Add(xmlDoc.SelectSingleNode("data").SelectNodes("item"));
  360. textAsset = Bundle.Config.LoadAsset<TextAsset>("ability_config");
  361. xmlDoc.LoadXml(textAsset.text);
  362. xmlNodeLists.Add(xmlDoc.SelectSingleNode("data").SelectNodes("item"));
  363. for (int i = 0; i < xmlNodeLists.Count; i++)
  364. {
  365. for (int j = 0; j < xmlNodeLists[i].Count; j++)
  366. {
  367. attributesList.Add(xmlNodeLists[i][j].Attributes);
  368. }
  369. }
  370. return attributesList;
  371. }
  372. public static List<XmlAttributeCollection> GetSignConfig()
  373. {
  374. TextAsset textAsset;
  375. XmlNodeList xmlNodeList;
  376. XmlDocument xmlDoc = new XmlDocument();
  377. List<XmlAttributeCollection> attributeList = new List<XmlAttributeCollection>();
  378. textAsset = Bundle.Config.LoadAsset<TextAsset>("signin_config");
  379. xmlDoc.LoadXml(textAsset.text);
  380. xmlNodeList = xmlDoc.SelectSingleNode("data").SelectNodes("item");
  381. for (int i = 0; i < xmlNodeList.Count; i++)
  382. {
  383. attributeList.Add(xmlNodeList[i].Attributes);
  384. }
  385. return attributeList;
  386. }
  387. public static List<XmlAttributeCollection> GetFlowerConfig()
  388. {
  389. TextAsset textAsset;
  390. XmlNodeList xmlNodeList;
  391. XmlDocument xmlDoc = new XmlDocument();
  392. List<XmlAttributeCollection> attributesList = new List<XmlAttributeCollection>();
  393. textAsset = Bundle.Config.LoadAsset<TextAsset>("flower_config");
  394. xmlDoc.LoadXml(textAsset.text);
  395. xmlNodeList = xmlDoc.SelectSingleNode("data").SelectNodes("item");
  396. for (int i = 0; i < xmlNodeList.Count; i++)
  397. {
  398. attributesList.Add(xmlNodeList[i].Attributes);
  399. }
  400. return attributesList;
  401. }
  402. }