123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734 |
- 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 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;
- ManaText.Add(ItemBtnLab, new LanStr("UI", "Fe_BtnLab4"), UnlockLv.ToString());
- }
- else
- {
- ItemBtn.interactable = true;
- ManaText.Add(ItemBtnLab, new LanStr("UI", "Fe_BtnLab0"), "\n", new LanStr("UI", "Fe_BtnLab4"), UnlockLv.ToString());
- }
- }
- else if (_ItemStatus == SkillStatus.UnLock)
- {
- ItemBtn.interactable = true;
- ManaText.Add(ItemBtnLab, new LanStr("UI", "Fe_BtnLab1"));
- }
- else if (_ItemStatus == SkillStatus.Upgrade)
- {
- ItemBtn.interactable = true;
- ManaText.Add(ItemTit, new LanStr("SkillName", _Name), " ", (Level + 1).ToString());
- ManaText.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;
- _Name = "Ability" + ID;
- 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 (_Name == "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<List<SkillRoot>> 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;
- ManaText.Add(ItemTit, new LanStr("SkillName", _Name));
- ItemLab.text = Description(0);
- ItemBtn.onClick.AddListener(OnClick);
- if (_ItemStatus == SkillStatus.Upgrade)
- {
- ManaDebug.Log(string.Format("技能<color=red>{0}</color>已解锁 等级 : {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);
-
- 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.ElfLevel++;
- ManaDebug.Log(string.Format("技能<color=red>{0}</color>已解锁", Name));
- UseConti();
- if (UpgradeCur != Current.Free)
- {
- ItemStatus = SkillStatus.Upgrade;
- }
- else
- {
- throw new Exception();
- }
- }
- }
- protected void OnClick()
- {
- if (Initializer.Tutorial)
- {
- TutorialClick();
- }
- else
- {
- RegularClick();
- }
- }
- protected void Upgrade()
- {
- if (Initializer.Tutorial)
- {
- TutorialUpgrade();
- }
- else
- {
- RegularUpgrade();
- }
- }
- protected void UseConti()
- {
- if (ValidAnim == false)
- {
- ValidAnim = true;
- 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.Character, false, 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("使用技能 : <color=red>{0}</color>", Name);
- if (Math.Abs(NewPlus) > 0.0005f)
- {
- strb.AppendFormat(" 收入加成<color=red>+{0}%</color>", NewPlus * 100);
- }
- if (Math.Abs(NewPerson) > 0.0005f)
- {
- strb.AppendFormat(" 参观人次<color=red>+{0}</color>", NewPerson);
- }
- if (Math.Abs(NewPersonBuff) > 0.0005f)
- {
- strb.AppendFormat(" 参观人次<color=red>+{0}%</color>", NewPersonBuff * 100);
- }
- if (Math.Abs(NewCoinPerson) > 0.0005f)
- {
- strb.AppendFormat(" 每次金币<color=red>+{0}</color>", NewCoinPerson);
- }
- if (Math.Abs(SkillCD) > 0.0005f)
- {
- strb.AppendFormat(" 减少冷却上限<color=red>{0}</color>", SkillCD);
- }
- if (Math.Abs(SkillCdBuff) > 0.0005f)
- {
- strb.AppendFormat(" 减少冷却上限<color=red>{0}%</color>", SkillCdBuff * 100);
- }
- if (!string.IsNullOrEmpty(UnlockPos))
- {
- int amt = int.Parse(UnlockPos);
- strb.AppendFormat(" 解锁了<color=red>{0}</color>块土地", amt);
- }
- strb.Append(" <color=red>永久有效</color>");
- ManaDebug.Log(strb.ToString());
- #endregion
- }
- protected void UnlockAhead()
- {
- if (ItemStatus != SkillStatus.Lock)
- {
- ManaDebug.Log("您并不需要提前解锁");
- return;
- }
- if (ManaData.Pay(UnlockAheadAmt, UnlockAheadCur))
- {
- ManaData.ElfLevel++;
- ManaDebug.Log(string.Format("技能<color=red>{0}</color>已解锁", Name));
- UseConti();
- 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",
- () =>
- {
- Upgrade();
- ManaReso.Get("Fe_Info").TweenBacCG();
- ManaTutorial.EndStep7();
- }
- );
- }
- 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.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 (_Name == "Ability1")
- {
- Level += 20;
- ManaData.Level += 20;
- }
- else
- {
- Level++;
- }
- ManaData.ElfLevel++;
- 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);
- ManaText.Add(ItemTit, new LanStr("SkillName", _Name), " ", (Level + 1).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("<color=red>{0}</color> 升级 : {1}", Name, Level));
- UseConti();
- }
- private void RegularUpgrade()
- {
- if (ManaData.Pay(NewUpgradeAmt, UpgradeCur))
- {
- if (_Name == "Ability1")
- {
- ManaData.Level++;
- }
- Level++;
- ManaData.ElfLevel++;
- 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);
- ManaText.Add(ItemTit, new LanStr("SkillName", _Name), " ", (Level + 1).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("<color=red>{0}</color> 升级 : {1}", Name, Level));
- 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("&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;
- UpgradeValue(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]);
- 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));
- }
- #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
- }
|