ManaData.cs 31 KB

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