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