ManaData.cs 31 KB

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