ManaData.cs 37 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114
  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.fixedDeltaTime;
  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. }
  173. else
  174. {
  175. PlayerDoc_ = DefaultDoc;
  176. }
  177. }
  178. public static void SaveSkillList()
  179. {
  180. if (ManaTutorial.TutorialA || !ManaCenter.Complete)
  181. {
  182. return;
  183. }
  184. XmlNode xmlNode;
  185. XmlAttribute xmlAttribute;
  186. xmlNode = PlayerNode.SelectSingleNode("SkillList");
  187. xmlNode.RemoveAll();
  188. for (int i = 0; i < ManaCenter.SkillList.Count; i++)
  189. {
  190. if (ManaCenter.SkillList[i].SkillType == SkillType.Skill)
  191. {
  192. #region Skill
  193. Skill skill = (Skill)ManaCenter.SkillList[i];
  194. xmlNode = xmlNode.AppendChild(PlayerDoc.CreateNode(XmlNodeType.Element, "Skill", ""));
  195. xmlAttribute = xmlNode.Attributes.Append(PlayerDoc.CreateAttribute("ID"));
  196. xmlAttribute.Value = skill.ID;
  197. xmlAttribute = xmlNode.Attributes.Append(PlayerDoc.CreateAttribute("SkillType"));
  198. xmlAttribute.Value = skill.SkillType.ToString();
  199. xmlAttribute = xmlNode.Attributes.Append(PlayerDoc.CreateAttribute("ItemStatus"));
  200. xmlAttribute.Value = skill.ItemStatus.ToString();
  201. xmlAttribute = xmlNode.Attributes.Append(PlayerDoc.CreateAttribute("Level"));
  202. xmlAttribute.Value = skill.Level.ToString();
  203. xmlAttribute = xmlNode.Attributes.Append(PlayerDoc.CreateAttribute("CoolTimer"));
  204. xmlAttribute.Value = skill.CoolTimer.ToString("0");
  205. xmlAttribute = xmlNode.Attributes.Append(PlayerDoc.CreateAttribute("UseTimer"));
  206. xmlAttribute.Value = skill.UseTimer.ToString("0");
  207. xmlNode = PlayerNode.SelectSingleNode("SkillList");
  208. #endregion
  209. }
  210. else if (ManaCenter.SkillList[i].SkillType == SkillType.Pack)
  211. {
  212. #region Pack
  213. Pack pack = (Pack)ManaCenter.SkillList[i];
  214. xmlNode = xmlNode.AppendChild(PlayerDoc.CreateNode(XmlNodeType.Element, "Skill", ""));
  215. xmlAttribute = xmlNode.Attributes.Append(PlayerDoc.CreateAttribute("ID"));
  216. xmlAttribute.Value = pack.ID;
  217. xmlAttribute = xmlNode.Attributes.Append(PlayerDoc.CreateAttribute("SkillType"));
  218. xmlAttribute.Value = pack.SkillType.ToString();
  219. xmlAttribute = xmlNode.Attributes.Append(PlayerDoc.CreateAttribute("ItemStatus"));
  220. xmlAttribute.Value = pack.ItemStatus.ToString();
  221. xmlAttribute = xmlNode.Attributes.Append(PlayerDoc.CreateAttribute("Level"));
  222. xmlAttribute.Value = pack.Level.ToString();
  223. xmlNode = PlayerNode.SelectSingleNode("SkillList");
  224. #endregion
  225. }
  226. else if (ManaCenter.SkillList[i].SkillType == SkillType.Ability)
  227. {
  228. #region Ability
  229. Ability ability = (Ability)ManaCenter.SkillList[i];
  230. xmlNode = xmlNode.AppendChild(PlayerDoc.CreateNode(XmlNodeType.Element, "Skill", ""));
  231. xmlAttribute = xmlNode.Attributes.Append(PlayerDoc.CreateAttribute("ID"));
  232. xmlAttribute.Value = ability.ID;
  233. xmlAttribute = xmlNode.Attributes.Append(PlayerDoc.CreateAttribute("SkillType"));
  234. xmlAttribute.Value = ability.SkillType.ToString();
  235. xmlAttribute = xmlNode.Attributes.Append(PlayerDoc.CreateAttribute("ItemStatus"));
  236. xmlAttribute.Value = ability.ItemStatus.ToString();
  237. xmlAttribute = xmlNode.Attributes.Append(PlayerDoc.CreateAttribute("Level"));
  238. xmlAttribute.Value = ability.Level.ToString();
  239. xmlNode = PlayerNode.SelectSingleNode("SkillList");
  240. #endregion
  241. }
  242. else if (ManaCenter.SkillList[i].SkillType == SkillType.BigSkill)
  243. {
  244. #region BigSkill
  245. BigSkill bigSkill = (BigSkill)ManaCenter.SkillList[i];
  246. xmlNode = xmlNode.AppendChild(PlayerDoc.CreateNode(XmlNodeType.Element, "Skill", ""));
  247. xmlAttribute = xmlNode.Attributes.Append(PlayerDoc.CreateAttribute("ID"));
  248. xmlAttribute.Value = bigSkill.ID;
  249. xmlAttribute = xmlNode.Attributes.Append(PlayerDoc.CreateAttribute("SkillType"));
  250. xmlAttribute.Value = bigSkill.SkillType.ToString();
  251. xmlAttribute = xmlNode.Attributes.Append(PlayerDoc.CreateAttribute("ItemStatus"));
  252. xmlAttribute.Value = bigSkill.ItemStatus.ToString();
  253. xmlAttribute = xmlNode.Attributes.Append(PlayerDoc.CreateAttribute("BarStatus"));
  254. xmlAttribute.Value = bigSkill.BarStatus.ToString();
  255. xmlAttribute = xmlNode.Attributes.Append(PlayerDoc.CreateAttribute("Level"));
  256. xmlAttribute.Value = bigSkill.Level.ToString();
  257. xmlAttribute = xmlNode.Attributes.Append(PlayerDoc.CreateAttribute("CoolTimer"));
  258. xmlAttribute.Value = bigSkill.CoolTimer.ToString("0");
  259. xmlAttribute = xmlNode.Attributes.Append(PlayerDoc.CreateAttribute("UseTimer"));
  260. xmlAttribute.Value = bigSkill.UseTimer.ToString("0");
  261. xmlNode = PlayerNode.SelectSingleNode("SkillList");
  262. #endregion
  263. }
  264. }
  265. }
  266. public static void SaveDress()
  267. {
  268. XmlNode xmlNode = PlayerNode.SelectSingleNode("DressList");
  269. xmlNode.Attributes[0].Value = "";
  270. for (int i = 0; i < ManaPlayer.BoughtCloseList.Count; i++)
  271. {
  272. xmlNode.Attributes[0].Value += ManaPlayer.BoughtCloseList[i] + " ";
  273. }
  274. xmlNode.Attributes[0].Value = xmlNode.Attributes[0].Value.TrimEnd(' ');
  275. xmlNode = PlayerNode.SelectSingleNode("DressData");
  276. for (int i = 0; i < ManaPlayer.DressData.Count; i++)
  277. {
  278. xmlNode.Attributes[i].Value = ManaPlayer.DressData[i];
  279. }
  280. }
  281. public static void SaveAchieve()
  282. {
  283. XmlNode xmlNode = PlayerNode.SelectSingleNode("AchieveList");
  284. xmlNode.Attributes[0].Value = "";
  285. foreach (var kv in ManaAchieve.AchieveDic)
  286. {
  287. if (!kv.Value.Lock)
  288. {
  289. xmlNode.Attributes[0].Value += kv.Value.ID_ + " ";
  290. }
  291. }
  292. xmlNode.Attributes[0].Value = xmlNode.Attributes[0].Value.TrimEnd(' ');
  293. PlayerNode.SelectSingleNode("AchieveData").Attributes[0].Value = ManaCenter.AdAmt.ToString("0");
  294. PlayerNode.SelectSingleNode("AchieveData").Attributes[1].Value = ManaCenter.SkillAmt.ToString("0");
  295. PlayerNode.SelectSingleNode("AchieveData").Attributes[2].Value = ManaCenter.SignAmt.ToString("0");
  296. PlayerNode.SelectSingleNode("AchieveData").Attributes[3].Value = ManaCenter.ShareAmt.ToString("0");
  297. PlayerNode.SelectSingleNode("AchieveData").Attributes[4].Value = ManaCenter.ElfLevel.ToString("0");
  298. PlayerNode.SelectSingleNode("AchieveData").Attributes[5].Value = ManaCenter.MiniGameAmt.ToString("0");
  299. PlayerNode.SelectSingleNode("AchieveData").Attributes[6].Value = ManaCenter.FlowerCoin.ToString("0");
  300. PlayerNode.SelectSingleNode("AchieveData").Attributes[7].Value = ManaCenter.TotalPerson.ToString("0");
  301. PlayerNode.SelectSingleNode("AchieveData").Attributes[8].Value = ManaCenter.CostDiamond.ToString("0");
  302. }
  303. public static void SavePlantList()
  304. {
  305. if (ManaVisit.InVisit || ManaTutorial.TutorialA)
  306. {
  307. return;
  308. }
  309. XmlAttributeCollection attribute = PlayerNode.SelectSingleNode("PlantList").Attributes;
  310. attribute[0].Value = "";
  311. for (int i = 0; i < ManaGarden.PlantList.Count; i++)
  312. {
  313. Slot slot = ManaGarden.PlantList[i];
  314. attribute[0].Value += slot.ID + "," + slot.Index + " ";
  315. }
  316. attribute[0].Value = attribute[0].Value.TrimEnd(' ');
  317. }
  318. public static void SaveCommon()
  319. {
  320. PlayerNode.SelectSingleNode("Coin").Attributes[0].Value = ManaCenter.Coin.ToString("0");
  321. PlayerNode.SelectSingleNode("Diamond").Attributes[0].Value = ManaCenter.Diamond.ToString("0");
  322. PlayerNode.SelectSingleNode("SignTime").Attributes[0].Value = ManaSign.SignTime.ToString();
  323. PlayerNode.SelectSingleNode("SignIndex").Attributes[0].Value = ManaSign.SignIndex.ToString();
  324. PlayerNode.SelectSingleNode("SignRound").Attributes[0].Value = ManaSign.SignRound.ToString();
  325. PlayerNode.SelectSingleNode("QuitFlag").Attributes[0].Value = ManaServer.Connect.ToInt().ToString();
  326. PlayerNode.SelectSingleNode("QuitTime").Attributes[0].Value = ManaServer.Time.ToString();
  327. PlayerNode.SelectSingleNode("MiniTimer").Attributes[0].Value = ManaCenter.MiniTimer.ToString("0");
  328. PlayerNode.SelectSingleNode("CircleTimer").Attributes[0].Value = ManaCenter.CircleTimer.ToString("0");
  329. PlayerNode.SelectSingleNode("ID").Attributes[0].Value = ManaServer.ID;
  330. PlayerNode.SelectSingleNode("Language").Attributes[0].Value = ManaLan.CurrentLan.ToString();
  331. PlayerNode.SelectSingleNode("MiniGameIndex").Attributes[0].Value = ManaMiniGame.MiniGameIndex.ToString();
  332. PlayerNode.SelectSingleNode("TutorialA").Attributes[0].Value = ManaTutorial.TutorialA.ToInt().ToString();
  333. PlayerNode.SelectSingleNode("TutorialB").Attributes[0].Value = ManaTutorial.TutorialB_.ToInt().ToString();
  334. PlayerNode.SelectSingleNode("TutorialC").Attributes[0].Value = ManaTutorial.TutorialC_.ToInt().ToString();
  335. PlayerNode.SelectSingleNode("TutorialD").Attributes[0].Value = ManaTutorial.TutorialD_.ToInt().ToString();
  336. PlayerNode.SelectSingleNode("TutorialE").Attributes[0].Value = ManaTutorial.TutorialE_.ToInt().ToString();
  337. PlayerNode.SelectSingleNode("TutorialIndexA").Attributes[0].Value = ManaTutorial.TutorialIndexA.ToString();
  338. PlayerNode.SelectSingleNode("TutorialIndexB").Attributes[0].Value = ManaTutorial.TutorialIndexB.ToString();
  339. PlayerNode.SelectSingleNode("TutorialIndexC").Attributes[0].Value = ManaTutorial.TutorialIndexC.ToString();
  340. PlayerNode.SelectSingleNode("TutorialIndexD").Attributes[0].Value = ManaTutorial.TutorialIndexD.ToString();
  341. PlayerNode.SelectSingleNode("TutorialIndexE").Attributes[0].Value = ManaTutorial.TutorialIndexE.ToString();
  342. }
  343. public static void SaveFlowerList()
  344. {
  345. XmlAttribute attribute = PlayerNode.SelectSingleNode("FlowerList").Attributes[0];
  346. attribute.Value = "";
  347. foreach (var kv in ManaGarden.FlowerInfoDic)
  348. {
  349. if (kv.Value.Unlock)
  350. {
  351. attribute.Value += kv.Value.ID_ + " ";
  352. }
  353. }
  354. attribute.Value = attribute.Value.Trim(' ');
  355. }
  356. public static void SavePlayerConfig()
  357. {
  358. if (Initializer.Complete)
  359. {
  360. SaveSkillList();
  361. SaveAchieve();
  362. SaveDress();
  363. SavePlantList();
  364. SaveCommon();
  365. SaveFlowerList();
  366. }
  367. }
  368. public static void ResetPlayerConfig()
  369. {
  370. PlayerPrefs.SetString("id", "");
  371. PlayerNode.SelectSingleNode("Version").Attributes[0].Value = "10000";
  372. SavePlayerConfig();
  373. ManaCenter.SaveLock = true;
  374. }
  375. public static int GetPlayerInt(string node)
  376. {
  377. return int.Parse(PlayerNode.SelectSingleNode(node).Attributes[0].Value);
  378. }
  379. public static bool GetPlayerBool(string node)
  380. {
  381. return int.Parse(PlayerNode.SelectSingleNode(node).Attributes[0].Value).ToBool();
  382. }
  383. public static float GetPlayerFloat(string node)
  384. {
  385. return float.Parse(PlayerNode.SelectSingleNode(node).Attributes[0].Value);
  386. }
  387. public static string GetPlayerString(string node)
  388. {
  389. return PlayerNode.SelectSingleNode(node).Attributes[0].Value;
  390. }
  391. public static double GetPlayerDouble(string node)
  392. {
  393. return double.Parse(PlayerNode.SelectSingleNode(node).Attributes[0].Value);
  394. }
  395. public static void SavePlayerInt(string node, int value)
  396. {
  397. PlayerNode.SelectSingleNode(node).Attributes[0].Value = value.ToString();
  398. }
  399. public static void SavePlayerBool(string node, bool value)
  400. {
  401. PlayerNode.SelectSingleNode(node).Attributes[0].Value = value.ToInt().ToString();
  402. }
  403. public static void SavePlayerFloat(string node, float value)
  404. {
  405. PlayerNode.SelectSingleNode(node).Attributes[0].Value = value.ToString();
  406. }
  407. public static void SavePlayerString(string node, string value)
  408. {
  409. PlayerNode.SelectSingleNode(node).Attributes[0].Value = value;
  410. }
  411. public static void SavePlayerDouble(string node, double value)
  412. {
  413. PlayerNode.SelectSingleNode(node).Attributes[0].Value = value.ToString();
  414. }
  415. public static List<int> GetDressList()
  416. {
  417. List<int> list = new List<int>();
  418. XmlAttributeCollection attribute = PlayerNode.SelectSingleNode("DressList").Attributes;
  419. return Auxiliary.IntListParse(' ', attribute[0].Value, list);
  420. }
  421. public static List<string> GetDressData(XmlNode node = null)
  422. {
  423. XmlNode xmlNode;
  424. if (node == null)
  425. {
  426. xmlNode = PlayerNode.SelectSingleNode("DressData");
  427. }
  428. else
  429. {
  430. xmlNode = node.SelectSingleNode("DressData");
  431. }
  432. List<string> dataList = new List<string>();
  433. if (xmlNode != null && xmlNode.Attributes.Count == 8)
  434. {
  435. dataList.Add(xmlNode.Attributes[0].Value);
  436. dataList.Add(xmlNode.Attributes[1].Value);
  437. dataList.Add(xmlNode.Attributes[2].Value);
  438. dataList.Add(xmlNode.Attributes[3].Value);
  439. dataList.Add(xmlNode.Attributes[4].Value);
  440. dataList.Add(xmlNode.Attributes[5].Value);
  441. dataList.Add(xmlNode.Attributes[6].Value);
  442. dataList.Add(xmlNode.Attributes[7].Value);
  443. }
  444. else
  445. {
  446. float rate = Random.Range(0f, 1f);
  447. if (rate < 0.33f)
  448. {
  449. dataList.Add("脑壳1");
  450. dataList.Add("裙子1");
  451. dataList.Add("鞋子1");
  452. dataList.Add("头饰品1");
  453. dataList.Add("上衣1");
  454. dataList.Add("眼睛1");
  455. dataList.Add("嘴巴1");
  456. dataList.Add("Empty");
  457. }
  458. else if (rate < 0.66f)
  459. {
  460. dataList.Add("脑壳2");
  461. dataList.Add("裙子2");
  462. dataList.Add("鞋子2");
  463. dataList.Add("头饰品2");
  464. dataList.Add("上衣2");
  465. dataList.Add("眼睛2");
  466. dataList.Add("嘴巴2");
  467. dataList.Add("Empty");
  468. }
  469. else
  470. {
  471. dataList.Add("脑壳3");
  472. dataList.Add("裙子3");
  473. dataList.Add("鞋子3");
  474. dataList.Add("头饰品3");
  475. dataList.Add("上衣3");
  476. dataList.Add("眼睛3");
  477. dataList.Add("嘴巴3");
  478. dataList.Add("Empty");
  479. }
  480. }
  481. return dataList;
  482. }
  483. public static List<int> GetFlowerList()
  484. {
  485. List<int> list = new List<int>();
  486. XmlAttributeCollection attribute = PlayerNode.SelectSingleNode("FlowerList").Attributes;
  487. return Auxiliary.IntListParse(' ', attribute[0].Value, list);
  488. }
  489. public static List<int> GetAchieveList()
  490. {
  491. return Auxiliary.IntListParse(' ', GetPlayerString("AchieveList"), new List<int>());
  492. }
  493. public static List<string> GetOfflineConfig()
  494. {
  495. TextAsset textAsset = ManaReso.Load<TextAsset>("offline_config", Folder.Config);
  496. XmlDocument xmlDoc = new XmlDocument();
  497. xmlDoc.LoadXml(textAsset.text);
  498. XmlNode xmlNode = xmlDoc.SelectSingleNode("data").SelectSingleNode("item");
  499. List<string> strList = new List<string>()
  500. {
  501. xmlNode.Attributes[1].Value,
  502. xmlNode.Attributes[2].Value,
  503. xmlNode.Attributes[3].Value,
  504. };
  505. return strList;
  506. }
  507. public static List<double> GetAchieveData()
  508. {
  509. List<double> dataList = new List<double>();
  510. dataList.Add(double.Parse(PlayerNode.SelectSingleNode("AchieveData").Attributes[0].Value));
  511. dataList.Add(double.Parse(PlayerNode.SelectSingleNode("AchieveData").Attributes[1].Value));
  512. dataList.Add(double.Parse(PlayerNode.SelectSingleNode("AchieveData").Attributes[2].Value));
  513. dataList.Add(double.Parse(PlayerNode.SelectSingleNode("AchieveData").Attributes[3].Value));
  514. dataList.Add(double.Parse(PlayerNode.SelectSingleNode("AchieveData").Attributes[4].Value));
  515. dataList.Add(double.Parse(PlayerNode.SelectSingleNode("AchieveData").Attributes[5].Value));
  516. dataList.Add(double.Parse(PlayerNode.SelectSingleNode("AchieveData").Attributes[6].Value));
  517. dataList.Add(double.Parse(PlayerNode.SelectSingleNode("AchieveData").Attributes[7].Value));
  518. dataList.Add(double.Parse(PlayerNode.SelectSingleNode("AchieveData").Attributes[8].Value));
  519. return dataList;
  520. }
  521. public static List<KV<int, int>> GetPlantList(XmlNode node = null)
  522. {
  523. List<KV<int, int>> list = new List<KV<int, int>>();
  524. XmlNode xmlNode;
  525. if (node == null)
  526. {
  527. xmlNode = PlayerNode.SelectSingleNode("PlantList");
  528. }
  529. else
  530. {
  531. xmlNode = node.SelectSingleNode("PlantList");
  532. }
  533. if (!string.IsNullOrEmpty(xmlNode.Attributes[0].Value))
  534. {
  535. string[] strings = xmlNode.Attributes[0].Value.Split(' ');
  536. for (int i = 0; i < strings.Length; i++)
  537. {
  538. list.Add(new KV<int, int>(int.Parse(strings[i].Split(',')[0]), int.Parse(strings[i].Split(',')[1])));
  539. }
  540. }
  541. return list;
  542. }
  543. public static List<XmlAttributeCollection> GetSkillList(XmlNode node = null)
  544. {
  545. List<XmlAttributeCollection> attributeList = new List<XmlAttributeCollection>();
  546. XmlNodeList xmlNodeList;
  547. if (node == null)
  548. {
  549. xmlNodeList = PlayerNode.SelectSingleNode("SkillList").ChildNodes;
  550. }
  551. else
  552. {
  553. xmlNodeList = node.SelectSingleNode("SkillList").ChildNodes;
  554. }
  555. for (int i = 0; i < xmlNodeList.Count; i++)
  556. {
  557. attributeList.Add(xmlNodeList[i].Attributes);
  558. }
  559. return attributeList;
  560. }
  561. public static XmlAttributeCollection GetVisitConfig()
  562. {
  563. TextAsset textAsset = ManaReso.Load<TextAsset>("visit_config", Folder.Config);
  564. XmlDocument xmlDoc = new XmlDocument();
  565. xmlDoc.LoadXml(textAsset.text);
  566. XmlNode xmlNode = xmlDoc.SelectSingleNode("data").SelectSingleNode("item");
  567. return xmlNode.Attributes;
  568. }
  569. public static XmlAttributeCollection GetAwardConfig()
  570. {
  571. TextAsset textAsset = ManaReso.Load<TextAsset>("award_config", Folder.Config);
  572. XmlDocument xmlDoc = new XmlDocument();
  573. xmlDoc.LoadXml(textAsset.text);
  574. XmlNode xmlNode = xmlDoc.SelectSingleNode("data").SelectSingleNode("item");
  575. return xmlNode.Attributes;
  576. }
  577. public static List<XmlAttributeCollection> GetIAPConfig()
  578. {
  579. TextAsset textAsset;
  580. XmlNodeList xmlNodeList;
  581. XmlDocument xmlDoc = new XmlDocument();
  582. List<XmlAttributeCollection> attributeList = new List<XmlAttributeCollection>();
  583. textAsset = ManaReso.Load<TextAsset>("iap_config", Folder.Config);
  584. xmlDoc.LoadXml(textAsset.text);
  585. xmlNodeList = xmlDoc.SelectSingleNode("data").SelectNodes("item");
  586. for (int i = 0; i < xmlNodeList.Count; i++)
  587. {
  588. attributeList.Add(xmlNodeList[i].Attributes);
  589. }
  590. return attributeList;
  591. }
  592. public static List<XmlAttributeCollection> GetSkillConfig()
  593. {
  594. TextAsset textAsset;
  595. XmlDocument xmlDoc = new XmlDocument();
  596. List<XmlNodeList> xmlNodeList = new List<XmlNodeList>();
  597. List<XmlAttributeCollection> attributeList = new List<XmlAttributeCollection>();
  598. textAsset = ManaReso.Load<TextAsset>("pack_config", Folder.Config);
  599. xmlDoc.LoadXml(textAsset.text);
  600. xmlNodeList.Add(xmlDoc.SelectSingleNode("data").SelectNodes("item"));
  601. textAsset = ManaReso.Load<TextAsset>("skill_config", Folder.Config);
  602. xmlDoc.LoadXml(textAsset.text);
  603. xmlNodeList.Add(xmlDoc.SelectSingleNode("data").SelectNodes("item"));
  604. textAsset = ManaReso.Load<TextAsset>("ability_config", Folder.Config);
  605. xmlDoc.LoadXml(textAsset.text);
  606. xmlNodeList.Add(xmlDoc.SelectSingleNode("data").SelectNodes("item"));
  607. for (int i = 0; i < xmlNodeList.Count; i++)
  608. {
  609. for (int j = 0; j < xmlNodeList[i].Count; j++)
  610. {
  611. attributeList.Add(xmlNodeList[i][j].Attributes);
  612. }
  613. }
  614. return attributeList;
  615. }
  616. public static List<XmlAttributeCollection> GetSignConfig()
  617. {
  618. TextAsset textAsset;
  619. XmlNodeList xmlNodeList;
  620. XmlDocument xmlDoc = new XmlDocument();
  621. List<XmlAttributeCollection> attributeList = new List<XmlAttributeCollection>();
  622. textAsset = ManaReso.Load<TextAsset>("signin_config", Folder.Config);
  623. xmlDoc.LoadXml(textAsset.text);
  624. xmlNodeList = xmlDoc.SelectSingleNode("data").SelectNodes("item");
  625. for (int i = 0; i < xmlNodeList.Count; i++)
  626. {
  627. attributeList.Add(xmlNodeList[i].Attributes);
  628. }
  629. return attributeList;
  630. }
  631. public static List<XmlAttributeCollection> GetFlowerConfig()
  632. {
  633. TextAsset textAsset;
  634. XmlNodeList xmlNodeList;
  635. XmlDocument xmlDoc = new XmlDocument();
  636. List<XmlAttributeCollection> attributeList = new List<XmlAttributeCollection>();
  637. textAsset = ManaReso.Load<TextAsset>("flower_config", Folder.Config);
  638. xmlDoc.LoadXml(textAsset.text);
  639. xmlNodeList = xmlDoc.SelectSingleNode("data").SelectNodes("item");
  640. for (int i = 0; i < xmlNodeList.Count; i++)
  641. {
  642. attributeList.Add(xmlNodeList[i].Attributes);
  643. }
  644. return attributeList;
  645. }
  646. public static List<XmlAttributeCollection> GetLotteryConfig()
  647. {
  648. TextAsset textAsset;
  649. XmlNodeList xmlNodeList;
  650. XmlDocument xmlDoc = new XmlDocument();
  651. List<XmlAttributeCollection> attributeList = new List<XmlAttributeCollection>();
  652. textAsset = ManaReso.Load<TextAsset>("lottery_config", Folder.Config);
  653. xmlDoc.LoadXml(textAsset.text);
  654. xmlNodeList = xmlDoc.SelectSingleNode("data").SelectNodes("item");
  655. for (int i = 0; i < xmlNodeList.Count; i++)
  656. {
  657. attributeList.Add(xmlNodeList[i].Attributes);
  658. }
  659. return attributeList;
  660. }
  661. public static List<XmlAttributeCollection> GetAchieveConfig()
  662. {
  663. TextAsset textAsset;
  664. XmlNodeList xmlNodeList;
  665. XmlDocument xmlDoc = new XmlDocument();
  666. List<XmlAttributeCollection> attributeList = new List<XmlAttributeCollection>();
  667. textAsset = ManaReso.Load<TextAsset>("achieve_config", Folder.Config);
  668. xmlDoc.LoadXml(textAsset.text);
  669. xmlNodeList = xmlDoc.SelectSingleNode("data").SelectNodes("item");
  670. for (int i = 0; i < xmlNodeList.Count; i++)
  671. {
  672. attributeList.Add(xmlNodeList[i].Attributes);
  673. }
  674. return attributeList;
  675. }
  676. public static List<XmlAttributeCollection> GetDressRoomConfig()
  677. {
  678. TextAsset textAsset;
  679. XmlNodeList xmlNodeList;
  680. XmlDocument xmlDoc = new XmlDocument();
  681. List<XmlAttributeCollection> attributeList = new List<XmlAttributeCollection>();
  682. textAsset = ManaReso.Load<TextAsset>("dressRoom_config", Folder.Config);
  683. xmlDoc.LoadXml(textAsset.text);
  684. xmlNodeList = xmlDoc.SelectSingleNode("data").SelectNodes("item");
  685. for (int i = 0; i < xmlNodeList.Count; i++)
  686. {
  687. attributeList.Add(xmlNodeList[i].Attributes);
  688. }
  689. return attributeList;
  690. }
  691. public static XmlDocument MergeXML(int nativeVersion, XmlDocument nativeDoc, XmlDocument defaultDoc)
  692. {
  693. if (nativeVersion < 681)
  694. {
  695. Debug.LogWarning("UpdateArchive");
  696. To681(nativeDoc, defaultDoc);
  697. }
  698. return nativeDoc;
  699. }
  700. public static XmlDocument To681(XmlDocument nativeDoc, XmlDocument defaultDoc)
  701. {
  702. string playerType = "";
  703. XmlNode xmlNode1 = nativeDoc.SelectSingleNode("PlayerConfig").SelectSingleNode("DressList");
  704. XmlNode xmlNode2 = nativeDoc.SelectSingleNode("PlayerConfig").SelectSingleNode("DressData");
  705. XmlNode xmlNode3 = nativeDoc.SelectSingleNode("PlayerConfig").SelectSingleNode("TutorialD");
  706. XmlNode xmlNode4 = nativeDoc.SelectSingleNode("PlayerConfig").SelectSingleNode("TutorialIndexD");
  707. XmlNode xmlNode5 = nativeDoc.SelectSingleNode("PlayerConfig").SelectSingleNode("Player");
  708. XmlNode xmlNode6 = nativeDoc.SelectSingleNode("PlayerConfig").SelectSingleNode("TutorialE");
  709. XmlNode xmlNode7 = nativeDoc.SelectSingleNode("PlayerConfig").SelectSingleNode("TutorialIndexE");
  710. XmlNode xmlNode8 = nativeDoc.SelectSingleNode("PlayerConfig").SelectSingleNode("AchieveData");
  711. if (xmlNode1 != null)
  712. {
  713. nativeDoc.SelectSingleNode("PlayerConfig").RemoveChild(xmlNode1);
  714. }
  715. if (xmlNode2 != null)
  716. {
  717. nativeDoc.SelectSingleNode("PlayerConfig").RemoveChild(xmlNode2);
  718. }
  719. if (xmlNode3 != null)
  720. {
  721. nativeDoc.SelectSingleNode("PlayerConfig").RemoveChild(xmlNode3);
  722. }
  723. if (xmlNode4 != null)
  724. {
  725. nativeDoc.SelectSingleNode("PlayerConfig").RemoveChild(xmlNode4);
  726. }
  727. if (xmlNode5 != null)
  728. {
  729. playerType = xmlNode5.Attributes[0].Value;
  730. nativeDoc.SelectSingleNode("PlayerConfig").RemoveChild(xmlNode5);
  731. }
  732. else
  733. {
  734. playerType = "PlayerBlond";
  735. }
  736. if (xmlNode6 != null)
  737. {
  738. nativeDoc.SelectSingleNode("PlayerConfig").RemoveChild(xmlNode6);
  739. }
  740. if (xmlNode7 != null)
  741. {
  742. nativeDoc.SelectSingleNode("PlayerConfig").RemoveChild(xmlNode7);
  743. }
  744. if (xmlNode8 != null)
  745. {
  746. nativeDoc.SelectSingleNode("PlayerConfig").RemoveChild(xmlNode8);
  747. }
  748. nativeDoc.SelectSingleNode("PlayerConfig").SelectSingleNode("Version").Attributes[0].Value = 681.ToString();
  749. xmlNode1 = defaultDoc.SelectSingleNode("PlayerConfig").SelectSingleNode("DressList");
  750. xmlNode2 = defaultDoc.SelectSingleNode("PlayerConfig").SelectSingleNode("DressData");
  751. xmlNode3 = defaultDoc.SelectSingleNode("PlayerConfig").SelectSingleNode("TutorialD");
  752. xmlNode4 = defaultDoc.SelectSingleNode("PlayerConfig").SelectSingleNode("TutorialIndexD");
  753. xmlNode5 = defaultDoc.SelectSingleNode("PlayerConfig").SelectSingleNode("Player");
  754. xmlNode6 = defaultDoc.SelectSingleNode("PlayerConfig").SelectSingleNode("TutorialE");
  755. xmlNode7 = defaultDoc.SelectSingleNode("PlayerConfig").SelectSingleNode("TutorialIndexE");
  756. xmlNode8 = defaultDoc.SelectSingleNode("PlayerConfig").SelectSingleNode("AchieveData");
  757. if (playerType == "PlayerBlond")
  758. {
  759. xmlNode2.Attributes[0].Value = "脑壳1";
  760. xmlNode2.Attributes[1].Value = "裙子1";
  761. xmlNode2.Attributes[2].Value = "鞋子1";
  762. xmlNode2.Attributes[3].Value = "头饰品1";
  763. xmlNode2.Attributes[4].Value = "上衣1";
  764. xmlNode2.Attributes[5].Value = "眼睛1";
  765. xmlNode2.Attributes[6].Value = "嘴巴1";
  766. xmlNode2.Attributes[7].Value = "Empty";
  767. }
  768. else if (playerType == "PlayerBrown")
  769. {
  770. xmlNode2.Attributes[0].Value = "脑壳2";
  771. xmlNode2.Attributes[1].Value = "裙子2";
  772. xmlNode2.Attributes[2].Value = "鞋子2";
  773. xmlNode2.Attributes[3].Value = "头饰品2";
  774. xmlNode2.Attributes[4].Value = "上衣2";
  775. xmlNode2.Attributes[5].Value = "眼睛2";
  776. xmlNode2.Attributes[6].Value = "嘴巴2";
  777. xmlNode2.Attributes[7].Value = "Empty";
  778. }
  779. else if (playerType == "PlayerPink")
  780. {
  781. xmlNode2.Attributes[0].Value = "脑壳3";
  782. xmlNode2.Attributes[1].Value = "裙子3";
  783. xmlNode2.Attributes[2].Value = "鞋子3";
  784. xmlNode2.Attributes[3].Value = "头饰品3";
  785. xmlNode2.Attributes[4].Value = "上衣3";
  786. xmlNode2.Attributes[5].Value = "眼睛3";
  787. xmlNode2.Attributes[6].Value = "嘴巴3";
  788. xmlNode2.Attributes[7].Value = "Empty";
  789. }
  790. nativeDoc.SelectSingleNode("PlayerConfig").AppendChild(nativeDoc.ImportNode(xmlNode1, true));
  791. nativeDoc.SelectSingleNode("PlayerConfig").AppendChild(nativeDoc.ImportNode(xmlNode2, true));
  792. nativeDoc.SelectSingleNode("PlayerConfig").AppendChild(nativeDoc.ImportNode(xmlNode3, true));
  793. nativeDoc.SelectSingleNode("PlayerConfig").AppendChild(nativeDoc.ImportNode(xmlNode4, true));
  794. nativeDoc.SelectSingleNode("PlayerConfig").AppendChild(nativeDoc.ImportNode(xmlNode5, true));
  795. nativeDoc.SelectSingleNode("PlayerConfig").AppendChild(nativeDoc.ImportNode(xmlNode6, true));
  796. nativeDoc.SelectSingleNode("PlayerConfig").AppendChild(nativeDoc.ImportNode(xmlNode7, true));
  797. nativeDoc.SelectSingleNode("PlayerConfig").AppendChild(nativeDoc.ImportNode(xmlNode8, true));
  798. xmlNode1 = nativeDoc.SelectSingleNode("PlayerConfig").SelectSingleNode("SkillList");
  799. xmlNode2 = defaultDoc.SelectSingleNode("PlayerConfig").SelectSingleNode("SkillList");
  800. XmlNodeList xmlNodeList1 = xmlNode1.ChildNodes;
  801. XmlNodeList xmlNodeList2 = xmlNode2.ChildNodes;
  802. for (int i = 0; i < xmlNodeList1.Count; i++)
  803. {
  804. string id = xmlNodeList1[i].Attributes[0].Value;
  805. if (id.Contains("Ability"))
  806. {
  807. int index = int.Parse(id.Replace("Ability", ""));
  808. if (index >= 15 && index <= 24)
  809. {
  810. xmlNode1.RemoveChild(xmlNodeList1[i--]);
  811. }
  812. }
  813. }
  814. for (int i = 0; i < xmlNodeList2.Count; i++)
  815. {
  816. string id = xmlNodeList2[i].Attributes[0].Value;
  817. if (id.Contains("Ability"))
  818. {
  819. int index = int.Parse(id.Replace("Ability", ""));
  820. if (index >= 15 && index <= 24)
  821. {
  822. xmlNode1.AppendChild(nativeDoc.ImportNode(xmlNodeList2[i], true));
  823. }
  824. }
  825. }
  826. return nativeDoc;
  827. }
  828. }