ManaData.cs 31 KB

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