ManaData.cs 40 KB

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