Data.cs 33 KB

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