123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779 |
- using UnityEngine;
- using UnityEngine.UI;
- using System;
- using System.Xml;
- using System.Text;
- using System.Collections;
- using System.Collections.Generic;
- using System.Linq;
- public class Skill : SkillRoot
- {
- #region 变量
- #region 配置
- protected float CD;
- protected float Person;
- protected float SkillCD;
- protected float UseAmt;
- protected float Duration;
- protected float CoinOnce;
- protected float CoinPerson;
- protected float DiamondOnce;
- protected double UpgradeAmt;
- protected bool ReduceCD;
- protected float Plus;
- protected float CdBuff;
- protected float PersonBuff;
- protected float SkillCdBuff;
- protected float CoinOnceBuff;
- protected int UnlockLv;
- protected float UnlockAmt;
- protected float UnlockAheadAmt;
- protected string UnlockPos;
- protected Current UseCur;
- protected Current UnlockCur;
- protected Current UpgradeCur;
- protected Current UnlockAheadCur;
- protected string Desc;
- protected string Label;
- protected string Anim;
- protected string UpgradeCD;
- protected string UpgradeFml;
- protected string UpgradePlus;
- protected string UpgradePerson;
- protected string UpgradeDuration;
- protected string UpgradeCoinOnce;
- #endregion
- public double CoolTimer; //冷却计时
- public double UsingTimer; //冷却计时
- protected float NewPlus;
- protected float NewPerson;
- protected float NewSkillCD;
- protected float NewDuration;
- protected float NewCoinOnce;
- protected float NewSkillCdBuff;
- protected float NewPersonBuff;
- protected float NewCoinPerson;
- protected float NewCoinOnceBuff;
- protected double NewUpgradeAmt;
- public SkillStatus ItemStatus
- {
- get { return _ItemStatus; }
- set
- {
- _ItemStatus = value;
- if (Tab == SkillTab.Null) //该技能不生成技能条
- {
- return;
- }
- if (_ItemStatus == SkillStatus.Cool)
- {
- ManaData.CoolList.Add(this);
- }
- else if (_ItemStatus == SkillStatus.Buy)
- {
- ItemBtnLab.text = string.Format("购买\n{0}{1}", UseCur, UseAmt);
- }
- else if (_ItemStatus == SkillStatus.Use)
- {
- ManaData.UsingList.Add(this);
- }
- else if (_ItemStatus == SkillStatus.Lock)
- {
- ItemBtnLab.text = string.Format("提前解锁\n等级{0}", UnlockLv);
- }
- else if (_ItemStatus == SkillStatus.UnLock)
- {
- ItemBtnLab.text = string.Format("解锁");
- }
- else if (_ItemStatus == SkillStatus.Upgrade)
- {
- ItemBtnLab.text = string.Format("升级");
- }
- else
- {
- throw new Exception();
- }
- }
- }
- public SkillStatus _ItemStatus;
- #endregion
- public Skill(XmlAttributeCollection attributes)
- {
- #region 配置
- Icon = attributes[30].Value;
- Desc = attributes[29].Value;
- Anim = attributes[31].Value;
- Label = attributes[32].Value;
- Name = attributes[1].Value;
- UnlockPos = attributes[18].Value;
- UpgradeCD = attributes[28].Value;
- UpgradeFml = attributes[23].Value;
- UpgradePlus = attributes[24].Value;
- UpgradePerson = attributes[25].Value;
- UpgradeDuration = attributes[27].Value;
- UpgradeCoinOnce = attributes[26].Value;
- ClassID = IntParse(attributes[3].Value);
- UnlockLv = IntParse(attributes[13].Value);
- CD = FloatParse(attributes[12].Value);
- UseAmt = FloatParse(attributes[20].Value);
- Duration = FloatParse(attributes[11].Value);
- UnlockAmt = FloatParse(attributes[17].Value); //Sa0
- DiamondOnce = FloatParse(attributes[9].Value);
- UnlockAheadAmt = FloatParse(attributes[15].Value);
- Tab = SkillClassParse(attributes[2].Value);
- ReduceCD = BoolParse(attributes[5].Value);
- UpgradeAmt = UpgradeAmtParse(attributes[22].Value); //Sa1
-
- UseCur = CurrentParse(attributes[19].Value);
- UnlockCur = CurrentParse(attributes[16].Value);
- UpgradeCur = CurrentParse(attributes[21].Value);
- UnlockAheadCur = CurrentParse(attributes[14].Value);
- ValueBuffParse(out Person, out PersonBuff, attributes[7].Value);
- ValueBuffParse(out SkillCD, out SkillCdBuff, attributes[10].Value);
- ValueBuffParse(out CoinOnce, out CoinOnceBuff, attributes[8].Value);
- ValueBuffParse(out CoinPerson, out Plus, attributes[6].Value);
- #endregion
- SkillType = SkillType.Skill;
- }
- public override void RegistValue(double elapse, List<List<SkillRoot>> ffList)
- {
- NewPlus = Plus;
- NewPerson = Person;
- NewSkillCD = SkillCD;
- NewDuration = Duration;
- NewCoinOnce = CoinOnce;
- NewSkillCdBuff = SkillCdBuff;
- NewPersonBuff = PersonBuff;
- NewCoinPerson = CoinPerson;
- NewUpgradeAmt = UpgradeAmt;
- NewCoinOnceBuff = CoinOnceBuff;
- if (!string.IsNullOrEmpty(UpgradeFml))
- {
- for (int i = 0; i < Level; i++)
- {
- NewUpgradeAmt = FmlParse(UpgradeFml, NewUpgradeAmt);
- }
- }
- UpgradeValue(ref NewPlus, Plus, UpgradePlus, Level);
- UpgradeValue(ref NewSkillCdBuff, UpgradeCD, Level);
- UpgradeValue(ref NewPersonBuff, PersonBuff, UpgradePerson, Level);
- UpgradeValue(ref NewCoinOnceBuff, UpgradeCoinOnce, Level);
- UpgradeValue(ref NewPerson, Person, UpgradePerson, Level);
- UpgradeValue(ref NewSkillCD, SkillCD, UpgradeCD, Level);
- UpgradeValue(ref NewDuration, Duration, UpgradeDuration, Level);
- UpgradeValue(ref NewCoinOnce, CoinOnce, UpgradeCoinOnce, Level);
- UpgradeValue(ref NewCoinPerson, CoinPerson, UpgradePlus, Level);
- ItemTit.text = Name;
- ItemLab.text = GetDescription(0);
- ItemBtn.onClick.AddListener(OnClick);
- if (_ItemStatus != SkillStatus.Lock && _ItemStatus != SkillStatus.UnLock)
- {
- ManaLog.Log(string.Format("初始化<color=red>{0}</color> 等级 : {1}", Name, Level));
- }
- if (_ItemStatus == SkillStatus.Use)
- {
- Effect();
- if (UsingTimer < elapse)
- {
- if (ffList.Count > 0)
- {
- if (UsingTimer < ManaData.CircleTimer)
- {
- ffList[0].UniqueAdd(this);
- }
- else
- {
- int ffCircle = 1 + Mathf.FloorToInt((float)(UsingTimer - ManaData.CircleTimer / ManaData.CircleTime));
- ffList[ffCircle].UniqueAdd(this);
- }
- }
- }
- else
- {
- UsingTimer -= elapse;
- ItemBtnLab.color = new Color(38 / 255f, 155 / 255f, 1, 1);
- }
- }
- else if (_ItemStatus == SkillStatus.Cool)
- {
- CoolTimer -= elapse;
- }
- ItemStatus = ItemStatus;
- }
- public virtual bool DoCool()
- {
- CoolTimer -= Time.deltaTime;
- TimeSpan timeSpan = new TimeSpan(0, 0, (int)CoolTimer);
- ItemBtnLab.text = string.Format("冷却中\n剩余时间({0}:{1})", timeSpan.Minutes, timeSpan.Seconds);
- if (CoolTimer <= 0)
- {
- ItemStatus = SkillStatus.Buy;
- ManaData.CoolList.Remove(this);
- return true;
- }
- else
- {
- return false;
- }
- }
- public override void ReceiveCool(float amt, bool isCurrent, bool isBuff)
- {
- if (!ReduceCD && ItemStatus == SkillStatus.Cool)
- {
- return;
- }
- if (isCurrent) //减少当前值
- {
- if (isBuff) //按比例减少
- {
- CoolTimer -= CD * amt;
- }
- else //按数值减少
- {
- CoolTimer -= amt;
- }
- }
- else //减少最大值
- {
- if (isBuff) //按比例减少
- {
- CdBuff -= amt;
- }
- else //按数值减少
- {
- CD -= amt;
- }
- }
- }
- public override void OnLevelChange()
- {
- if (ManaData.Level >= UnlockLv) //到达解锁等级
- {
- if (ItemStatus == SkillStatus.Lock)
- {
- if (UnlockCur == Current.Free) //自动解锁
- {
- Unlock();
- }
- else //付费解锁
- {
- ItemStatus = SkillStatus.UnLock;
- }
- }
- }
- }
- protected void OnClick()
- {
- if (ManaData.Connect == false)
- {
- ManaReso.Get("Fg_Reconnect").TweenForCG();
- return;
- }
- ManaReso.Get("Fe_Info").TweenForCG();
- ManaReso.SetText("Fe_Tit", Name);
- if (ItemStatus == SkillStatus.Buy)
- {
- ManaReso.SetText("Fe_Lab1", GetDescription(0));
- ManaReso.SetText("Fe_BtnLab", string.Format("购买({0}{1})", UseCur, UseAmt));
- ManaReso.SetButtonEvent
- (
- "Fe_Btn",
- () =>
- {
- Use();
- ManaReso.Get("Fe_Info").TweenBacCG();
- }
- );
- }
- else if (ItemStatus == SkillStatus.Use)
- {
- }
- else if (ItemStatus == SkillStatus.Lock)
- {
- ManaReso.SetText("Fe_Lab0", "");
- ManaReso.SetText("Fe_Lab1", GetDescription(0));
- ManaReso.SetText("Fe_BtnLab", string.Format("提前解锁({0}{1})", UnlockAheadCur, UnlockAheadAmt));
- ManaReso.SetButtonEvent
- (
- "Fe_Btn",
- () =>
- {
- UnlockAhead();
- ManaReso.Get("Fe_Info").TweenBacCG();
- }
- );
- }
- else if (ItemStatus == SkillStatus.UnLock)
- {
- ManaReso.SetText("Fe_Lab0", "");
- ManaReso.SetText("Fe_Lab1", GetDescription(0));
- ManaReso.SetText("Fe_BtnLab", string.Format("解锁({0}{1})", UnlockCur, UnlockAmt));
- ManaReso.SetButtonEvent
- (
- "Fe_Btn",
- () =>
- {
- Unlock();
- ManaReso.Get("Fe_Info").TweenBacCG();
- }
- );
- }
- else if (ItemStatus == SkillStatus.Upgrade)
- {
- ManaReso.SetText("Fe_Lab0", GetDescription(0));
- ManaReso.SetText("Fe_Lab1", GetDescription(1));
- ManaReso.SetText("Fe_BtnLab", string.Format("升级({0}{1:0})", UpgradeCur, NewUpgradeAmt));
- ManaReso.SetButtonEvent
- (
- "Fe_Btn",
- () =>
- {
- Upgrade();
- }
- );
- }
- else
- {
- throw new Exception();
- }
- }
- protected virtual void Upgrade()
- {
- if (ManaData.Pay(NewUpgradeAmt, UpgradeCur))
- {
- Level++;
- NewUpgradeAmt = FmlParse(UpgradeFml, NewUpgradeAmt);
- UpgradeValue(ref NewPlus, Plus, UpgradePlus, 1);
- UpgradeValue(ref NewSkillCdBuff, UpgradeCD, 1);
- UpgradeValue(ref NewPersonBuff, PersonBuff, UpgradePerson, 1);
- UpgradeValue(ref NewCoinOnceBuff, UpgradeCoinOnce, 1);
- UpgradeValue(ref NewPerson, Person, UpgradePerson, 1);
- UpgradeValue(ref NewSkillCD, SkillCD, UpgradeCD, 1);
- UpgradeValue(ref NewDuration, Duration, UpgradeDuration, 1);
- UpgradeValue(ref NewCoinOnce, CoinOnce, UpgradeCoinOnce, 1);
- UpgradeValue(ref NewCoinPerson, CoinPerson, UpgradePlus, 1);
- ItemLab.text = GetDescription(0);
- ManaReso.SetText("Fe_Lab0", GetDescription(0));
- ManaReso.SetText("Fe_Lab1", GetDescription(1));
- ManaReso.SetText("Fe_BtnLab", string.Format("升级({0}{1:0})", UpgradeCur, NewUpgradeAmt));
- ManaLog.Log(string.Format("<color=red>{0}</color> 升级 : {1}", Name, Level));
- if (ItemStatus == SkillStatus.Use) //更新技能效果
- {
- Annul();
- Effect();
- }
- }
- }
- protected virtual void Use()
- {
- if (ManaData.Pay(UseAmt, UseCur))
- {
- CoolTimer = CD * (1 + CdBuff);
- UsingTimer = NewDuration;
- if (Math.Abs(Duration) < 0.0005f)
- {
- ItemStatus = SkillStatus.Cool;
- }
- else
- {
- ItemStatus = SkillStatus.Use;
- ItemBtnLab.color = new Color(38/255f, 155/255f, 1, 1);
- }
- Effect();
- EffectOnce();
- #region 调试输出
- StringBuilder strb = new StringBuilder();
- strb.AppendFormat("使用技能 : <color=red>{0}</color>", Name);
- if (Math.Abs(NewPlus) > 0.0005f)
- {
- strb.AppendFormat(" 收入加成<color=red>+{0}%</color>", NewPlus * 100);
- }
- if (Math.Abs(NewPerson) > 0.0005f)
- {
- strb.AppendFormat(" 参观人次<color=red>+{0}</color>", NewPerson);
- }
- if (Math.Abs(NewPersonBuff) > 0.0005f)
- {
- strb.AppendFormat(" 参观人次<color=red>+{0}%</color>", NewPersonBuff * 100);
- }
- if (Math.Abs(NewCoinPerson) > 0.0005f)
- {
- strb.AppendFormat(" 每次金币<color=red>+{0}</color>", NewCoinPerson);
- }
- if (Math.Abs(NewSkillCD) > 0.0005f)
- {
- strb.AppendFormat(" 减少冷却<color=red>{0}</color>", NewSkillCD);
- }
- if (Math.Abs(NewSkillCdBuff) > 0.0005f)
- {
- strb.AppendFormat(" 减少冷却<color=red>{0}%</color>", NewSkillCdBuff * 100);
- }
- if (Math.Abs(NewCoinOnce) > 0.0005f)
- {
- strb.AppendFormat(" 获得金币<color=red>{0}</color>", NewCoinOnce);
- }
- if (Math.Abs(NewCoinOnceBuff) > 0.0005f)
- {
- strb.AppendFormat(" 获得金币<color=red>{0}</color>", ManaData.Person * ManaData.CoinPerson * ManaData.CircleTime * NewCoinOnceBuff);
- }
- if (Math.Abs(DiamondOnce) > 0.0005f)
- {
- strb.AppendFormat(" 获得钻石<color=red>{0}</color>", DiamondOnce);
- }
- if (Math.Abs(NewDuration) > 0.0005f)
- {
- strb.AppendFormat(" 持续时间<color=red>{0}</color>秒", NewDuration);
- }
- else
- {
- strb.Append(" <color=red>永久有效</color>");
- }
- ManaLog.Log(strb.ToString());
- #endregion
- }
- }
- protected virtual void Unlock()
- {
- if (ManaData.Pay(UnlockAmt, UnlockCur))
- {
- if (UseCur != Current.Free) //使用类型
- {
- ItemStatus = SkillStatus.Buy;
- }
- else if (UpgradeCur != Current.Free) //升级类型
- {
- ItemStatus = SkillStatus.Upgrade;
- }
- else
- {
- throw new Exception();
- }
- ManaLog.Log(string.Format("技能<color=red>{0}</color>已解锁", Name));
- }
- }
- protected virtual void UnlockAhead()
- {
- if (ItemStatus != SkillStatus.Lock)
- {
- ManaLog.Log("您并不需要提前解锁");
- return;
- }
- if (ManaData.Pay(UnlockAheadAmt, UnlockAheadCur))
- {
- if (UseCur != Current.Free) //使用类型
- {
- ItemStatus = SkillStatus.Buy;
- }
- else if (UpgradeCur != Current.Free) //升级类型
- {
- ItemStatus = SkillStatus.Upgrade;
- }
- else
- {
- throw new Exception();
- }
- ManaLog.Log(string.Format("技能<color=red>{0}</color>已解锁", Name));
- }
- }
- protected void UpgradeValue(ref float target, float baseValue, string fml, int offset)
- {
- if (Math.Abs(target) < 0.0005f)
- {
- return;
- }
- if (string.IsNullOrEmpty(fml))
- {
- }
- else if (fml.Contains("%"))
- {
- float step = float.Parse(fml.Replace("%", "")) / 100;
- target += baseValue * step * offset;
- }
- else
- {
- target += float.Parse(fml) * offset;
- }
- }
- public override void Annul() //注销技能
- {
- ItemBtnLab.color = new Color(1, 1, 1, 1);
- ItemStatus = SkillStatus.Cool;
- ManaData.SkillPlus -= NewPlus;
- ManaData.SkillPerson -= NewPerson;
- ManaData.SkillPersonBuff -= NewPersonBuff;
- ManaData.SkillCoinPerson -= NewCoinPerson;
- if (Math.Abs(NewSkillCD) > 0.0005f)
- {
- for (int i = 0; i < ManaData.SkillList.Count; i++)
- {
- ManaData.SkillList[i].ReceiveCool(-NewSkillCD, true, false);
- }
- }
- if (Math.Abs(NewSkillCdBuff) > 0.0005f)
- {
- for (int i = 0; i < ManaData.SkillList.Count; i++)
- {
- ManaData.SkillList[i].ReceiveCool(-NewSkillCdBuff, true, true);
- }
- }
- ManaLog.Log(string.Format("技能结束 <color=red>{0}</color>", Name));
- }
- public override bool DoUse()
- {
- UsingTimer -= Time.deltaTime;
- ItemLab.text = UsingTimer.ToString("0.0");
- if (UsingTimer <= 0)
- {
- Annul();
- ManaData.UsingList.Remove(this);
- return true;
- }
- else
- {
- return false;
- }
- }
- protected void Effect()
- {
- ManaData.SkillPerson += NewPerson;
- ManaData.SkillPlus += NewPlus;
- ManaData.SkillPersonBuff += NewPersonBuff;
- ManaData.SkillCoinPerson += NewCoinPerson;
- if (Math.Abs(NewSkillCD) > 0.0005f)
- {
- for (int i = 0; i < ManaData.SkillList.Count; i++)
- {
- ManaData.SkillList[i].ReceiveCool(NewSkillCD, true, false);
- }
- }
- if (Math.Abs(NewSkillCdBuff) > 0.0005f)
- {
- for (int i = 0; i < ManaData.SkillList.Count; i++)
- {
- ManaData.SkillList[i].ReceiveCool(NewSkillCdBuff, true, true);
- }
- }
- }
- protected void EffectOnce()
- {
- ManaData.Coin += NewCoinOnce;
- ManaData.Coin += ManaData.Person * ManaData.CoinPerson * ManaData.CircleTime * NewCoinOnceBuff;
- ManaData.Diamond += DiamondOnce;
- }
- #region 解读器
- protected string GetDescription(int offset)
- {
- float temp;
- string[] strings = Desc.Split('[', ']');
- StringBuilder stringBuilder = new StringBuilder();
- for (int i = 0; i < strings.Length; i++)
- {
- if (strings[i].Contains("lv"))
- {
- }
- else if (strings[i].Contains("&person&"))
- {
- #region MyRegion
- if (Math.Abs(Person) > 0.0005f)
- {
- temp = NewPerson;
- UpgradeValue(ref temp, Person, UpgradePerson, offset);
- UpgradeUnit(ref temp, strings[i]);
- stringBuilder.Append(temp);
- }
- else if (Math.Abs(PersonBuff) > 0.0005f)
- {
- temp = NewPersonBuff;
- UpgradeValue(ref temp, PersonBuff, UpgradePerson, offset);
- stringBuilder.Append(string.Format("{0}%", temp * 100));
- }
- else
- {
- }
- #endregion
- }
- else if (strings[i].Contains("&duration&"))
- {
- #region MyRegion
- temp = NewDuration;
- UpgradeValue(ref temp, Duration, UpgradeDuration, offset);
- UpgradeUnit(ref temp, strings[i]);
- stringBuilder.Append(temp.ToString("0.0"));
- #endregion
- }
- else if (strings[i].Contains("&coin_once&"))
- {
- #region MyRegion
- if (Math.Abs(CoinOnce) > 0.0005f)
- {
- temp = NewCoinOnce;
- UpgradeValue(ref temp, CoinOnce, UpgradeCoinOnce, offset);
- stringBuilder.Append(temp);
- }
- else if (Math.Abs(CoinOnceBuff) > 0.0005f)
- {
- temp = NewCoinOnceBuff;
- UpgradeValue(ref temp, CoinOnceBuff, UpgradeCoinOnce, offset);
- stringBuilder.Append(string.Format("{0}%", temp * 100));
- }
- else
- {
- throw new Exception();
- }
- #endregion
- }
- else
- {
- stringBuilder.Append(strings[i]);
- }
- }
- return stringBuilder.ToString();
- } //得到说明
- protected double UpgradeAmtParse(string str)
- {
- if (string.IsNullOrEmpty(str))
- {
- return UnlockAmt; //Sa
- }
- else
- {
- return double.Parse(str);
- }
- }
- #endregion
- }
|