ManaData.cs 36 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081
  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. }
  302. public static void SavePlantList()
  303. {
  304. if (ManaVisit.InVisit || ManaTutorial.TutorialA)
  305. {
  306. return;
  307. }
  308. XmlAttributeCollection attribute = PlayerNode.SelectSingleNode("PlantList").Attributes;
  309. attribute[0].Value = "";
  310. for (int i = 0; i < ManaGarden.PlantList.Count; i++)
  311. {
  312. Slot slot = ManaGarden.PlantList[i];
  313. attribute[0].Value += slot.ID + "," + slot.Index + " ";
  314. }
  315. attribute[0].Value = attribute[0].Value.TrimEnd(' ');
  316. }
  317. public static void SaveCommon()
  318. {
  319. PlayerNode.SelectSingleNode("Coin").Attributes[0].Value = ManaCenter.Coin.ToString("0");
  320. PlayerNode.SelectSingleNode("Diamond").Attributes[0].Value = ManaCenter.Diamond.ToString("0");
  321. PlayerNode.SelectSingleNode("SignTime").Attributes[0].Value = ManaSign.SignTime.ToString();
  322. PlayerNode.SelectSingleNode("SignIndex").Attributes[0].Value = ManaSign.SignIndex.ToString();
  323. PlayerNode.SelectSingleNode("SignRound").Attributes[0].Value = ManaSign.SignRound.ToString();
  324. PlayerNode.SelectSingleNode("QuitFlag").Attributes[0].Value = ManaServer.Connect.ToInt().ToString();
  325. PlayerNode.SelectSingleNode("QuitTime").Attributes[0].Value = ManaServer.Time.ToString();
  326. PlayerNode.SelectSingleNode("MiniTimer").Attributes[0].Value = ManaCenter.MiniTimer.ToString("0");
  327. PlayerNode.SelectSingleNode("CircleTimer").Attributes[0].Value = ManaCenter.CircleTimer.ToString("0");
  328. PlayerNode.SelectSingleNode("ID").Attributes[0].Value = ManaServer.ID;
  329. PlayerNode.SelectSingleNode("Language").Attributes[0].Value = ManaLan.CurrentLan.ToString();
  330. PlayerNode.SelectSingleNode("MiniGameIndex").Attributes[0].Value = ManaMiniGame.MiniGameIndex.ToString();
  331. PlayerNode.SelectSingleNode("TutorialA").Attributes[0].Value = ManaTutorial.TutorialA.ToInt().ToString();
  332. PlayerNode.SelectSingleNode("TutorialB").Attributes[0].Value = ManaTutorial.TutorialB_.ToInt().ToString();
  333. PlayerNode.SelectSingleNode("TutorialC").Attributes[0].Value = ManaTutorial.TutorialC_.ToInt().ToString();
  334. PlayerNode.SelectSingleNode("TutorialD").Attributes[0].Value = ManaTutorial.TutorialD_.ToInt().ToString();
  335. PlayerNode.SelectSingleNode("TutorialE").Attributes[0].Value = ManaTutorial.TutorialE_.ToInt().ToString();
  336. PlayerNode.SelectSingleNode("TutorialIndexA").Attributes[0].Value = ManaTutorial.TutorialIndexA.ToString();
  337. PlayerNode.SelectSingleNode("TutorialIndexB").Attributes[0].Value = ManaTutorial.TutorialIndexB.ToString();
  338. PlayerNode.SelectSingleNode("TutorialIndexC").Attributes[0].Value = ManaTutorial.TutorialIndexC.ToString();
  339. PlayerNode.SelectSingleNode("TutorialIndexD").Attributes[0].Value = ManaTutorial.TutorialIndexD.ToString();
  340. PlayerNode.SelectSingleNode("TutorialIndexE").Attributes[0].Value = ManaTutorial.TutorialIndexE.ToString();
  341. }
  342. public static void SaveFlowerList()
  343. {
  344. XmlAttribute attribute = PlayerNode.SelectSingleNode("FlowerList").Attributes[0];
  345. attribute.Value = "";
  346. foreach (var kv in ManaGarden.FlowerInfoDic)
  347. {
  348. if (kv.Value.Unlock)
  349. {
  350. attribute.Value += kv.Value.ID_ + " ";
  351. }
  352. }
  353. attribute.Value = attribute.Value.Trim(' ');
  354. }
  355. public static void SavePlayerConfig()
  356. {
  357. if (Initializer.Complete)
  358. {
  359. SaveSkillList();
  360. SaveAchieve();
  361. SaveDress();
  362. SavePlantList();
  363. SaveCommon();
  364. SaveFlowerList();
  365. }
  366. }
  367. public static void ResetPlayerConfig()
  368. {
  369. PlayerPrefs.SetString("id", "");
  370. PlayerNode.SelectSingleNode("Version").Attributes[0].Value = "10000";
  371. SavePlayerConfig();
  372. ManaCenter.SaveLock = true;
  373. }
  374. public static int GetPlayerInt(string node)
  375. {
  376. return int.Parse(PlayerNode.SelectSingleNode(node).Attributes[0].Value);
  377. }
  378. public static bool GetPlayerBool(string node)
  379. {
  380. return int.Parse(PlayerNode.SelectSingleNode(node).Attributes[0].Value).ToBool();
  381. }
  382. public static float GetPlayerFloat(string node)
  383. {
  384. return float.Parse(PlayerNode.SelectSingleNode(node).Attributes[0].Value);
  385. }
  386. public static string GetPlayerString(string node)
  387. {
  388. return PlayerNode.SelectSingleNode(node).Attributes[0].Value;
  389. }
  390. public static double GetPlayerDouble(string node)
  391. {
  392. return double.Parse(PlayerNode.SelectSingleNode(node).Attributes[0].Value);
  393. }
  394. public static void SavePlayerInt(string node, int value)
  395. {
  396. PlayerNode.SelectSingleNode(node).Attributes[0].Value = value.ToString();
  397. }
  398. public static void SavePlayerBool(string node, bool value)
  399. {
  400. PlayerNode.SelectSingleNode(node).Attributes[0].Value = value.ToInt().ToString();
  401. }
  402. public static void SavePlayerFloat(string node, float value)
  403. {
  404. PlayerNode.SelectSingleNode(node).Attributes[0].Value = value.ToString();
  405. }
  406. public static void SavePlayerString(string node, string value)
  407. {
  408. PlayerNode.SelectSingleNode(node).Attributes[0].Value = value;
  409. }
  410. public static void SavePlayerDouble(string node, double value)
  411. {
  412. PlayerNode.SelectSingleNode(node).Attributes[0].Value = value.ToString();
  413. }
  414. public static List<int> GetDressList()
  415. {
  416. List<int> list = new List<int>();
  417. XmlAttributeCollection attribute = PlayerNode.SelectSingleNode("DressList").Attributes;
  418. return Auxiliary.IntListParse(' ', attribute[0].Value, list);
  419. }
  420. public static List<string> GetDressData(XmlNode node = null)
  421. {
  422. XmlNode xmlNode;
  423. if (node == null)
  424. {
  425. xmlNode = PlayerNode.SelectSingleNode("DressData");
  426. }
  427. else
  428. {
  429. xmlNode = node.SelectSingleNode("DressData");
  430. }
  431. List<string> dataList = new List<string>();
  432. if (xmlNode != null && xmlNode.Attributes.Count == 8)
  433. {
  434. dataList.Add(xmlNode.Attributes[0].Value);
  435. dataList.Add(xmlNode.Attributes[1].Value);
  436. dataList.Add(xmlNode.Attributes[2].Value);
  437. dataList.Add(xmlNode.Attributes[3].Value);
  438. dataList.Add(xmlNode.Attributes[4].Value);
  439. dataList.Add(xmlNode.Attributes[5].Value);
  440. dataList.Add(xmlNode.Attributes[6].Value);
  441. dataList.Add(xmlNode.Attributes[7].Value);
  442. }
  443. else
  444. {
  445. float rate = Random.Range(0f, 1f);
  446. if (rate < 0.33f)
  447. {
  448. dataList.Add("脑壳1");
  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("Empty");
  456. }
  457. else if (rate < 0.66f)
  458. {
  459. dataList.Add("脑壳2");
  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("Empty");
  467. }
  468. else
  469. {
  470. dataList.Add("脑壳3");
  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("Empty");
  478. }
  479. }
  480. return dataList;
  481. }
  482. public static List<int> GetFlowerList()
  483. {
  484. List<int> list = new List<int>();
  485. XmlAttributeCollection attribute = PlayerNode.SelectSingleNode("FlowerList").Attributes;
  486. return Auxiliary.IntListParse(' ', attribute[0].Value, list);
  487. }
  488. public static List<int> GetAchieveList()
  489. {
  490. return Auxiliary.IntListParse(' ', GetPlayerString("AchieveList"), new List<int>());
  491. }
  492. public static List<string> GetOfflineConfig()
  493. {
  494. TextAsset textAsset = ManaReso.Load<TextAsset>("offline_config", Folder.Config);
  495. XmlDocument xmlDoc = new XmlDocument();
  496. xmlDoc.LoadXml(textAsset.text);
  497. XmlNode xmlNode = xmlDoc.SelectSingleNode("data").SelectSingleNode("item");
  498. List<string> strList = new List<string>()
  499. {
  500. xmlNode.Attributes[1].Value,
  501. xmlNode.Attributes[2].Value,
  502. xmlNode.Attributes[3].Value,
  503. };
  504. return strList;
  505. }
  506. public static List<double> GetAchieveData()
  507. {
  508. List<double> dataList = new List<double>();
  509. dataList.Add(double.Parse(PlayerNode.SelectSingleNode("AchieveData").Attributes[0].Value));
  510. dataList.Add(double.Parse(PlayerNode.SelectSingleNode("AchieveData").Attributes[1].Value));
  511. dataList.Add(double.Parse(PlayerNode.SelectSingleNode("AchieveData").Attributes[2].Value));
  512. dataList.Add(double.Parse(PlayerNode.SelectSingleNode("AchieveData").Attributes[3].Value));
  513. dataList.Add(double.Parse(PlayerNode.SelectSingleNode("AchieveData").Attributes[4].Value));
  514. dataList.Add(double.Parse(PlayerNode.SelectSingleNode("AchieveData").Attributes[5].Value));
  515. dataList.Add(double.Parse(PlayerNode.SelectSingleNode("AchieveData").Attributes[6].Value));
  516. dataList.Add(double.Parse(PlayerNode.SelectSingleNode("AchieveData").Attributes[7].Value));
  517. return dataList;
  518. }
  519. public static List<KV<int, int>> GetPlantList(XmlNode node = null)
  520. {
  521. List<KV<int, int>> list = new List<KV<int, int>>();
  522. XmlNode xmlNode;
  523. if (node == null)
  524. {
  525. xmlNode = PlayerNode.SelectSingleNode("PlantList");
  526. }
  527. else
  528. {
  529. xmlNode = node.SelectSingleNode("PlantList");
  530. }
  531. if (!string.IsNullOrEmpty(xmlNode.Attributes[0].Value))
  532. {
  533. string[] strings = xmlNode.Attributes[0].Value.Split(' ');
  534. for (int i = 0; i < strings.Length; i++)
  535. {
  536. list.Add(new KV<int, int>(int.Parse(strings[i].Split(',')[0]), int.Parse(strings[i].Split(',')[1])));
  537. }
  538. }
  539. return list;
  540. }
  541. public static List<XmlAttributeCollection> GetSkillList(XmlNode node = null)
  542. {
  543. List<XmlAttributeCollection> attributeList = new List<XmlAttributeCollection>();
  544. XmlNodeList xmlNodeList;
  545. if (node == null)
  546. {
  547. xmlNodeList = PlayerNode.SelectSingleNode("SkillList").ChildNodes;
  548. }
  549. else
  550. {
  551. xmlNodeList = node.SelectSingleNode("SkillList").ChildNodes;
  552. }
  553. for (int i = 0; i < xmlNodeList.Count; i++)
  554. {
  555. attributeList.Add(xmlNodeList[i].Attributes);
  556. }
  557. return attributeList;
  558. }
  559. public static XmlAttributeCollection GetVisitConfig()
  560. {
  561. TextAsset textAsset = ManaReso.Load<TextAsset>("visit_config", Folder.Config);
  562. XmlDocument xmlDoc = new XmlDocument();
  563. xmlDoc.LoadXml(textAsset.text);
  564. XmlNode xmlNode = xmlDoc.SelectSingleNode("data").SelectSingleNode("item");
  565. return xmlNode.Attributes;
  566. }
  567. public static XmlAttributeCollection GetAwardConfig()
  568. {
  569. TextAsset textAsset = ManaReso.Load<TextAsset>("award_config", Folder.Config);
  570. XmlDocument xmlDoc = new XmlDocument();
  571. xmlDoc.LoadXml(textAsset.text);
  572. XmlNode xmlNode = xmlDoc.SelectSingleNode("data").SelectSingleNode("item");
  573. return xmlNode.Attributes;
  574. }
  575. public static List<XmlAttributeCollection> GetSkillConfig()
  576. {
  577. TextAsset textAsset;
  578. XmlDocument xmlDoc = new XmlDocument();
  579. List<XmlNodeList> xmlNodeList = new List<XmlNodeList>();
  580. List<XmlAttributeCollection> attributeList = new List<XmlAttributeCollection>();
  581. textAsset = ManaReso.Load<TextAsset>("pack_config", Folder.Config);
  582. xmlDoc.LoadXml(textAsset.text);
  583. xmlNodeList.Add(xmlDoc.SelectSingleNode("data").SelectNodes("item"));
  584. textAsset = ManaReso.Load<TextAsset>("skill_config", Folder.Config);
  585. xmlDoc.LoadXml(textAsset.text);
  586. xmlNodeList.Add(xmlDoc.SelectSingleNode("data").SelectNodes("item"));
  587. textAsset = ManaReso.Load<TextAsset>("ability_config", Folder.Config);
  588. xmlDoc.LoadXml(textAsset.text);
  589. xmlNodeList.Add(xmlDoc.SelectSingleNode("data").SelectNodes("item"));
  590. for (int i = 0; i < xmlNodeList.Count; i++)
  591. {
  592. for (int j = 0; j < xmlNodeList[i].Count; j++)
  593. {
  594. attributeList.Add(xmlNodeList[i][j].Attributes);
  595. }
  596. }
  597. return attributeList;
  598. }
  599. public static List<XmlAttributeCollection> GetSignConfig()
  600. {
  601. TextAsset textAsset;
  602. XmlNodeList xmlNodeList;
  603. XmlDocument xmlDoc = new XmlDocument();
  604. List<XmlAttributeCollection> attributeList = new List<XmlAttributeCollection>();
  605. textAsset = ManaReso.Load<TextAsset>("signin_config", Folder.Config);
  606. xmlDoc.LoadXml(textAsset.text);
  607. xmlNodeList = xmlDoc.SelectSingleNode("data").SelectNodes("item");
  608. for (int i = 0; i < xmlNodeList.Count; i++)
  609. {
  610. attributeList.Add(xmlNodeList[i].Attributes);
  611. }
  612. return attributeList;
  613. }
  614. public static List<XmlAttributeCollection> GetFlowerConfig()
  615. {
  616. TextAsset textAsset;
  617. XmlNodeList xmlNodeList;
  618. XmlDocument xmlDoc = new XmlDocument();
  619. List<XmlAttributeCollection> attributeList = new List<XmlAttributeCollection>();
  620. textAsset = ManaReso.Load<TextAsset>("flower_config", Folder.Config);
  621. xmlDoc.LoadXml(textAsset.text);
  622. xmlNodeList = xmlDoc.SelectSingleNode("data").SelectNodes("item");
  623. for (int i = 0; i < xmlNodeList.Count; i++)
  624. {
  625. attributeList.Add(xmlNodeList[i].Attributes);
  626. }
  627. return attributeList;
  628. }
  629. public static List<XmlAttributeCollection> GetLotteryConfig()
  630. {
  631. TextAsset textAsset;
  632. XmlNodeList xmlNodeList;
  633. XmlDocument xmlDoc = new XmlDocument();
  634. List<XmlAttributeCollection> attributeList = new List<XmlAttributeCollection>();
  635. textAsset = ManaReso.Load<TextAsset>("lottery_config", Folder.Config);
  636. xmlDoc.LoadXml(textAsset.text);
  637. xmlNodeList = xmlDoc.SelectSingleNode("data").SelectNodes("item");
  638. for (int i = 0; i < xmlNodeList.Count; i++)
  639. {
  640. attributeList.Add(xmlNodeList[i].Attributes);
  641. }
  642. return attributeList;
  643. }
  644. public static List<XmlAttributeCollection> GetAchieveConfig()
  645. {
  646. TextAsset textAsset;
  647. XmlNodeList xmlNodeList;
  648. XmlDocument xmlDoc = new XmlDocument();
  649. List<XmlAttributeCollection> attributeList = new List<XmlAttributeCollection>();
  650. textAsset = ManaReso.Load<TextAsset>("achieve_config", Folder.Config);
  651. xmlDoc.LoadXml(textAsset.text);
  652. xmlNodeList = xmlDoc.SelectSingleNode("data").SelectNodes("item");
  653. for (int i = 0; i < xmlNodeList.Count; i++)
  654. {
  655. attributeList.Add(xmlNodeList[i].Attributes);
  656. }
  657. return attributeList;
  658. }
  659. public static List<XmlAttributeCollection> GetDressRoomConfig()
  660. {
  661. TextAsset textAsset;
  662. XmlNodeList xmlNodeList;
  663. XmlDocument xmlDoc = new XmlDocument();
  664. List<XmlAttributeCollection> attributeList = new List<XmlAttributeCollection>();
  665. textAsset = ManaReso.Load<TextAsset>("dressRoom_config", Folder.Config);
  666. xmlDoc.LoadXml(textAsset.text);
  667. xmlNodeList = xmlDoc.SelectSingleNode("data").SelectNodes("item");
  668. for (int i = 0; i < xmlNodeList.Count; i++)
  669. {
  670. attributeList.Add(xmlNodeList[i].Attributes);
  671. }
  672. return attributeList;
  673. }
  674. public static XmlDocument MergeXML(int nativeVersion, XmlDocument nativeDoc, XmlDocument defaultDoc)
  675. {
  676. if (nativeVersion < 680)
  677. {
  678. Debug.LogWarning("UpdateArchive");
  679. To680(nativeDoc, defaultDoc);
  680. }
  681. return nativeDoc;
  682. }
  683. public static XmlDocument To680(XmlDocument nativeDoc, XmlDocument defaultDoc)
  684. {
  685. string playerType = "";
  686. XmlNode xmlNode1 = nativeDoc.SelectSingleNode("PlayerConfig").SelectSingleNode("DressList");
  687. XmlNode xmlNode2 = nativeDoc.SelectSingleNode("PlayerConfig").SelectSingleNode("DressData");
  688. XmlNode xmlNode3 = nativeDoc.SelectSingleNode("PlayerConfig").SelectSingleNode("TutorialD");
  689. XmlNode xmlNode4 = nativeDoc.SelectSingleNode("PlayerConfig").SelectSingleNode("TutorialIndexD");
  690. XmlNode xmlNode5 = nativeDoc.SelectSingleNode("PlayerConfig").SelectSingleNode("Player");
  691. XmlNode xmlNode6 = nativeDoc.SelectSingleNode("PlayerConfig").SelectSingleNode("TutorialE");
  692. XmlNode xmlNode7 = nativeDoc.SelectSingleNode("PlayerConfig").SelectSingleNode("TutorialIndexE");
  693. if (xmlNode1 != null)
  694. {
  695. nativeDoc.SelectSingleNode("PlayerConfig").RemoveChild(xmlNode1);
  696. }
  697. if (xmlNode2 != null)
  698. {
  699. nativeDoc.SelectSingleNode("PlayerConfig").RemoveChild(xmlNode2);
  700. }
  701. if (xmlNode3 != null)
  702. {
  703. nativeDoc.SelectSingleNode("PlayerConfig").RemoveChild(xmlNode3);
  704. }
  705. if (xmlNode4 != null)
  706. {
  707. nativeDoc.SelectSingleNode("PlayerConfig").RemoveChild(xmlNode4);
  708. }
  709. if (xmlNode5 != null)
  710. {
  711. playerType = xmlNode5.Attributes[0].Value;
  712. nativeDoc.SelectSingleNode("PlayerConfig").RemoveChild(xmlNode5);
  713. }
  714. else
  715. {
  716. playerType = "PlayerBlond";
  717. }
  718. if (xmlNode6 != null)
  719. {
  720. nativeDoc.SelectSingleNode("PlayerConfig").RemoveChild(xmlNode6);
  721. }
  722. if (xmlNode7 != null)
  723. {
  724. nativeDoc.SelectSingleNode("PlayerConfig").RemoveChild(xmlNode7);
  725. }
  726. nativeDoc.SelectSingleNode("PlayerConfig").SelectSingleNode("Version").Attributes[0].Value = 680.ToString();
  727. xmlNode1 = defaultDoc.SelectSingleNode("PlayerConfig").SelectSingleNode("DressList");
  728. xmlNode2 = defaultDoc.SelectSingleNode("PlayerConfig").SelectSingleNode("DressData");
  729. xmlNode3 = defaultDoc.SelectSingleNode("PlayerConfig").SelectSingleNode("TutorialD");
  730. xmlNode4 = defaultDoc.SelectSingleNode("PlayerConfig").SelectSingleNode("TutorialIndexD");
  731. xmlNode5 = defaultDoc.SelectSingleNode("PlayerConfig").SelectSingleNode("Player");
  732. xmlNode6 = defaultDoc.SelectSingleNode("PlayerConfig").SelectSingleNode("TutorialE");
  733. xmlNode7 = defaultDoc.SelectSingleNode("PlayerConfig").SelectSingleNode("TutorialIndexE");
  734. if (playerType == "PlayerBlond")
  735. {
  736. xmlNode2.Attributes[0].Value = "脑壳1";
  737. xmlNode2.Attributes[1].Value = "裙子1";
  738. xmlNode2.Attributes[2].Value = "鞋子1";
  739. xmlNode2.Attributes[3].Value = "头饰品1";
  740. xmlNode2.Attributes[4].Value = "上衣1";
  741. xmlNode2.Attributes[5].Value = "眼睛1";
  742. xmlNode2.Attributes[6].Value = "嘴巴1";
  743. xmlNode2.Attributes[7].Value = "Empty";
  744. }
  745. else if (playerType == "PlayerBrown")
  746. {
  747. xmlNode2.Attributes[0].Value = "脑壳2";
  748. xmlNode2.Attributes[1].Value = "裙子2";
  749. xmlNode2.Attributes[2].Value = "鞋子2";
  750. xmlNode2.Attributes[3].Value = "头饰品2";
  751. xmlNode2.Attributes[4].Value = "上衣2";
  752. xmlNode2.Attributes[5].Value = "眼睛2";
  753. xmlNode2.Attributes[6].Value = "嘴巴2";
  754. xmlNode2.Attributes[7].Value = "Empty";
  755. }
  756. else if (playerType == "PlayerPink")
  757. {
  758. xmlNode2.Attributes[0].Value = "脑壳3";
  759. xmlNode2.Attributes[1].Value = "裙子3";
  760. xmlNode2.Attributes[2].Value = "鞋子3";
  761. xmlNode2.Attributes[3].Value = "头饰品3";
  762. xmlNode2.Attributes[4].Value = "上衣3";
  763. xmlNode2.Attributes[5].Value = "眼睛3";
  764. xmlNode2.Attributes[6].Value = "嘴巴3";
  765. xmlNode2.Attributes[7].Value = "Empty";
  766. }
  767. nativeDoc.SelectSingleNode("PlayerConfig").AppendChild(nativeDoc.ImportNode(xmlNode1, true));
  768. nativeDoc.SelectSingleNode("PlayerConfig").AppendChild(nativeDoc.ImportNode(xmlNode2, true));
  769. nativeDoc.SelectSingleNode("PlayerConfig").AppendChild(nativeDoc.ImportNode(xmlNode3, true));
  770. nativeDoc.SelectSingleNode("PlayerConfig").AppendChild(nativeDoc.ImportNode(xmlNode4, true));
  771. nativeDoc.SelectSingleNode("PlayerConfig").AppendChild(nativeDoc.ImportNode(xmlNode5, true));
  772. nativeDoc.SelectSingleNode("PlayerConfig").AppendChild(nativeDoc.ImportNode(xmlNode6, true));
  773. nativeDoc.SelectSingleNode("PlayerConfig").AppendChild(nativeDoc.ImportNode(xmlNode7, true));
  774. xmlNode1 = nativeDoc.SelectSingleNode("PlayerConfig").SelectSingleNode("SkillList");
  775. xmlNode2 = defaultDoc.SelectSingleNode("PlayerConfig").SelectSingleNode("SkillList");
  776. XmlNodeList xmlNodeList1 = xmlNode1.ChildNodes;
  777. XmlNodeList xmlNodeList2 = xmlNode2.ChildNodes;
  778. for (int i = 0; i < xmlNodeList1.Count; i++)
  779. {
  780. string id = xmlNodeList1[i].Attributes[0].Value;
  781. if (id.Contains("Ability"))
  782. {
  783. int index = int.Parse(id.Replace("Ability", ""));
  784. if (index >= 15 && index <= 24)
  785. {
  786. xmlNode1.RemoveChild(xmlNodeList1[i--]);
  787. }
  788. }
  789. }
  790. for (int i = 0; i < xmlNodeList2.Count; i++)
  791. {
  792. string id = xmlNodeList2[i].Attributes[0].Value;
  793. if (id.Contains("Ability"))
  794. {
  795. int index = int.Parse(id.Replace("Ability", ""));
  796. if (index >= 15 && index <= 24)
  797. {
  798. xmlNode1.AppendChild(nativeDoc.ImportNode(xmlNodeList2[i], true));
  799. }
  800. }
  801. }
  802. return nativeDoc;
  803. }
  804. }