Data.cs 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850
  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. if (!ManaTutorial.TutorialA)
  223. {
  224. PlayerNode.SelectSingleNode("Level").Attributes[0].Value = ManaData.Level.ToString();
  225. }
  226. PlayerNode.SelectSingleNode("SignIndex").Attributes[0].Value = ManaSign.SignIndex.ToString();
  227. PlayerNode.SelectSingleNode("SignRound").Attributes[0].Value = ManaSign.SignRound.ToString();
  228. PlayerNode.SelectSingleNode("Coin").Attributes[0].Value = ManaData.Coin.ToString("0");
  229. PlayerNode.SelectSingleNode("Diamond").Attributes[0].Value = ManaData.Diamond.ToString();
  230. PlayerNode.SelectSingleNode("QuitTime").Attributes[0].Value = ManaServer.Time.ToString();
  231. PlayerNode.SelectSingleNode("MiniTimer").Attributes[0].Value = ManaData.MiniTimer.ToString();
  232. PlayerNode.SelectSingleNode("CircleTimer").Attributes[0].Value = ManaData.CircleTimer.ToString();
  233. PlayerNode.SelectSingleNode("MiniGameIndex").Attributes[0].Value = ManaMiniGame.MiniGameIndex.ToString();
  234. PlayerNode.SelectSingleNode("Player").Attributes[0].Value = ManaPlayer.SelePlayer;
  235. PlayerNode.SelectSingleNode("Language").Attributes[0].Value = ManaLan.CurrentLan.ToString();
  236. PlayerNode.SelectSingleNode("ID").Attributes[0].Value = ManaServer.ID;
  237. PlayerNode.SelectSingleNode("SignTime").Attributes[0].Value = ManaSign.SignTime.ToString();
  238. if (ManaServer.Connect)
  239. {
  240. PlayerNode.SelectSingleNode("QuitFlag").Attributes[0].Value = "1";
  241. }
  242. else
  243. {
  244. PlayerNode.SelectSingleNode("QuitFlag").Attributes[0].Value = "0";
  245. }
  246. if (ManaTutorial.TutorialA)
  247. {
  248. PlayerNode.SelectSingleNode("TutorialA").Attributes[0].Value = "1";
  249. }
  250. else
  251. {
  252. PlayerNode.SelectSingleNode("TutorialA").Attributes[0].Value = "0";
  253. }
  254. if (ManaTutorial.TutorialB_)
  255. {
  256. PlayerNode.SelectSingleNode("TutorialB").Attributes[0].Value = "1";
  257. }
  258. else
  259. {
  260. PlayerNode.SelectSingleNode("TutorialB").Attributes[0].Value = "0";
  261. }
  262. PlayerNode.SelectSingleNode("TutorialIndexA").Attributes[0].Value = ManaTutorial.TutorialIndexA.ToString();
  263. PlayerNode.SelectSingleNode("TutorialIndexB").Attributes[0].Value = ManaTutorial.TutorialIndexB.ToString();
  264. }
  265. private static void SaveFlowerList()
  266. {
  267. XmlAttribute attribute = PlayerNode.SelectSingleNode("FlowerList").Attributes[0];
  268. attribute.Value = "";
  269. foreach (var kv in ManaGarden.FlowerInfoDic)
  270. {
  271. if (kv.Value.Unlock)
  272. {
  273. attribute.Value += kv.Value.ID_ + " ";
  274. }
  275. }
  276. attribute.Value = attribute.Value.Trim(' ');
  277. }
  278. public static void SavePlayerConfig()
  279. {
  280. SaveSkillList();
  281. SaveAchieve();
  282. SavePlantList();
  283. SaveCommon();
  284. SaveFlowerList();
  285. }
  286. private static void ResetSkillList()
  287. {
  288. XmlNode xmlNode;
  289. XmlAttribute xmlAttribute;
  290. xmlNode = PlayerNode.SelectSingleNode("SkillList");
  291. xmlNode.RemoveAll();
  292. for (int i = 0; i < ManaData.SkillList.Count; i++)
  293. {
  294. if (ManaData.SkillList[i].SkillType == SkillType.Skill)
  295. {
  296. #region Skill
  297. Skill skill = (Skill)ManaData.SkillList[i];
  298. xmlNode = xmlNode.AppendChild(PlayerDoc.CreateNode(XmlNodeType.Element, "Skill", ""));
  299. xmlAttribute = xmlNode.Attributes.Append(PlayerDoc.CreateAttribute("ID"));
  300. xmlAttribute.Value = skill.ID.ToString();
  301. xmlAttribute = xmlNode.Attributes.Append(PlayerDoc.CreateAttribute("SkillType"));
  302. xmlAttribute.Value = skill.SkillType.ToString();
  303. xmlAttribute = xmlNode.Attributes.Append(PlayerDoc.CreateAttribute("ItemStatus"));
  304. xmlAttribute.Value = SkillStatus.Lock.ToString();
  305. xmlAttribute = xmlNode.Attributes.Append(PlayerDoc.CreateAttribute("Level"));
  306. xmlAttribute.Value = 0.ToString();
  307. xmlAttribute = xmlNode.Attributes.Append(PlayerDoc.CreateAttribute("CdTimer"));
  308. xmlAttribute.Value = 0.ToString();
  309. xmlAttribute = xmlNode.Attributes.Append(PlayerDoc.CreateAttribute("EffectTimer"));
  310. xmlAttribute.Value = 0.ToString();
  311. xmlNode = PlayerNode.SelectSingleNode("SkillList");
  312. #endregion
  313. }
  314. else if (ManaData.SkillList[i].SkillType == SkillType.Pack)
  315. {
  316. #region Pack
  317. Pack pack = (Pack)ManaData.SkillList[i];
  318. xmlNode = xmlNode.AppendChild(PlayerDoc.CreateNode(XmlNodeType.Element, "Skill", ""));
  319. xmlAttribute = xmlNode.Attributes.Append(PlayerDoc.CreateAttribute("ID"));
  320. xmlAttribute.Value = pack.ID.ToString();
  321. xmlAttribute = xmlNode.Attributes.Append(PlayerDoc.CreateAttribute("SkillType"));
  322. xmlAttribute.Value = pack.SkillType.ToString();
  323. xmlAttribute = xmlNode.Attributes.Append(PlayerDoc.CreateAttribute("ItemStatus"));
  324. xmlAttribute.Value = SkillStatus.Lock.ToString();
  325. xmlAttribute = xmlNode.Attributes.Append(PlayerDoc.CreateAttribute("Level"));
  326. xmlAttribute.Value = 0.ToString();
  327. xmlNode = PlayerNode.SelectSingleNode("SkillList");
  328. #endregion
  329. }
  330. else if (ManaData.SkillList[i].SkillType == SkillType.Ability)
  331. {
  332. #region Ability
  333. Ability ability = (Ability)ManaData.SkillList[i];
  334. xmlNode = xmlNode.AppendChild(PlayerDoc.CreateNode(XmlNodeType.Element, "Skill", ""));
  335. xmlAttribute = xmlNode.Attributes.Append(PlayerDoc.CreateAttribute("ID"));
  336. xmlAttribute.Value = ability.ID.ToString();
  337. xmlAttribute = xmlNode.Attributes.Append(PlayerDoc.CreateAttribute("SkillType"));
  338. xmlAttribute.Value = ability.SkillType.ToString();
  339. xmlAttribute = xmlNode.Attributes.Append(PlayerDoc.CreateAttribute("ItemStatus"));
  340. xmlAttribute.Value = SkillStatus.Lock.ToString();
  341. xmlAttribute = xmlNode.Attributes.Append(PlayerDoc.CreateAttribute("Level"));
  342. xmlAttribute.Value = 0.ToString();
  343. xmlNode = PlayerNode.SelectSingleNode("SkillList");
  344. #endregion
  345. }
  346. else if (ManaData.SkillList[i].SkillType == SkillType.BigSkill)
  347. {
  348. #region BigSkill
  349. BigSkill bigSkill = (BigSkill)ManaData.SkillList[i];
  350. xmlNode = xmlNode.AppendChild(PlayerDoc.CreateNode(XmlNodeType.Element, "Skill", ""));
  351. xmlAttribute = xmlNode.Attributes.Append(PlayerDoc.CreateAttribute("ID"));
  352. xmlAttribute.Value = bigSkill.ID.ToString();
  353. xmlAttribute = xmlNode.Attributes.Append(PlayerDoc.CreateAttribute("SkillType"));
  354. xmlAttribute.Value = bigSkill.SkillType.ToString();
  355. xmlAttribute = xmlNode.Attributes.Append(PlayerDoc.CreateAttribute("ItemStatus"));
  356. xmlAttribute.Value = SkillStatus.Lock.ToString();
  357. xmlAttribute = xmlNode.Attributes.Append(PlayerDoc.CreateAttribute("BarStatus"));
  358. xmlAttribute.Value = SkillStatus.UnLock.ToString();
  359. xmlAttribute = xmlNode.Attributes.Append(PlayerDoc.CreateAttribute("Level"));
  360. xmlAttribute.Value = 0.ToString();
  361. xmlAttribute = xmlNode.Attributes.Append(PlayerDoc.CreateAttribute("CdTimer"));
  362. xmlAttribute.Value = 0.ToString();
  363. xmlAttribute = xmlNode.Attributes.Append(PlayerDoc.CreateAttribute("EffectTimer"));
  364. xmlAttribute.Value = 0.ToString();
  365. xmlNode = PlayerNode.SelectSingleNode("SkillList");
  366. #endregion
  367. }
  368. }
  369. }
  370. private static void ResetAchieve()
  371. {
  372. XmlNode xmlNode = PlayerNode.SelectSingleNode("AchieveList");
  373. xmlNode.Attributes[0].Value = "";
  374. PlayerNode.SelectSingleNode("AchieveData").Attributes[0].Value = "0";
  375. PlayerNode.SelectSingleNode("AchieveData").Attributes[1].Value = "0";
  376. PlayerNode.SelectSingleNode("AchieveData").Attributes[2].Value = "0";
  377. PlayerNode.SelectSingleNode("AchieveData").Attributes[3].Value = "0";
  378. PlayerNode.SelectSingleNode("AchieveData").Attributes[4].Value = "0";
  379. PlayerNode.SelectSingleNode("AchieveData").Attributes[5].Value = "0";
  380. PlayerNode.SelectSingleNode("AchieveData").Attributes[6].Value = "0";
  381. PlayerNode.SelectSingleNode("AchieveData").Attributes[7].Value = "0";
  382. }
  383. private static void ResetPlantList()
  384. {
  385. XmlNode xmlNode = PlayerNode.SelectSingleNode("PlantList");
  386. xmlNode.Attributes[0].Value = "";
  387. }
  388. private static void ResetCommon()
  389. {
  390. PlayerNode.SelectSingleNode("Slot").Attributes[0].Value = "1";
  391. PlayerNode.SelectSingleNode("SignIndex").Attributes[0].Value = "1";
  392. PlayerNode.SelectSingleNode("SignRound").Attributes[0].Value = "1";
  393. PlayerNode.SelectSingleNode("Coin").Attributes[0].Value = "0";
  394. PlayerNode.SelectSingleNode("Level").Attributes[0].Value = "0";
  395. PlayerNode.SelectSingleNode("Diamond").Attributes[0].Value = "0";
  396. PlayerNode.SelectSingleNode("QuitTime").Attributes[0].Value = DateTime.Now.ToString();
  397. PlayerNode.SelectSingleNode("MiniTimer").Attributes[0].Value = "0";
  398. PlayerNode.SelectSingleNode("CircleTimer").Attributes[0].Value = "10";
  399. PlayerNode.SelectSingleNode("MiniGameIndex").Attributes[0].Value = "0";
  400. PlayerNode.SelectSingleNode("Player").Attributes[0].Value = "PlayerBlond";
  401. PlayerNode.SelectSingleNode("TutorialA").Attributes[0].Value = "1";
  402. PlayerNode.SelectSingleNode("TutorialB").Attributes[0].Value = "1";
  403. PlayerNode.SelectSingleNode("TutorialIndexA").Attributes[0].Value = "1";
  404. PlayerNode.SelectSingleNode("TutorialIndexB").Attributes[0].Value = "1";
  405. PlayerNode.SelectSingleNode("ID").Attributes[0].Value = "Default";
  406. PlayerNode.SelectSingleNode("QuitFlag").Attributes[0].Value = "1";
  407. PlayerNode.SelectSingleNode("SignTime").Attributes[0].Value = "4/22/2017 09:30:00 AM";
  408. PlayerNode.SelectSingleNode("Language").Attributes[0].Value = "ChineseSimplified";
  409. }
  410. private static void ResetFlowerList()
  411. {
  412. XmlAttribute attribute = PlayerNode.SelectSingleNode("FlowerList").Attributes[0];
  413. attribute.Value = "1";
  414. }
  415. public static void ResetPlayerConfig()
  416. {
  417. ResetSkillList();
  418. ResetAchieve();
  419. ResetPlantList();
  420. ResetCommon();
  421. ResetFlowerList();
  422. ManaData.Reset = true;
  423. }
  424. public static int GetPlayerInt(string node)
  425. {
  426. return int.Parse(PlayerNode.SelectSingleNode(node).Attributes[0].Value);
  427. }
  428. public static bool GetPlayerBool(string node)
  429. {
  430. return Convert.ToBoolean(int.Parse(PlayerNode.SelectSingleNode(node).Attributes[0].Value));
  431. }
  432. public static float GetPlayerFloat(string node)
  433. {
  434. return float.Parse(PlayerNode.SelectSingleNode(node).Attributes[0].Value);
  435. }
  436. public static string GetPlayerString(string node)
  437. {
  438. return PlayerNode.SelectSingleNode(node).Attributes[0].Value;
  439. }
  440. public static double GetPlayerDouble(string node)
  441. {
  442. return double.Parse(PlayerNode.SelectSingleNode(node).Attributes[0].Value);
  443. }
  444. public static void SavePlayerInt(string node, int value)
  445. {
  446. PlayerNode.SelectSingleNode(node).Attributes[0].Value = value.ToString();
  447. }
  448. public static void SavePlayerBool(string node, bool value)
  449. {
  450. string str;
  451. if (value)
  452. {
  453. str = "1";
  454. }
  455. else
  456. {
  457. str = "0";
  458. }
  459. PlayerNode.SelectSingleNode(node).Attributes[0].Value = str;
  460. SaveXml();
  461. }
  462. public static void SavePlayerFloat(string node, float value)
  463. {
  464. PlayerNode.SelectSingleNode(node).Attributes[0].Value = value.ToString();
  465. }
  466. public static void SavePlayerString(string node, string value)
  467. {
  468. PlayerNode.SelectSingleNode(node).Attributes[0].Value = value;
  469. }
  470. public static void SavePlayerDouble(string node, double value)
  471. {
  472. PlayerNode.SelectSingleNode(node).Attributes[0].Value = value.ToString();
  473. }
  474. public static List<int> GetFlowerList()
  475. {
  476. List<int> list = new List<int>();
  477. XmlAttributeCollection attribute = PlayerNode.SelectSingleNode("FlowerList").Attributes;
  478. if (!string.IsNullOrEmpty(attribute[0].Value))
  479. {
  480. string[] strings = attribute[0].Value.Split(' ');
  481. for (int i = 0; i < strings.Length; i++)
  482. {
  483. list.Add(int.Parse(strings[i]));
  484. }
  485. }
  486. return list;
  487. }
  488. public static List<int> GetAchieveList()
  489. {
  490. return Auxiliary.IntListParse(' ', GetPlayerString("AchieveList"), new List<int>());
  491. }
  492. public static List<string> GetOfflineConfig()
  493. {
  494. TextAsset textAsset;
  495. XmlDocument xmlDoc = new XmlDocument();
  496. textAsset = ManaReso.Load<TextAsset>("offline_config", Folder.Config);
  497. xmlDoc.LoadXml(textAsset.text);
  498. XmlNode xmlNode = xmlDoc.SelectSingleNode("data").SelectSingleNode("item");
  499. List<string> strList = new List<string>()
  500. {
  501. xmlNode.Attributes[1].Value,
  502. xmlNode.Attributes[2].Value,
  503. xmlNode.Attributes[3].Value,
  504. };
  505. return strList;
  506. }
  507. public static List<double> GetAchieveData()
  508. {
  509. List<double> dataList = new List<double>();
  510. dataList.Add(double.Parse(PlayerNode.SelectSingleNode("AchieveData").Attributes[0].Value));
  511. dataList.Add(double.Parse(PlayerNode.SelectSingleNode("AchieveData").Attributes[1].Value));
  512. dataList.Add(double.Parse(PlayerNode.SelectSingleNode("AchieveData").Attributes[2].Value));
  513. dataList.Add(double.Parse(PlayerNode.SelectSingleNode("AchieveData").Attributes[3].Value));
  514. dataList.Add(double.Parse(PlayerNode.SelectSingleNode("AchieveData").Attributes[4].Value));
  515. dataList.Add(double.Parse(PlayerNode.SelectSingleNode("AchieveData").Attributes[5].Value));
  516. dataList.Add(double.Parse(PlayerNode.SelectSingleNode("AchieveData").Attributes[6].Value));
  517. dataList.Add(double.Parse(PlayerNode.SelectSingleNode("AchieveData").Attributes[7].Value));
  518. return dataList;
  519. }
  520. public static List<KV<int, int>> GetPlantList()
  521. {
  522. List<KV<int, int>> list = new List<KV<int, int>>();
  523. XmlNode xmlNode = PlayerNode.SelectSingleNode("PlantList");
  524. if (!string.IsNullOrEmpty(xmlNode.Attributes[0].Value))
  525. {
  526. string[] strings = xmlNode.Attributes[0].Value.Split(' ');
  527. for (int i = 0; i < strings.Length; i++)
  528. {
  529. list.Add(new KV<int, int>(int.Parse(strings[i].Split(',')[0]), int.Parse(strings[i].Split(',')[1])));
  530. }
  531. }
  532. return list;
  533. }
  534. public static List<XmlAttributeCollection> GetSkillList()
  535. {
  536. List<XmlAttributeCollection> attributeList = new List<XmlAttributeCollection>();
  537. XmlNodeList xmlNodeList = PlayerNode.SelectSingleNode("SkillList").ChildNodes;
  538. for (int i = 0; i < xmlNodeList.Count; i++)
  539. {
  540. attributeList.Add(xmlNodeList[i].Attributes);
  541. }
  542. return attributeList;
  543. }
  544. public static XmlAttributeCollection GetAwardConfig()
  545. {
  546. TextAsset textAsset;
  547. XmlDocument xmlDoc = new XmlDocument();
  548. textAsset = ManaReso.Load<TextAsset>("award_config", Folder.Config);
  549. xmlDoc.LoadXml(textAsset.text);
  550. XmlNode xmlNode = xmlDoc.SelectSingleNode("data").SelectSingleNode("item");
  551. return xmlNode.Attributes;
  552. }
  553. public static List<XmlAttributeCollection> GetSkillConfig()
  554. {
  555. TextAsset textAsset;
  556. XmlDocument xmlDoc = new XmlDocument();
  557. List<XmlNodeList> xmlNodeLists = new List<XmlNodeList>();
  558. List<XmlAttributeCollection> attributeList = new List<XmlAttributeCollection>();
  559. textAsset = ManaReso.Load<TextAsset>("pack_config", Folder.Config);
  560. xmlDoc.LoadXml(textAsset.text);
  561. xmlNodeLists.Add(xmlDoc.SelectSingleNode("data").SelectNodes("item"));
  562. textAsset = ManaReso.Load<TextAsset>("skill_config", Folder.Config);
  563. xmlDoc.LoadXml(textAsset.text);
  564. xmlNodeLists.Add(xmlDoc.SelectSingleNode("data").SelectNodes("item"));
  565. textAsset = ManaReso.Load<TextAsset>("ability_config", Folder.Config);
  566. xmlDoc.LoadXml(textAsset.text);
  567. xmlNodeLists.Add(xmlDoc.SelectSingleNode("data").SelectNodes("item"));
  568. for (int i = 0; i < xmlNodeLists.Count; i++)
  569. {
  570. for (int j = 0; j < xmlNodeLists[i].Count; j++)
  571. {
  572. attributeList.Add(xmlNodeLists[i][j].Attributes);
  573. }
  574. }
  575. return attributeList;
  576. }
  577. public static List<XmlAttributeCollection> GetSignConfig()
  578. {
  579. TextAsset textAsset;
  580. XmlNodeList xmlNodeList;
  581. XmlDocument xmlDoc = new XmlDocument();
  582. List<XmlAttributeCollection> attributeList = new List<XmlAttributeCollection>();
  583. textAsset = ManaReso.Load<TextAsset>("signin_config", Folder.Config);
  584. xmlDoc.LoadXml(textAsset.text);
  585. xmlNodeList = xmlDoc.SelectSingleNode("data").SelectNodes("item");
  586. for (int i = 0; i < xmlNodeList.Count; i++)
  587. {
  588. attributeList.Add(xmlNodeList[i].Attributes);
  589. }
  590. return attributeList;
  591. }
  592. public static List<XmlAttributeCollection> GetFlowerConfig()
  593. {
  594. TextAsset textAsset;
  595. XmlNodeList xmlNodeList;
  596. XmlDocument xmlDoc = new XmlDocument();
  597. List<XmlAttributeCollection> attributeList = new List<XmlAttributeCollection>();
  598. textAsset = ManaReso.Load<TextAsset>("flower_config", Folder.Config);
  599. xmlDoc.LoadXml(textAsset.text);
  600. xmlNodeList = xmlDoc.SelectSingleNode("data").SelectNodes("item");
  601. for (int i = 0; i < xmlNodeList.Count; i++)
  602. {
  603. attributeList.Add(xmlNodeList[i].Attributes);
  604. }
  605. return attributeList;
  606. }
  607. public static List<XmlAttributeCollection> GetAchieveConfig()
  608. {
  609. TextAsset textAsset;
  610. XmlNodeList xmlNodeList;
  611. XmlDocument xmlDoc = new XmlDocument();
  612. List<XmlAttributeCollection> attributeList = new List<XmlAttributeCollection>();
  613. textAsset = ManaReso.Load<TextAsset>("achieve_config", Folder.Config);
  614. xmlDoc.LoadXml(textAsset.text);
  615. xmlNodeList = xmlDoc.SelectSingleNode("data").SelectNodes("item");
  616. for (int i = 0; i < xmlNodeList.Count; i++)
  617. {
  618. attributeList.Add(xmlNodeList[i].Attributes);
  619. }
  620. return attributeList;
  621. }
  622. }