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 配置 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 SkillStatus ItemStatus { get { return _ItemStatus; } set { _ItemStatus = value; if (SkillTab == SkillTab.Null) { return; } if (_ItemStatus == SkillStatus.Cool) { ManaData.CoolList.Add(this); } else if (_ItemStatus == SkillStatus.Buy) { ManaText.Add(ItemBtnLab, ImageParse(BuyCur), UseAmt.ToString("0"), "\n", new LanStr("UI", "Fe_BtnLab3")); } else if (_ItemStatus == SkillStatus.Use) { } else if (_ItemStatus == SkillStatus.Lock) { ManaText.Add(ItemBtnLab, new LanStr("UI", "Fe_BtnLab0"), "\n", new LanStr("UI", "Fe_BtnLab4"), UnlockLv.ToString()); } else if (_ItemStatus == SkillStatus.UnLock) { ManaText.Add(ItemBtnLab, new LanStr("UI", "Fe_BtnLab1")); } else if (_ItemStatus == SkillStatus.Upgrade) { ManaText.Add(ItemBtnLab, new LanStr("UI", "Fe_BtnLab2")); } else { throw new Exception(); } } } 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; _Name ="Skill" +ID; 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; ClassID = IntParse(attribute[3].Value); UnlockLv = IntParse(attribute[13].Value); CD = FloatParse(attribute[12].Value); UseAmt = FloatParse(attribute[20].Value); Duration = FloatParse(attribute[11].Value); UnlockAmt = FloatParse(attribute[17].Value); DiamondOnce = FloatParse(attribute[9].Value); UnlockAheadAmt = FloatParse(attribute[15].Value); SkillTab = SkillClassParse(attribute[2].Value); ReduceCD = BoolParse(attribute[5].Value); 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; ManaData.CoolList.Remove(this); ManaDebug.Log(string.Format("技能{0}已冷却", Name)); return true; } else { return false; } } public override void Annul() { CoolTimer = CD * (1 + CdBuff); ItemStatus = SkillStatus.Cool; ItemBtnLab.color = Color.white; AnnulConti(); ManaDebug.Log(string.Format("技能结束 {0}", Name)); } public virtual void AnnulConti() { 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(); ManaData.UseList.Remove(this); return true; } else { return false; } } public override void UpdateStatus() { if (ManaData.Level >= UnlockLv) { if (ItemStatus == SkillStatus.Lock) { if (UnlockCur == Current.Free) { Unlock(); } else { ItemStatus = SkillStatus.UnLock; } } } } public override void RegistValue(float elapse, List> ffList, 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; ManaText.Add(ItemTit, new LanStr("SkillName", _Name)); ItemLab.text = Description(0); ItemBtn.onClick.AddListener(OnClick); if (_ItemStatus != SkillStatus.Lock && _ItemStatus != SkillStatus.UnLock) { ManaDebug.Log(string.Format("技能{0}已解锁", Name)); } else if (_ItemStatus == SkillStatus.Use) { UseConti(); if (UseTimer < elapse) { if (ffList.Count > 0) { if (UseTimer < ManaData.CircleTimer) { ffList[0].UniqueAdd(this); } else { int ffCircle = 1 + Mathf.FloorToInt((float)(UseTimer - ManaData.CircleTimer / ManaData.CircleTime)); ffList[ffCircle].UniqueAdd(this); } } } else { UseTimer -= elapse; ItemBtnLab.color = Color.blue; } } else if (_ItemStatus == SkillStatus.Cool) { CoolTimer -= elapse; } ItemStatus = ItemStatus; } 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 (ManaTutorial.TutorialA) { TutorialClick(); } else { RegularClick(); } } protected void UseConti() { 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 UseImmed() { ManaData.Coin += NewCoinOnce; ManaData.Coin += ManaData.CoinPerson * NewCoinOnceBuff; ManaData.Diamond += DiamondOnce; } protected virtual void Buy() { if (ManaData.Pay(UseAmt, BuyCur)) { ManaData.Skill++; UseTimer = NewDuration; ManaData.UseList.Add(this); if (Math.Abs(Duration) < 0.0005f) { ItemStatus = SkillStatus.Cool; } else { ItemStatus = SkillStatus.Use; ItemBtnLab.color = Color.blue; } UseConti(); UseImmed(); #region 调试 StringBuilder strb = new StringBuilder(); strb.AppendFormat("使用技能 : {0}", Name); if (Math.Abs(NewPlus) > 0.0005f) { strb.AppendFormat(" 收入加成+{0}%", NewPlus * 100); } if (Math.Abs(NewPerson) > 0.0005f) { strb.AppendFormat(" 参观人次+{0}", NewPerson); } if (Math.Abs(NewPersonBuff) > 0.0005f) { strb.AppendFormat(" 参观人次+{0}%", NewPersonBuff * 100); } if (Math.Abs(NewCoinPerson) > 0.0005f) { strb.AppendFormat(" 每次金币+{0}", NewCoinPerson); } if (Math.Abs(NewSkillCD) > 0.0005f) { strb.AppendFormat(" 减少冷却{0}", NewSkillCD); } if (Math.Abs(NewSkillCdBuff) > 0.0005f) { strb.AppendFormat(" 减少冷却{0}%", NewSkillCdBuff * 100); } if (Math.Abs(NewCoinOnce) > 0.0005f) { strb.AppendFormat(" 获得金币{0}", NewCoinOnce); } if (Math.Abs(NewCoinOnceBuff) > 0.0005f) { strb.AppendFormat(" 获得金币{0}", ManaData.Person * ManaData.CoinPerson * ManaData.CircleTime * NewCoinOnceBuff); } if (Math.Abs(DiamondOnce) > 0.0005f) { strb.AppendFormat(" 获得钻石{0}", DiamondOnce); } if (Math.Abs(NewDuration) > 0.0005f) { strb.AppendFormat(" 持续时间{0}秒", NewDuration); } else { strb.Append(" 永久有效"); } ManaDebug.Log(strb.ToString()); #endregion } } protected virtual void Unlock() { if (ManaData.Pay(UnlockAmt, UnlockCur)) { if (BuyCur != Current.Free) { ItemStatus = SkillStatus.Buy; } else if (UpgradeCur != Current.Free) { ItemStatus = SkillStatus.Upgrade; } else { throw new Exception(); } ManaDebug.Log(string.Format("技能{0}已解锁", Name)); } } protected virtual void Upgrade() { if (ManaTutorial.TutorialA || ManaTutorial.TutorialB && ManaData.Level >= 200) { TutorialUpgrade(); } else { RegularUpgrade(); } } protected virtual void UnlockAhead() { if (ItemStatus != SkillStatus.Lock) { ManaDebug.Log("您并不需要提前解锁"); return; } if (ManaData.Pay(UnlockAheadAmt, UnlockAheadCur)) { if (BuyCur != Current.Free) { ItemStatus = SkillStatus.Buy; } else if (UpgradeCur != Current.Free) { ItemStatus = SkillStatus.Upgrade; } else { throw new Exception(); } ManaDebug.Log(string.Format("技能{0}已解锁", Name)); } } private void TutorialClick() { ManaReso.Get("Fe_Info").TweenForCG(); ManaReso.SetText("Fe_Tit", Name); ManaReso.SetSprite("Fe_Icon", ItemIcon.sprite); if (ItemStatus == SkillStatus.Buy) { 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) { Tutorial.HightDisable(0, true); 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)); if (ManaTutorial.TutorialA) { ManaReso.AddButtonEventOnetime ( "Fe_Btn", () => { Upgrade(); ManaReso.Get("Fe_Info").TweenBacCG(); ManaTutorial.EndStep8(); } ); } } else if (ItemStatus == SkillStatus.Use) { } else { throw new Exception(); } } private void RegularClick() { if (ManaData.Connect == false) { ManaReso.Get("Fg_Reconnect").TweenForCG(); return; } ManaReso.Get("Fe_Info").TweenForCG(); ManaReso.SetText("Fe_Tit", Name); ManaReso.SetSprite("Fe_Icon", ItemIcon.sprite); if (ItemStatus == SkillStatus.Buy) { 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(); } ); } else if (ItemStatus == SkillStatus.Use) { } else { throw new Exception(); } } private void TutorialUpgrade() { Level++; if (ItemStatus == SkillStatus.Use) { AnnulConti(); } 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); ItemLab.text = Description(0); 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("{0}升级 : {1}", Name, Level)); if (ItemStatus == SkillStatus.Use) { UseConti(); } } private void RegularUpgrade() { if (ManaData.Pay(NewUpgradeAmt, UpgradeCur)) { Level++; if (ItemStatus == SkillStatus.Use) { AnnulConti(); } 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); ItemLab.text = Description(0); 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("{0}升级 : {1}", Name, Level)); if (ItemStatus == SkillStatus.Use) { UseConti(); } } } #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 }