ManaData.cs 16 KB

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