SkillRoot.cs 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  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 SkillTab
  16. {
  17. Elf,
  18. Null,
  19. Store,
  20. Magic,
  21. Garden,
  22. }
  23. public enum SkillType
  24. {
  25. Skill,
  26. Pack,
  27. Ability,
  28. BigSkill,
  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. #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 SkillTab SkillTab;
  55. public SkillType SkillType;
  56. public Transform SkillItem;
  57. public abstract void RegistValue(float elapse, List<List<SkillRoot>> ffList);
  58. public abstract void UpdateStatus();
  59. #endregion
  60. public static int Sort(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 virtual void Annul()
  80. {
  81. }
  82. public virtual bool DoUse()
  83. {
  84. return true;
  85. }
  86. public virtual void ReceiveCool(float amt, bool current, bool buff)
  87. {
  88. }
  89. public virtual void RegistReference()
  90. {
  91. if (SkillItem == null)
  92. {
  93. return;
  94. }
  95. Dictionary<string, Transform> childDic = new Dictionary<string, Transform>();
  96. Auxiliary.CompileDic(SkillItem, childDic);
  97. ItemTit = childDic["Tit"].GetComponent<Text>();
  98. ItemBtn = childDic["Btn"].GetComponent<Button>();
  99. ItemLab = childDic["Lab"].GetComponent<Text>();
  100. ItemIcon = childDic["Icon"].GetComponent<Image>();
  101. ItemBtnLab = childDic["BtnLab"].GetComponent<Text>();
  102. if (!string.IsNullOrEmpty(Icon))
  103. {
  104. ItemIcon.sprite = ManaReso.Load<Sprite>(Icon, Folder.Skill);
  105. }
  106. }
  107. #region 解读器
  108. protected int IntParse(string str)
  109. {
  110. if (string.IsNullOrEmpty(str))
  111. {
  112. return 0;
  113. }
  114. else
  115. {
  116. return int.Parse(str);
  117. }
  118. }
  119. protected bool BoolParse(string str)
  120. {
  121. if (string.IsNullOrEmpty(str))
  122. {
  123. return false;
  124. }
  125. else
  126. {
  127. return Convert.ToBoolean(int.Parse(str));
  128. }
  129. }
  130. protected float FloatParse(string str)
  131. {
  132. if (string.IsNullOrEmpty(str))
  133. {
  134. return 0;
  135. }
  136. else
  137. {
  138. return float.Parse(str);
  139. }
  140. }
  141. protected Current CurrentParse(string str)
  142. {
  143. if (string.IsNullOrEmpty(str))
  144. {
  145. return Current.Free;
  146. }
  147. else
  148. {
  149. int number = int.Parse(str);
  150. if (number == 1)
  151. {
  152. return Current.Coin;
  153. }
  154. else if (number == 2)
  155. {
  156. return Current.Diamond;
  157. }
  158. else if (number == 3)
  159. {
  160. return Current.Cash;
  161. }
  162. else if (number == 4)
  163. {
  164. return Current.Other;
  165. }
  166. else if (number == 5)
  167. {
  168. return Current.AD;
  169. }
  170. else
  171. {
  172. throw new Exception(number.ToString());
  173. }
  174. }
  175. }
  176. protected SkillTab SkillClassParse(string str)
  177. {
  178. if (string.IsNullOrEmpty(str))
  179. {
  180. return SkillTab.Null;
  181. }
  182. else
  183. {
  184. int number = int.Parse(str);
  185. if (number == 1)
  186. {
  187. return SkillTab.Garden;
  188. }
  189. else if (number == 2)
  190. {
  191. return SkillTab.Elf;
  192. }
  193. else if (number == 3)
  194. {
  195. return SkillTab.Magic;
  196. }
  197. else if (number == 4)
  198. {
  199. return SkillTab.Store;
  200. }
  201. else
  202. {
  203. throw new Exception();
  204. }
  205. }
  206. }
  207. protected void UpgradeUnit(ref float target, string fml)
  208. {
  209. if (fml.Contains("*"))
  210. {
  211. target *= float.Parse(fml.Split('*')[1]);
  212. }
  213. else if (fml.Contains("/"))
  214. {
  215. target /= float.Parse(fml.Split('/')[1]);
  216. }
  217. }
  218. protected void UpgradeValue(ref float target, string fml, int offet)
  219. {
  220. if (string.IsNullOrEmpty(fml))
  221. {
  222. }
  223. else if (fml.Contains("%"))
  224. {
  225. target += (float.Parse(fml.Replace("%", ""))/100)*offet;
  226. }
  227. else
  228. {
  229. }
  230. }
  231. protected void ValueBuffParse(out float value, out float buff, string str)
  232. {
  233. if (str.Contains("%"))
  234. {
  235. float step = float.Parse(str.Replace("%", "")) / 100;
  236. buff = step;
  237. value = 0;
  238. }
  239. else
  240. {
  241. buff = 0;
  242. value = FloatParse(str);
  243. }
  244. }
  245. #endregion
  246. }