ManaData.cs 13 KB

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