123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802 |
- using UnityEngine;
- using UnityEngine.UI;
- using System;
- using System.Xml;
- using System.Linq;
- using System.Text;
- using System.Collections;
- using System.Collections.Generic;
- public class Skill : SkillRoot
- {
- #region 变量
- #region 配置
- public override string ID
- {
- get { return "Skill" + ID_; }
- }
- 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 bool ReduceCD;
- protected double UpgradeAmt;
- 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 BuyCur;
- protected Current UnlockCur;
- protected Current UpgradeCur;
- protected Current UnlockAheadCur;
- 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 float UseTimer;
- public float CoolTimer;
- 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 virtual SkillStatus ItemStatus
- {
- get { return ItemStatus_; }
- set
- {
- ItemStatus_ = value;
- if (SkillTab == SkillTab.Null)
- {
- return;
- }
- if (ItemStatus_ == SkillStatus.Buy)
- {
- if (BuyCur == Current.AD)
- {
- ManaLan.Add(ItemBtnLab, new LanStr("Common", "AD"));
- }
- else
- {
- ManaLan.Add(ItemBtnLab, ImageParse(BuyCur), UseAmt.ToString("0"), "\n", new LanStr("UI", "Fe_BtnLab3"));
- }
- }
- else if (ItemStatus_ == SkillStatus.Lock)
- {
- ManaLan.Add(ItemBtnLab, new LanStr("UI", "Fe_BtnLab0"), "\n", new LanStr("UI", "Fe_BtnLab4"), UnlockLv.ToString());
- }
- else if (ItemStatus_ == SkillStatus.UnLock)
- {
- if (UnlockCur == Current.Free)
- {
- ManaLan.Add(ItemBtnLab, new LanStr("UI", "Fe_BtnLab1"));
- }
- else
- {
- ManaLan.Add(ItemBtnLab, new LanStr("UI", "Fe_BtnLab1"), "\n", ImageParse(UnlockCur), UnlockAmt.ToString("0"));
- }
- }
- else if (ItemStatus_ == SkillStatus.Upgrade)
- {
- ManaLan.Add(ItemBtnLab, new LanStr("UI", "Fe_BtnLab2"), "\n", ImageParse(UpgradeCur), NewUpgradeAmt.ToString("0"));
- }
- }
- }
- public SkillStatus ItemStatus_;
- #endregion
- public Skill(XmlAttributeCollection attribute)
- {
- #region 配置
- ID_ = int.Parse(attribute[0].Value);
- Icon_ = attribute[30].Value;
- Anim = attribute[31].Value;
- Label = attribute[32].Value;
- UnlockPos = attribute[18].Value;
- UpgradeCD = attribute[28].Value;
- UpgradeFml = attribute[23].Value;
- UpgradePlus = attribute[24].Value;
- UpgradePerson = attribute[25].Value;
- UpgradeDuration = attribute[27].Value;
- UpgradeCoinOnce = attribute[26].Value;
- ItemIndex = Auxiliary.IntParse(attribute[3].Value,0);
- UnlockLv = Auxiliary.IntParse(attribute[13].Value,0);
- CD = Auxiliary.FloatParse(attribute[12].Value,0);
- UseAmt = Auxiliary.FloatParse(attribute[20].Value,0);
- Duration = Auxiliary.FloatParse(attribute[11].Value,0);
- UnlockAmt = Auxiliary.FloatParse(attribute[17].Value,0);
- DiamondOnce = Auxiliary.FloatParse(attribute[9].Value,0);
- UnlockAheadAmt = Auxiliary.FloatParse(attribute[15].Value,0);
- SkillTab = SkillClassParse(attribute[2].Value);
- ReduceCD = Auxiliary.BoolParse(attribute[5].Value, false);
- UpgradeAmt = UpgradeAmtParse(attribute[22].Value);
-
- BuyCur = CurrentParse(attribute[19].Value);
- UnlockCur = CurrentParse(attribute[16].Value);
- UpgradeCur = CurrentParse(attribute[21].Value);
- UnlockAheadCur = CurrentParse(attribute[14].Value);
-
- ValueBuffParse(out Person, out PersonBuff, attribute[7].Value);
- ValueBuffParse(out SkillCD, out SkillCdBuff, attribute[10].Value);
- ValueBuffParse(out CoinOnce, out CoinOnceBuff, attribute[8].Value);
- ValueBuffParse(out CoinPerson, out Plus, attribute[6].Value);
-
- #endregion
- SkillType = SkillType.Skill;
- }
- public virtual bool DoCool()
- {
- CoolTimer -= Time.deltaTime;
- TimeSpan timeSpan = new TimeSpan(0, 0, (int)CoolTimer);
- ItemBtnLab.text = string.Format("{0}\n{1}({2}:{3})", Language.GetStr("UI", "Fe_BtnLab6"), Language.GetStr("UI", "Fe_BtnLab7"), timeSpan.Minutes, timeSpan.Seconds);
- if (CoolTimer <= 0)
- {
- ItemStatus = SkillStatus.Buy;
- ManaDebug.Log(string.Format("技能<color=red>{0}</color>已冷却", Name));
- return true;
- }
- else
- {
- return false;
- }
- }
- public override void Annul()
- {
- CoolTimer = CD * (1 + CdBuff);
-
- ManaData.CoolList.Add(this);
- ItemStatus = SkillStatus.Cool;
- ItemBtnLab.color = Color.white;
- AnnulA();
- ManaDebug.Log(string.Format("技能结束 <color=red>{0}</color>", Name));
- }
- public virtual void AnnulA()
- {
- 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);
- }
- }
- }
- public override bool DoUse()
- {
- UseTimer -= Time.deltaTime;
- ItemLab.text = UseTimer.ToString("0.0");
- if (UseTimer <= 0)
- {
- Annul();
- return true;
- }
- else
- {
- return false;
- }
- }
- public override void UpdateStatus()
- {
- if (ManaData.Level >= UnlockLv)
- {
- if (ItemStatus == SkillStatus.Lock)
- {
- if (BuyCur == Current.Free)
- {
- ItemStatus = SkillStatus.UnLock;
- }
- else
- {
- ItemStatus = SkillStatus.Buy;
- }
- }
- }
- }
- public override void RegistValue(float elapse, List<List<Skill>> useList, XmlAttributeCollection attribute)
- {
- Level = int.Parse(attribute[3].Value);
- UseTimer = float.Parse(attribute[5].Value);
- CoolTimer = float.Parse(attribute[4].Value);
- ItemStatus = (SkillStatus)Enum.Parse(typeof(SkillStatus), attribute[2].Value);
- NewPlus = Plus;
- NewPerson = Person;
- NewSkillCD = SkillCD;
- NewDuration = Duration;
- NewCoinOnce = CoinOnce;
- NewSkillCdBuff = SkillCdBuff;
- NewPersonBuff = PersonBuff;
- NewCoinPerson = CoinPerson;
- NewUpgradeAmt = UpgradeAmt;
- NewCoinOnceBuff = CoinOnceBuff;
- ItemLab.text = Description(0);
- ItemBtn.onClick.AddListener(OnClick);
- if (ItemStatus == SkillStatus.Use)
- {
- UseA();
- if (UseTimer < elapse)
- {
- if (useList.Count > 0)
- {
- if (UseTimer < ManaData.CircleTimer)
- {
- useList[0].UniqueAdd(this);
- }
- else
- {
- int ffCircle = 1 + Mathf.FloorToInt(UseTimer - ManaData.CircleTimer / ManaData.CircleTime);
- useList[ffCircle].UniqueAdd(this);
- }
- }
- }
- else
- {
- UseTimer -= elapse;
- ItemBtnLab.color = Color.blue;
- }
- }
- else if (ItemStatus == SkillStatus.Cool)
- {
- CoolTimer -= elapse;
- }
- if (ItemStatus != SkillStatus.Lock && ItemStatus != SkillStatus.UnLock)
- {
- ManaDebug.Log(string.Format("技能<color=red>{0}</color>已解锁", Name));
- }
- }
- public override void ReceiveCool(float amt, bool current, bool buff)
- {
- if (!ReduceCD)
- {
- return;
- }
- if (current)
- {
- if (ItemStatus != SkillStatus.Cool)
- {
- return;
- }
- if (buff)
- {
- CoolTimer -= CD * amt;
- }
- else
- {
- CoolTimer -= amt;
- }
- }
- else
- {
- if (buff)
- {
- CdBuff -= amt;
- }
- else
- {
- CD -= amt;
- }
- }
- }
- protected void OnClick()
- {
- if (!ManaServer.Connect)
- {
- ManaReso.Get("Fg_Reconnect").TweenForCG();
- return;
- }
- ManaReso.Get("Fe_Info").TweenForCG();
- ManaReso.SetText("Fe_Tit", NameParse());
- ManaReso.SetSprite("Fe_Icon", Icon);
- if (ItemStatus == SkillStatus.Buy)
- {
- ManaReso.SetText("Fe_Lab0", "");
- ManaReso.SetText("Fe_Lab1", Description(0));
- ManaReso.SetText("Fe_BtnLab", string.Format("{0}({1}{2:0})", Language.GetStr("UI", "Fe_BtnLab3"), ImageParse(BuyCur), UseAmt));
- ManaReso.SetButtonEvent
- (
- "Fe_Btn",
- () =>
- {
- Buy();
- ManaReso.Get("Fe_Info").TweenBacCG();
- }
- );
- }
- else if (ItemStatus == SkillStatus.Lock)
- {
- ManaReso.SetText("Fe_Lab0", "");
- ManaReso.SetText("Fe_Lab1", Description(0));
- ManaReso.SetText("Fe_BtnLab", string.Format("{0}({1}{2:0})", Language.GetStr("UI", "Fe_BtnLab0"), ImageParse(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", Description(0));
- ManaReso.SetText("Fe_BtnLab", string.Format("{0}({1}{2:0})", Language.GetStr("UI", "Fe_BtnLab1"), ImageParse(UnlockCur), UnlockAmt));
- ManaReso.SetButtonEvent
- (
- "Fe_Btn",
- () =>
- {
- Unlock();
- ManaReso.Get("Fe_Info").TweenBacCG();
- }
- );
- }
- else if (ItemStatus == SkillStatus.Upgrade)
- {
- ManaReso.SetText("Fe_Lab0", Description(0));
- ManaReso.SetText("Fe_Lab1", Description(1));
- ManaReso.SetText("Fe_BtnLab", string.Format("{0}({1}{2:0})", Language.GetStr("UI", "Fe_BtnLab2"), ImageParse(UpgradeCur), NewUpgradeAmt));
- ManaReso.SetButtonEvent
- (
- "Fe_Btn",
- () =>
- {
- Upgrade();
- ItemLab.text = Description(0);
- ManaReso.SetText("Fe_Tit", NameParse());
- ManaReso.SetText("Fe_Lab0", Description(0));
- ManaReso.SetText("Fe_Lab1", Description(1));
- ManaReso.SetText("Fe_BtnLab", string.Format("{0}({1}{2:0})", Language.GetStr("UI", "Fe_BtnLab2"), ImageParse(UpgradeCur), NewUpgradeAmt));
- ManaDebug.Log(string.Format("<color=red>{0}</color>升级 : {1}", Name, Level));
- }
- );
- }
- }
- protected void UseA()
- {
- ManaData.UseList.Add(this);
- 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);
- }
- }
- }
- protected void UseB()
- {
- ManaData.Coin += NewCoinOnce;
- ManaData.Coin += ManaData.CoinPerson * NewCoinOnceBuff;
- ManaData.Diamond += DiamondOnce;
- }
- protected virtual void Buy()
- {
- if (!ManaData.Pay(UseAmt, BuyCur))
- {
- return;
- }
- ManaData.Skill++;
- UseTimer = NewDuration;
- if (Math.Abs(Duration) < 0.0005f)
- {
- ItemStatus = SkillStatus.Cool;
- }
- else
- {
- ItemStatus = SkillStatus.Use;
- ItemBtnLab.color = Color.blue;
- }
- UseA();
- UseB();
- #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>");
- }
- ManaDebug.Log(strb.ToString());
- #endregion
- }
- protected virtual void Unlock()
- {
- if (!ManaData.Pay(UnlockAmt, UnlockCur))
- {
- return;
- }
- if (BuyCur != Current.Free)
- {
- ItemStatus = SkillStatus.Buy;
- }
- else if (UpgradeCur != Current.Free)
- {
- ItemStatus = SkillStatus.Upgrade;
- }
- else
- {
- throw new Exception();
- }
- ManaDebug.Log(string.Format("技能<color=red>{0}</color>已解锁", Name));
- }
- protected virtual void Upgrade()
- {
- if (!ManaData.Pay(NewUpgradeAmt, UpgradeCur))
- {
- return;
- }
- Level++;
- if (ItemStatus == SkillStatus.Use)
- {
- AnnulA();
- }
- NewUpgradeAmt = Auxiliary.FmlParse(UpgradeFml, "a", NewUpgradeAmt.ToString());
- 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);
- if (ItemStatus == SkillStatus.Use)
- {
- UseA();
- }
- }
- protected virtual void UnlockAhead()
- {
- if (ItemStatus != SkillStatus.Lock)
- {
- ManaDebug.Log("您并不需要提前解锁");
- return;
- }
- if (!ManaData.Pay(UnlockAheadAmt, UnlockAheadCur))
- {
- return;
- }
- if (BuyCur != Current.Free)
- {
- ItemStatus = SkillStatus.Buy;
- }
- else if (UpgradeCur != Current.Free)
- {
- ItemStatus = SkillStatus.UnLock;
- }
- else
- {
- throw new Exception();
- }
- ManaDebug.Log(string.Format("技能<color=red>{0}</color>已解锁", Name));
- }
- #region 解读器
- protected override string Description(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.ToString("0"));
- }
- else if (Math.Abs(PersonBuff) > 0.0005f)
- {
- temp = NewPersonBuff;
- UpgradeValue(ref temp, PersonBuff, UpgradePerson, offset);
- stringBuilder.Append(string.Format("{0:0}%", temp * 100));
- }
- #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"));
- #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.ToString("0"));
- }
- else if (Math.Abs(CoinOnceBuff) > 0.0005f)
- {
- temp = NewCoinOnceBuff;
-
- UpgradeValue(ref temp, CoinOnceBuff, UpgradeCoinOnce, offset);
- stringBuilder.Append(temp.ToString("0"));
- }
- #endregion
- }
- else if (strings[i].Contains("&diamond_once&"))
- {
- #region MyRegion
- stringBuilder.Append(DiamondOnce.ToString("0"));
- #endregion
- }
- else if (strings[i].Contains("&coin_person&"))
- {
- #region MyRegion
-
- if (Math.Abs(CoinPerson) > 0.0005f)
- {
- temp = NewCoinPerson;
- UpgradeValue(ref temp, CoinPerson, UpgradePlus, offset);
- stringBuilder.Append(temp.ToString("0.0"));
- }
- else if (Math.Abs(Plus) > 0.0005f)
- {
- temp = NewPlus;
- UpgradeValue(ref temp, Plus, UpgradePlus, offset);
- stringBuilder.Append(string.Format("{0: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;
- }
- else
- {
- return double.Parse(str);
- }
- }
- #endregion
- }
|