using UnityEngine; using System; using System.Xml; using System.Text; using System.Collections; using System.Collections.Generic; public class Ability : SkillRoot { #region 变量 #region 配置 protected float Person; protected float SkillCD; protected float CoinPerson; protected double UpgradeAmt; protected float Plus; protected float PersonBuff; protected float SkillCdBuff; protected int UnlockLv; protected float UnlockAmt; protected float UnlockAheadAmt; protected string UnlockPos; protected Current UnlockCur; protected Current UpgradeCur; protected Current UnlockAheadCur; protected bool Article; protected string Desc; protected string Label; protected string Anim; protected string UpgradeCD; protected string UpgradeFml; protected string UpgradePlus; protected string UpgradePerson; #endregion protected float NewPlus; protected float NewPerson; protected float NewSkillCD; protected float NewSkillCdBuff; protected float NewPersonBuff; protected float NewCoinPerson; protected double NewUpgradeAmt; public SkillStatus ItemStatus { get { return _ItemStatus; } set { _ItemStatus = value; if (_ItemStatus == SkillStatus.Lock) { ItemBtnLab.text = string.Format("{0}\n{1}{2}", Language.GetStr("UI", "Fe_BtnLab0"), Language.GetStr("UI", "Fe_BtnLab4"), UnlockLv); } else if (_ItemStatus == SkillStatus.UnLock) { ItemBtnLab.text = string.Format(Language.GetStr("UI", "Fe_BtnLab1")); } else if (_ItemStatus == SkillStatus.Upgrade) { ItemBtnLab.text = string.Format(Language.GetStr("UI", "Fe_BtnLab2")); } else { throw new Exception(_ItemStatus.ToString()); } } } public SkillStatus _ItemStatus; #endregion public Ability(XmlAttributeCollection attributes) { #region 配置 ID = int.Parse(attributes[0].Value); Icon = attributes[20].Value; Desc = Language.GetStr("SkillDescription", "Ability" + ID); Anim = attributes[21].Value; Label = attributes[22].Value; Name = Language.GetStr("SkillName", "Ability" + ID); UnlockPos = attributes[12].Value; UpgradeCD = attributes[18].Value; UpgradeFml = attributes[15].Value; UpgradePlus = attributes[16].Value; UpgradePerson = attributes[17].Value; ClassID = IntParse(attributes[3].Value); UnlockLv = IntParse(attributes[7].Value); UnlockAmt = FloatParse(attributes[11].Value); UnlockAheadAmt = FloatParse(attributes[9].Value); SkillTab = SkillClassParse(attributes[2].Value); UpgradeAmt = UpgradeAmtParse(attributes[14].Value); UnlockCur = CurrentParse(attributes[10].Value); UpgradeCur = CurrentParse(attributes[13].Value); UnlockAheadCur = CurrentParse(attributes[8].Value); ValueBuffParse(out Person, out PersonBuff, attributes[5].Value); ValueBuffParse(out SkillCD, out SkillCdBuff, attributes[6].Value); ValueBuffParse(out CoinPerson, out Plus, attributes[4].Value); #endregion ValueBuffParse(out NewPerson, out NewPersonBuff, UpgradePerson); ValueBuffParse(out NewSkillCD, out NewSkillCdBuff, UpgradeCD); ValueBuffParse(out NewCoinPerson, out NewPlus, UpgradePlus); SkillType = SkillType.Ability; } public override void RegistValue(float elapse, List> ffList) { ItemTit.text = Name; ItemLab.text = Description(0); ItemBtn.onClick.AddListener(OnClick); NewPlus = Plus; NewPerson = Person; NewSkillCD = SkillCD; NewSkillCdBuff = SkillCdBuff; NewPersonBuff = PersonBuff; NewCoinPerson = CoinPerson; NewUpgradeAmt = UpgradeAmt; if (ItemStatus == SkillStatus.Upgrade) { ManaDebug.Log(string.Format("初始化{0} 等级 : {1}", Name, Level)); if (!string.IsNullOrEmpty(UpgradeFml)) { for (int i = 0; i < Level; i++) { NewUpgradeAmt = Auxiliary.FmlParse(UpgradeFml, "a", NewUpgradeAmt.ToString()); } } UpgradeValue(ref NewPlus, Plus, UpgradePlus, Level); UpgradeValue(ref NewSkillCdBuff, UpgradeCD, Level); UpgradeValue(ref NewPersonBuff, PersonBuff, UpgradePerson, Level); UpgradeValue(ref NewPerson, Person, UpgradePerson, Level); UpgradeValue(ref NewSkillCD, SkillCD, UpgradeCD, Level); UpgradeValue(ref NewCoinPerson, CoinPerson, UpgradePlus, Level); UsePerma(); } } public override void UpdateStatus() { if (ManaData.Level >= UnlockLv) { if (ItemStatus == SkillStatus.Lock) { if (UnlockCur == Current.Free) { Unlock(); } else { ItemStatus = SkillStatus.UnLock; } } } } protected void Unlock() { if (ManaData.Pay(UnlockAmt, UnlockCur)) { ManaDebug.Log(string.Format("技能{0}已解锁", Name)); UsePerma(); if (UpgradeCur != Current.Free) { ItemStatus = SkillStatus.Upgrade; } else { throw new Exception(); } } } 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.Lock) { ManaReso.SetText("Fe_Lab0", ""); ManaReso.SetText("Fe_Lab1", Description(0)); ManaReso.SetText("Fe_BtnLab", string.Format("{0}({1}{2})", Language.GetStr("UI", "Fe_BtnLab0"), 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})", Language.GetStr("UI", "Fe_BtnLab1"), 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"), UpgradeCur, NewUpgradeAmt)); ManaReso.SetButtonEvent ( "Fe_Btn", () => { Upgrade(); } ); } else { throw new Exception(); } } protected void Upgrade() { if (ManaData.Pay(NewUpgradeAmt, UpgradeCur)) { Level++; NewUpgradeAmt = Auxiliary.FmlParse(UpgradeFml, "a", NewUpgradeAmt.ToString()); UpgradeValue(ref NewPerson, Person, UpgradePerson, 1); UpgradeValue(ref NewSkillCD, SkillCD, UpgradeCD, 1); UpgradeValue(ref NewCoinPerson, CoinPerson, UpgradePlus, 1); UpgradeValue(ref NewPlus, Plus, UpgradePlus, 1); UpgradeValue(ref NewSkillCdBuff, UpgradeCD, 1); UpgradeValue(ref NewPersonBuff, PersonBuff, UpgradePerson, 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"), UpgradeCur, NewUpgradeAmt)); ManaDebug.Log(string.Format("{0} 升级 : {1}", Name, Level)); if (ItemStatus == SkillStatus.Use) { Annul(); UsePerma(); } } } protected void UsePerma() { if (Article == false) { Article = true; if (!string.IsNullOrEmpty(Anim)) { string[] strings = Anim.Split(','); ManaReso.Get(strings[0], Folder.Object, false, ManaReso.Get(strings[1]), true); } } if (Name == "花园") { ManaData.Person += Person; ManaData.CoinPerson += CoinPerson; } else { ManaData.SkillPerson += Person; ManaData.SkillCoinPerson += CoinPerson; } ManaData.SkillPlus += NewPlus; ManaData.SkillPersonBuff += NewPersonBuff; if (Math.Abs(NewSkillCD) > 0.0005f) { for (int i = 0; i < ManaData.SkillList.Count; i++) { ManaData.SkillList[i].ReceiveCool(NewSkillCD, false, false); } } if (Math.Abs(NewSkillCdBuff) > 0.0005f) { for (int i = 0; i < ManaData.SkillList.Count; i++) { ManaData.SkillList[i].ReceiveCool(NewSkillCdBuff, false, true); } } #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(SkillCD) > 0.0005f) { strb.AppendFormat(" 减少冷却上限{0}", SkillCD); } if (Math.Abs(SkillCdBuff) > 0.0005f) { strb.AppendFormat(" 减少冷却上限{0}%", SkillCdBuff * 100); } strb.Append(" 永久有效"); ManaDebug.Log(strb.ToString()); #endregion } protected void UnlockAhead() { if (ItemStatus != SkillStatus.Lock) { ManaDebug.Log("您并不需要提前解锁"); return; } if (ManaData.Pay(UnlockAheadAmt, UnlockAheadCur)) { UsePerma(); if (UpgradeCur != Current.Free) { ItemStatus = SkillStatus.Upgrade; } else { throw new Exception(); } ManaDebug.Log(string.Format("技能{0}已解锁", Name)); } } #region 解读器 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; } } protected 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 = Person + NewPerson * (Level + offset); UpgradeUnit(ref temp, strings[i]); stringBuilder.Append(temp); } else if (Math.Abs(PersonBuff) > 0.0005f) { temp = PersonBuff + NewPersonBuff * (Level + offset); stringBuilder.Append(string.Format("{0}%", temp * 100)); } else { } #endregion } else if (strings[i].Contains("&skill_cd&")) { #region MyRegion if (Math.Abs(SkillCD) > 0.0005f) { temp = SkillCD + NewSkillCD * (Level + offset); UpgradeUnit(ref temp, strings[i]); stringBuilder.Append(temp); } else if (Math.Abs(SkillCdBuff) > 0.0005f) { temp = SkillCdBuff + NewSkillCdBuff * (Level + offset); stringBuilder.Append(string.Format("{0}%", temp * 100)); } else { } #endregion } else if (strings[i].Contains("&coin_person&")) { #region MyRegion if (Math.Abs(CoinPerson) > 0.0005f) { temp = CoinPerson + NewCoinPerson * (Level+offset); UpgradeUnit(ref temp, strings[i]); stringBuilder.Append(temp); } else if (Math.Abs(Plus) > 0.0005f) { temp = Plus + NewPlus * (Level + offset); stringBuilder.Append(string.Format("{0}%", temp * 100)); } else { } #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 }