ManaData.cs 31 KB

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