SkillRoot.cs 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327
  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. throw new Exception();
  85. }
  86. public virtual void ReceiveCool(float amt, bool current, bool buff)
  87. {
  88. }
  89. public virtual void RegistReference()
  90. {
  91. if (SkillTab == SkillTab.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. ItemIcon.sprite = ManaReso.Load<Sprite>(Icon, Folder.Skill);
  103. }
  104. #region 解读器
  105. protected int IntParse(string str)
  106. {
  107. if (string.IsNullOrEmpty(str))
  108. {
  109. return 0;
  110. }
  111. else
  112. {
  113. return int.Parse(str);
  114. }
  115. }
  116. protected bool BoolParse(string str)
  117. {
  118. if (string.IsNullOrEmpty(str))
  119. {
  120. return false;
  121. }
  122. else
  123. {
  124. return Convert.ToBoolean(int.Parse(str));
  125. }
  126. }
  127. protected float FloatParse(string str)
  128. {
  129. if (string.IsNullOrEmpty(str))
  130. {
  131. return 0;
  132. }
  133. else
  134. {
  135. return float.Parse(str);
  136. }
  137. }
  138. protected string ImageParse(Current current)
  139. {
  140. if (current == Current.Coin)
  141. {
  142. return "<(金币)>";
  143. }
  144. else if (current == Current.Diamond)
  145. {
  146. return "<(钻石)>";
  147. }
  148. else if (current == Current.Cash)
  149. {
  150. return "<(现金)>";
  151. }
  152. else if (current == Current.AD)
  153. {
  154. return "<(广告)>";
  155. }
  156. else
  157. {
  158. throw new Exception();
  159. }
  160. }
  161. protected Current CurrentParse(string str)
  162. {
  163. if (string.IsNullOrEmpty(str))
  164. {
  165. return Current.Free;
  166. }
  167. else
  168. {
  169. int number = int.Parse(str);
  170. if (number == 1)
  171. {
  172. return Current.Coin;
  173. }
  174. else if (number == 2)
  175. {
  176. return Current.Diamond;
  177. }
  178. else if (number == 3)
  179. {
  180. return Current.Cash;
  181. }
  182. else if (number == 4)
  183. {
  184. return Current.Other;
  185. }
  186. else if (number == 5)
  187. {
  188. return Current.AD;
  189. }
  190. else
  191. {
  192. throw new Exception(number.ToString());
  193. }
  194. }
  195. }
  196. protected SkillTab SkillClassParse(string str)
  197. {
  198. if (string.IsNullOrEmpty(str))
  199. {
  200. return SkillTab.Null;
  201. }
  202. else
  203. {
  204. int number = int.Parse(str);
  205. if (number == 1)
  206. {
  207. return SkillTab.Garden;
  208. }
  209. else if (number == 2)
  210. {
  211. return SkillTab.Elf;
  212. }
  213. else if (number == 3)
  214. {
  215. return SkillTab.Magic;
  216. }
  217. else if (number == 4)
  218. {
  219. return SkillTab.Store;
  220. }
  221. else
  222. {
  223. throw new Exception();
  224. }
  225. }
  226. }
  227. protected void UpgradeUnit(ref float target, string fml)
  228. {
  229. if (fml.Contains("*"))
  230. {
  231. target *= float.Parse(fml.Split('*')[1]);
  232. }
  233. else if (fml.Contains("/"))
  234. {
  235. target /= float.Parse(fml.Split('/')[1]);
  236. }
  237. }
  238. protected void UpgradeValue(ref float target, string fml, int offet)
  239. {
  240. if (string.IsNullOrEmpty(fml))
  241. {
  242. }
  243. else if (fml.Contains("%"))
  244. {
  245. target += (float.Parse(fml.Replace("%", ""))/100)*offet;
  246. }
  247. }
  248. protected void UpgradeValue(ref float target, float baseValue, string fml, int offset)
  249. {
  250. if (Math.Abs(target) < 0.0005f)
  251. {
  252. return;
  253. }
  254. if (string.IsNullOrEmpty(fml))
  255. {
  256. }
  257. else if (fml.Contains("%"))
  258. {
  259. float step = float.Parse(fml.Replace("%", "")) / 100;
  260. target += baseValue * step * offset;
  261. }
  262. else
  263. {
  264. target += float.Parse(fml) * offset;
  265. }
  266. }
  267. protected void ValueBuffParse(out float value, out float buff, string str)
  268. {
  269. if (str.Contains("%"))
  270. {
  271. float step = float.Parse(str.Replace("%", "")) / 100;
  272. buff = step;
  273. value = 0;
  274. }
  275. else
  276. {
  277. buff = 0;
  278. value = FloatParse(str);
  279. }
  280. }
  281. #endregion
  282. }