123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427 |
- 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<List<SkillRoot>> 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<List<SkillRoot>> 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;
- }
- 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
- }
|