SkillRoot.cs 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365
  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 class SkillItemLabel
  41. {
  42. public static string Btn = "Btn";
  43. public static string Arrow0 = "Arrow0";
  44. public static string Arrow1 = "Arrow1";
  45. }
  46. public abstract class SkillRoot
  47. {
  48. #region Config
  49. #region 配置
  50. public Sprite Icon
  51. {
  52. get
  53. {
  54. return ResourceManager.LoadSprite(Icon_, Folder.UI);
  55. }
  56. }
  57. public string Desc
  58. {
  59. get
  60. {
  61. return Language.GetStr(LabelUtility.CombineLanguageLabel(LanguageLabel.SkillDesc, FullID));
  62. }
  63. }
  64. public string FullID
  65. {
  66. get { return FullIDPrefix + ID_; }
  67. }
  68. public virtual string FullIDPrefix
  69. {
  70. get { throw new Exception(); }
  71. }
  72. public virtual string Name
  73. {
  74. get
  75. {
  76. if (Level == 0)
  77. {
  78. return Language.GetStr(LabelUtility.CombineLanguageLabel(LanguageLabel.SkillName, FullID));
  79. }
  80. else
  81. {
  82. return Language.GetStr(LabelUtility.CombineLanguageLabel(LanguageLabel.SkillName, FullID)) + Level;
  83. }
  84. }
  85. }
  86. public int ID_;
  87. public string Icon_;
  88. public int ItemIndex;
  89. #endregion
  90. public virtual int Level
  91. {
  92. get { return Level_; }
  93. set
  94. {
  95. Level_ = value;
  96. if (SkillTab == SkillTab.Null)
  97. {
  98. return;
  99. }
  100. if (Level == 0)
  101. {
  102. LanguageManager.Add(ItemTit, new MulLanStr(LabelUtility.CombineLanguageLabel(LanguageLabel.SkillName, FullID)));
  103. }
  104. else
  105. {
  106. LanguageManager.Add(ItemTit, new MulLanStr(LabelUtility.CombineLanguageLabel(LanguageLabel.SkillName, FullID)), Level);
  107. }
  108. }
  109. }
  110. public int Level_;
  111. public Text ItemTit;
  112. public Text ItemLab;
  113. public Text IconLab1;
  114. public Text ItemBtnLab;
  115. public Image ItemIcon;
  116. public Image ItemIcon1;
  117. public Button ItemBtn;
  118. public SkillTab SkillTab;
  119. public SkillType SkillType;
  120. public Transform SkillItem;
  121. public virtual SkillStatus ItemStatus
  122. {
  123. get { return ItemStatus_; }
  124. set
  125. {
  126. ItemStatus_ = value;
  127. }
  128. }
  129. public SkillStatus ItemStatus_;
  130. #endregion
  131. public static int Sort(SkillRoot skillRootA, SkillRoot skillRootB)
  132. {
  133. if (skillRootA.ItemIndex == skillRootB.ItemIndex)
  134. {
  135. return 0;
  136. }
  137. else if (skillRootA.ItemIndex > skillRootB.ItemIndex)
  138. {
  139. return 1;
  140. }
  141. else if (skillRootA.ItemIndex < skillRootB.ItemIndex)
  142. {
  143. return -1;
  144. }
  145. else
  146. {
  147. throw new Exception();
  148. }
  149. }
  150. public virtual void Reactive()
  151. {
  152. }
  153. public virtual void Init(bool firstInit, float elapse, List<List<Skill>> useList, XmlAttributeCollection attribute)
  154. {
  155. }
  156. public virtual void RegistReference()
  157. {
  158. if (SkillTab == SkillTab.Null)
  159. {
  160. return;
  161. }
  162. Dictionary<string, Transform> childDic = new Dictionary<string, Transform>();
  163. Auxiliary.CompileDic(SkillItem, childDic);
  164. ItemTit = childDic["Tit"].GetComponent<Text>();
  165. ItemBtn = childDic["Btn"].GetComponent<Button>();
  166. ItemLab = childDic["Lab"].GetComponent<Text>();
  167. IconLab1 = childDic["IconLab1"].GetComponent<Text>();
  168. ItemIcon = childDic["Icon"].GetComponent<Image>();
  169. ItemIcon1 = childDic["Icon1"].GetComponent<Image>();
  170. ItemBtnLab = childDic["BtnLab"].GetComponent<Text>();
  171. ItemIcon.sprite = Icon;
  172. }
  173. public virtual void SwitchLanguage()
  174. {
  175. if (SkillTab != SkillTab.Null)
  176. {
  177. ItemLab.text = GetDescription(0);
  178. }
  179. }
  180. public virtual void AnnulEffect()
  181. {
  182. }
  183. public virtual bool DoUpdate()
  184. {
  185. throw new Exception();
  186. }
  187. public virtual void ReceiveCool(float amt, bool current, bool buff)
  188. {
  189. }
  190. public virtual void UpdateStatus()
  191. {
  192. }
  193. #region 解读器
  194. protected SkillTab SkillClassParse(string str)
  195. {
  196. if (string.IsNullOrEmpty(str))
  197. {
  198. return SkillTab.Null;
  199. }
  200. else
  201. {
  202. int number = int.Parse(str);
  203. if (number == 1)
  204. {
  205. return SkillTab.Garden;
  206. }
  207. else if (number == 2)
  208. {
  209. return SkillTab.Elf;
  210. }
  211. else if (number == 3)
  212. {
  213. return SkillTab.Magic;
  214. }
  215. else if (number == 4)
  216. {
  217. return SkillTab.Store;
  218. }
  219. else
  220. {
  221. throw new Exception();
  222. }
  223. }
  224. }
  225. protected void UpgradeUnit(ref float target, string fml)
  226. {
  227. if (fml.Contains("*"))
  228. {
  229. target *= float.Parse(fml.Split('*')[1]);
  230. }
  231. else if (fml.Contains("/"))
  232. {
  233. target /= float.Parse(fml.Split('/')[1]);
  234. }
  235. }
  236. protected void UpgradeValue(ref float target, string fml, int offset)
  237. {
  238. if (target.Equal(0))
  239. {
  240. return;
  241. }
  242. if (fml.Contains("%"))
  243. {
  244. target += (float.Parse(fml.Replace("%", ""))/100)*offset;
  245. }
  246. }
  247. protected void UpgradeValue(ref float target, float baseValue, string fml, int offset)
  248. {
  249. if (target.Equal(0))
  250. {
  251. return;
  252. }
  253. if (string.IsNullOrEmpty(fml))
  254. {
  255. return;
  256. }
  257. 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 UpgradeSkillCdBuff(ref float target, string fml, int offset)
  268. {
  269. if (fml.Contains("%"))
  270. {
  271. float unit = (float.Parse(fml.Replace("%", "")))/100;
  272. for (int i = 0; i < offset; i++)
  273. {
  274. target += (1 - target) * unit;
  275. }
  276. }
  277. }
  278. protected void ValueBuffParse(out float value, out float buff, string str)
  279. {
  280. if (str.Contains("%"))
  281. {
  282. float step = float.Parse(str.Replace("%", "")) / 100;
  283. buff = step;
  284. value = 0;
  285. }
  286. else
  287. {
  288. buff = 0;
  289. value = Auxiliary.StringToFloat(str, 0);
  290. }
  291. }
  292. protected virtual string GetDescription(int offset)
  293. {
  294. throw new Exception();
  295. }
  296. #endregion
  297. }
  298. #region DebugList
  299. //语言切换
  300. #endregion