ManaData.cs 39 KB

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