SkillRoot.cs 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427
  1. using UnityEngine;
  2. using UnityEngine.UI;
  3. using System;
  4. using System.Collections;
  5. using System.Collections.Generic;
  6. public enum Current
  7. {
  8. AD,
  9. Free,
  10. Coin,
  11. Cash,
  12. Other,
  13. Diamond,
  14. }
  15. public enum SkillType
  16. {
  17. Skill,
  18. Pack,
  19. Ability,
  20. BigSkill,
  21. }
  22. public enum SkillTab
  23. {
  24. Elf,
  25. Null,
  26. Store,
  27. Magic,
  28. Garden,
  29. }
  30. public enum SkillStatus
  31. {
  32. Buy,
  33. Use,
  34. Cool,
  35. Lock,
  36. UnLock,
  37. Upgrade,
  38. }
  39. public abstract class SkillRoot
  40. {
  41. #region 变量
  42. #region 配置
  43. public int ClassID;
  44. public string Icon;
  45. public string Name;
  46. public SkillTab Tab;
  47. #endregion
  48. public int Level;
  49. public Text ItemTit;
  50. public Text ItemLab;
  51. public Text ItemBtnLab;
  52. public Image ItemIcon;
  53. public Button ItemBtn;
  54. public SkillType SkillType;
  55. public abstract bool DoUse();
  56. public abstract void RegistValue(double elapse, List<List<SkillRoot>> ffList);
  57. public abstract void OnLevelChange();
  58. #endregion
  59. public static int SortByClassID(SkillRoot skillRootA, SkillRoot skillRootB)
  60. {
  61. if (skillRootA.ClassID == skillRootB.ClassID)
  62. {
  63. return 0;
  64. }
  65. else if (skillRootA.ClassID > skillRootB.ClassID)
  66. {
  67. return 1;
  68. }
  69. else if (skillRootA.ClassID < skillRootB.ClassID)
  70. {
  71. return -1;
  72. }
  73. else
  74. {
  75. throw new Exception();
  76. }
  77. }
  78. public static int SortByTimer(SkillRoot skillRootA, SkillRoot skillRootB)
  79. {
  80. Skill skillA = (Skill) skillRootA;
  81. Skill skillB = (Skill) skillRootB;
  82. if (skillA == null || skillB == null)
  83. {
  84. return 0;
  85. }
  86. if (Math.Abs(skillA.UsingTimer - skillB.UsingTimer) < 0.0005f)
  87. {
  88. return 0;
  89. }
  90. else if (skillA.UsingTimer > skillB.UsingTimer)
  91. {
  92. return 1;
  93. }
  94. else if (skillA.UsingTimer < skillB.UsingTimer)
  95. {
  96. return -1;
  97. }
  98. else
  99. {
  100. throw new Exception();
  101. }
  102. }
  103. public virtual void Annul()
  104. {
  105. }
  106. public virtual void ReceiveCool(float amt, bool isCurrent, bool isBuff)
  107. {
  108. }
  109. public virtual void FastForward(List<List<SkillRoot>> ffList, float time, int index)
  110. {
  111. }
  112. public virtual void RegistReference()
  113. {
  114. }
  115. #region 解读器
  116. private string Calculate1(string str)
  117. {
  118. int index = 0;
  119. int openIndex = 0;
  120. bool flag = false;
  121. bool group = false;
  122. for (int i = 0; i < str.Length; i++)
  123. {
  124. if (group)
  125. {
  126. if (str[i] == '+' || str[i] == '-' || str[i] == '*' || str[i] == '/')
  127. {
  128. str = str.Replace(openIndex, i - 1, Calculate2(str[index], str.Between(openIndex, index - 1), str.Between(index + 1, i - 1)));
  129. i = 0;
  130. group = false;
  131. }
  132. else if (i == str.Length - 1)
  133. {
  134. str = str.Replace(openIndex, i, Calculate2(str[index], str.Between(openIndex, index - 1), str.Between(index + 1, i)));
  135. break;
  136. }
  137. }
  138. else
  139. {
  140. if (str[i] == '+' || str[i] == '-')
  141. {
  142. flag = true;
  143. openIndex = i + 1;
  144. }
  145. else if (str[i] == '*' || str[i] == '/')
  146. {
  147. index = i;
  148. group = true;
  149. if (!flag)
  150. {
  151. openIndex = 0;
  152. }
  153. }
  154. }
  155. }
  156. group = false;
  157. for (int i = 0; i < str.Length; i++)
  158. {
  159. if (group)
  160. {
  161. if (str[i] == '+' || str[i] == '-')
  162. {
  163. str = str.Replace(0, i - 1, Calculate2(str[index], str.Between(0, index - 1), str.Between(index + 1, i - 1)));
  164. i = -1;
  165. group = false;
  166. }
  167. else if (i == str.Length - 1)
  168. {
  169. return Calculate2(str[index], str.Between(0, index - 1), str.Between(index + 1, i));
  170. }
  171. }
  172. else
  173. {
  174. if (str[i] == '+' || str[i] == '-')
  175. {
  176. index = i;
  177. group = true;
  178. }
  179. }
  180. }
  181. return str;
  182. }
  183. private string Calculate2(char operatorR, string str1, string str2)
  184. {
  185. double var1 = double.Parse(str1);
  186. double var2 = double.Parse(str2);
  187. if (operatorR == '+')
  188. {
  189. return (var1 + var2).ToString();
  190. }
  191. else if (operatorR == '-')
  192. {
  193. return (var1 - var2).ToString();
  194. }
  195. else if (operatorR == '*')
  196. {
  197. return (var1 * var2).ToString();
  198. }
  199. else if (operatorR == '/')
  200. {
  201. return (var1 / var2).ToString();
  202. }
  203. else
  204. {
  205. throw new Exception(operatorR.ToString());
  206. }
  207. }
  208. protected int IntParse(string str)
  209. {
  210. if (string.IsNullOrEmpty(str))
  211. {
  212. return 0;
  213. }
  214. else
  215. {
  216. return int.Parse(str);
  217. }
  218. }
  219. protected float FloatParse(string str)
  220. {
  221. if (string.IsNullOrEmpty(str))
  222. {
  223. return 0;
  224. }
  225. else
  226. {
  227. return float.Parse(str);
  228. }
  229. }
  230. protected double FmlParse(string str, params double[] vars)
  231. {
  232. for (int i = 0; i < vars.Length; i++)
  233. {
  234. str = str.Replace(((char) (97 + i)).ToString(), vars[i].ToString());
  235. }
  236. int openIndex = 0;
  237. for (int i = 0; i < str.Length; i++)
  238. {
  239. if (str[i] == '(')
  240. {
  241. openIndex = i;
  242. }
  243. else if (str[i] == ')')
  244. {
  245. str = str.Replace(openIndex, i, Calculate1(str.Between(openIndex + 1, i - 1)));
  246. i = -1;
  247. }
  248. }
  249. return double.Parse(Calculate1(str));
  250. }
  251. protected bool BoolParse(string str)
  252. {
  253. if (string.IsNullOrEmpty(str))
  254. {
  255. return false;
  256. }
  257. else
  258. {
  259. return Convert.ToBoolean(int.Parse(str));
  260. }
  261. }
  262. protected Current CurrentParse(string str)
  263. {
  264. if (string.IsNullOrEmpty(str))
  265. {
  266. return Current.Free;
  267. }
  268. else
  269. {
  270. int number = int.Parse(str);
  271. if (number == 1)
  272. {
  273. return Current.Coin;
  274. }
  275. else if (number == 2)
  276. {
  277. return Current.Diamond;
  278. }
  279. else if (number == 3)
  280. {
  281. return Current.Cash;
  282. }
  283. else if (number == 4)
  284. {
  285. return Current.Other;
  286. }
  287. else if (number == 5)
  288. {
  289. return Current.AD;
  290. }
  291. else
  292. {
  293. throw new Exception(number.ToString());
  294. }
  295. }
  296. }
  297. protected SkillTab SkillClassParse(string str)
  298. {
  299. if (string.IsNullOrEmpty(str))
  300. {
  301. return SkillTab.Null;
  302. }
  303. else
  304. {
  305. int number = int.Parse(str);
  306. if (number == 1)
  307. {
  308. return SkillTab.Garden;
  309. }
  310. else if (number == 2)
  311. {
  312. return SkillTab.Elf;
  313. }
  314. else if (number == 3)
  315. {
  316. return SkillTab.Magic;
  317. }
  318. else if (number == 4)
  319. {
  320. return SkillTab.Store;
  321. }
  322. else
  323. {
  324. throw new Exception();
  325. }
  326. }
  327. }
  328. protected void UpgradeUnit(ref float target, string fml)
  329. {
  330. if (fml.Contains("*"))
  331. {
  332. target *= float.Parse(fml.Split('*')[1]);
  333. }
  334. else if (fml.Contains("/"))
  335. {
  336. target /= float.Parse(fml.Split('/')[1]);
  337. }
  338. } //进行单位换算
  339. protected void UpgradeValue(ref float target, string fml, int offet)
  340. {
  341. if (string.IsNullOrEmpty(fml))
  342. {
  343. }
  344. else if (fml.Contains("%"))
  345. {
  346. target += float.Parse(fml.Replace("%", "")) / 100;
  347. }
  348. else
  349. {
  350. }
  351. }
  352. protected void ValueBuffParse(out float value, out float buff, string str)
  353. {
  354. if (str.Contains("%")) //比例加成
  355. {
  356. float step = float.Parse(str.Replace("%", "")) / 100;
  357. buff = step;
  358. value = 0;
  359. }
  360. else //数值加成
  361. {
  362. buff = 0;
  363. value = FloatParse(str);
  364. }
  365. }
  366. #endregion
  367. }