ManaData.cs 33 KB

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