Data.cs 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880
  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. string path = Application.persistentDataPath + "/ICON2.png";
  38. if (!File.Exists(path))
  39. {
  40. Texture2D texture2D = ManaReso.Load<Texture2D>("ICON2", Folder.UI);
  41. File.WriteAllBytes(path, texture2D.EncodeToPNG());
  42. }
  43. StreamReader sr = new StreamReader(Application.persistentDataPath + "/PlayerConfig.xml");
  44. tempDoc1 = new XmlDocument();
  45. tempDoc1.LoadXml(sr.ReadToEnd());
  46. sr.Close();
  47. TextAsset textAsset = Bundle.Config.LoadAsset<TextAsset>("PlayerConfig");
  48. tempDoc2 = new XmlDocument();
  49. tempDoc2.LoadXml(textAsset.text);
  50. version = int.Parse(tempDoc2.SelectSingleNode("PlayerConfig").SelectSingleNode("Version").Attributes[0].Value);
  51. temoNode = tempDoc1.SelectSingleNode("PlayerConfig").SelectSingleNode("Version");
  52. if (temoNode == null)
  53. {
  54. StreamWriter sw = new StreamWriter(Application.persistentDataPath + "/PlayerConfig.xml");
  55. sw.Write(tempDoc2.OuterXml);
  56. sw.Close();
  57. _PlayerDoc = tempDoc2;
  58. }
  59. else
  60. {
  61. nativeVersion = int.Parse(temoNode.Attributes[0].Value);
  62. if (nativeVersion != version)
  63. {
  64. StreamWriter sw = new StreamWriter(Application.persistentDataPath + "/PlayerConfig.xml");
  65. sw.Write(tempDoc2.OuterXml);
  66. sw.Close();
  67. _PlayerDoc = tempDoc2;
  68. }
  69. else
  70. {
  71. _PlayerDoc = tempDoc1;
  72. }
  73. }
  74. }
  75. else
  76. {
  77. TextAsset textAsset = Bundle.Config.LoadAsset<TextAsset>("PlayerConfig");
  78. tempDoc2 = new XmlDocument();
  79. tempDoc2.LoadXml(textAsset.text);
  80. StreamWriter sw = new StreamWriter(Application.persistentDataPath + "/PlayerConfig.xml");
  81. sw.Write(tempDoc2.OuterXml);
  82. sw.Close();
  83. _PlayerDoc = tempDoc2;
  84. _PlayerDoc.SelectSingleNode("PlayerConfig").SelectSingleNode("QuitTime").Attributes[0].Value = DateTime.Now.ToString();
  85. }
  86. }
  87. return _PlayerDoc;
  88. }
  89. set { _PlayerDoc = value; }
  90. }
  91. public static XmlNode _PlayerNode;
  92. public static XmlDocument _PlayerDoc;
  93. #endregion
  94. public static void SaveXml()
  95. {
  96. if (Initializer.LoadComplete)
  97. {
  98. StreamWriter sw = new StreamWriter(Application.persistentDataPath + "/PlayerConfig.xml");
  99. sw.Write(PlayerDoc.OuterXml);
  100. sw.Close();
  101. }
  102. }
  103. public static void SaveSkillList()
  104. {
  105. if (ManaTutorial.TutorialA || !ManaData.InitiateComplete)
  106. {
  107. return;
  108. }
  109. XmlNode xmlNode;
  110. XmlAttribute xmlAttribute;
  111. xmlNode = PlayerNode.SelectSingleNode("SkillList");
  112. xmlNode.RemoveAll();
  113. for (int i = 0; i < ManaData.SkillList.Count; i++)
  114. {
  115. if (ManaData.SkillList[i].SkillType == SkillType.Skill)
  116. {
  117. #region Skill
  118. Skill skill = (Skill)ManaData.SkillList[i];
  119. xmlNode = xmlNode.AppendChild(PlayerDoc.CreateNode(XmlNodeType.Element, "Skill", ""));
  120. xmlAttribute = xmlNode.Attributes.Append(PlayerDoc.CreateAttribute("ID"));
  121. xmlAttribute.Value = skill.ID.ToString();
  122. xmlAttribute = xmlNode.Attributes.Append(PlayerDoc.CreateAttribute("SkillType"));
  123. xmlAttribute.Value = skill.SkillType.ToString();
  124. xmlAttribute = xmlNode.Attributes.Append(PlayerDoc.CreateAttribute("ItemStatus"));
  125. xmlAttribute.Value = skill.ItemStatus.ToString();
  126. xmlAttribute = xmlNode.Attributes.Append(PlayerDoc.CreateAttribute("Level"));
  127. xmlAttribute.Value = skill.Level.ToString();
  128. xmlAttribute = xmlNode.Attributes.Append(PlayerDoc.CreateAttribute("CdTimer"));
  129. xmlAttribute.Value = skill.CoolTimer.ToString();
  130. xmlAttribute = xmlNode.Attributes.Append(PlayerDoc.CreateAttribute("EffectTimer"));
  131. xmlAttribute.Value = skill.UseTimer.ToString();
  132. xmlNode = PlayerNode.SelectSingleNode("SkillList");
  133. #endregion
  134. }
  135. else if (ManaData.SkillList[i].SkillType == SkillType.Pack)
  136. {
  137. #region Pack
  138. Pack pack = (Pack)ManaData.SkillList[i];
  139. xmlNode = xmlNode.AppendChild(PlayerDoc.CreateNode(XmlNodeType.Element, "Skill", ""));
  140. xmlAttribute = xmlNode.Attributes.Append(PlayerDoc.CreateAttribute("ID"));
  141. xmlAttribute.Value = pack.ID.ToString();
  142. xmlAttribute = xmlNode.Attributes.Append(PlayerDoc.CreateAttribute("SkillType"));
  143. xmlAttribute.Value = pack.SkillType.ToString();
  144. xmlAttribute = xmlNode.Attributes.Append(PlayerDoc.CreateAttribute("ItemStatus"));
  145. xmlAttribute.Value = pack.ItemStatus.ToString();
  146. xmlAttribute = xmlNode.Attributes.Append(PlayerDoc.CreateAttribute("Level"));
  147. xmlAttribute.Value = pack.Level.ToString();
  148. xmlNode = PlayerNode.SelectSingleNode("SkillList");
  149. #endregion
  150. }
  151. else if (ManaData.SkillList[i].SkillType == SkillType.Ability)
  152. {
  153. #region Ability
  154. Ability ability = (Ability)ManaData.SkillList[i];
  155. xmlNode = xmlNode.AppendChild(PlayerDoc.CreateNode(XmlNodeType.Element, "Skill", ""));
  156. xmlAttribute = xmlNode.Attributes.Append(PlayerDoc.CreateAttribute("ID"));
  157. xmlAttribute.Value = ability.ID.ToString();
  158. xmlAttribute = xmlNode.Attributes.Append(PlayerDoc.CreateAttribute("SkillType"));
  159. xmlAttribute.Value = ability.SkillType.ToString();
  160. xmlAttribute = xmlNode.Attributes.Append(PlayerDoc.CreateAttribute("ItemStatus"));
  161. xmlAttribute.Value = ability.ItemStatus.ToString();
  162. xmlAttribute = xmlNode.Attributes.Append(PlayerDoc.CreateAttribute("Level"));
  163. xmlAttribute.Value = ability.Level.ToString();
  164. xmlNode = PlayerNode.SelectSingleNode("SkillList");
  165. #endregion
  166. }
  167. else if (ManaData.SkillList[i].SkillType == SkillType.BigSkill)
  168. {
  169. #region BigSkill
  170. BigSkill bigSkill = (BigSkill)ManaData.SkillList[i];
  171. xmlNode = xmlNode.AppendChild(PlayerDoc.CreateNode(XmlNodeType.Element, "Skill", ""));
  172. xmlAttribute = xmlNode.Attributes.Append(PlayerDoc.CreateAttribute("ID"));
  173. xmlAttribute.Value = bigSkill.ID.ToString();
  174. xmlAttribute = xmlNode.Attributes.Append(PlayerDoc.CreateAttribute("SkillType"));
  175. xmlAttribute.Value = bigSkill.SkillType.ToString();
  176. xmlAttribute = xmlNode.Attributes.Append(PlayerDoc.CreateAttribute("ItemStatus"));
  177. xmlAttribute.Value = bigSkill.ItemStatus.ToString();
  178. xmlAttribute = xmlNode.Attributes.Append(PlayerDoc.CreateAttribute("BarStatus"));
  179. xmlAttribute.Value = bigSkill.BarStatus.ToString();
  180. xmlAttribute = xmlNode.Attributes.Append(PlayerDoc.CreateAttribute("Level"));
  181. xmlAttribute.Value = bigSkill.Level.ToString();
  182. xmlAttribute = xmlNode.Attributes.Append(PlayerDoc.CreateAttribute("CdTimer"));
  183. xmlAttribute.Value = bigSkill.CoolTimer.ToString();
  184. xmlAttribute = xmlNode.Attributes.Append(PlayerDoc.CreateAttribute("EffectTimer"));
  185. xmlAttribute.Value = bigSkill.UseTimer.ToString();
  186. xmlNode = PlayerNode.SelectSingleNode("SkillList");
  187. #endregion
  188. }
  189. }
  190. }
  191. public static void SaveAchieve()
  192. {
  193. XmlNode xmlNode = PlayerNode.SelectSingleNode("AchieveList");
  194. xmlNode.Attributes[0].Value = "";
  195. foreach (var kv in ManaAchieve.AchieveDic)
  196. {
  197. if (!kv.Value.Available)
  198. {
  199. xmlNode.Attributes[0].Value += kv.Value.ID_ + " ";
  200. }
  201. }
  202. xmlNode.Attributes[0].Value = xmlNode.Attributes[0].Value.TrimEnd(' ');
  203. PlayerNode.SelectSingleNode("AchieveData").Attributes[0].Value = ManaData.AdAmt.ToString("0");
  204. PlayerNode.SelectSingleNode("AchieveData").Attributes[1].Value = ManaData.SkillAmt.ToString("0");
  205. PlayerNode.SelectSingleNode("AchieveData").Attributes[2].Value = ManaData.SignAmt.ToString("0");
  206. PlayerNode.SelectSingleNode("AchieveData").Attributes[3].Value = ManaData.ShareAmt.ToString("0");
  207. PlayerNode.SelectSingleNode("AchieveData").Attributes[4].Value = ManaData.ElfLevel.ToString("0");
  208. PlayerNode.SelectSingleNode("AchieveData").Attributes[5].Value = ManaData.MiniGameAmt.ToString("0");
  209. PlayerNode.SelectSingleNode("AchieveData").Attributes[6].Value = ManaData.FlowerCoin.ToString("0");
  210. PlayerNode.SelectSingleNode("AchieveData").Attributes[7].Value = ManaData.TotalPerson.ToString("0");
  211. }
  212. public static void SavePlantList()
  213. {
  214. XmlAttributeCollection attribute = PlayerNode.SelectSingleNode("PlantList").Attributes;
  215. attribute[0].Value = "";
  216. for (int i = 0; i < ManaGarden.PlantList.Count; i++)
  217. {
  218. Slot slot = ManaGarden.PlantList[i];
  219. attribute[0].Value = slot.ID + "," + slot.Index;
  220. if (i < ManaGarden.PlantList.Count - 1)
  221. {
  222. attribute[0].Value += " ";
  223. }
  224. }
  225. }
  226. public static void SaveCommon()
  227. {
  228. if (!ManaTutorial.TutorialA)
  229. {
  230. PlayerNode.SelectSingleNode("Level").Attributes[0].Value = ManaData.Level.ToString();
  231. }
  232. PlayerNode.SelectSingleNode("SignIndex").Attributes[0].Value = ManaSign.SignIndex.ToString();
  233. PlayerNode.SelectSingleNode("SignRound").Attributes[0].Value = ManaSign.SignRound.ToString();
  234. PlayerNode.SelectSingleNode("Coin").Attributes[0].Value = ManaData.Coin.ToString("0");
  235. PlayerNode.SelectSingleNode("Diamond").Attributes[0].Value = ManaData.Diamond.ToString();
  236. PlayerNode.SelectSingleNode("QuitTime").Attributes[0].Value = ManaServer.Time.ToString();
  237. PlayerNode.SelectSingleNode("MiniTimer").Attributes[0].Value = ManaData.MiniTimer.ToString();
  238. PlayerNode.SelectSingleNode("CircleTimer").Attributes[0].Value = ManaData.CircleTimer.ToString();
  239. PlayerNode.SelectSingleNode("MiniGameIndex").Attributes[0].Value = ManaMiniGame.MiniGameIndex.ToString();
  240. PlayerNode.SelectSingleNode("Player").Attributes[0].Value = ManaPlayer.SelePlayer;
  241. PlayerNode.SelectSingleNode("Language").Attributes[0].Value = ManaLan.CurrentLan.ToString();
  242. PlayerNode.SelectSingleNode("ID").Attributes[0].Value = ManaServer.ID;
  243. PlayerNode.SelectSingleNode("SignTime").Attributes[0].Value = ManaSign.SignTime.ToString();
  244. if (ManaServer.Connect)
  245. {
  246. PlayerNode.SelectSingleNode("QuitFlag").Attributes[0].Value = "1";
  247. }
  248. else
  249. {
  250. PlayerNode.SelectSingleNode("QuitFlag").Attributes[0].Value = "0";
  251. }
  252. if (ManaTutorial.TutorialA)
  253. {
  254. PlayerNode.SelectSingleNode("TutorialA").Attributes[0].Value = "1";
  255. }
  256. else
  257. {
  258. PlayerNode.SelectSingleNode("TutorialA").Attributes[0].Value = "0";
  259. }
  260. if (ManaTutorial.TutorialB_)
  261. {
  262. PlayerNode.SelectSingleNode("TutorialB").Attributes[0].Value = "1";
  263. }
  264. else
  265. {
  266. PlayerNode.SelectSingleNode("TutorialB").Attributes[0].Value = "0";
  267. }
  268. PlayerNode.SelectSingleNode("TutorialIndexA").Attributes[0].Value = ManaTutorial.TutorialIndexA.ToString();
  269. PlayerNode.SelectSingleNode("TutorialIndexB").Attributes[0].Value = ManaTutorial.TutorialIndexB.ToString();
  270. }
  271. public static void SaveFlowerList()
  272. {
  273. XmlAttribute attribute = PlayerNode.SelectSingleNode("FlowerList").Attributes[0];
  274. attribute.Value = "";
  275. foreach (var kv in ManaGarden.FlowerInfoDic)
  276. {
  277. if (kv.Value.Unlock)
  278. {
  279. attribute.Value += kv.Value.ID_ + " ";
  280. }
  281. }
  282. attribute.Value = attribute.Value.Trim(' ');
  283. }
  284. public static void SavePlayerConfig()
  285. {
  286. ManaVisit.DataReverse();
  287. SaveSkillList();
  288. SaveAchieve();
  289. SavePlantList();
  290. SaveCommon();
  291. SaveFlowerList();
  292. }
  293. public static void ResetSkillList()
  294. {
  295. XmlNode xmlNode;
  296. XmlAttribute xmlAttribute;
  297. xmlNode = PlayerNode.SelectSingleNode("SkillList");
  298. xmlNode.RemoveAll();
  299. for (int i = 0; i < ManaData.SkillList.Count; i++)
  300. {
  301. if (ManaData.SkillList[i].SkillType == SkillType.Skill)
  302. {
  303. #region Skill
  304. Skill skill = (Skill)ManaData.SkillList[i];
  305. xmlNode = xmlNode.AppendChild(PlayerDoc.CreateNode(XmlNodeType.Element, "Skill", ""));
  306. xmlAttribute = xmlNode.Attributes.Append(PlayerDoc.CreateAttribute("ID"));
  307. xmlAttribute.Value = skill.ID.ToString();
  308. xmlAttribute = xmlNode.Attributes.Append(PlayerDoc.CreateAttribute("SkillType"));
  309. xmlAttribute.Value = skill.SkillType.ToString();
  310. xmlAttribute = xmlNode.Attributes.Append(PlayerDoc.CreateAttribute("ItemStatus"));
  311. xmlAttribute.Value = SkillStatus.Lock.ToString();
  312. xmlAttribute = xmlNode.Attributes.Append(PlayerDoc.CreateAttribute("Level"));
  313. xmlAttribute.Value = 0.ToString();
  314. xmlAttribute = xmlNode.Attributes.Append(PlayerDoc.CreateAttribute("CdTimer"));
  315. xmlAttribute.Value = 0.ToString();
  316. xmlAttribute = xmlNode.Attributes.Append(PlayerDoc.CreateAttribute("EffectTimer"));
  317. xmlAttribute.Value = 0.ToString();
  318. xmlNode = PlayerNode.SelectSingleNode("SkillList");
  319. #endregion
  320. }
  321. else if (ManaData.SkillList[i].SkillType == SkillType.Pack)
  322. {
  323. #region Pack
  324. Pack pack = (Pack)ManaData.SkillList[i];
  325. xmlNode = xmlNode.AppendChild(PlayerDoc.CreateNode(XmlNodeType.Element, "Skill", ""));
  326. xmlAttribute = xmlNode.Attributes.Append(PlayerDoc.CreateAttribute("ID"));
  327. xmlAttribute.Value = pack.ID.ToString();
  328. xmlAttribute = xmlNode.Attributes.Append(PlayerDoc.CreateAttribute("SkillType"));
  329. xmlAttribute.Value = pack.SkillType.ToString();
  330. xmlAttribute = xmlNode.Attributes.Append(PlayerDoc.CreateAttribute("ItemStatus"));
  331. xmlAttribute.Value = SkillStatus.Lock.ToString();
  332. xmlAttribute = xmlNode.Attributes.Append(PlayerDoc.CreateAttribute("Level"));
  333. xmlAttribute.Value = 0.ToString();
  334. xmlNode = PlayerNode.SelectSingleNode("SkillList");
  335. #endregion
  336. }
  337. else if (ManaData.SkillList[i].SkillType == SkillType.Ability)
  338. {
  339. #region Ability
  340. Ability ability = (Ability)ManaData.SkillList[i];
  341. xmlNode = xmlNode.AppendChild(PlayerDoc.CreateNode(XmlNodeType.Element, "Skill", ""));
  342. xmlAttribute = xmlNode.Attributes.Append(PlayerDoc.CreateAttribute("ID"));
  343. xmlAttribute.Value = ability.ID.ToString();
  344. xmlAttribute = xmlNode.Attributes.Append(PlayerDoc.CreateAttribute("SkillType"));
  345. xmlAttribute.Value = ability.SkillType.ToString();
  346. xmlAttribute = xmlNode.Attributes.Append(PlayerDoc.CreateAttribute("ItemStatus"));
  347. xmlAttribute.Value = SkillStatus.Lock.ToString();
  348. xmlAttribute = xmlNode.Attributes.Append(PlayerDoc.CreateAttribute("Level"));
  349. xmlAttribute.Value = 0.ToString();
  350. xmlNode = PlayerNode.SelectSingleNode("SkillList");
  351. #endregion
  352. }
  353. else if (ManaData.SkillList[i].SkillType == SkillType.BigSkill)
  354. {
  355. #region BigSkill
  356. BigSkill bigSkill = (BigSkill)ManaData.SkillList[i];
  357. xmlNode = xmlNode.AppendChild(PlayerDoc.CreateNode(XmlNodeType.Element, "Skill", ""));
  358. xmlAttribute = xmlNode.Attributes.Append(PlayerDoc.CreateAttribute("ID"));
  359. xmlAttribute.Value = bigSkill.ID.ToString();
  360. xmlAttribute = xmlNode.Attributes.Append(PlayerDoc.CreateAttribute("SkillType"));
  361. xmlAttribute.Value = bigSkill.SkillType.ToString();
  362. xmlAttribute = xmlNode.Attributes.Append(PlayerDoc.CreateAttribute("ItemStatus"));
  363. xmlAttribute.Value = SkillStatus.Lock.ToString();
  364. xmlAttribute = xmlNode.Attributes.Append(PlayerDoc.CreateAttribute("BarStatus"));
  365. xmlAttribute.Value = SkillStatus.UnLock.ToString();
  366. xmlAttribute = xmlNode.Attributes.Append(PlayerDoc.CreateAttribute("Level"));
  367. xmlAttribute.Value = 0.ToString();
  368. xmlAttribute = xmlNode.Attributes.Append(PlayerDoc.CreateAttribute("CdTimer"));
  369. xmlAttribute.Value = 0.ToString();
  370. xmlAttribute = xmlNode.Attributes.Append(PlayerDoc.CreateAttribute("EffectTimer"));
  371. xmlAttribute.Value = 0.ToString();
  372. xmlNode = PlayerNode.SelectSingleNode("SkillList");
  373. #endregion
  374. }
  375. }
  376. }
  377. public static void ResetAchieve()
  378. {
  379. XmlNode xmlNode = PlayerNode.SelectSingleNode("AchieveList");
  380. xmlNode.Attributes[0].Value = "";
  381. PlayerNode.SelectSingleNode("AchieveData").Attributes[0].Value = "0";
  382. PlayerNode.SelectSingleNode("AchieveData").Attributes[1].Value = "0";
  383. PlayerNode.SelectSingleNode("AchieveData").Attributes[2].Value = "0";
  384. PlayerNode.SelectSingleNode("AchieveData").Attributes[3].Value = "0";
  385. PlayerNode.SelectSingleNode("AchieveData").Attributes[4].Value = "0";
  386. PlayerNode.SelectSingleNode("AchieveData").Attributes[5].Value = "0";
  387. PlayerNode.SelectSingleNode("AchieveData").Attributes[6].Value = "0";
  388. PlayerNode.SelectSingleNode("AchieveData").Attributes[7].Value = "0";
  389. }
  390. public static void ResetPlantList()
  391. {
  392. XmlNode xmlNode = PlayerNode.SelectSingleNode("PlantList");
  393. xmlNode.Attributes[0].Value = "";
  394. }
  395. public static void ResetCommon()
  396. {
  397. PlayerNode.SelectSingleNode("Slot").Attributes[0].Value = "1";
  398. PlayerNode.SelectSingleNode("SignIndex").Attributes[0].Value = "1";
  399. PlayerNode.SelectSingleNode("SignRound").Attributes[0].Value = "1";
  400. PlayerNode.SelectSingleNode("Coin").Attributes[0].Value = "0";
  401. PlayerNode.SelectSingleNode("Level").Attributes[0].Value = "0";
  402. PlayerNode.SelectSingleNode("Diamond").Attributes[0].Value = "0";
  403. PlayerNode.SelectSingleNode("QuitTime").Attributes[0].Value = DateTime.Now.ToString();
  404. PlayerNode.SelectSingleNode("MiniTimer").Attributes[0].Value = "0";
  405. PlayerNode.SelectSingleNode("CircleTimer").Attributes[0].Value = "10";
  406. PlayerNode.SelectSingleNode("MiniGameIndex").Attributes[0].Value = "0";
  407. PlayerNode.SelectSingleNode("Player").Attributes[0].Value = "PlayerBlond";
  408. PlayerNode.SelectSingleNode("TutorialA").Attributes[0].Value = "1";
  409. PlayerNode.SelectSingleNode("TutorialB").Attributes[0].Value = "1";
  410. PlayerNode.SelectSingleNode("TutorialIndexA").Attributes[0].Value = "1";
  411. PlayerNode.SelectSingleNode("TutorialIndexB").Attributes[0].Value = "1";
  412. PlayerNode.SelectSingleNode("ID").Attributes[0].Value = "Default";
  413. PlayerNode.SelectSingleNode("QuitFlag").Attributes[0].Value = "1";
  414. PlayerNode.SelectSingleNode("SignTime").Attributes[0].Value = "4/22/2017 09:30:00 AM";
  415. PlayerNode.SelectSingleNode("Language").Attributes[0].Value = "ChineseSimplified";
  416. }
  417. public static void ResetFlowerList()
  418. {
  419. XmlAttribute attribute = PlayerNode.SelectSingleNode("FlowerList").Attributes[0];
  420. attribute.Value = "1";
  421. }
  422. public static void ResetPlayerConfig()
  423. {
  424. ResetSkillList();
  425. ResetAchieve();
  426. ResetPlantList();
  427. ResetCommon();
  428. ResetFlowerList();
  429. ManaData.Reset = true;
  430. }
  431. public static int GetPlayerInt(string node)
  432. {
  433. return int.Parse(PlayerNode.SelectSingleNode(node).Attributes[0].Value);
  434. }
  435. public static bool GetPlayerBool(string node)
  436. {
  437. return Convert.ToBoolean(int.Parse(PlayerNode.SelectSingleNode(node).Attributes[0].Value));
  438. }
  439. public static float GetPlayerFloat(string node)
  440. {
  441. return float.Parse(PlayerNode.SelectSingleNode(node).Attributes[0].Value);
  442. }
  443. public static string GetPlayerString(string node)
  444. {
  445. return PlayerNode.SelectSingleNode(node).Attributes[0].Value;
  446. }
  447. public static double GetPlayerDouble(string node)
  448. {
  449. return double.Parse(PlayerNode.SelectSingleNode(node).Attributes[0].Value);
  450. }
  451. public static void SavePlayerInt(string node, int value)
  452. {
  453. PlayerNode.SelectSingleNode(node).Attributes[0].Value = value.ToString();
  454. }
  455. public static void SavePlayerBool(string node, bool value)
  456. {
  457. string str;
  458. if (value)
  459. {
  460. str = "1";
  461. }
  462. else
  463. {
  464. str = "0";
  465. }
  466. PlayerNode.SelectSingleNode(node).Attributes[0].Value = str;
  467. SaveXml();
  468. }
  469. public static void SavePlayerFloat(string node, float value)
  470. {
  471. PlayerNode.SelectSingleNode(node).Attributes[0].Value = value.ToString();
  472. }
  473. public static void SavePlayerString(string node, string value)
  474. {
  475. PlayerNode.SelectSingleNode(node).Attributes[0].Value = value;
  476. }
  477. public static void SavePlayerDouble(string node, double value)
  478. {
  479. PlayerNode.SelectSingleNode(node).Attributes[0].Value = value.ToString();
  480. }
  481. public static List<int> GetFlowerList()
  482. {
  483. List<int> list = new List<int>();
  484. XmlAttributeCollection attribute = PlayerNode.SelectSingleNode("FlowerList").Attributes;
  485. if (!string.IsNullOrEmpty(attribute[0].Value))
  486. {
  487. string[] strings = attribute[0].Value.Split(' ');
  488. for (int i = 0; i < strings.Length; i++)
  489. {
  490. list.Add(int.Parse(strings[i]));
  491. }
  492. }
  493. return list;
  494. }
  495. public static List<int> GetAchieveList()
  496. {
  497. return Auxiliary.IntListParse(' ', GetPlayerString("AchieveList"), new List<int>());
  498. }
  499. public static List<string> GetOfflineConfig()
  500. {
  501. TextAsset textAsset;
  502. XmlDocument xmlDoc = new XmlDocument();
  503. textAsset = ManaReso.Load<TextAsset>("offline_config", Folder.Config);
  504. xmlDoc.LoadXml(textAsset.text);
  505. XmlNode xmlNode = xmlDoc.SelectSingleNode("data").SelectSingleNode("item");
  506. List<string> strList = new List<string>()
  507. {
  508. xmlNode.Attributes[1].Value,
  509. xmlNode.Attributes[2].Value,
  510. xmlNode.Attributes[3].Value,
  511. };
  512. return strList;
  513. }
  514. public static List<double> GetAchieveData()
  515. {
  516. List<double> dataList = new List<double>();
  517. dataList.Add(double.Parse(PlayerNode.SelectSingleNode("AchieveData").Attributes[0].Value));
  518. dataList.Add(double.Parse(PlayerNode.SelectSingleNode("AchieveData").Attributes[1].Value));
  519. dataList.Add(double.Parse(PlayerNode.SelectSingleNode("AchieveData").Attributes[2].Value));
  520. dataList.Add(double.Parse(PlayerNode.SelectSingleNode("AchieveData").Attributes[3].Value));
  521. dataList.Add(double.Parse(PlayerNode.SelectSingleNode("AchieveData").Attributes[4].Value));
  522. dataList.Add(double.Parse(PlayerNode.SelectSingleNode("AchieveData").Attributes[5].Value));
  523. dataList.Add(double.Parse(PlayerNode.SelectSingleNode("AchieveData").Attributes[6].Value));
  524. dataList.Add(double.Parse(PlayerNode.SelectSingleNode("AchieveData").Attributes[7].Value));
  525. return dataList;
  526. }
  527. public static List<KV<int, int>> GetPlantList(XmlNode node = null)
  528. {
  529. List<KV<int, int>> list = new List<KV<int, int>>();
  530. XmlNode xmlNode;
  531. if (node == null)
  532. {
  533. xmlNode = PlayerNode.SelectSingleNode("PlantList");
  534. }
  535. else
  536. {
  537. xmlNode = node.SelectSingleNode("PlantList");
  538. }
  539. if (!string.IsNullOrEmpty(xmlNode.Attributes[0].Value))
  540. {
  541. string[] strings = xmlNode.Attributes[0].Value.Split(' ');
  542. for (int i = 0; i < strings.Length; i++)
  543. {
  544. list.Add(new KV<int, int>(int.Parse(strings[i].Split(',')[0]), int.Parse(strings[i].Split(',')[1])));
  545. }
  546. }
  547. return list;
  548. }
  549. public static List<XmlAttributeCollection> GetSkillList(XmlNode node = null)
  550. {
  551. List<XmlAttributeCollection> attributeList = new List<XmlAttributeCollection>();
  552. XmlNodeList xmlNodeList;
  553. if (node == null)
  554. {
  555. xmlNodeList = PlayerNode.SelectSingleNode("SkillList").ChildNodes;
  556. }
  557. else
  558. {
  559. xmlNodeList = node.SelectSingleNode("SkillList").ChildNodes;
  560. }
  561. for (int i = 0; i < xmlNodeList.Count; i++)
  562. {
  563. attributeList.Add(xmlNodeList[i].Attributes);
  564. }
  565. return attributeList;
  566. }
  567. public static XmlAttributeCollection GetAwardConfig()
  568. {
  569. TextAsset textAsset;
  570. XmlDocument xmlDoc = new XmlDocument();
  571. textAsset = ManaReso.Load<TextAsset>("award_config", Folder.Config);
  572. xmlDoc.LoadXml(textAsset.text);
  573. XmlNode xmlNode = xmlDoc.SelectSingleNode("data").SelectSingleNode("item");
  574. return xmlNode.Attributes;
  575. }
  576. public static List<XmlAttributeCollection> GetSkillConfig()
  577. {
  578. TextAsset textAsset;
  579. XmlDocument xmlDoc = new XmlDocument();
  580. List<XmlNodeList> xmlNodeLists = new List<XmlNodeList>();
  581. List<XmlAttributeCollection> attributeList = new List<XmlAttributeCollection>();
  582. textAsset = ManaReso.Load<TextAsset>("pack_config", Folder.Config);
  583. xmlDoc.LoadXml(textAsset.text);
  584. xmlNodeLists.Add(xmlDoc.SelectSingleNode("data").SelectNodes("item"));
  585. textAsset = ManaReso.Load<TextAsset>("skill_config", Folder.Config);
  586. xmlDoc.LoadXml(textAsset.text);
  587. xmlNodeLists.Add(xmlDoc.SelectSingleNode("data").SelectNodes("item"));
  588. textAsset = ManaReso.Load<TextAsset>("ability_config", Folder.Config);
  589. xmlDoc.LoadXml(textAsset.text);
  590. xmlNodeLists.Add(xmlDoc.SelectSingleNode("data").SelectNodes("item"));
  591. for (int i = 0; i < xmlNodeLists.Count; i++)
  592. {
  593. for (int j = 0; j < xmlNodeLists[i].Count; j++)
  594. {
  595. attributeList.Add(xmlNodeLists[i][j].Attributes);
  596. }
  597. }
  598. return attributeList;
  599. }
  600. public static List<XmlAttributeCollection> GetSignConfig()
  601. {
  602. TextAsset textAsset;
  603. XmlNodeList xmlNodeList;
  604. XmlDocument xmlDoc = new XmlDocument();
  605. List<XmlAttributeCollection> attributeList = new List<XmlAttributeCollection>();
  606. textAsset = ManaReso.Load<TextAsset>("signin_config", Folder.Config);
  607. xmlDoc.LoadXml(textAsset.text);
  608. xmlNodeList = xmlDoc.SelectSingleNode("data").SelectNodes("item");
  609. for (int i = 0; i < xmlNodeList.Count; i++)
  610. {
  611. attributeList.Add(xmlNodeList[i].Attributes);
  612. }
  613. return attributeList;
  614. }
  615. public static List<XmlAttributeCollection> GetFlowerConfig()
  616. {
  617. TextAsset textAsset;
  618. XmlNodeList xmlNodeList;
  619. XmlDocument xmlDoc = new XmlDocument();
  620. List<XmlAttributeCollection> attributeList = new List<XmlAttributeCollection>();
  621. textAsset = ManaReso.Load<TextAsset>("flower_config", Folder.Config);
  622. xmlDoc.LoadXml(textAsset.text);
  623. xmlNodeList = xmlDoc.SelectSingleNode("data").SelectNodes("item");
  624. for (int i = 0; i < xmlNodeList.Count; i++)
  625. {
  626. attributeList.Add(xmlNodeList[i].Attributes);
  627. }
  628. return attributeList;
  629. }
  630. public static List<XmlAttributeCollection> GetAchieveConfig()
  631. {
  632. TextAsset textAsset;
  633. XmlNodeList xmlNodeList;
  634. XmlDocument xmlDoc = new XmlDocument();
  635. List<XmlAttributeCollection> attributeList = new List<XmlAttributeCollection>();
  636. textAsset = ManaReso.Load<TextAsset>("achieve_config", Folder.Config);
  637. xmlDoc.LoadXml(textAsset.text);
  638. xmlNodeList = xmlDoc.SelectSingleNode("data").SelectNodes("item");
  639. for (int i = 0; i < xmlNodeList.Count; i++)
  640. {
  641. attributeList.Add(xmlNodeList[i].Attributes);
  642. }
  643. return attributeList;
  644. }
  645. }