SkillRoot.cs 6.9 KB

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