ManaData.cs 34 KB

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