123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737 |
- 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 float UnlockAheadAmt
- {
- get { return UnlockAheadBaseAmt + (UnlockLv - ManaCenter.Level - 1) * UnlockAheadDeltaAmt; }
- }
- public override string ID
- {
- get
- {
- return "Skill" + ID_;
- }
- }
- public bool CoolLock;
- public float CD;
- public float Person;
- public float SkillCD;
- public float UseAmt;
- public float Duration;
- public float CoinOnce;
- public float CoinPerson;
- public float DiamondOnce;
- public double UpgradeAmt;
- public float Plus;
- public float CdBuff = 1;
- public float PersonBuff;
- public float SkillCdBuff;
- public float CoinOnceBuff;
- public int UnlockLv;
- public float UnlockAmt;
- public float UnlockAheadBaseAmt;
- public float UnlockAheadDeltaAmt;
- public string UnlockPos;
- public Current BuyCur;
- public Current UnlockCur;
- public Current UpgradeCur;
- public Current UnlockAheadCur;
- public string Label;
- public string Anim;
- public string UpgradeCD;
- public string UpgradeFml;
- public string UpgradePlus;
- public string UpgradePerson;
- public string UpgradeDuration;
- public string UpgradeCoinOnce;
- #endregion
- public float UseTimer;
- public float CoolTimer;
- public float NewPlus;
- public float NewPerson;
- public float NewSkillCD;
- public float NewDuration;
- public float NewCoinOnce;
- public float NewSkillCdBuff;
- public float NewPersonBuff;
- public float NewCoinPerson;
- public float NewCoinOnceBuff;
- public double NewUpgradeAmt;
- public override SkillStatus ItemStatus
- {
- get { return ItemStatus_; }
- set
- {
- ItemStatus_ = value;
- if (ItemStatus_ == SkillStatus.Buy)
- {
- ItemBtn.interactable = true;
- if (BuyCur == Current.AD)
- {
- ManaLan.Add(ItemBtnLab, new LanStr("Common", "AD"));
- }
- else
- {
- ManaLan.Add(ItemBtnLab, new LanStr("UI", "Fe_BtnLab3"), "\n", Auxiliary.ImageParse(BuyCur), UseAmt.ToString("0"));
- }
- }
- else if (ItemStatus_ == SkillStatus.Use)
- {
- ItemBtn.interactable = false;
- }
- else if (ItemStatus_ == SkillStatus.Lock)
- {
- ItemBtn.interactable = true;
- ManaLan.Add(ItemBtnLab, new LanStr("UI", "Fe_BtnLab0"), "\n", new LanStr("UI", "Fe_BtnLab4"), UnlockLv.ToString());
- }
- else if (ItemStatus_ == SkillStatus.Cool)
- {
- ItemBtn.interactable = false;
- }
- }
- }
- #endregion
- public Skill(XmlAttributeCollection attribute)
- {
- #region 配置
- ID_ = int.Parse(attribute[0].Value);
- Icon_ = attribute[31].Value;
- Anim = attribute[32].Value;
- Label = attribute[33].Value;
- UnlockPos = attribute[19].Value;
- UpgradeCD = attribute[29].Value;
- UpgradeFml = attribute[24].Value;
- UpgradePlus = attribute[25].Value;
- UpgradePerson = attribute[26].Value;
- UpgradeDuration = attribute[28].Value;
- UpgradeCoinOnce = attribute[27].Value;
- UnlockLv = Auxiliary.IntParse(attribute[13].Value,0);
- ItemIndex = Auxiliary.IntParse(attribute[3].Value,0);
- CD = Auxiliary.FloatParse(attribute[12].Value,0);
- UseAmt = Auxiliary.FloatParse(attribute[21].Value,0);
- Duration = Auxiliary.FloatParse(attribute[11].Value,0);
- UnlockAmt = Auxiliary.FloatParse(attribute[18].Value,0);
- DiamondOnce = Auxiliary.FloatParse(attribute[9].Value,0);
- UnlockAheadBaseAmt = Auxiliary.FloatParse(attribute[16].Value,0);
- UnlockAheadDeltaAmt = Auxiliary.FloatParse(attribute[15].Value, 0);
- SkillTab = SkillClassParse(attribute[2].Value);
- CoolLock = Auxiliary.BoolParse(attribute[5].Value, false);
- UpgradeAmt = UpgradeAmtParse(attribute[23].Value);
-
- BuyCur = Auxiliary.CurrentParse(attribute[20].Value);
- UnlockCur = Auxiliary.CurrentParse(attribute[17].Value);
- UpgradeCur = Auxiliary.CurrentParse(attribute[22].Value);
- UnlockAheadCur = Auxiliary.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 void AnnulB()
- {
- ManaCenter.SkillPlus -= NewPlus;
- ManaCenter.SkillPerson -= NewPerson;
- ManaCenter.SkillPersonBuff -= NewPersonBuff;
- ManaCenter.SkillCoinPerson -= NewCoinPerson;
- if (!NewSkillCD.Equal(0))
- {
- for (int i = 0; i < ManaCenter.SkillList.Count; i++)
- {
- ManaCenter.SkillList[i].ReceiveCool(-NewSkillCD, true, false);
- }
- }
- if (!NewSkillCdBuff.Equal(0))
- {
- for (int i = 0; i < ManaCenter.SkillList.Count; i++)
- {
- ManaCenter.SkillList[i].ReceiveCool(-NewSkillCdBuff, true, true);
- }
- }
- }
- public virtual bool DoCool()
- {
- CoolTimer -= Time.fixedDeltaTime;
-
- TimeSpan timeSpan = new TimeSpan(0, 0, Mathf.CeilToInt(CoolTimer));
- if (timeSpan.Hours >= 1)
- {
- ItemBtnLab.text = string.Format("{0}\n{1}{2}:{3}", Language.GetStr("UI", "Fe_BtnLab6"), Language.GetStr("UI", "Fe_BtnLab7"), timeSpan.Hours.ToString("00"), timeSpan.Minutes.ToString("00"));
- }
- else
- {
- ItemBtnLab.text = string.Format("{0}\n{1}{2}:{3}", Language.GetStr("UI", "Fe_BtnLab6"), Language.GetStr("UI", "Fe_BtnLab7"), timeSpan.Minutes.ToString("00"), timeSpan.Seconds.ToString("00"));
- }
- if (CoolTimer <= 0)
- {
- ItemStatus = SkillStatus.Buy;
- return true;
- }
- else
- {
- return false;
- }
- }
- public override bool DoUse()
- {
- UseTimer -= Time.fixedDeltaTime;
- TimeSpan timeSpan = new TimeSpan(0, 0, Mathf.CeilToInt(UseTimer));
- if (timeSpan.Hours >= 1)
- {
- ItemBtnLab.text = string.Format("{0}\n{1}{2}:{3}", Language.GetStr("UI", "Fe_BtnLab8"), Language.GetStr("UI", "Fe_BtnLab7"), timeSpan.Hours.ToString("00"), timeSpan.Minutes.ToString("00"));
- }
- else
- {
- ItemBtnLab.text = string.Format("{0}\n{1}{2}:{3}", Language.GetStr("UI", "Fe_BtnLab8"), Language.GetStr("UI", "Fe_BtnLab7"), timeSpan.Minutes.ToString("00"), timeSpan.Seconds.ToString("00"));
- }
- if (UseTimer <= 0)
- {
- AnnulA();
- return true;
- }
- else
- {
- return false;
- }
- }
- public override void AnnulA()
- {
- CoolTimer = CD * CdBuff - 1;
- ItemStatus = SkillStatus.Cool;
- ManaCenter.CoolList.Add(this);
- AnnulB();
- }
- public override void UpdateStatus()
- {
- if (!ManaCenter.Complete)
- {
- return;
- }
- if (ManaCenter.Level >= UnlockLv)
- {
- if (ItemStatus == SkillStatus.Lock)
- {
- ItemIcon.material = null;
- ItemStatus = SkillStatus.Buy;
- }
- }
- }
- protected virtual void UseB()
- {
- float temp = NewCoinOnce + ManaCenter.CoinPerson * NewCoinOnceBuff;
- ManaCenter.AddCoin(temp, StaticsManager.ItemID.获得金币, StaticsManager.ConsumeModule.AD);
- ManaCenter.AddDiamond(DiamondOnce, StaticsManager.ItemID.获得钻石, StaticsManager.ConsumeModule.AD);
- StringBuilder sb = new StringBuilder();
- if (!temp.Equal(0))
- {
- sb.AppendFormat("{0}{1}{2}", Language.GetStr("UI", "J_Info0"), "<(金币)>", temp.ToString("0"));
- }
- if (!DiamondOnce.Equal(0))
- {
- sb.AppendFormat("{0}{1}{2}", Language.GetStr("UI", "J_Info0"), "<(钻石)>", DiamondOnce.ToString("0"));
- }
- string str = sb.ToString();
- if (!string.IsNullOrEmpty(str))
- {
- ManaInfo.Show(sb.ToString(), 10f);
- }
- }
- protected virtual void UseA()
- {
- if (UseTimer.Equal(-1))
- {
- AnnulA();
- }
- else
- {
- ItemStatus = SkillStatus.Use;
- ManaCenter.UseList.Add(this);
- }
- ManaCenter.SkillPlus += NewPlus;
- ManaCenter.SkillPerson += NewPerson;
- ManaCenter.SkillPersonBuff += NewPersonBuff;
- ManaCenter.SkillCoinPerson += NewCoinPerson;
- if (!NewSkillCD.Equal(0))
- {
- for (int i = 0; i < ManaCenter.SkillList.Count; i++)
- {
- ManaCenter.SkillList[i].ReceiveCool(NewSkillCD, true, false);
- }
- }
- if (!NewSkillCdBuff.Equal(0))
- {
- for (int i = 0; i < ManaCenter.SkillList.Count; i++)
- {
- ManaCenter.SkillList[i].ReceiveCool(NewSkillCdBuff, true, true);
- }
- }
- }
- protected virtual void Buy()
- {
- if (ID_ == 5)
- {
- StaticsManager.GetInstance().AdClicked(1);
- }
- else if (ID_ == 6)
- {
- StaticsManager.GetInstance().AdClicked(2);
- }
- ManaCenter.Pay
- (
- ID,
- UseAmt,
- BuyCur,
- () =>
- {
- ManaAudio.PlayClip(Clip.SkillClip);
- if (BuyCur != Current.AD)
- {
- ManaCenter.SkillAmt++;
- }
- UseTimer = NewDuration - 1;
-
- UseA();
- UseB();
- ManaInfo.Show(string.Format("{0}{1}", Language.GetStr("UI", "J_Info1"), Language.GetStr("SkillName", ID)), 10f);
- },
- StaticsManager.ItemID.使用技能,
- StaticsManager.ConsumeModule.Shop
- );
- }
- protected virtual void OnClick()
- {
- ManaAudio.PlayClip(Clip.BtnClip);
- if (ItemStatus == SkillStatus.Buy)
- {
- if (BuyCur == Current.AD)
- {
- Buy();
- }
- else
- {
- ManaReso.Get("Fe_Info").TweenForCG();
- ManaReso.SetText("Fe_Tit", Name);
- ManaReso.SetSprite("Fe_Icon", Icon);
- ManaReso.SetText("Fe_Lab0", "");
- ManaReso.SetText("Fe_Lab1", GetDescription(0));
- ManaReso.SetText("Fe_BtnLab", string.Format("{0}({1}{2:0})", Language.GetStr("UI", "Fe_BtnLab3"), Auxiliary.ImageParse(BuyCur), UseAmt));
- ManaReso.SetButtonEvent
- (
- "Fe_Btn",
- () =>
- {
- Buy();
- ManaReso.Get("Fe_Info").TweenBacCG();
- }
- );
- }
- }
- else if (ItemStatus == SkillStatus.Lock)
- {
- ManaReso.Get("Fe_Info").TweenForCG();
- ManaReso.SetText("Fe_Tit", Name);
- ManaReso.SetSprite("Fe_Icon", Icon);
- ManaReso.SetText("Fe_Lab0", "");
- ManaReso.SetText("Fe_Lab1", GetDescription(0));
- ManaReso.SetText("Fe_BtnLab", string.Format("{0}({1}{2:0})", Language.GetStr("UI", "Fe_BtnLab0"), Auxiliary.ImageParse(UnlockAheadCur), UnlockAheadAmt.ToString("0")));
- ManaReso.SetButtonEvent
- (
- "Fe_Btn",
- () =>
- {
- UnlockAhead();
- ManaReso.Get("Fe_Info").TweenBacCG();
- }
- );
- }
- }
- protected virtual void UnlockAhead()
- {
- ManaCenter.Pay
- (
- ID,
- UnlockAheadAmt,
- UnlockAheadCur,
- () =>
- {
- ManaAudio.PlayClip(Clip.BtnClip);
- ItemIcon.material = null;
- ItemStatus = SkillStatus.Buy;
- },
- StaticsManager.ItemID.提前解锁技能,
- StaticsManager.ConsumeModule.Shop
- );
- }
- public override void Reactive()
- {
- if (ItemStatus == SkillStatus.Use)
- {
- AnnulB();
- ManaCenter.UseList.Remove(this);
- }
- else if (ItemStatus == SkillStatus.Cool)
- {
- ManaCenter.CoolList.Remove(this);
- }
- }
- public override void RegistValue(bool firstRegist, 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;
- if (ItemStatus_ == SkillStatus.Lock || ItemStatus_ == SkillStatus.UnLock)
- {
- ItemIcon.material = Lib.GrayMat;
- }
- else
- {
- ItemIcon.material = null;
- }
- if (ItemStatus_ == SkillStatus.Use)
- {
- UseA();
- if (UseTimer < elapse)
- {
- ManaCenter.UseList.Remove(this);
- if (useList.Count > 0)
- {
- if (UseTimer < ManaCenter.CircleTimer)
- {
- useList[0].UniqueAdd(this);
- }
- else
- {
- int circle = 1 + Mathf.FloorToInt((UseTimer - ManaCenter.CircleTimer)/ManaCenter.CircleTime);
- useList[circle].UniqueAdd(this);
- }
- }
- }
- else
- {
- UseTimer -= elapse;
- }
- }
- else if (ItemStatus_ == SkillStatus.Cool)
- {
- CoolTimer -= elapse;
- ManaCenter.CoolList.Add(this);
- }
- ItemBtn.onClick.RemoveAllListeners();
- ItemBtn.onClick.AddListener(OnClick);
- ItemLab.text = GetDescription(0);
- ItemStatus = ItemStatus;
- }
- public override void ReceiveCool(float amt, bool current, bool buff)
- {
- if (!CoolLock)
- {
- return;
- }
- if (current)
- {
- if (ItemStatus != SkillStatus.Cool)
- {
- return;
- }
- if (buff)
- {
- CoolTimer -= CD * amt;
- }
- else
- {
- CoolTimer -= amt;
- }
- }
- else
- {
- if (buff)
- {
- CdBuff = 1 - amt;
- }
- else
- {
- CD -= amt;
- }
- }
- }
- #region 解读器
- protected double UpgradeAmtParse(string str)
- {
- if (string.IsNullOrEmpty(str))
- {
- return UnlockAmt;
- }
- else
- {
- return double.Parse(str);
- }
- }
- protected override 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 (!Person.Equal(0))
- {
- temp = NewPerson;
- UpgradeValue(ref temp, Person, UpgradePerson, offset);
- UpgradeUnit(ref temp, strings[i]);
- float remainder = temp % 1;
- if (remainder > 0)
- {
- stringBuilder.Append(temp.ToString("0") + "+");
- }
- else
- {
- stringBuilder.Append(temp.ToString("0"));
- }
- }
- else if (!PersonBuff.Equal(0))
- {
- temp = NewPersonBuff;
- UpgradeValue(ref temp, 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 (!CoinOnce.Equal(0))
- {
- temp = NewCoinOnce;
- UpgradeValue(ref temp, CoinOnce, UpgradeCoinOnce, offset);
- stringBuilder.Append(temp.ToString("0"));
- }
- else if (!CoinOnceBuff.Equal(0))
- {
- temp = NewCoinOnceBuff;
-
- UpgradeValue(ref temp, 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 (!CoinPerson.Equal(0))
- {
- temp = NewCoinPerson;
- UpgradeValue(ref temp, CoinPerson, UpgradePlus, offset);
- float remainder = temp % 1;
- if (remainder > 0)
- {
- stringBuilder.Append(temp.ToString("0") + "+");
- }
- else
- {
- stringBuilder.Append(temp.ToString("0"));
- }
- }
- else if (!Plus.Equal(0))
- {
- temp = NewPlus;
- UpgradeValue(ref temp, UpgradePlus, offset);
- stringBuilder.Append(string.Format("{0:0}%", temp * 100));
- }
- else
- {
- throw new Exception();
- }
- #endregion
- }
- else
- {
- stringBuilder.Append(strings[i]);
- }
- }
- return stringBuilder.ToString();
- }
- #endregion
- }
|