ManaData.cs 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582
  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. public override void Instantiate()
  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. Mini = true;
  177. ManaReso.Get("C_MiniGame").TweenForCG();
  178. }
  179. }
  180. if (Auxiliary.AnyKeyUp)
  181. {
  182. OpTimer = 0;
  183. if (Main == 0)
  184. {
  185. ManaReso.Get("C_Main").TweenForCG();
  186. }
  187. }
  188. else
  189. {
  190. OpTimer += Time.deltaTime;
  191. if (OpTimer >= OpTime)
  192. {
  193. OpTimer = 0;
  194. if (Main == -1)
  195. {
  196. ManaReso.Get("C_Main").TweenBacCG();
  197. }
  198. }
  199. }
  200. }
  201. private void FixedUpdate()
  202. {
  203. #region 使用技能
  204. for (int i = 0; i < UseList.Count; i++)
  205. {
  206. if (UseList[i].DoUse())
  207. {
  208. i--;
  209. }
  210. }
  211. #endregion
  212. #region 冷却技能
  213. for (int i = 0; i < CoolList.Count; i++)
  214. {
  215. if (CoolList[i].DoCool())
  216. {
  217. i--;
  218. }
  219. }
  220. #endregion
  221. #region 计算参观收入
  222. CircleTimer -= Time.deltaTime;
  223. if (CircleTimer < 0)
  224. {
  225. CircleTimer = CircleTime;
  226. NewPerson = Person*(1 + SkillPersonBuff) + SkillPerson;
  227. NewCoinPerson = CoinPerson + SkillCoinPerson;
  228. float temp = (NewPerson*NewCoinPerson*CircleTime)*(1 + SkillPlus);
  229. Coin += temp;
  230. if (Main == -1)
  231. {
  232. ManaReso.GetHudText("+" + temp.ToString("0"), Color.red, 25, ManaReso.Get("C_HudTra"), ManaReso.Get("C_Main"), false);
  233. }
  234. 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));
  235. }
  236. #endregion
  237. }
  238. public override void RegistValueA()
  239. {
  240. OpTime = 90;
  241. MiniTimer = 0;
  242. CircleTime = 10;
  243. #region 调试
  244. if (ManaReso.Get("B_SignIn").gameObject.activeSelf)
  245. {
  246. Main = 1;
  247. }
  248. else
  249. {
  250. Main = 0;
  251. }
  252. #endregion
  253. #region 读花朵存档
  254. XmlAttributeCollection attributes = Data.PlayerNode.SelectSingleNode("FlowerList").Attributes;
  255. if (!string.IsNullOrEmpty(attributes[0].Value))
  256. {
  257. string[] strings = attributes[0].Value.Split(' ');
  258. for (int i = 0; i < strings.Length; i++)
  259. {
  260. int id = int.Parse(strings[i]);
  261. ManaGarden.FlowerInfoList[id].Unlock = true;
  262. }
  263. }
  264. attributes = Data.PlayerNode.SelectSingleNode("PlantList").Attributes;
  265. for (int i = 0; i < attributes.Count; i++)
  266. {
  267. int id = int.Parse(attributes[i].Value);
  268. ManaGarden.PlantFlower(id, attributes[i].Name);
  269. }
  270. #endregion
  271. #region 读数据存档
  272. Sign = int.Parse(Data.PlayerNode.SelectSingleNode("Sign").Attributes[0].Value);
  273. CircleTimer = float.Parse(Data.PlayerNode.SelectSingleNode("CircleTimer").Attributes[0].Value);
  274. #endregion
  275. }
  276. public override void RegistValueC()
  277. {
  278. #region 读技能存档
  279. UseList = new List<SkillRoot>();
  280. CoolList = new List<Skill>();
  281. float elapse = (float) DateTime.Now.Subtract(DateTime.Parse(Data.PlayerNode.SelectSingleNode("QuitTime").Attributes[0].Value)).TotalSeconds;
  282. if (elapse > 43200)
  283. {
  284. elapse = 43200;
  285. }
  286. ManaDebug.Log(string.Format("离线时间<color=red>{0}</color>", elapse));
  287. XmlNodeList xmlNodeList = Data.PlayerNode.SelectSingleNode("SkillList").ChildNodes;
  288. List<SkillRoot> ffCoolList = new List<SkillRoot>();
  289. List<List<SkillRoot>> ffUseList = new List<List<SkillRoot>>();
  290. if (elapse > CircleTimer)
  291. {
  292. int ffCircle = 1 + Mathf.FloorToInt((elapse - CircleTimer)/CircleTime);
  293. ManaDebug.Log(string.Format("离线周期<color=red>{0}</color>", ffCircle));
  294. for (int i = 0; i < ffCircle; i++)
  295. {
  296. ffUseList.Add(new List<SkillRoot>());
  297. }
  298. }
  299. else
  300. {
  301. ManaDebug.Log(string.Format("离线周期<color=red>{0}</color>", 0));
  302. }
  303. for (int i = 0; i < xmlNodeList.Count; i++)
  304. {
  305. if (xmlNodeList[i].Attributes[0].Value == SkillType.Skill.ToString())
  306. {
  307. Skill skill = (Skill)SkillDic[xmlNodeList[i].Name];
  308. skill.RegistReference();
  309. skill.Level = int.Parse(xmlNodeList[i].Attributes[2].Value);
  310. skill.CoolTimer = float.Parse(xmlNodeList[i].Attributes[3].Value);
  311. skill.UseTimer = float.Parse(xmlNodeList[i].Attributes[4].Value);
  312. skill._ItemStatus = (SkillStatus)Enum.Parse(typeof(SkillStatus), xmlNodeList[i].Attributes[1].Value);
  313. skill.RegistValue(elapse, ffUseList);
  314. }
  315. else if (xmlNodeList[i].Attributes[0].Value == SkillType.BigSkill.ToString())
  316. {
  317. BigSkill bigSkill = (BigSkill)SkillDic[xmlNodeList[i].Name];
  318. bigSkill.RegistReference();
  319. bigSkill.Level = int.Parse(xmlNodeList[i].Attributes[3].Value);
  320. bigSkill.CoolTimer = float.Parse(xmlNodeList[i].Attributes[4].Value);
  321. bigSkill.UseTimer = float.Parse(xmlNodeList[i].Attributes[5].Value);
  322. bigSkill._ItemStatus = (SkillStatus)Enum.Parse(typeof(SkillStatus), xmlNodeList[i].Attributes[1].Value);
  323. bigSkill._BarStatus = (SkillStatus)Enum.Parse(typeof(SkillStatus), xmlNodeList[i].Attributes[2].Value);
  324. bigSkill.RegistValue(elapse, ffUseList);
  325. }
  326. else if (xmlNodeList[i].Attributes[0].Value == SkillType.Pack.ToString())
  327. {
  328. Pack pack = (Pack)SkillDic[xmlNodeList[i].Attributes[1].Value];
  329. pack.RegistReference();
  330. pack.Level = int.Parse(xmlNodeList[i].Attributes[3].Value);
  331. pack._ItemStatus = (SkillStatus)Enum.Parse(typeof(SkillStatus), xmlNodeList[i].Attributes[2].Value);
  332. pack.RegistValue(elapse, ffUseList);
  333. }
  334. else if (xmlNodeList[i].Attributes[0].Value == SkillType.Ability.ToString())
  335. {
  336. Ability ability = (Ability)SkillDic[xmlNodeList[i].Name];
  337. ability.RegistReference();
  338. ability.Level = int.Parse(xmlNodeList[i].Attributes[2].Value);
  339. ability._ItemStatus = (SkillStatus)Enum.Parse(typeof(SkillStatus), xmlNodeList[i].Attributes[1].Value);
  340. ability.RegistValue(elapse, ffUseList);
  341. }
  342. else
  343. {
  344. throw new Exception();
  345. }
  346. }
  347. #endregion
  348. #region 读数据存档
  349. Level = int.Parse(Data.PlayerNode.SelectSingleNode("Level").Attributes[0].Value);
  350. MiniTimer = float.Parse(Data.PlayerNode.SelectSingleNode("MiniTimer").Attributes[0].Value);
  351. ManaDebug.Log(string.Format("<color=red>{0:0}</color>后激活小游戏", MiniTimer));
  352. Coin = double.Parse(Data.PlayerNode.SelectSingleNode("Coin").Attributes[0].Value);
  353. Diamond = double.Parse(Data.PlayerNode.SelectSingleNode("Diamond").Attributes[0].Value);
  354. int slot = int.Parse(Data.PlayerNode.SelectSingleNode("Slot").Attributes[0].Value);
  355. for (int i = 0; i < slot; i++)
  356. {
  357. ManaGarden.UnlockSlot();
  358. }
  359. #endregion
  360. #region 计算离线收入
  361. float collectCoin = 0;
  362. if (ffUseList.Count > 0)
  363. {
  364. for (int i = 0; i < ffUseList.Count; i++)
  365. {
  366. for (int j = 0; j < ffCoolList.Count; j++)
  367. {
  368. if (ffCoolList[j] is Skill)
  369. {
  370. if (i == 0)
  371. {
  372. ((Skill)ffCoolList[j]).CoolTimer -= CircleTimer;
  373. }
  374. else
  375. {
  376. ((Skill)ffCoolList[j]).CoolTimer -= CircleTime;
  377. }
  378. }
  379. }
  380. for (int j = 0; j < ffUseList[i].Count; j++)
  381. {
  382. ffUseList[i][j].Annul();
  383. ffCoolList.Add(ffUseList[i][j]);
  384. }
  385. NewPerson = Person * (1 + SkillPersonBuff) + SkillPerson;
  386. NewCoinPerson = CoinPerson + SkillCoinPerson;
  387. collectCoin += (NewPerson * NewCoinPerson * CircleTime) * (1 + SkillPlus);
  388. }
  389. CircleTimer = (elapse - CircleTimer)%CircleTime;
  390. for (int j = 0; j < ffCoolList.Count; j++)
  391. {
  392. if (ffCoolList[j] is Skill)
  393. {
  394. ((Skill) ffCoolList[j]).CoolTimer -= CircleTime - CircleTimer;
  395. }
  396. }
  397. Coin += collectCoin;
  398. ManaReso.SetText("Ba_IconLab", collectCoin.ToString("0"));
  399. }
  400. else
  401. {
  402. CircleTimer = CircleTimer - elapse;
  403. ManaReso.SetText("Ba_IconLab", "0");
  404. }
  405. #endregion
  406. }
  407. public static bool Pay(double amt, Current current)
  408. {
  409. amt = (long) amt;
  410. if (current == Current.Free)
  411. {
  412. return true;
  413. }
  414. else if (current == Current.AD)
  415. {
  416. return true;
  417. }
  418. else if (current == Current.Cash)
  419. {
  420. return true;
  421. }
  422. else if (current == Current.Coin)
  423. {
  424. if (Coin >= amt)
  425. {
  426. Coin -= amt;
  427. return true;
  428. }
  429. else
  430. {
  431. ManaDebug.Log("您没有足够的金币");
  432. return false;
  433. }
  434. }
  435. else if (current == Current.Diamond)
  436. {
  437. if (Diamond >= amt)
  438. {
  439. Diamond -= amt;
  440. return true;
  441. }
  442. else
  443. {
  444. ManaDebug.Log("您没有足够的钻石");
  445. return false;
  446. }
  447. }
  448. else
  449. {
  450. throw new Exception(current.ToString());
  451. }
  452. }
  453. }