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