ManaData.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403
  1. using LitJson;
  2. using UnityEngine;
  3. using System;
  4. using System.Xml;
  5. using System.Collections;
  6. using System.Collections.Generic;
  7. public class ManaData : MonoBehaviour
  8. {
  9. #region 变量
  10. public static int Level
  11. {
  12. get { return _Level; }
  13. set
  14. {
  15. _Level = value;
  16. UpdateSkillStatus();
  17. ManaLog.Log(string.Format("已升级 花园等级 : <color=red>{0}</color>", _Level));
  18. }
  19. }
  20. public static float Person
  21. {
  22. get { return _Person; }
  23. set
  24. {
  25. _Person = value;
  26. ManaReso.SetText("F_PersonLab", _Person.ToString("0"));
  27. }
  28. }
  29. public static float CoinPerson
  30. {
  31. get { return _CoinPerson; }
  32. set
  33. {
  34. _CoinPerson = value;
  35. ManaReso.SetText("F_CoinPersonLab", _CoinPerson.ToString("0"));
  36. }
  37. }
  38. public static double Coin
  39. {
  40. get { return _Coin; }
  41. set
  42. {
  43. _Coin = value;
  44. ManaReso.SetText("F_CoinLab", _Coin.ToString("0"));
  45. ManaReso.SetText("C_CoinLab", _Coin.ToString("0"));
  46. }
  47. }
  48. public static double Diamond
  49. {
  50. get { return _Diamond; }
  51. set
  52. {
  53. _Diamond = value;
  54. ManaReso.SetText("F_DiamondLab", _Diamond.ToString("0"));
  55. }
  56. }
  57. private static int _Level;
  58. private static float _Person;
  59. private static float _CoinPerson;
  60. private static double _Coin;
  61. private static double _Diamond;
  62. public static bool SkillBar;
  63. public static bool Connect;
  64. public static float OpTimer;
  65. public static float NewPerson;
  66. public static float NewCoinPerson;
  67. public static double Circle;
  68. public static double OfflineCoin;
  69. public static double CircleTimer;
  70. public static List<Skill> CoolList;
  71. public static List<SkillRoot> SkillList;
  72. public static List<SkillRoot> UsingList;
  73. public static Dictionary<string, SkillRoot> SkillDic;
  74. public static float SkillPerson;
  75. public static float SkillPlusPerm;
  76. public static float SkillPlusTemp;
  77. public static float SkillPersonBuff;
  78. public static float SkillCoinPerson;
  79. #endregion
  80. private void Awake()
  81. {
  82. Initializer.RegistValue += RegistValue;
  83. #region 读取技能配置
  84. SkillDic = new Dictionary<string, SkillRoot>();
  85. SkillList = new List<SkillRoot>();
  86. List<XmlAttributeCollection> attributesList = Data.GetSkillConfig();
  87. for (int i = 0; i < attributesList.Count; i++)
  88. {
  89. SkillRoot skillRoot;
  90. #region MyRegion
  91. if (attributesList[i].Count == 17)
  92. {
  93. skillRoot = new Pack(attributesList[i]);
  94. }
  95. else if (attributesList[i].Count == 23)
  96. {
  97. skillRoot = new Ability(attributesList[i]);
  98. }
  99. else if (attributesList[i].Count == 33)
  100. {
  101. if (string.IsNullOrEmpty(attributesList[i][4].Value))
  102. {
  103. skillRoot = new Skill(attributesList[i]);
  104. }
  105. else
  106. {
  107. skillRoot = new BigSkill(attributesList[i]);
  108. }
  109. }
  110. else
  111. {
  112. throw new Exception(attributesList[i].Count.ToString());
  113. }
  114. #endregion
  115. SkillList.Add(skillRoot);
  116. SkillDic.Add(skillRoot.Name, skillRoot);
  117. }
  118. SkillList.Sort();
  119. #endregion
  120. #region 创建技能条
  121. for (int i = 0; i < SkillList.Count; i++)
  122. {
  123. if (SkillList[i].Class != SkillClass.Null)
  124. {
  125. ManaReso.GetSkillItem(SkillList[i]);
  126. }
  127. }
  128. #endregion
  129. }
  130. private void Update()
  131. {
  132. #region 计算参观收益
  133. CircleTimer -= Time.deltaTime;
  134. if (CircleTimer < 0)
  135. {
  136. CircleTimer = Circle;
  137. NewPerson = Person*(1 + SkillPersonBuff) + SkillPerson;
  138. NewCoinPerson = CoinPerson + SkillCoinPerson;
  139. Coin += (NewPerson*NewCoinPerson*Circle)*(1 + SkillPlusPerm);
  140. ManaLog.Log(string.Format("参观收益<color=red>{0:0}</color> = <color=red>{1}</color> * <color=red>{2}</color> * <color=red>{3}</color> * <color=red>{4}</color> (人次*金币*时间*加成)", (NewPerson * NewCoinPerson * Circle) * (1 + SkillPlusPerm), NewPerson, NewCoinPerson, Circle, 1 + SkillPlusPerm));
  141. }
  142. #endregion
  143. #region 使用中的技能
  144. for (int i = 0; i < UsingList.Count; i++)
  145. {
  146. if (UsingList[i].DoTiming())
  147. {
  148. i--;
  149. }
  150. }
  151. #endregion
  152. #region 冷却中的技能
  153. for (int i = 0; i < CoolList.Count; i++)
  154. {
  155. if (CoolList[i].DoCool())
  156. {
  157. i--;
  158. }
  159. }
  160. #endregion
  161. #region 检测是否有操作
  162. OpTimer += Time.deltaTime;
  163. if (OpTimer >= 60)
  164. {
  165. OpTimer = 0;
  166. }
  167. #endregion
  168. }
  169. private void RegistValue()
  170. {
  171. CoolList = new List<Skill>();
  172. UsingList = new List<SkillRoot>();
  173. #region 读取技能状态
  174. XmlNodeList xmlNodeList = Data.PlayerNode.SelectSingleNode("SkillList").ChildNodes;
  175. for (int i = 0; i < xmlNodeList.Count; i++)
  176. {
  177. if (xmlNodeList[i].Attributes[0].Value == SkillCato.Skill.ToString())
  178. {
  179. Skill skill = (Skill)SkillDic[xmlNodeList[i].Name];
  180. skill.Level = int.Parse(xmlNodeList[i].Attributes[2].Value);
  181. skill.CoolTimer = float.Parse(xmlNodeList[i].Attributes[3].Value);
  182. skill.UsingTimer = float.Parse(xmlNodeList[i].Attributes[4].Value);
  183. skill.ItemStatus = (SkillStatus)Enum.Parse(typeof(SkillStatus), xmlNodeList[i].Attributes[1].Value);
  184. }
  185. else if (xmlNodeList[i].Attributes[0].Value == SkillCato.BigSkill.ToString())
  186. {
  187. BigSkill bigSkill = (BigSkill)SkillDic[xmlNodeList[i].Name];
  188. bigSkill.Level = int.Parse(xmlNodeList[i].Attributes[3].Value);
  189. bigSkill.CoolTimer = float.Parse(xmlNodeList[i].Attributes[4].Value);
  190. bigSkill.UsingTimer = float.Parse(xmlNodeList[i].Attributes[5].Value);
  191. bigSkill.ItemStatus = (SkillStatus)Enum.Parse(typeof(SkillStatus), xmlNodeList[i].Attributes[1].Value); //Sa0
  192. bigSkill.BarStatus = (SkillStatus)Enum.Parse(typeof(SkillStatus), xmlNodeList[i].Attributes[2].Value); //Sa1
  193. }
  194. else if (xmlNodeList[i].Attributes[0].Value == SkillCato.Pack.ToString())
  195. {
  196. Pack pack = (Pack)SkillDic[xmlNodeList[i].Attributes[1].Value];
  197. pack.Level = int.Parse(xmlNodeList[i].Attributes[3].Value);
  198. pack.ItemStatus = (SkillStatus)Enum.Parse(typeof(SkillStatus), xmlNodeList[i].Attributes[2].Value);
  199. }
  200. else if (xmlNodeList[i].Attributes[0].Value == SkillCato.Ability.ToString())
  201. {
  202. Ability ability = (Ability)SkillDic[xmlNodeList[i].Name];
  203. ability.Level = int.Parse(xmlNodeList[i].Attributes[2].Value);
  204. ability.ItemStatus = (SkillStatus)Enum.Parse(typeof(SkillStatus), xmlNodeList[i].Attributes[1].Value);
  205. }
  206. else
  207. {
  208. throw new Exception();
  209. }
  210. }
  211. for (int i = 0; i < SkillList.Count; i++)
  212. {
  213. SkillList[i].Initialize();
  214. }
  215. #endregion
  216. #region 读取已解锁的花
  217. XmlAttributeCollection attributes = Data.PlayerNode.SelectSingleNode("FlowerList").Attributes;
  218. string[] strings = attributes[0].Value.Split(' ');
  219. for (int i = 0; i < strings.Length; i++)
  220. {
  221. int id = int.Parse(strings[i]);
  222. FlowerInfo flowerInfo = ManaGarden.FlowerDic[id];
  223. flowerInfo.Unlock = true;
  224. }
  225. #endregion
  226. #region 读取已种植的花
  227. attributes = Data.PlayerNode.SelectSingleNode("PlantList").Attributes;
  228. for (int i = 0; i < attributes.Count; i++)
  229. {
  230. int id = int.Parse(attributes[i].Value);
  231. ManaGarden.PlaceFlower(id, ManaReso.Get(attributes[i].Name));
  232. }
  233. #endregion
  234. Coin = double.Parse(Data.PlayerNode.SelectSingleNode("Coin").Attributes[0].Value);
  235. Level = int.Parse(Data.PlayerNode.SelectSingleNode("Level").Attributes[0].Value);
  236. Circle = 10;
  237. Diamond = double.Parse(Data.PlayerNode.SelectSingleNode("Diamond").Attributes[0].Value);
  238. OfflineCoin = 0;
  239. #region 离线期间的收入
  240. double elapse = DateTime.Now.Subtract(DateTime.Parse(Data.PlayerNode.SelectSingleNode("QuitTime").Attributes[0].Value)).TotalSeconds; //离开时间
  241. if (elapse > CircleTimer)
  242. {
  243. elapse -= CircleTimer;
  244. int offlineCircle = 1 + Mathf.FloorToInt((float) (elapse/Circle)); //离线周期
  245. for (int i = 0; i < SkillList.Count; i++)
  246. {
  247. SkillList[i].CollectCoin(offlineCircle);
  248. }
  249. OfflineCoin += (Person * CoinPerson * Circle * offlineCircle) * (1 + SkillPlusPerm);
  250. }
  251. else
  252. {
  253. CircleTimer -= elapse;
  254. }
  255. Coin += OfflineCoin;
  256. ManaReso.SetText("A_IconLab", OfflineCoin.ToString("0"));
  257. #endregion
  258. }
  259. public static void UpdateSkillStatus()
  260. {
  261. for (int i = 0; i < SkillList.Count; i++)
  262. {
  263. SkillList[i].OnLevelChange();
  264. }
  265. }
  266. public static bool Pay(double amt, Current current)
  267. {
  268. amt = (int) amt;
  269. if (current == Current.Free)
  270. {
  271. return true;
  272. }
  273. else if (current == Current.AD)
  274. {
  275. return true;
  276. }
  277. else if (current == Current.Cash)
  278. {
  279. return true;
  280. }
  281. else if (current == Current.Coin)
  282. {
  283. #region MyRegion
  284. if (Coin >= amt)
  285. {
  286. Coin -= amt;
  287. return true;
  288. }
  289. else
  290. {
  291. ManaMessage.Show("您没有足够的金币", 1);
  292. return false;
  293. }
  294. #endregion
  295. }
  296. else if (current == Current.Diamond)
  297. {
  298. #region MyRegion
  299. if (Diamond >= amt)
  300. {
  301. Diamond -= amt;
  302. return true;
  303. }
  304. else
  305. {
  306. ManaMessage.Show("您没有足够的钻石", 1);
  307. return false;
  308. }
  309. #endregion
  310. }
  311. else
  312. {
  313. throw new Exception(current.ToString());
  314. }
  315. }
  316. }