SkillRoot.cs 8.9 KB

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