SkillRoot.cs 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363
  1. using UnityEngine;
  2. using UnityEngine.UI;
  3. using System;
  4. using System.Xml;
  5. using System.Collections;
  6. using System.Collections.Generic;
  7. public enum Current
  8. {
  9. AD,
  10. Free,
  11. Coin,
  12. Cash,
  13. Other,
  14. Diamond,
  15. }
  16. public enum SkillTab
  17. {
  18. Elf,
  19. Null,
  20. Store,
  21. Magic,
  22. Garden,
  23. }
  24. public enum SkillType
  25. {
  26. Skill,
  27. Pack,
  28. Ability,
  29. BigSkill,
  30. }
  31. public enum SkillStatus
  32. {
  33. Buy,
  34. Use,
  35. Lock,
  36. Cool,
  37. UnLock,
  38. Upgrade,
  39. }
  40. public abstract class SkillRoot
  41. {
  42. #region 变量
  43. #region 配置
  44. public string Desc
  45. {
  46. get
  47. {
  48. return Language.GetStr("SkillDesc", ID);
  49. }
  50. }
  51. public string Name
  52. {
  53. get
  54. {
  55. return Language.GetStr("SkillName", ID);
  56. }
  57. }
  58. public virtual string ID
  59. {
  60. get { throw new Exception(); }
  61. }
  62. public Sprite Icon
  63. {
  64. get { return ManaReso.Load<Sprite>(Icon_, Folder.UI); }
  65. }
  66. public int ID_;
  67. public int ItemIndex;
  68. public string Icon_;
  69. #endregion
  70. public int Level
  71. {
  72. get { return Level_; }
  73. set
  74. {
  75. Level_ = value;
  76. RegistName(ItemTit);
  77. }
  78. }
  79. public int Level_;
  80. public Text ItemTit;
  81. public Text ItemLab;
  82. public Text ItemBtnLab;
  83. public Image ItemIcon;
  84. public Button ItemBtn;
  85. public SkillTab SkillTab;
  86. public SkillType SkillType;
  87. public Transform SkillItem;
  88. public abstract void RegistValue(float elapse, List<List<Skill>> useList, XmlAttributeCollection attribute);
  89. public abstract void UpdateStatus();
  90. #endregion
  91. public static int Sort(SkillRoot skillRootA, SkillRoot skillRootB)
  92. {
  93. if (skillRootA.ItemIndex == skillRootB.ItemIndex)
  94. {
  95. return 0;
  96. }
  97. else if (skillRootA.ItemIndex > skillRootB.ItemIndex)
  98. {
  99. return 1;
  100. }
  101. else if (skillRootA.ItemIndex < skillRootB.ItemIndex)
  102. {
  103. return -1;
  104. }
  105. else
  106. {
  107. throw new Exception();
  108. }
  109. }
  110. public virtual void SwitchLanguage()
  111. {
  112. if (ItemLab != null)
  113. {
  114. ItemLab.text = Description(0);
  115. }
  116. }
  117. public virtual void Annul()
  118. {
  119. }
  120. public virtual bool DoUse()
  121. {
  122. throw new Exception();
  123. }
  124. public virtual void ReceiveCool(float amt, bool current, bool buff)
  125. {
  126. }
  127. public virtual void RegistReference()
  128. {
  129. if (SkillTab == SkillTab.Null)
  130. {
  131. return;
  132. }
  133. Dictionary<string, Transform> childDic = new Dictionary<string, Transform>();
  134. Auxiliary.CompileDic(SkillItem, childDic);
  135. ItemTit = childDic["Tit"].GetComponent<Text>();
  136. ItemBtn = childDic["Btn"].GetComponent<Button>();
  137. ItemLab = childDic["Lab"].GetComponent<Text>();
  138. ItemIcon = childDic["Icon"].GetComponent<Image>();
  139. ItemBtnLab = childDic["BtnLab"].GetComponent<Text>();
  140. ItemIcon.sprite = Icon;
  141. }
  142. #region 解读器
  143. protected void RegistName(Text text)
  144. {
  145. if (SkillTab == SkillTab.Null)
  146. {
  147. return;
  148. }
  149. if (Level == 0)
  150. {
  151. ManaLan.Add(text, new LanStr("SkillName", ID));
  152. }
  153. else
  154. {
  155. ManaLan.Add(text, new LanStr("SkillName", ID), Level);
  156. }
  157. }
  158. protected string NameParse()
  159. {
  160. if (Level == 0)
  161. {
  162. return Language.GetStr("SkillName", ID);
  163. }
  164. else
  165. {
  166. return Language.GetStr("SkillName", ID) + Level;
  167. }
  168. }
  169. protected string ImageParse(Current current)
  170. {
  171. if (current == Current.Coin)
  172. {
  173. return "<(金币)>";
  174. }
  175. else if (current == Current.Diamond)
  176. {
  177. return "<(钻石)>";
  178. }
  179. else if (current == Current.Cash)
  180. {
  181. return Language.GetStr("Common", "Cash");
  182. }
  183. else
  184. {
  185. throw new Exception(current.ToString());
  186. }
  187. }
  188. protected Current CurrentParse(string str)
  189. {
  190. if (string.IsNullOrEmpty(str))
  191. {
  192. return Current.Free;
  193. }
  194. else
  195. {
  196. int number = int.Parse(str);
  197. if (number == 1)
  198. {
  199. return Current.Coin;
  200. }
  201. else if (number == 2)
  202. {
  203. return Current.Diamond;
  204. }
  205. else if (number == 3)
  206. {
  207. return Current.Cash;
  208. }
  209. else if (number == 4)
  210. {
  211. return Current.Other;
  212. }
  213. else if (number == 5)
  214. {
  215. return Current.AD;
  216. }
  217. else
  218. {
  219. throw new Exception(number.ToString());
  220. }
  221. }
  222. }
  223. protected SkillTab SkillClassParse(string str)
  224. {
  225. if (string.IsNullOrEmpty(str))
  226. {
  227. return SkillTab.Null;
  228. }
  229. else
  230. {
  231. int number = int.Parse(str);
  232. if (number == 1)
  233. {
  234. return SkillTab.Garden;
  235. }
  236. else if (number == 2)
  237. {
  238. return SkillTab.Elf;
  239. }
  240. else if (number == 3)
  241. {
  242. return SkillTab.Magic;
  243. }
  244. else if (number == 4)
  245. {
  246. return SkillTab.Store;
  247. }
  248. else
  249. {
  250. throw new Exception();
  251. }
  252. }
  253. }
  254. protected void UpgradeUnit(ref float target, string fml)
  255. {
  256. if (fml.Contains("*"))
  257. {
  258. target *= float.Parse(fml.Split('*')[1]);
  259. }
  260. else if (fml.Contains("/"))
  261. {
  262. target /= float.Parse(fml.Split('/')[1]);
  263. }
  264. }
  265. protected void UpgradeValue(ref float target, string fml, int offet)
  266. {
  267. 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 = Auxiliary.FloatParse(str, 0);
  303. }
  304. }
  305. protected abstract string Description(int offset);
  306. #endregion
  307. }