Data.cs 18 KB

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