ManaData.cs 37 KB

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