SkillRoot.cs 7.5 KB

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