ManaData.cs 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583
  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. Sign = int.Parse(Data.PlayerNode.SelectSingleNode("Sign").Attributes[0].Value);
  255. ManaMiniGame.MiniGameAmt = int.Parse(Data.PlayerNode.SelectSingleNode("MiniGameAmt").Attributes[0].Value);
  256. CircleTimer = float.Parse(Data.PlayerNode.SelectSingleNode("CircleTimer").Attributes[0].Value);
  257. int slot = int.Parse(Data.PlayerNode.SelectSingleNode("Slot").Attributes[0].Value);
  258. for (int i = 0; i < slot; i++)
  259. {
  260. ManaGarden.UnlockSlot();
  261. }
  262. #endregion
  263. #region 读花朵存档
  264. XmlAttributeCollection attributes = Data.PlayerNode.SelectSingleNode("FlowerList").Attributes;
  265. if (!string.IsNullOrEmpty(attributes[0].Value))
  266. {
  267. string[] strings = attributes[0].Value.Split(' ');
  268. for (int i = 0; i < strings.Length; i++)
  269. {
  270. int id = int.Parse(strings[i]);
  271. ManaGarden.FlowerInfoList[id].Unlock = true;
  272. }
  273. }
  274. attributes = Data.PlayerNode.SelectSingleNode("PlantList").Attributes;
  275. for (int i = 0; i < attributes.Count; i++)
  276. {
  277. int id = int.Parse(attributes[i].Value);
  278. ManaGarden.PlantFlower(id, attributes[i].Name);
  279. }
  280. #endregion
  281. }
  282. public override void RegistValueC()
  283. {
  284. #region 读技能存档
  285. UseList = new List<SkillRoot>();
  286. CoolList = new List<Skill>();
  287. float elapse = (float) DateTime.Now.Subtract(DateTime.Parse(Data.PlayerNode.SelectSingleNode("QuitTime").Attributes[0].Value)).TotalSeconds;
  288. if (elapse > 43200)
  289. {
  290. elapse = 43200;
  291. }
  292. ManaDebug.Log(string.Format("离线时间<color=red>{0}</color>", elapse));
  293. XmlNodeList xmlNodeList = Data.PlayerNode.SelectSingleNode("SkillList").ChildNodes;
  294. List<SkillRoot> ffCoolList = new List<SkillRoot>();
  295. List<List<SkillRoot>> ffUseList = new List<List<SkillRoot>>();
  296. if (elapse > CircleTimer)
  297. {
  298. int ffCircle = 1 + Mathf.FloorToInt((elapse - CircleTimer)/CircleTime);
  299. ManaDebug.Log(string.Format("离线周期<color=red>{0}</color>", ffCircle));
  300. for (int i = 0; i < ffCircle; i++)
  301. {
  302. ffUseList.Add(new List<SkillRoot>());
  303. }
  304. }
  305. else
  306. {
  307. ManaDebug.Log(string.Format("离线周期<color=red>{0}</color>", 0));
  308. }
  309. for (int i = 0; i < xmlNodeList.Count; i++)
  310. {
  311. if (xmlNodeList[i].Attributes[0].Value == SkillType.Skill.ToString())
  312. {
  313. Skill skill = (Skill)SkillDic[xmlNodeList[i].Name];
  314. skill.RegistReference();
  315. skill.Level = int.Parse(xmlNodeList[i].Attributes[2].Value);
  316. skill.CoolTimer = float.Parse(xmlNodeList[i].Attributes[3].Value);
  317. skill.UseTimer = float.Parse(xmlNodeList[i].Attributes[4].Value);
  318. skill._ItemStatus = (SkillStatus)Enum.Parse(typeof(SkillStatus), xmlNodeList[i].Attributes[1].Value);
  319. skill.RegistValue(elapse, ffUseList);
  320. }
  321. else if (xmlNodeList[i].Attributes[0].Value == SkillType.BigSkill.ToString())
  322. {
  323. BigSkill bigSkill = (BigSkill)SkillDic[xmlNodeList[i].Name];
  324. bigSkill.RegistReference();
  325. bigSkill.Level = int.Parse(xmlNodeList[i].Attributes[3].Value);
  326. bigSkill.CoolTimer = float.Parse(xmlNodeList[i].Attributes[4].Value);
  327. bigSkill.UseTimer = float.Parse(xmlNodeList[i].Attributes[5].Value);
  328. bigSkill._ItemStatus = (SkillStatus)Enum.Parse(typeof(SkillStatus), xmlNodeList[i].Attributes[1].Value);
  329. bigSkill._BarStatus = (SkillStatus)Enum.Parse(typeof(SkillStatus), xmlNodeList[i].Attributes[2].Value);
  330. bigSkill.RegistValue(elapse, ffUseList);
  331. }
  332. else if (xmlNodeList[i].Attributes[0].Value == SkillType.Pack.ToString())
  333. {
  334. Pack pack = (Pack)SkillDic[xmlNodeList[i].Attributes[1].Value];
  335. pack.RegistReference();
  336. pack.Level = int.Parse(xmlNodeList[i].Attributes[3].Value);
  337. pack._ItemStatus = (SkillStatus)Enum.Parse(typeof(SkillStatus), xmlNodeList[i].Attributes[2].Value);
  338. pack.RegistValue(elapse, ffUseList);
  339. }
  340. else if (xmlNodeList[i].Attributes[0].Value == SkillType.Ability.ToString())
  341. {
  342. Ability ability = (Ability)SkillDic[xmlNodeList[i].Name];
  343. ability.RegistReference();
  344. ability.Level = int.Parse(xmlNodeList[i].Attributes[2].Value);
  345. ability._ItemStatus = (SkillStatus)Enum.Parse(typeof(SkillStatus), xmlNodeList[i].Attributes[1].Value);
  346. ability.RegistValue(elapse, ffUseList);
  347. }
  348. else
  349. {
  350. throw new Exception();
  351. }
  352. }
  353. #endregion
  354. #region 读数据存档
  355. Level = int.Parse(Data.PlayerNode.SelectSingleNode("Level").Attributes[0].Value);
  356. MiniTimer = float.Parse(Data.PlayerNode.SelectSingleNode("MiniTimer").Attributes[0].Value);
  357. ManaDebug.Log(string.Format("<color=red>{0:0}</color>秒后激活小游戏", MiniTimer));
  358. Coin = double.Parse(Data.PlayerNode.SelectSingleNode("Coin").Attributes[0].Value);
  359. Diamond = double.Parse(Data.PlayerNode.SelectSingleNode("Diamond").Attributes[0].Value);
  360. #endregion
  361. #region 计算离线收入
  362. float collectCoin = 0;
  363. if (ffUseList.Count > 0)
  364. {
  365. for (int i = 0; i < ffUseList.Count; i++)
  366. {
  367. for (int j = 0; j < ffCoolList.Count; j++)
  368. {
  369. if (ffCoolList[j] is Skill)
  370. {
  371. if (i == 0)
  372. {
  373. ((Skill)ffCoolList[j]).CoolTimer -= CircleTimer;
  374. }
  375. else
  376. {
  377. ((Skill)ffCoolList[j]).CoolTimer -= CircleTime;
  378. }
  379. }
  380. }
  381. for (int j = 0; j < ffUseList[i].Count; j++)
  382. {
  383. ffUseList[i][j].Annul();
  384. ffCoolList.Add(ffUseList[i][j]);
  385. }
  386. NewPerson = Person * (1 + SkillPersonBuff) + SkillPerson;
  387. NewCoinPerson = CoinPerson + SkillCoinPerson;
  388. collectCoin += (NewPerson * NewCoinPerson * CircleTime) * (1 + SkillPlus);
  389. }
  390. CircleTimer = (elapse - CircleTimer)%CircleTime;
  391. for (int j = 0; j < ffCoolList.Count; j++)
  392. {
  393. if (ffCoolList[j] is Skill)
  394. {
  395. ((Skill) ffCoolList[j]).CoolTimer -= CircleTime - CircleTimer;
  396. }
  397. }
  398. Coin += collectCoin;
  399. ManaReso.SetText("Ba_IconLab", collectCoin.ToString("0"));
  400. }
  401. else
  402. {
  403. CircleTimer = CircleTimer - elapse;
  404. ManaReso.SetText("Ba_IconLab", "0");
  405. }
  406. #endregion
  407. }
  408. public static bool Pay(double amt, Current current)
  409. {
  410. amt = (long) amt;
  411. if (current == Current.Free)
  412. {
  413. return true;
  414. }
  415. else if (current == Current.AD)
  416. {
  417. return true;
  418. }
  419. else if (current == Current.Cash)
  420. {
  421. return true;
  422. }
  423. else if (current == Current.Coin)
  424. {
  425. if (Coin >= amt)
  426. {
  427. Coin -= amt;
  428. return true;
  429. }
  430. else
  431. {
  432. ManaDebug.Log("您没有足够的金币");
  433. return false;
  434. }
  435. }
  436. else if (current == Current.Diamond)
  437. {
  438. if (Diamond >= amt)
  439. {
  440. Diamond -= amt;
  441. return true;
  442. }
  443. else
  444. {
  445. ManaDebug.Log("您没有足够的钻石");
  446. return false;
  447. }
  448. }
  449. else
  450. {
  451. throw new Exception(current.ToString());
  452. }
  453. }
  454. }