ManaData.cs 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014
  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.DownloadBySerialNumber(ManaServer.SerialNumber, 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("SerialNumber").Attributes[0].Value = ManaServer.SerialNumber;
  335. PlayerNode.SelectSingleNode("Language").Attributes[0].Value = ManaLan.CurrentLan.ToString();
  336. PlayerNode.SelectSingleNode("MiniGameIndex").Attributes[0].Value = ManaMiniGame.MiniGameIndex.ToString();
  337. PlayerNode.SelectSingleNode("TutorialA").Attributes[0].Value = ManaTutorial.TutorialA.ToInt().ToString();
  338. PlayerNode.SelectSingleNode("TutorialB").Attributes[0].Value = ManaTutorial.TutorialB_.ToInt().ToString();
  339. PlayerNode.SelectSingleNode("TutorialC").Attributes[0].Value = ManaTutorial.TutorialC_.ToInt().ToString();
  340. PlayerNode.SelectSingleNode("TutorialD").Attributes[0].Value = ManaTutorial.TutorialD_.ToInt().ToString();
  341. PlayerNode.SelectSingleNode("TutorialE").Attributes[0].Value = ManaTutorial.TutorialE_.ToInt().ToString();
  342. PlayerNode.SelectSingleNode("TutorialIndexA").Attributes[0].Value = ManaTutorial.TutorialIndexA.ToString();
  343. PlayerNode.SelectSingleNode("TutorialIndexB").Attributes[0].Value = ManaTutorial.TutorialIndexB.ToString();
  344. PlayerNode.SelectSingleNode("TutorialIndexC").Attributes[0].Value = ManaTutorial.TutorialIndexC.ToString();
  345. PlayerNode.SelectSingleNode("TutorialIndexD").Attributes[0].Value = ManaTutorial.TutorialIndexD.ToString();
  346. PlayerNode.SelectSingleNode("TutorialIndexE").Attributes[0].Value = ManaTutorial.TutorialIndexE.ToString();
  347. }
  348. public static void SaveFlowerList()
  349. {
  350. XmlAttribute attribute = PlayerNode.SelectSingleNode("FlowerList").Attributes[0];
  351. attribute.Value = "";
  352. foreach (var kv in ManaGarden.FlowerInfoDic)
  353. {
  354. if (kv.Value.Unlock)
  355. {
  356. attribute.Value += kv.Value.ID_ + " ";
  357. }
  358. }
  359. attribute.Value = attribute.Value.Trim(' ');
  360. }
  361. public static void SavePlayerConfig()
  362. {
  363. if (Initializer.Complete)
  364. {
  365. SaveSkillList();
  366. SaveAchieve();
  367. SaveDress();
  368. SavePlantList();
  369. SaveCommon();
  370. SaveFlowerList();
  371. }
  372. }
  373. public static void ResetPlayerConfig()
  374. {
  375. PlayerPrefs.SetString("id", "");
  376. PlayerNode.SelectSingleNode("Version").Attributes[0].Value = "10000";
  377. SavePlayerConfig();
  378. ManaCenter.SaveLock = true;
  379. }
  380. public static int GetPlayerInt(string node)
  381. {
  382. return int.Parse(PlayerNode.SelectSingleNode(node).Attributes[0].Value);
  383. }
  384. public static bool GetPlayerBool(string node)
  385. {
  386. return int.Parse(PlayerNode.SelectSingleNode(node).Attributes[0].Value).ToBool();
  387. }
  388. public static float GetPlayerFloat(string node)
  389. {
  390. return float.Parse(PlayerNode.SelectSingleNode(node).Attributes[0].Value);
  391. }
  392. public static string GetPlayerString(string node)
  393. {
  394. return PlayerNode.SelectSingleNode(node).Attributes[0].Value;
  395. }
  396. public static double GetPlayerDouble(string node)
  397. {
  398. return double.Parse(PlayerNode.SelectSingleNode(node).Attributes[0].Value);
  399. }
  400. public static void SavePlayerInt(string node, int value)
  401. {
  402. PlayerNode.SelectSingleNode(node).Attributes[0].Value = value.ToString();
  403. }
  404. public static void SavePlayerBool(string node, bool value)
  405. {
  406. PlayerNode.SelectSingleNode(node).Attributes[0].Value = value.ToInt().ToString();
  407. }
  408. public static void SavePlayerFloat(string node, float value)
  409. {
  410. PlayerNode.SelectSingleNode(node).Attributes[0].Value = value.ToString();
  411. }
  412. public static void SavePlayerString(string node, string value)
  413. {
  414. PlayerNode.SelectSingleNode(node).Attributes[0].Value = value;
  415. }
  416. public static void SavePlayerDouble(string node, double value)
  417. {
  418. PlayerNode.SelectSingleNode(node).Attributes[0].Value = value.ToString();
  419. }
  420. public static List<int> GetDressList()
  421. {
  422. List<int> list = new List<int>();
  423. XmlAttributeCollection attribute = PlayerNode.SelectSingleNode("DressList").Attributes;
  424. return Auxiliary.IntListParse(' ', attribute[0].Value, list);
  425. }
  426. public static List<string> GetDressData(XmlNode node = null)
  427. {
  428. XmlNode xmlNode;
  429. if (node == null)
  430. {
  431. xmlNode = PlayerNode.SelectSingleNode("DressData");
  432. }
  433. else
  434. {
  435. xmlNode = node.SelectSingleNode("DressData");
  436. }
  437. List<string> dataList = new List<string>();
  438. if (xmlNode != null && xmlNode.Attributes.Count == 8)
  439. {
  440. dataList.Add(xmlNode.Attributes[0].Value);
  441. dataList.Add(xmlNode.Attributes[1].Value);
  442. dataList.Add(xmlNode.Attributes[2].Value);
  443. dataList.Add(xmlNode.Attributes[3].Value);
  444. dataList.Add(xmlNode.Attributes[4].Value);
  445. dataList.Add(xmlNode.Attributes[5].Value);
  446. dataList.Add(xmlNode.Attributes[6].Value);
  447. dataList.Add(xmlNode.Attributes[7].Value);
  448. }
  449. else
  450. {
  451. float rate = Random.Range(0f, 1f);
  452. if (rate < 0.33f)
  453. {
  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("嘴巴1");
  461. dataList.Add("Empty");
  462. }
  463. else if (rate < 0.66f)
  464. {
  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("嘴巴2");
  472. dataList.Add("Empty");
  473. }
  474. else
  475. {
  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("嘴巴3");
  483. dataList.Add("Empty");
  484. }
  485. }
  486. return dataList;
  487. }
  488. public static List<int> GetFlowerList()
  489. {
  490. List<int> list = new List<int>();
  491. XmlAttributeCollection attribute = PlayerNode.SelectSingleNode("FlowerList").Attributes;
  492. return Auxiliary.IntListParse(' ', attribute[0].Value, list);
  493. }
  494. public static List<int> GetAchieveList()
  495. {
  496. return Auxiliary.IntListParse(' ', GetPlayerString("AchieveList"), new List<int>());
  497. }
  498. public static List<string> GetOfflineConfig()
  499. {
  500. TextAsset textAsset = ManaReso.Load<TextAsset>("offline_config", Folder.Config);
  501. XmlDocument xmlDoc = new XmlDocument();
  502. xmlDoc.LoadXml(textAsset.text);
  503. XmlNode xmlNode = xmlDoc.SelectSingleNode("data").SelectSingleNode("item");
  504. List<string> strList = new List<string>()
  505. {
  506. xmlNode.Attributes[1].Value,
  507. xmlNode.Attributes[2].Value,
  508. xmlNode.Attributes[3].Value,
  509. };
  510. return strList;
  511. }
  512. public static List<double> GetAchieveData()
  513. {
  514. List<double> dataList = new List<double>();
  515. dataList.Add(double.Parse(PlayerNode.SelectSingleNode("AchieveData").Attributes[0].Value));
  516. dataList.Add(double.Parse(PlayerNode.SelectSingleNode("AchieveData").Attributes[1].Value));
  517. dataList.Add(double.Parse(PlayerNode.SelectSingleNode("AchieveData").Attributes[2].Value));
  518. dataList.Add(double.Parse(PlayerNode.SelectSingleNode("AchieveData").Attributes[3].Value));
  519. dataList.Add(double.Parse(PlayerNode.SelectSingleNode("AchieveData").Attributes[4].Value));
  520. dataList.Add(double.Parse(PlayerNode.SelectSingleNode("AchieveData").Attributes[5].Value));
  521. dataList.Add(double.Parse(PlayerNode.SelectSingleNode("AchieveData").Attributes[6].Value));
  522. dataList.Add(double.Parse(PlayerNode.SelectSingleNode("AchieveData").Attributes[7].Value));
  523. dataList.Add(double.Parse(PlayerNode.SelectSingleNode("AchieveData").Attributes[8].Value));
  524. return dataList;
  525. }
  526. public static List<KV<int, int>> GetPlantList(XmlNode node = null)
  527. {
  528. List<KV<int, int>> list = new List<KV<int, int>>();
  529. XmlNode xmlNode;
  530. if (node == null)
  531. {
  532. xmlNode = PlayerNode.SelectSingleNode("PlantList");
  533. }
  534. else
  535. {
  536. xmlNode = node.SelectSingleNode("PlantList");
  537. }
  538. if (!string.IsNullOrEmpty(xmlNode.Attributes[0].Value))
  539. {
  540. string[] strings = xmlNode.Attributes[0].Value.Split(' ');
  541. for (int i = 0; i < strings.Length; i++)
  542. {
  543. list.Add(new KV<int, int>(int.Parse(strings[i].Split(',')[0]), int.Parse(strings[i].Split(',')[1])));
  544. }
  545. }
  546. return list;
  547. }
  548. public static List<XmlAttributeCollection> GetSkillList(XmlNode node = null)
  549. {
  550. List<XmlAttributeCollection> attributeList = new List<XmlAttributeCollection>();
  551. XmlNodeList xmlNodeList;
  552. if (node == null)
  553. {
  554. xmlNodeList = PlayerNode.SelectSingleNode("SkillList").ChildNodes;
  555. }
  556. else
  557. {
  558. xmlNodeList = node.SelectSingleNode("SkillList").ChildNodes;
  559. }
  560. for (int i = 0; i < xmlNodeList.Count; i++)
  561. {
  562. attributeList.Add(xmlNodeList[i].Attributes);
  563. }
  564. return attributeList;
  565. }
  566. public static XmlAttributeCollection GetVisitConfig()
  567. {
  568. TextAsset textAsset = ManaReso.Load<TextAsset>("visit_config", Folder.Config);
  569. XmlDocument xmlDoc = new XmlDocument();
  570. xmlDoc.LoadXml(textAsset.text);
  571. XmlNode xmlNode = xmlDoc.SelectSingleNode("data").SelectSingleNode("item");
  572. return xmlNode.Attributes;
  573. }
  574. public static XmlAttributeCollection GetAwardConfig()
  575. {
  576. TextAsset textAsset = ManaReso.Load<TextAsset>("award_config", Folder.Config);
  577. XmlDocument xmlDoc = new XmlDocument();
  578. xmlDoc.LoadXml(textAsset.text);
  579. XmlNode xmlNode = xmlDoc.SelectSingleNode("data").SelectSingleNode("item");
  580. return xmlNode.Attributes;
  581. }
  582. public static List<XmlAttributeCollection> GetIAPConfig()
  583. {
  584. TextAsset textAsset;
  585. XmlNodeList xmlNodeList;
  586. XmlDocument xmlDoc = new XmlDocument();
  587. List<XmlAttributeCollection> attributeList = new List<XmlAttributeCollection>();
  588. textAsset = ManaReso.Load<TextAsset>("iap_config", Folder.Config);
  589. xmlDoc.LoadXml(textAsset.text);
  590. xmlNodeList = xmlDoc.SelectSingleNode("data").SelectNodes("item");
  591. for (int i = 0; i < xmlNodeList.Count; i++)
  592. {
  593. attributeList.Add(xmlNodeList[i].Attributes);
  594. }
  595. return attributeList;
  596. }
  597. public static List<XmlAttributeCollection> GetSkillConfig()
  598. {
  599. TextAsset textAsset;
  600. XmlDocument xmlDoc = new XmlDocument();
  601. List<XmlNodeList> xmlNodeList = new List<XmlNodeList>();
  602. List<XmlAttributeCollection> attributeList = new List<XmlAttributeCollection>();
  603. textAsset = ManaReso.Load<TextAsset>("pack_config", Folder.Config);
  604. xmlDoc.LoadXml(textAsset.text);
  605. xmlNodeList.Add(xmlDoc.SelectSingleNode("data").SelectNodes("item"));
  606. textAsset = ManaReso.Load<TextAsset>("skill_config", Folder.Config);
  607. xmlDoc.LoadXml(textAsset.text);
  608. xmlNodeList.Add(xmlDoc.SelectSingleNode("data").SelectNodes("item"));
  609. textAsset = ManaReso.Load<TextAsset>("ability_config", Folder.Config);
  610. xmlDoc.LoadXml(textAsset.text);
  611. xmlNodeList.Add(xmlDoc.SelectSingleNode("data").SelectNodes("item"));
  612. for (int i = 0; i < xmlNodeList.Count; i++)
  613. {
  614. for (int j = 0; j < xmlNodeList[i].Count; j++)
  615. {
  616. attributeList.Add(xmlNodeList[i][j].Attributes);
  617. }
  618. }
  619. return attributeList;
  620. }
  621. public static List<XmlAttributeCollection> GetSignConfig()
  622. {
  623. TextAsset textAsset;
  624. XmlNodeList xmlNodeList;
  625. XmlDocument xmlDoc = new XmlDocument();
  626. List<XmlAttributeCollection> attributeList = new List<XmlAttributeCollection>();
  627. textAsset = ManaReso.Load<TextAsset>("signin_config", Folder.Config);
  628. xmlDoc.LoadXml(textAsset.text);
  629. xmlNodeList = xmlDoc.SelectSingleNode("data").SelectNodes("item");
  630. for (int i = 0; i < xmlNodeList.Count; i++)
  631. {
  632. attributeList.Add(xmlNodeList[i].Attributes);
  633. }
  634. return attributeList;
  635. }
  636. public static List<XmlAttributeCollection> GetFlowerConfig()
  637. {
  638. TextAsset textAsset;
  639. XmlNodeList xmlNodeList;
  640. XmlDocument xmlDoc = new XmlDocument();
  641. List<XmlAttributeCollection> attributeList = new List<XmlAttributeCollection>();
  642. textAsset = ManaReso.Load<TextAsset>("flower_config", Folder.Config);
  643. xmlDoc.LoadXml(textAsset.text);
  644. xmlNodeList = xmlDoc.SelectSingleNode("data").SelectNodes("item");
  645. for (int i = 0; i < xmlNodeList.Count; i++)
  646. {
  647. attributeList.Add(xmlNodeList[i].Attributes);
  648. }
  649. return attributeList;
  650. }
  651. public static List<XmlAttributeCollection> GetLotteryConfig()
  652. {
  653. TextAsset textAsset;
  654. XmlNodeList xmlNodeList;
  655. XmlDocument xmlDoc = new XmlDocument();
  656. List<XmlAttributeCollection> attributeList = new List<XmlAttributeCollection>();
  657. textAsset = ManaReso.Load<TextAsset>("lottery_config", Folder.Config);
  658. xmlDoc.LoadXml(textAsset.text);
  659. xmlNodeList = xmlDoc.SelectSingleNode("data").SelectNodes("item");
  660. for (int i = 0; i < xmlNodeList.Count; i++)
  661. {
  662. attributeList.Add(xmlNodeList[i].Attributes);
  663. }
  664. return attributeList;
  665. }
  666. public static List<XmlAttributeCollection> GetAchieveConfig()
  667. {
  668. TextAsset textAsset;
  669. XmlNodeList xmlNodeList;
  670. XmlDocument xmlDoc = new XmlDocument();
  671. List<XmlAttributeCollection> attributeList = new List<XmlAttributeCollection>();
  672. textAsset = ManaReso.Load<TextAsset>("achieve_config", Folder.Config);
  673. xmlDoc.LoadXml(textAsset.text);
  674. xmlNodeList = xmlDoc.SelectSingleNode("data").SelectNodes("item");
  675. for (int i = 0; i < xmlNodeList.Count; i++)
  676. {
  677. attributeList.Add(xmlNodeList[i].Attributes);
  678. }
  679. return attributeList;
  680. }
  681. public static List<XmlAttributeCollection> GetDressRoomConfig()
  682. {
  683. TextAsset textAsset;
  684. XmlNodeList xmlNodeList;
  685. XmlDocument xmlDoc = new XmlDocument();
  686. List<XmlAttributeCollection> attributeList = new List<XmlAttributeCollection>();
  687. textAsset = ManaReso.Load<TextAsset>("dressRoom_config", Folder.Config);
  688. xmlDoc.LoadXml(textAsset.text);
  689. xmlNodeList = xmlDoc.SelectSingleNode("data").SelectNodes("item");
  690. for (int i = 0; i < xmlNodeList.Count; i++)
  691. {
  692. attributeList.Add(xmlNodeList[i].Attributes);
  693. }
  694. return attributeList;
  695. }
  696. public static XmlDocument MergeXML(int nativeVersion, XmlDocument nativeDoc, XmlDocument defaultDoc)
  697. {
  698. if (nativeVersion < 0)
  699. {
  700. Debug.LogWarning("UpdateArchive to 0");
  701. To0(nativeDoc, defaultDoc);
  702. }
  703. if (nativeVersion < 1)
  704. {
  705. Debug.LogWarning("UpdateArchive to 1");
  706. To1(nativeDoc, defaultDoc);
  707. }
  708. if (nativeVersion < 2)
  709. {
  710. Debug.LogWarning("UpdateArchive to 2");
  711. To2(nativeDoc, defaultDoc);
  712. }
  713. return nativeDoc;
  714. }
  715. public static XmlDocument To0(XmlDocument nativeDoc, XmlDocument defaultDoc)
  716. {
  717. nativeDoc.SelectSingleNode("PlayerConfig").SelectSingleNode("Version").Attributes[0].Value = 0.ToString();
  718. XmlNode xmlNode1 = defaultDoc.SelectSingleNode("PlayerConfig").SelectSingleNode("ADPlayTime");
  719. nativeDoc.SelectSingleNode("PlayerConfig").AppendChild(nativeDoc.ImportNode(xmlNode1, true));
  720. return nativeDoc;
  721. }
  722. public static XmlDocument To1(XmlDocument nativeDoc, XmlDocument defaultDoc)
  723. {
  724. nativeDoc.SelectSingleNode("PlayerConfig").SelectSingleNode("Version").Attributes[0].Value = 1.ToString();
  725. XmlNode xmlNode1 = defaultDoc.SelectSingleNode("PlayerConfig").SelectSingleNode("SerialNumber");
  726. nativeDoc.SelectSingleNode("PlayerConfig").AppendChild(nativeDoc.ImportNode(xmlNode1, true));
  727. return nativeDoc;
  728. }
  729. public static XmlDocument To2(XmlDocument nativeDoc, XmlDocument defaultDoc)
  730. {
  731. nativeDoc.SelectSingleNode("PlayerConfig").SelectSingleNode("Version").Attributes[0].Value = 2.ToString();
  732. XmlNode xmlNode1 = defaultDoc.SelectSingleNode("PlayerConfig").SelectSingleNode("NotificationIndex");
  733. nativeDoc.SelectSingleNode("PlayerConfig").AppendChild(nativeDoc.ImportNode(xmlNode1, true));
  734. return nativeDoc;
  735. }
  736. }