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_; } } 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 UnlockAheadAmt; 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", ImageParse(BuyCur), UseAmt.ToString("0")); } } else if (ItemStatus_ == SkillStatus.Use) { ItemBtn.interactable = false; } else if (ItemStatus_ == SkillStatus.Lock) { ItemBtn.interactable = false; 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[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; 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[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); CoolLock = 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 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) { ItemStatus = SkillStatus.Buy; } } } protected virtual void UseB() { float temp = NewCoinOnce + ManaCenter.CoinPerson * NewCoinOnceBuff; ManaCenter.Coin += temp; ManaCenter.Diamond += DiamondOnce; 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() { 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); } ); } 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"), 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"), ImageParse(UnlockAheadCur), UnlockAheadAmt)); ManaReso.SetButtonEvent ( "Fe_Btn", () => { UnlockAhead(); ManaReso.Get("Fe_Info").TweenBacCG(); } ); } } protected virtual void UnlockAhead() { ManaCenter.Pay ( ID, UnlockAheadAmt, UnlockAheadCur, () => { ManaAudio.PlayClip(Clip.BtnClip); ItemStatus = SkillStatus.Buy; } ); } 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(float elapse, List> 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.Use) { UseA(); if (UseTimer < elapse) { 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 }