ManaData.cs 37 KB

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