using UnityEngine; using UnityEngine.UI; using System; using System.Xml; using System.Text; using System.Collections; using System.Collections.Generic; public class Ability : SkillRoot { #region 变量 #region 配置 public override string ID { get { return "Ability" + ID_; } } 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 ValidSlot; protected bool ValidAnim; 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) { if (UnlockAheadCur == Current.Free) { ItemBtn.interactable = false; ManaLan.Add(ItemBtnLab, new LanStr("UI", "Fe_BtnLab4"), UnlockLv.ToString()); } else { ItemBtn.interactable = true; ManaLan.Add(ItemBtnLab, new LanStr("UI", "Fe_BtnLab0"), "\n", new LanStr("UI", "Fe_BtnLab4"), UnlockLv.ToString()); } } else if (_ItemStatus == SkillStatus.UnLock) { ItemBtn.interactable = true; ManaLan.Add(ItemBtnLab, new LanStr("UI", "Fe_BtnLab1")); } else if (_ItemStatus == SkillStatus.Upgrade) { ItemBtn.interactable = true; ManaLan.Add(ItemTit, new LanStr("SkillName", ID), " ", Level .ToString()); ManaLan.Add(ItemBtnLab, new LanStr("UI", "Fe_BtnLab2")); } else { throw new Exception(_ItemStatus.ToString()); } } } public SkillStatus _ItemStatus; #endregion public Ability(XmlAttributeCollection attribute) { #region 配置 ID_ = int.Parse(attribute[0].Value); Icon = attribute[20].Value; Anim = attribute[21].Value; Label = attribute[22].Value; UnlockPos = attribute[12].Value; UpgradeCD = attribute[18].Value; UpgradeFml = attribute[15].Value; UpgradePlus = attribute[16].Value; UpgradePerson = attribute[17].Value; ClassID = IntParse(attribute[3].Value); UnlockLv = IntParse(attribute[7].Value); UnlockAmt = FloatParse(attribute[11].Value); UnlockAheadAmt = FloatParse(attribute[9].Value); SkillTab = SkillClassParse(attribute[2].Value); UpgradeAmt = UpgradeAmtParse(attribute[14].Value); UnlockCur = CurrentParse(attribute[10].Value); UpgradeCur = CurrentParse(attribute[13].Value); UnlockAheadCur = CurrentParse(attribute[8].Value); ValueBuffParse(out Person, out PersonBuff, attribute[5].Value); ValueBuffParse(out SkillCD, out SkillCdBuff, attribute[6].Value); ValueBuffParse(out CoinPerson, out Plus, attribute[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 Annul() { if (ID == "Ability1") { ManaData.Person -= NewPerson; ManaData.CoinPerson -= NewCoinPerson; } else { ManaData.SkillPerson -= NewPerson; ManaData.SkillCoinPerson -= NewCoinPerson; } 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); } } } public override void RegistValue(float elapse, List> ffList, XmlAttributeCollection attribute) { Level = int.Parse(attribute[3].Value); _ItemStatus = (SkillStatus)Enum.Parse(typeof(SkillStatus), attribute[2].Value); NewPlus = Plus; NewPerson = Person; NewSkillCD = SkillCD; NewSkillCdBuff = SkillCdBuff; NewPersonBuff = PersonBuff; NewCoinPerson = CoinPerson; NewUpgradeAmt = UpgradeAmt; ManaLan.Add(ItemTit, new LanStr("SkillName", ID)); ItemLab.text = Description(0); ItemBtn.onClick.AddListener(OnClick); if (_ItemStatus == SkillStatus.Upgrade) { ManaDebug.Log(string.Format("技能{0}已解锁 等级 : {1}", Name, Level)); 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); if (Level > 0) { UseConti(); } } ItemStatus = ItemStatus; } 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)) { ManaData.Elf++; ManaDebug.Log(string.Format("技能{0}已解锁", Name)); if (UpgradeCur != Current.Free) { ItemStatus = SkillStatus.Upgrade; } else { throw new Exception(); } } } protected void OnClick() { if (ManaTutorial.TutorialA || ManaTutorial.TutorialB && ManaData.Level >= 200) { TutorialClick(); } else { RegularClick(); } } protected void Upgrade() { if (ManaTutorial.TutorialA || (ManaTutorial.TutorialA && ManaData.Level >= 200)) { TutorialUpgrade(); } else { RegularUpgrade(); } } protected void UseConti() { if (ValidAnim == false) { if (!string.IsNullOrEmpty(Anim)) { string[] strings = Anim.Split(','); if (strings.Length == 1) { ManaGarden.AnimList.Add((ObjType) Enum.Parse(typeof(ObjType), strings[0])); } else if (strings.Length > 1) { ManaReso.Get(strings[0], Folder.Scene, true, ManaReso.Get(strings[1]), false); } } } if (ValidSlot == false) { ValidSlot = true; if (!string.IsNullOrEmpty(UnlockPos)) { for (int i = 0; i < int.Parse(UnlockPos); i++) { ManaGarden.UnlockSlot(); } } } ManaData.Person += NewPerson; ManaData.CoinPerson += NewCoinPerson; 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); } if (!string.IsNullOrEmpty(UnlockPos)) { int amt = int.Parse(UnlockPos); strb.AppendFormat(" 解锁了{0}块土地", amt); } strb.Append(" 永久有效"); ManaDebug.Log(strb.ToString()); #endregion } protected void UnlockAhead() { if (ItemStatus != SkillStatus.Lock) { ManaDebug.Log("您并不需要提前解锁"); return; } if (ManaData.Pay(UnlockAheadAmt, UnlockAheadCur)) { ManaData.Elf++; ManaDebug.Log(string.Format("技能{0}已解锁", Name)); if (UpgradeCur != Current.Free) { ItemStatus = SkillStatus.Upgrade; } else { throw new Exception(); } } } private void TutorialClick() { ManaReso.Get("Fe_Info").TweenForCG(); ManaReso.SetText("Fe_Tit", Name); ManaReso.SetSprite("Fe_Icon", ItemIcon.sprite); 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)); ManaReso.AddButtonEventOnetime ( "Fe_Btn", () => { TutorialUpgrade(); ManaReso.Get("Fe_Info").TweenBacCG(); if (ManaTutorial.TutorialA) { ManaTutorial.EndStep7(); } else if (ManaTutorial.TutorialB) { ManaTutorial.EndStep10(); } } ); } else { throw new Exception(); } } private void RegularClick() { if (ManaServer.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.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 { throw new Exception(); } } private void TutorialUpgrade() { if (ID == "Ability1") { Level += 20; ManaData.Level += 20; } else { Level++; } ManaData.Elf++; Annul(); 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); ManaLan.Add(ItemTit, new LanStr("SkillName", ID), " ", Level.ToString()); 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)); UseConti(); if (ValidAnim == false) { ValidAnim = true; if (!string.IsNullOrEmpty(Anim)) { string[] strings = Anim.Split(','); if (strings.Length == 1) { if (ManaGarden.PlantList.Count == 0) { return; } Flower flower = ManaGarden.PlantList.Random().Flower; flower.PlayAnim(ManaGarden.AnimList.Last(0)); ManaReso.Get