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 string Label; protected string Anim; protected string UpgradeCD; protected string UpgradeFml; protected string UpgradePlus; protected string UpgradePerson; #endregion public bool ValidSlot = true; protected bool ValidAnim = true; protected string Elf; protected string Item; 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_BtnLab1"), "\n", 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; if (UnlockCur == Current.Free) { ManaLan.Add(ItemBtnLab, new LanStr("UI", "Fe_BtnLab1")); } else { ItemBtnLab.text = Language.GetStr("UI", "Fe_BtnLab1") + "\n" + ImageParse(UnlockCur) + Auxiliary.ShrinkNumberStr(UnlockAmt); } } else if (ItemStatus_ == SkillStatus.Upgrade) { ItemBtn.interactable = true; ItemBtnLab.text = Language.GetStr("UI", "Fe_BtnLab2") + "\n" + ImageParse(UpgradeCur) + Auxiliary.ShrinkNumberStr(NewUpgradeAmt); } } } 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; UnlockLv = Auxiliary.IntParse(attribute[7].Value,0); ItemIndex = Auxiliary.IntParse(attribute[3].Value,0); UnlockAmt = Auxiliary.FloatParse(attribute[11].Value,0); UnlockAheadAmt = Auxiliary.FloatParse(attribute[9].Value,0); 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 SkillType = SkillType.Ability; } public override void Reactive() { if (Level > 0) { Annul(); } } public override void RegistValue(float elapse, List> useList, 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; if (ItemStatus == SkillStatus.Upgrade) { if (Level > 0) { for (int i = 0; i < Level - 1; i++) { NewUpgradeAmt = Auxiliary.FmlParse(UpgradeFml, "a", NewUpgradeAmt.ToString()); } UpgradeValue(ref NewPlus, Plus, UpgradePlus, Level - 1); UpgradeSkillCdBuff(ref NewSkillCdBuff, UpgradeCD, Level - 1); UpgradeValue(ref NewPersonBuff, PersonBuff, UpgradePerson, Level - 1); UpgradeValue(ref NewPerson, Person, UpgradePerson, Level - 1); UpgradeValue(ref NewSkillCD, SkillCD, UpgradeCD, Level - 1); UpgradeValue(ref NewCoinPerson, CoinPerson, UpgradePlus, Level - 1); } UseA(); } ItemStatus = ItemStatus; ItemBtn.onClick.RemoveAllListeners(); ItemBtn.onClick.AddListener(OnClick); ItemLab.text = Description(0); } public override void SwitchLanguage() { base.SwitchLanguage(); ItemStatus = ItemStatus; } protected void UseA() { if (ValidAnim) { ValidAnim = false; if (!string.IsNullOrEmpty(Anim)) { if (Anim.Contains("Elf")) { string[] strings = Anim.Split(','); for (int i = 1; i < strings.Length; i++) { ManaGarden.ElfList.Add((ObjType)Enum.Parse(typeof(ObjType), strings[i])); } Elf = strings[1]; } else if (Anim.Contains("Item")) { string[] strings = Anim.Split(','); for (int i = 1; i < strings.Length; i++) { ManaReso.Get(strings[i]).TweenForSr(); } Item = strings[1]; } } } if (ValidSlot) { ValidSlot = false; for (int i = 0; i < Auxiliary.IntParse(UnlockPos, 0); i++) { ManaGarden.UnlockSlot(); } } ManaData.Person += NewPerson; ManaData.CoinPerson += NewCoinPerson; ManaData.SkillPlus += NewPlus; ManaData.SkillPersonBuff += NewPersonBuff; if (!NewSkillCD.Equal(0)) { for (int i = 0; i < ManaData.SkillList.Count; i++) { ManaData.SkillList[i].ReceiveCool(NewSkillCD, false, false); } } if (!NewSkillCdBuff.Equal(0)) { for (int i = 0; i < ManaData.SkillList.Count; i++) { ManaData.SkillList[i].ReceiveCool(NewSkillCdBuff, false, true); } } } protected void UseB() { if (!string.IsNullOrEmpty(Elf)) { ManaData.ElfLevel++; } } protected void Zoom() { if (!string.IsNullOrEmpty(Elf)) { if (ManaGarden.PlantList.Count == 0) { return; } Flower flower = ManaGarden.PlantList.Random().Flower; flower.GetElf(ManaGarden.ElfList.Last(0), 0, 0, 0, 0); ManaReso.Get("Fe_Info").TweenBacCG(); ManaReso.Get("F_Manage").TweenBacGra(); Tween tween = ManaReso.Get("F_Manage0").GetTweenVec(); tween.AddEventOnetime ( EventType.BackwardFinish, () => { ManaReso.Get("MainCamera").Zoom2D(1.5f, 3f, 1, flower.ElfList.Last(0), Curve.EaseOutQuad); } ); } else if (!string.IsNullOrEmpty(Item)) { Tween tween = ManaReso.Get(Item).GetTweenSr(); Vector3 pos = ManaReso.Get(Item).position; pos.z = -2; tween.AddEventOnetime ( EventType.ForwardFinish, () => { ManaReso.GetFirework(pos); } ); ManaReso.Get("Fe_Info").TweenBacCG(); ManaReso.Get("F_Manage").TweenBacGra(); tween = ManaReso.Get("F_Manage0").GetTweenVec(); tween.AddEventOnetime ( EventType.BackwardFinish, () => { ManaReso.Get("MainCamera").Zoom2D(3.5f, 3f, 1, ManaReso.Get(Item), Curve.EaseOutQuad); } ); } } protected void Unlock() { ManaData.Pay(ID, UnlockAmt, UnlockCur, () => { ItemStatus = SkillStatus.Upgrade; ManaAudio.PlayClip(Clip.SkillClip); Level = 1; if (ID == "Ability1") { ManaData.Level += 1; } UseA(); UseB(); Zoom(); }); } protected void OnClick() { ManaAudio.PlayClip(Clip.BtnClip); ManaReso.Get("Fe_Info").TweenForCG(); ManaReso.SetText("Fe_Tit", Name); ManaReso.SetSprite("Fe_Icon", Icon); 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)); if (UnlockCur == Current.Free) { ManaReso.SetText("Fe_BtnLab", string.Format("{0}", Language.GetStr("UI", "Fe_BtnLab1"))); } else { 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), Auxiliary.ShrinkNumberStr(NewUpgradeAmt))); ManaReso.SetButtonEvent ( "Fe_Btn", () => { Upgrade(); ItemLab.text = Description(0); ItemBtnLab.text = Language.GetStr("UI", "Fe_BtnLab2") + "\n" + ImageParse(UpgradeCur) + Auxiliary.ShrinkNumberStr(NewUpgradeAmt); ManaReso.SetText("Fe_Tit", Name); 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), Auxiliary.ShrinkNumberStr(NewUpgradeAmt))); } ); } } protected void Upgrade() { ManaData.Pay(ID, NewUpgradeAmt, UpgradeCur, () => { Level += 1; ManaAudio.PlayClip(Clip.SkillClip); if (ID == "Ability1") { ManaData.Level += 1; } 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); UpgradeSkillCdBuff(ref NewSkillCdBuff, UpgradeCD, 1); UpgradeValue(ref NewPersonBuff, PersonBuff, UpgradePerson, 1); UseA(); UseB(); }); } protected void UnlockAhead() { if (ItemStatus != SkillStatus.Lock) { Toast.Show(1.5f, "您并不需要提前解锁"); return; } ManaData.Pay(ID, UnlockAheadAmt, UnlockAheadCur, () => { if (UnlockCur == Current.Free) { Unlock(); } else { ManaAudio.PlayClip(Clip.SkillClip); ItemStatus = SkillStatus.UnLock; } }); } public override void Annul() { 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); } } } public override void UpdateStatus() { if (!ManaData.InitiateComplete) { return; } if (ManaData.Level >= UnlockLv) { if (ItemStatus == SkillStatus.Lock) { if (UnlockCur == Current.Free) { Unlock(); } else { ItemStatus = SkillStatus.UnLock; } } } } #region 解读器 protected double UpgradeAmtParse(string str) { if (string.IsNullOrEmpty(str)) { return UnlockAmt; } else { return double.Parse(str); } } 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]); float remainder = temp % 1; if (remainder > 0) { stringBuilder.Append(temp.ToString("0") + "+"); } else { 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("&skill_cd&")) { #region MyRegion if (Math.Abs(SkillCD) > 0.0005f) { temp = NewSkillCD; UpgradeValue(ref temp, SkillCD, UpgradeCD, offset); UpgradeUnit(ref temp, strings[i]); stringBuilder.Append(temp.ToString("0")); } else if (Math.Abs(SkillCdBuff) > 0.0005f) { temp = NewSkillCdBuff; UpgradeSkillCdBuff(ref temp, UpgradeCD, offset); stringBuilder.Append(string.Format("{0:0}%", temp * 100)); } #endregion } else if (strings[i].Contains("&coin_person&")) { #region MyRegion if (Math.Abs(CoinPerson) > 0.0005f) { temp = NewCoinPerson; UpgradeValue(ref temp, CoinPerson, UpgradePlus, 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 (Math.Abs(Plus) > 0.0005f) { temp = NewPlus; UpgradeValue(ref temp, Plus, UpgradePlus, offset); stringBuilder.Append(string.Format("{0:0}%", temp * 100)); } #endregion } else { stringBuilder.Append(strings[i]); } } return stringBuilder.ToString(); } #endregion }