ManaData.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495
  1. using LitJson;
  2. using UnityEngine;
  3. using UnityEngine.EventSystems;
  4. using System;
  5. using System.Xml;
  6. using System.Collections;
  7. using System.Collections.Generic;
  8. public class ManaData : MonoBehaviour
  9. {
  10. #region 变量
  11. public static int Level
  12. {
  13. get { return _Level; }
  14. set
  15. {
  16. _Level = value;
  17. for (int i = 0; i < SkillList.Count; i++)
  18. {
  19. SkillList[i].OnLevelChange();
  20. }
  21. ManaLog.Log(string.Format("已升级 花园等级 : <color=red>{0}</color>", _Level));
  22. }
  23. }
  24. public static float Person
  25. {
  26. get { return _Person; }
  27. set
  28. {
  29. _Person = value;
  30. ManaReso.SetText("F_PersonLab", _Person.ToString("0"));
  31. }
  32. }
  33. public static float CoinPerson
  34. {
  35. get { return _CoinPerson; }
  36. set
  37. {
  38. _CoinPerson = value;
  39. ManaReso.SetText("F_CoinPersonLab", _CoinPerson.ToString("0"));
  40. }
  41. }
  42. public static double Coin
  43. {
  44. get { return _Coin; }
  45. set
  46. {
  47. _Coin = value;
  48. ManaReso.SetText("F_CoinLab", _Coin.ToString("0"));
  49. ManaReso.SetText("C_CoinLab", _Coin.ToString("0"));
  50. }
  51. }
  52. public static double Diamond
  53. {
  54. get { return _Diamond; }
  55. set
  56. {
  57. _Diamond = value;
  58. ManaReso.SetText("F_DiamondLab", _Diamond.ToString("0"));
  59. }
  60. }
  61. private static int _Level;
  62. private static float _Person;
  63. private static float _CoinPerson;
  64. private static double _Coin;
  65. private static double _Diamond;
  66. public static float SkillPlus;
  67. public static float SkillPerson;
  68. public static float SkillPersonBuff;
  69. public static float SkillCoinPerson;
  70. public static int Main;
  71. public static bool SkillBar;
  72. public static bool Connect;
  73. public static float OpTime;
  74. public static float CircleTime;
  75. public static float OpTimer;
  76. public static float CircleTimer;
  77. public static float NewPerson;
  78. public static float NewCoinPerson;
  79. public static List<Skill> CoolList;
  80. public static List<SkillRoot> SkillList;
  81. public static List<SkillRoot> UsingList;
  82. public static Dictionary<string, SkillRoot> SkillDic;
  83. #endregion
  84. private void Awake()
  85. {
  86. Initializer.RegistValue += RegistValue;
  87. #region 读技能配置
  88. SkillDic = new Dictionary<string, SkillRoot>();
  89. SkillList = new List<SkillRoot>();
  90. List<XmlAttributeCollection> attributesList = Data.GetSkillConfig();
  91. for (int i = 0; i < attributesList.Count; i++)
  92. {
  93. SkillRoot skillRoot;
  94. #region MyRegion
  95. if (attributesList[i].Count == 17)
  96. {
  97. skillRoot = new Pack(attributesList[i]);
  98. }
  99. else if (attributesList[i].Count == 23)
  100. {
  101. skillRoot = new Ability(attributesList[i]);
  102. }
  103. else if (attributesList[i].Count == 33)
  104. {
  105. if (string.IsNullOrEmpty(attributesList[i][4].Value))
  106. {
  107. skillRoot = new Skill(attributesList[i]);
  108. }
  109. else
  110. {
  111. skillRoot = new BigSkill(attributesList[i]);
  112. }
  113. }
  114. else
  115. {
  116. throw new Exception(attributesList[i].Count.ToString());
  117. }
  118. #endregion
  119. SkillList.Add(skillRoot);
  120. SkillDic.Add(skillRoot.Name, skillRoot);
  121. }
  122. SkillList.Sort(SkillRoot.SortByClassID);
  123. #endregion
  124. #region 创建技能条
  125. for (int i = 0; i < SkillList.Count; i++)
  126. {
  127. if (SkillList[i].Tab != SkillTab.Null)
  128. {
  129. ManaReso.GetSkillItem(SkillList[i]);
  130. }
  131. }
  132. #endregion
  133. }
  134. private void Update()
  135. {
  136. if (Math.Abs(Time.timeScale) < 0.0005f)
  137. {
  138. return;
  139. }
  140. if (Auxiliary.AnyKeyUp)
  141. {
  142. OpTimer = 0;
  143. if (Main == 0)
  144. {
  145. ManaReso.Get("C_Main").TweenForCG();
  146. Main--;
  147. }
  148. }
  149. else
  150. {
  151. OpTimer += Time.deltaTime;
  152. if (OpTimer >= OpTime)
  153. {
  154. OpTimer = 0;
  155. if (Main == -1)
  156. {
  157. ManaReso.Get("C_Main").TweenBacCG();
  158. Main++;
  159. }
  160. }
  161. }
  162. }
  163. private void FixedUpdate()
  164. {
  165. #region 使用技能
  166. for (int i = 0; i < UsingList.Count; i++)
  167. {
  168. if (UsingList[i].DoUse())
  169. {
  170. i--;
  171. }
  172. }
  173. #endregion
  174. #region 冷却技能
  175. for (int i = 0; i < CoolList.Count; i++)
  176. {
  177. if (CoolList[i].DoCool())
  178. {
  179. i--;
  180. }
  181. }
  182. #endregion
  183. #region 计算参观收入
  184. CircleTimer -= Time.deltaTime;
  185. if (CircleTimer < 0)
  186. {
  187. CircleTimer = CircleTime;
  188. NewPerson = Person*(1 + SkillPersonBuff) + SkillPerson;
  189. NewCoinPerson = CoinPerson + SkillCoinPerson;
  190. float temp = (NewPerson*NewCoinPerson*CircleTime)*(1 + SkillPlus);
  191. Coin += temp;
  192. if (Main == -1)
  193. {
  194. ManaReso.GetHudText("+" + temp.ToString("0"), ManaReso.Get("C_HudTra"), false, 25, Color.red);
  195. }
  196. 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> (人次*金币*时间*加成)", temp, NewPerson, NewCoinPerson, CircleTime, 1 + SkillPlus));
  197. }
  198. #endregion
  199. }
  200. private void RegistValue()
  201. {
  202. if (ManaReso.Get("B_SignIn").gameObject.activeSelf)
  203. {
  204. Main = 1;
  205. }
  206. else
  207. {
  208. Main = 0;
  209. }
  210. OpTime = 5;
  211. CircleTime = 10;
  212. CircleTimer = 10;
  213. CoolList = new List<Skill>();
  214. UsingList = new List<SkillRoot>();
  215. #region 读技能存档
  216. double elapse = DateTime.Now.Subtract(DateTime.Parse(Data.PlayerNode.SelectSingleNode("QuitTime").Attributes[0].Value)).TotalSeconds;
  217. XmlNodeList xmlNodeList = Data.PlayerNode.SelectSingleNode("SkillList").ChildNodes;
  218. List<SkillRoot> ffCoolList = new List<SkillRoot>();
  219. List<List<SkillRoot>> ffList = new List<List<SkillRoot>>();
  220. if (elapse > CircleTimer)
  221. {
  222. int ffCircle = 1 + Mathf.FloorToInt((float)((elapse - CircleTimer) / CircleTime));
  223. for (int i = 0; i < ffCircle; i++)
  224. {
  225. ffList.Add(new List<SkillRoot>());
  226. }
  227. }
  228. for (int i = 0; i < xmlNodeList.Count; i++)
  229. {
  230. if (xmlNodeList[i].Attributes[0].Value == SkillType.Skill.ToString())
  231. {
  232. Skill skill = (Skill)SkillDic[xmlNodeList[i].Name];
  233. skill.RegistReference();
  234. skill.Level = int.Parse(xmlNodeList[i].Attributes[2].Value);
  235. skill.CoolTimer = float.Parse(xmlNodeList[i].Attributes[3].Value);
  236. skill.UsingTimer = float.Parse(xmlNodeList[i].Attributes[4].Value);
  237. skill._ItemStatus = (SkillStatus)Enum.Parse(typeof(SkillStatus), xmlNodeList[i].Attributes[1].Value);
  238. skill.RegistValue(elapse, ffList);
  239. }
  240. else if (xmlNodeList[i].Attributes[0].Value == SkillType.BigSkill.ToString())
  241. {
  242. BigSkill bigSkill = (BigSkill)SkillDic[xmlNodeList[i].Name];
  243. bigSkill.RegistReference();
  244. bigSkill.Level = int.Parse(xmlNodeList[i].Attributes[3].Value);
  245. bigSkill.CoolTimer = float.Parse(xmlNodeList[i].Attributes[4].Value);
  246. bigSkill.UsingTimer = float.Parse(xmlNodeList[i].Attributes[5].Value);
  247. bigSkill._ItemStatus = (SkillStatus)Enum.Parse(typeof(SkillStatus), xmlNodeList[i].Attributes[1].Value); //Sa0
  248. bigSkill._BarStatus = (SkillStatus)Enum.Parse(typeof(SkillStatus), xmlNodeList[i].Attributes[2].Value); //Sa1
  249. bigSkill.RegistValue(elapse, ffList);
  250. }
  251. else if (xmlNodeList[i].Attributes[0].Value == SkillType.Pack.ToString())
  252. {
  253. Pack pack = (Pack)SkillDic[xmlNodeList[i].Attributes[1].Value];
  254. pack.RegistReference();
  255. pack.Level = int.Parse(xmlNodeList[i].Attributes[3].Value);
  256. pack._ItemStatus = (SkillStatus)Enum.Parse(typeof(SkillStatus), xmlNodeList[i].Attributes[2].Value);
  257. pack.RegistValue(elapse, ffList);
  258. }
  259. else if (xmlNodeList[i].Attributes[0].Value == SkillType.Ability.ToString())
  260. {
  261. Ability ability = (Ability)SkillDic[xmlNodeList[i].Name];
  262. ability.RegistReference();
  263. ability.Level = int.Parse(xmlNodeList[i].Attributes[2].Value);
  264. ability._ItemStatus = (SkillStatus)Enum.Parse(typeof(SkillStatus), xmlNodeList[i].Attributes[1].Value);
  265. ability.RegistValue(elapse, ffList);
  266. }
  267. else
  268. {
  269. throw new Exception();
  270. }
  271. }
  272. #endregion
  273. #region 读花朵存档
  274. XmlAttributeCollection attributes = Data.PlayerNode.SelectSingleNode("FlowerList").Attributes;
  275. if (string.IsNullOrEmpty(attributes[0].Value) == false)
  276. {
  277. string[] strings = attributes[0].Value.Split(' ');
  278. for (int i = 0; i < strings.Length; i++)
  279. {
  280. if (string.IsNullOrEmpty(strings[i]))
  281. {
  282. continue;
  283. }
  284. int id = int.Parse(strings[i]);
  285. ManaGarden.FlowerDic[id].Unlock = true;
  286. }
  287. }
  288. attributes = Data.PlayerNode.SelectSingleNode("PlantList").Attributes;
  289. for (int i = 0; i < attributes.Count; i++)
  290. {
  291. int id = int.Parse(attributes[i].Value);
  292. ManaGarden.PlaceFlower(id, ManaReso.Get(attributes[i].Name));
  293. }
  294. #endregion
  295. #region 读数据存档
  296. Level = int.Parse(Data.PlayerNode.SelectSingleNode("Level").Attributes[0].Value);
  297. Coin = double.Parse(Data.PlayerNode.SelectSingleNode("Coin").Attributes[0].Value);
  298. Diamond = double.Parse(Data.PlayerNode.SelectSingleNode("Diamond").Attributes[0].Value);
  299. #endregion
  300. #region 计算离线收入
  301. double collectCoin = 0;
  302. if (ffList.Count > 0)
  303. {
  304. for (int i = 0; i < ffList.Count; i++)
  305. {
  306. for (int j = 0; j < ffCoolList.Count; j++)
  307. {
  308. if (ffCoolList[j].SkillType == SkillType.Skill || ffCoolList[j].SkillType == SkillType.BigSkill)
  309. {
  310. if (i == 0)
  311. {
  312. ((Skill) ffCoolList[j]).CoolTimer -= CircleTimer;
  313. }
  314. else
  315. {
  316. ((Skill)ffCoolList[j]).CoolTimer -= CircleTime;
  317. }
  318. }
  319. }
  320. for (int j = 0; j < ffList[i].Count; j++)
  321. {
  322. ffList[i][j].Annul();
  323. ffCoolList.Add(ffList[i][j]);
  324. }
  325. NewPerson = Person * (1 + SkillPersonBuff) + SkillPerson;
  326. NewCoinPerson = CoinPerson + SkillCoinPerson;
  327. collectCoin += (NewPerson * NewCoinPerson * CircleTime) * (1 + SkillPlus);
  328. }
  329. Coin += collectCoin;
  330. ManaReso.SetText("Ba_IconLab", collectCoin.ToString("0"));
  331. CircleTimer = (float)((elapse - CircleTimer) % CircleTime);
  332. }
  333. else
  334. {
  335. CircleTimer = (float)(CircleTimer - elapse);
  336. ManaReso.SetText("Ba_IconLab", "0");
  337. }
  338. #endregion
  339. }
  340. public static bool Pay(double amt, Current current)
  341. {
  342. amt = (long) amt;
  343. if (current == Current.Free)
  344. {
  345. return true;
  346. }
  347. else if (current == Current.AD)
  348. {
  349. return true;
  350. }
  351. else if (current == Current.Cash)
  352. {
  353. return true;
  354. }
  355. else if (current == Current.Coin)
  356. {
  357. if (Coin >= amt)
  358. {
  359. Coin -= amt;
  360. return true;
  361. }
  362. else
  363. {
  364. ManaLog.Log("您没有足够的金币");
  365. return false;
  366. }
  367. }
  368. else if (current == Current.Diamond)
  369. {
  370. if (Diamond >= amt)
  371. {
  372. Diamond -= amt;
  373. return true;
  374. }
  375. else
  376. {
  377. ManaLog.Log("您没有足够的钻石");
  378. return false;
  379. }
  380. }
  381. else
  382. {
  383. throw new Exception(current.ToString());
  384. }
  385. }
  386. }