SkillRoot.cs 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359
  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 string Desc
  44. {
  45. get
  46. {
  47. return Language.GetStr("SkillDescription", _Name);
  48. }
  49. set { _Desc = value; }
  50. }
  51. public string Name
  52. {
  53. get
  54. {
  55. return Language.GetStr("SkillName", _Name);
  56. }
  57. set { _Name = value; }
  58. }
  59. public string _Desc;
  60. public string _Name;
  61. public int ID;
  62. public int ClassID;
  63. public string Icon;
  64. #endregion
  65. public int Level;
  66. public Text ItemTit;
  67. public Text ItemLab;
  68. public Text ItemBtnLab;
  69. public Image ItemIcon;
  70. public Button ItemBtn;
  71. public SkillTab SkillTab;
  72. public SkillType SkillType;
  73. public Transform SkillItem;
  74. public abstract void RegistValue(float elapse, List<List<SkillRoot>> ffList);
  75. public abstract void UpdateStatus();
  76. #endregion
  77. public static int Sort(SkillRoot skillRootA, SkillRoot skillRootB)
  78. {
  79. if (skillRootA.ClassID == skillRootB.ClassID)
  80. {
  81. return 0;
  82. }
  83. else if (skillRootA.ClassID > skillRootB.ClassID)
  84. {
  85. return 1;
  86. }
  87. else if (skillRootA.ClassID < skillRootB.ClassID)
  88. {
  89. return -1;
  90. }
  91. else
  92. {
  93. throw new Exception();
  94. }
  95. }
  96. public void SwitchLanguage()
  97. {
  98. if (ItemLab != null)
  99. {
  100. ItemLab.text = Description(0);
  101. }
  102. }
  103. public virtual void Annul()
  104. {
  105. }
  106. public virtual bool DoUse()
  107. {
  108. throw new Exception();
  109. }
  110. public virtual void ReceiveCool(float amt, bool current, bool buff)
  111. {
  112. }
  113. public virtual void RegistReference()
  114. {
  115. if (SkillTab == SkillTab.Null)
  116. {
  117. return;
  118. }
  119. Dictionary<string, Transform> childDic = new Dictionary<string, Transform>();
  120. Auxiliary.CompileDic(SkillItem, childDic);
  121. ItemTit = childDic["Tit"].GetComponent<Text>();
  122. ItemBtn = childDic["Btn"].GetComponent<Button>();
  123. ItemLab = childDic["Lab"].GetComponent<Text>();
  124. ItemIcon = childDic["Icon"].GetComponent<Image>();
  125. ItemBtnLab = childDic["BtnLab"].GetComponent<Text>();
  126. ItemIcon.sprite = ManaReso.Load<Sprite>(Icon, Folder.Skill);
  127. }
  128. #region 解读器
  129. protected int IntParse(string str)
  130. {
  131. if (string.IsNullOrEmpty(str))
  132. {
  133. return 0;
  134. }
  135. else
  136. {
  137. return int.Parse(str);
  138. }
  139. }
  140. protected bool BoolParse(string str)
  141. {
  142. if (string.IsNullOrEmpty(str))
  143. {
  144. return false;
  145. }
  146. else
  147. {
  148. return Convert.ToBoolean(int.Parse(str));
  149. }
  150. }
  151. protected float FloatParse(string str)
  152. {
  153. if (string.IsNullOrEmpty(str))
  154. {
  155. return 0;
  156. }
  157. else
  158. {
  159. return float.Parse(str);
  160. }
  161. }
  162. protected string ImageParse(Current current)
  163. {
  164. if (current == Current.Coin)
  165. {
  166. return "<(金币)>";
  167. }
  168. else if (current == Current.Diamond)
  169. {
  170. return "<(钻石)>";
  171. }
  172. else if (current == Current.Cash)
  173. {
  174. return "<(现金)>";
  175. }
  176. else if (current == Current.AD)
  177. {
  178. return "<(广告)>";
  179. }
  180. else
  181. {
  182. throw new Exception();
  183. }
  184. }
  185. protected Current CurrentParse(string str)
  186. {
  187. if (string.IsNullOrEmpty(str))
  188. {
  189. return Current.Free;
  190. }
  191. else
  192. {
  193. int number = int.Parse(str);
  194. if (number == 1)
  195. {
  196. return Current.Coin;
  197. }
  198. else if (number == 2)
  199. {
  200. return Current.Diamond;
  201. }
  202. else if (number == 3)
  203. {
  204. return Current.Cash;
  205. }
  206. else if (number == 4)
  207. {
  208. return Current.Other;
  209. }
  210. else if (number == 5)
  211. {
  212. return Current.AD;
  213. }
  214. else
  215. {
  216. throw new Exception(number.ToString());
  217. }
  218. }
  219. }
  220. protected SkillTab SkillClassParse(string str)
  221. {
  222. if (string.IsNullOrEmpty(str))
  223. {
  224. return SkillTab.Null;
  225. }
  226. else
  227. {
  228. int number = int.Parse(str);
  229. if (number == 1)
  230. {
  231. return SkillTab.Garden;
  232. }
  233. else if (number == 2)
  234. {
  235. return SkillTab.Elf;
  236. }
  237. else if (number == 3)
  238. {
  239. return SkillTab.Magic;
  240. }
  241. else if (number == 4)
  242. {
  243. return SkillTab.Store;
  244. }
  245. else
  246. {
  247. throw new Exception();
  248. }
  249. }
  250. }
  251. protected void UpgradeUnit(ref float target, string fml)
  252. {
  253. if (fml.Contains("*"))
  254. {
  255. target *= float.Parse(fml.Split('*')[1]);
  256. }
  257. else if (fml.Contains("/"))
  258. {
  259. target /= float.Parse(fml.Split('/')[1]);
  260. }
  261. }
  262. protected void UpgradeValue(ref float target, string fml, int offet)
  263. {
  264. if (string.IsNullOrEmpty(fml))
  265. {
  266. }
  267. else if (fml.Contains("%"))
  268. {
  269. target += (float.Parse(fml.Replace("%", ""))/100)*offet;
  270. }
  271. }
  272. protected void UpgradeValue(ref float target, float baseValue, string fml, int offset)
  273. {
  274. if (Math.Abs(target) < 0.0005f)
  275. {
  276. return;
  277. }
  278. if (string.IsNullOrEmpty(fml))
  279. {
  280. }
  281. else if (fml.Contains("%"))
  282. {
  283. float step = float.Parse(fml.Replace("%", "")) / 100;
  284. target += baseValue * step * offset;
  285. }
  286. else
  287. {
  288. target += float.Parse(fml) * offset;
  289. }
  290. }
  291. protected void ValueBuffParse(out float value, out float buff, string str)
  292. {
  293. if (str.Contains("%"))
  294. {
  295. float step = float.Parse(str.Replace("%", "")) / 100;
  296. buff = step;
  297. value = 0;
  298. }
  299. else
  300. {
  301. buff = 0;
  302. value = FloatParse(str);
  303. }
  304. }
  305. protected abstract string Description(int offset);
  306. #endregion
  307. }