using UnityEngine; using UnityEngine.UI; using System; using System.Collections; using System.Collections.Generic; public enum Current { AD, Free, Coin, Cash, Other, Diamond, } public enum SkillType { Skill, Pack, Ability, BigSkill, } public enum SkillTab { Elf, Null, Store, Magic, Garden, } public enum SkillStatus { Buy, Use, Cool, Lock, UnLock, Upgrade, } public abstract class SkillRoot { #region 变量 #region 配置 public int ClassID; public string Icon; public string Name; public SkillTab Tab; #endregion public int Level; public Text ItemTit; public Text ItemLab; public Text ItemBtnLab; public Image ItemIcon; public Button ItemBtn; public SkillType SkillType; public abstract bool DoUse(); public abstract void RegistValue(double elapse, List> ffList); public abstract void OnLevelChange(); #endregion public static int SortByClassID(SkillRoot skillRootA, SkillRoot skillRootB) { if (skillRootA.ClassID == skillRootB.ClassID) { return 0; } else if (skillRootA.ClassID > skillRootB.ClassID) { return 1; } else if (skillRootA.ClassID < skillRootB.ClassID) { return -1; } else { throw new Exception(); } } public static int SortByTimer(SkillRoot skillRootA, SkillRoot skillRootB) { Skill skillA = (Skill) skillRootA; Skill skillB = (Skill) skillRootB; if (skillA == null || skillB == null) { return 0; } if (Math.Abs(skillA.UsingTimer - skillB.UsingTimer) < 0.0005f) { return 0; } else if (skillA.UsingTimer > skillB.UsingTimer) { return 1; } else if (skillA.UsingTimer < skillB.UsingTimer) { return -1; } else { throw new Exception(); } } public virtual void Annul() { } public virtual void ReceiveCool(float amt, bool isCurrent, bool isBuff) { } public virtual void FastForward(List> ffList, float time, int index) { } public virtual void RegistReference() { } #region 解读器 private string Calculate1(string str) { int index = 0; int openIndex = 0; bool flag = false; bool group = false; for (int i = 0; i < str.Length; i++) { if (group) { if (str[i] == '+' || str[i] == '-' || str[i] == '*' || str[i] == '/') { str = str.Replace(openIndex, i - 1, Calculate2(str[index], str.Between(openIndex, index - 1), str.Between(index + 1, i - 1))); i = 0; group = false; } else if (i == str.Length - 1) { str = str.Replace(openIndex, i, Calculate2(str[index], str.Between(openIndex, index - 1), str.Between(index + 1, i))); break; } } else { if (str[i] == '+' || str[i] == '-') { flag = true; openIndex = i + 1; } else if (str[i] == '*' || str[i] == '/') { index = i; group = true; if (!flag) { openIndex = 0; } } } } group = false; for (int i = 0; i < str.Length; i++) { if (group) { if (str[i] == '+' || str[i] == '-') { str = str.Replace(0, i - 1, Calculate2(str[index], str.Between(0, index - 1), str.Between(index + 1, i - 1))); i = -1; group = false; } else if (i == str.Length - 1) { return Calculate2(str[index], str.Between(0, index - 1), str.Between(index + 1, i)); } } else { if (str[i] == '+' || str[i] == '-') { index = i; group = true; } } } return str; } private string Calculate2(char operatorR, string str1, string str2) { double var1 = double.Parse(str1); double var2 = double.Parse(str2); if (operatorR == '+') { return (var1 + var2).ToString(); } else if (operatorR == '-') { return (var1 - var2).ToString(); } else if (operatorR == '*') { return (var1 * var2).ToString(); } else if (operatorR == '/') { return (var1 / var2).ToString(); } else { throw new Exception(operatorR.ToString()); } } protected int IntParse(string str) { if (string.IsNullOrEmpty(str)) { return 0; } else { return int.Parse(str); } } protected float FloatParse(string str) { if (string.IsNullOrEmpty(str)) { return 0; } else { return float.Parse(str); } } protected double FmlParse(string str, params double[] vars) { for (int i = 0; i < vars.Length; i++) { str = str.Replace(((char) (97 + i)).ToString(), vars[i].ToString()); } int openIndex = 0; for (int i = 0; i < str.Length; i++) { if (str[i] == '(') { openIndex = i; } else if (str[i] == ')') { str = str.Replace(openIndex, i, Calculate1(str.Between(openIndex + 1, i - 1))); i = -1; } } return double.Parse(Calculate1(str)); } protected bool BoolParse(string str) { if (string.IsNullOrEmpty(str)) { return false; } else { return Convert.ToBoolean(int.Parse(str)); } } protected Current CurrentParse(string str) { if (string.IsNullOrEmpty(str)) { return Current.Free; } else { int number = int.Parse(str); if (number == 1) { return Current.Coin; } else if (number == 2) { return Current.Diamond; } else if (number == 3) { return Current.Cash; } else if (number == 4) { return Current.Other; } else if (number == 5) { return Current.AD; } else { throw new Exception(number.ToString()); } } } protected SkillTab SkillClassParse(string str) { if (string.IsNullOrEmpty(str)) { return SkillTab.Null; } else { int number = int.Parse(str); if (number == 1) { return SkillTab.Garden; } else if (number == 2) { return SkillTab.Elf; } else if (number == 3) { return SkillTab.Magic; } else if (number == 4) { return SkillTab.Store; } else { throw new Exception(); } } } protected void UpgradeUnit(ref float target, string fml) { if (fml.Contains("*")) { target *= float.Parse(fml.Split('*')[1]); } else if (fml.Contains("/")) { target /= float.Parse(fml.Split('/')[1]); } } //进行单位换算 protected void UpgradeValue(ref float target, string fml, int offet) { if (string.IsNullOrEmpty(fml)) { } else if (fml.Contains("%")) { target += (float.Parse(fml.Replace("%", ""))/100)*offet; } else { } } protected void ValueBuffParse(out float value, out float buff, string str) { if (str.Contains("%")) //比例加成 { float step = float.Parse(str.Replace("%", "")) / 100; buff = step; value = 0; } else //数值加成 { buff = 0; value = FloatParse(str); } } #endregion }