ManaData.cs 15 KB

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