Data.cs 29 KB

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