ManaData.cs 14 KB

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