123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746 |
- 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 Config
- #region 配置
- public float UnlockAheadAmt
- {
- get { return UnlockAheadBaseAmt + (UnlockLv - Manager.GardenLevel - 1) * UnlockAheadDeltaAmt; }
- }
- public override string FullID
- {
- get { return SkillFullIDPrefix + ID; }
- }
- public bool CoolLock;
- public float CD;
- public float Person;
- public float SkillCD;
- public float UseAmt;
- public float Duration;
- public float CoinOnce;
- public float CoinPerson;
- public float DiamondOnce;
- public double UpgradeAmt;
- public float Plus;
- public float CdBuff = 1;
- public float PersonBuff;
- public float SkillCdBuff;
- public float CoinOnceBuff;
- public int UnlockLv;
- public float UnlockAmt;
- public float UnlockAheadBaseAmt;
- public float UnlockAheadDeltaAmt;
- public string UnlockPos;
- public Current BuyCur;
- public Current UnlockCur;
- public Current UpgradeCur;
- public Current UnlockAheadCur;
- public string Label;
- public string Anim;
- public string UpgradeCD;
- public string UpgradeFml;
- public string UpgradePlus;
- public string UpgradePerson;
- public string UpgradeDuration;
- public string UpgradeCoinOnce;
- #endregion
- public float UseTimer;
- public float CoolTimer;
- public float NewPlus;
- public float NewPerson;
- public float NewSkillCD;
- public float NewDuration;
- public float NewCoinOnce;
- public float NewSkillCdBuff;
- public float NewPersonBuff;
- public float NewCoinPerson;
- public float NewCoinOnceBuff;
- public double NewUpgradeAmt;
- public override SkillStatus ItemStatus
- {
- get { return itemStatus; }
- set
- {
- itemStatus = value;
- if (itemStatus == SkillStatus.Buy)
- {
- button.interactable = true;
- if (BuyCur == Current.AD)
- {
- LanguageManager.Add(ButtonTitle, new MulLanStr(LanguageLabel.Common__AD));
- }
- else
- {
- LanguageManager.Add(ButtonTitle, new MulLanStr(LanguageLabel.UI__Fe_BtnLab3), "\n", Auxiliary.ImageParse(BuyCur), UseAmt.ToString("0"));
- }
- }
- else if (itemStatus == SkillStatus.Use)
- {
- button.interactable = false;
- }
- else if (itemStatus == SkillStatus.Lock)
- {
- button.interactable = true;
- LanguageManager.Add(ButtonTitle, new MulLanStr(LanguageLabel.UI__Fe_BtnLab0), "\n", new MulLanStr(LanguageLabel.UI__Fe_BtnLab4), UnlockLv.ToString());
- }
- else if (itemStatus == SkillStatus.Cool)
- {
- button.interactable = false;
- }
- }
- }
- #endregion
- public Skill(XmlAttributeCollection attribute)
- {
- #region 配置
- ID = int.Parse(attribute[0].Value);
- icon = attribute[31].Value;
- Anim = attribute[32].Value;
- Label = attribute[33].Value;
- UnlockPos = attribute[19].Value;
- UpgradeCD = attribute[29].Value;
- UpgradeFml = attribute[24].Value;
- UpgradePlus = attribute[25].Value;
- UpgradePerson = attribute[26].Value;
- UpgradeDuration = attribute[28].Value;
- UpgradeCoinOnce = attribute[27].Value;
- UnlockLv = Auxiliary.StringToInt(attribute[13].Value,0);
- ItemIndex = Auxiliary.StringToInt(attribute[3].Value,0);
- CD = Auxiliary.StringToFloat(attribute[12].Value,0);
- UseAmt = Auxiliary.StringToFloat(attribute[21].Value,0);
- Duration = Auxiliary.StringToFloat(attribute[11].Value,0);
- UnlockAmt = Auxiliary.StringToFloat(attribute[18].Value,0);
- DiamondOnce = Auxiliary.StringToFloat(attribute[9].Value,0);
- UnlockAheadBaseAmt = Auxiliary.StringToFloat(attribute[16].Value,0);
- UnlockAheadDeltaAmt = Auxiliary.StringToFloat(attribute[15].Value, 0);
- SkillTab = SkillClassParse(attribute[2].Value);
- CoolLock = Auxiliary.StringToBool(attribute[5].Value, false);
- UpgradeAmt = GetUpgradeAmt(attribute[23].Value);
-
- BuyCur = Auxiliary.CurrentParse(attribute[20].Value);
- UnlockCur = Auxiliary.CurrentParse(attribute[17].Value);
- UpgradeCur = Auxiliary.CurrentParse(attribute[22].Value);
- UnlockAheadCur = Auxiliary.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 void AnnulBuff()
- {
- Manager.TempSkillCoinPersonBuff -= NewPlus;
- Manager.TempSkillPerson -= NewPerson;
- Manager.TempSkillPersonBuff -= NewPersonBuff;
- Manager.TempSkillCoinPerson -= NewCoinPerson;
- Manager.ExtraPersonSourceSpritesName.Remove(icon);
- Manager.ExtraCoinPersonSourceSpritesName.Remove(icon);
- if (!NewSkillCD.Equal(0))
- {
- for (int i = 0; i < Manager.SkillList.Count; i++)
- {
- Manager.SkillList[i].Cool(-NewSkillCD, true, false);
- }
- }
- if (!NewSkillCdBuff.Equal(0))
- {
- for (int i = 0; i < Manager.SkillList.Count; i++)
- {
- Manager.SkillList[i].Cool(-NewSkillCdBuff, true, true);
- }
- }
- }
- public virtual bool DoCD()
- {
- CoolTimer -= Time.deltaTime;
-
- TimeSpan timeSpan = new TimeSpan(0, 0, Mathf.CeilToInt(CoolTimer));
- if (timeSpan.Hours >= 1)
- {
- ButtonTitle.text = string.Format("{0}\n{1}{2}:{3}", Language.GetStr(LanguageLabel.UI__Fe_BtnLab6), Language.GetStr(LanguageLabel.UI__Fe_BtnLab7), timeSpan.Hours.ToString("00"), timeSpan.Minutes.ToString("00"));
- }
- else
- {
- ButtonTitle.text = string.Format("{0}\n{1}{2}:{3}", Language.GetStr(LanguageLabel.UI__Fe_BtnLab6), Language.GetStr(LanguageLabel.UI__Fe_BtnLab7), timeSpan.Minutes.ToString("00"), timeSpan.Seconds.ToString("00"));
- }
- if (CoolTimer <= 0)
- {
- ItemStatus = SkillStatus.Buy;
- return true;
- }
- else
- {
- return false;
- }
- }
- public override bool DoUpdate()
- {
- UseTimer -= Time.deltaTime;
- TimeSpan timeSpan = new TimeSpan(0, 0, Mathf.CeilToInt(UseTimer));
- if (timeSpan.Hours >= 1)
- {
- ButtonTitle.text = string.Format("{0}\n{1}{2}:{3}", Language.GetStr(LanguageLabel.UI__Fe_BtnLab8), Language.GetStr(LanguageLabel.UI__Fe_BtnLab7), timeSpan.Hours.ToString("00"), timeSpan.Minutes.ToString("00"));
- }
- else
- {
- ButtonTitle.text = string.Format("{0}\n{1}{2}:{3}", Language.GetStr(LanguageLabel.UI__Fe_BtnLab8), Language.GetStr(LanguageLabel.UI__Fe_BtnLab7), timeSpan.Minutes.ToString("00"), timeSpan.Seconds.ToString("00"));
- }
- if (UseTimer <= 0)
- {
- AnnulEffect();
- return true;
- }
- else
- {
- return false;
- }
- }
- public override void AnnulEffect()
- {
- CoolTimer = CD * CdBuff - 1;
- ItemStatus = SkillStatus.Cool;
- Manager.CoolSkillList.Add(this);
- AnnulBuff();
- }
- public override void UpdateStatus()
- {
- if (!Manager.Inited)
- {
- return;
- }
- if (Manager.GardenLevel >= UnlockLv)
- {
- if (ItemStatus == SkillStatus.Lock)
- {
- SkillIcon.material = null;
- ItemStatus = SkillStatus.Buy;
- }
- }
- }
- protected virtual void GetAward()
- {
- float temp = NewCoinOnce + Manager.CoinPerson * NewCoinOnceBuff;
- Manager.AddCoin(temp, StaticsManager.ItemID.获得金币, StaticsManager.ConsumeModule.AD);
- Manager.AddDiamond(DiamondOnce, StaticsManager.ItemID.获得钻石, StaticsManager.ConsumeModule.AD);
- StringBuilder sb = new StringBuilder();
- if (!temp.Equal(0))
- {
- sb.AppendFormat("{0}{1}{2}", Language.GetStr(LanguageLabel.UI__J_Info0), TransferLabel.CoinSprite, temp.ToString("0"));
- }
- if (!DiamondOnce.Equal(0))
- {
- sb.AppendFormat("{0}{1}{2}", Language.GetStr(LanguageLabel.UI__J_Info0), TransferLabel.DiamondSprite, DiamondOnce.ToString("0"));
- }
- string str = sb.ToString();
- if (!string.IsNullOrEmpty(str))
- {
- InfoBoxManager.GardenInfoBox.Display(sb.ToString(), 10f, Color.white, ResourceManager.LoadSprite("Atlas", Folder.Atlas));
- }
- }
- protected virtual void GetBuff()
- {
- if (UseTimer.Equal(-1))
- {
- AnnulEffect();
- }
- else
- {
- ItemStatus = SkillStatus.Use;
- Manager.UsingSkillList.Add(this);
- }
- Manager.TempSkillCoinPersonBuff += NewPlus;
- Manager.TempSkillPerson += NewPerson;
- Manager.TempSkillPersonBuff += NewPersonBuff;
- Manager.TempSkillCoinPerson += NewCoinPerson;
- if (Math.Abs(NewPerson) > 0.001f || Math.Abs(NewPersonBuff) > 0.001f)
- {
- Manager.ExtraPersonSourceSpritesName.UniqueAdd(icon);
- }
- if (Math.Abs(NewPlus) > 0.001f || Math.Abs(NewCoinPerson) > 0.001f)
- {
- Manager.ExtraCoinPersonSourceSpritesName.UniqueAdd(icon);
- }
- if (!NewSkillCD.Equal(0))
- {
- for (int i = 0; i < Manager.SkillList.Count; i++)
- {
- Manager.SkillList[i].Cool(NewSkillCD, true, false);
- }
- }
- if (!NewSkillCdBuff.Equal(0))
- {
- for (int i = 0; i < Manager.SkillList.Count; i++)
- {
- Manager.SkillList[i].Cool(NewSkillCdBuff, true, true);
- }
- }
- }
- protected virtual void Buy()
- {
- if (ID == 5)
- {
- StaticsManager.GetInstance().AdClicked(1);
- }
- else if (ID == 6)
- {
- StaticsManager.GetInstance().AdClicked(2);
- }
- Manager.Pay
- (
- FullID,
- UseAmt,
- BuyCur,
- () =>
- {
- AudioManager.PlayClip(AudioLabel.UseSkill);
- if (BuyCur != Current.AD)
- {
- Manager.UseSkillAmt++;
- }
- UseTimer = NewDuration - 1;
-
- GetBuff();
- GetAward();
- InfoBoxManager.GardenInfoBox.Display(string.Format("{0}{1}", Language.GetStr(LanguageLabel.UI__J_Info1), Language.GetStr(LanguageLabel.CombineLanguageLabel(LanguageLabel.SkillName, FullID))), 10f, Color.white, ResourceManager.LoadSprite(ResourceLabel.Atlas, Folder.Atlas));
- ConfigManager.SaveConfigDocument();
- ConfigManager.SaveConfigDocumentToDisk();
- },
- StaticsManager.ItemID.使用技能,
- StaticsManager.ConsumeModule.Shop
- );
- }
- protected virtual void OnClick()
- {
- AudioManager.PlayClip(AudioLabel.ClickButton);
- if (ItemStatus == SkillStatus.Buy)
- {
- if (BuyCur == Current.AD)
- {
- Buy();
- }
- else
- {
- ResourceManager.Get(CanvasLabel.Fe_Info).TweenForCG();
- ResourceManager.SetText(CanvasLabel.Fe_Tit, Name);
- ResourceManager.SetSprite(CanvasLabel.Fe_Icon, Icon);
- ResourceManager.SetText(CanvasLabel.Fe_Lab0, "");
- ResourceManager.SetText(CanvasLabel.Fe_Lab1, GetDescription(0));
- ResourceManager.SetText(CanvasLabel.Fe_BtnLab, string.Format("{0}({1}{2:0})", Language.GetStr(LanguageLabel.UI__Fe_BtnLab3), Auxiliary.ImageParse(BuyCur), UseAmt));
- ResourceManager.SetButtonEvent
- (
- CanvasLabel.Fe_Btn,
- () =>
- {
- Buy();
- ResourceManager.Get(CanvasLabel.Fe_Info).TweenBacCG();
- }
- );
- }
- }
- else if (ItemStatus == SkillStatus.Lock)
- {
- ResourceManager.Get(CanvasLabel.Fe_Info).TweenForCG();
- ResourceManager.SetText(CanvasLabel.Fe_Tit, Name);
- ResourceManager.SetSprite(CanvasLabel.Fe_Icon, Icon);
- ResourceManager.SetText(CanvasLabel.Fe_Lab0, "");
- ResourceManager.SetText(CanvasLabel.Fe_Lab1, GetDescription(0));
- ResourceManager.SetText(CanvasLabel.Fe_BtnLab, string.Format("{0}({1}{2:0})", Language.GetStr(LanguageLabel.UI__Fe_BtnLab0), Auxiliary.ImageParse(UnlockAheadCur), UnlockAheadAmt.ToString("0")));
- ResourceManager.SetButtonEvent
- (
- CanvasLabel.Fe_Btn,
- () =>
- {
- UnlockAhead();
- ResourceManager.Get(CanvasLabel.Fe_Info).TweenBacCG();
- }
- );
- }
- }
- protected virtual void UnlockAhead()
- {
- Manager.Pay
- (
- FullID,
- UnlockAheadAmt,
- UnlockAheadCur,
- () =>
- {
- AudioManager.PlayClip(AudioLabel.ClickButton);
- SkillIcon.material = null;
- ItemStatus = SkillStatus.Buy;
- ConfigManager.SaveConfigDocument();
- ConfigManager.SaveConfigDocumentToDisk();
- },
- StaticsManager.ItemID.提前解锁技能,
- StaticsManager.ConsumeModule.Shop
- );
- }
- public override void Reactive()
- {
- if (ItemStatus == SkillStatus.Use)
- {
- AnnulBuff();
- Manager.UsingSkillList.Remove(this);
- }
- else if (ItemStatus == SkillStatus.Cool)
- {
- Manager.CoolSkillList.Remove(this);
- }
- }
- public override void Init(bool firstInit, float elapse, List<List<Skill>> useList, 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;
- if (itemStatus == SkillStatus.Lock || itemStatus == SkillStatus.UnLock)
- {
- SkillIcon.material = Lib.GrayMat;
- }
- else
- {
- SkillIcon.material = null;
- }
- if (itemStatus == SkillStatus.Use)
- {
- GetBuff();
- if (UseTimer < elapse)
- {
- Manager.UsingSkillList.Remove(this);
- if (useList.Count > 0)
- {
- if (UseTimer < Manager.IncomeCircleTimer)
- {
- useList[0].UniqueAdd(this);
- }
- else
- {
- int circle = 1 + Mathf.FloorToInt((UseTimer - Manager.IncomeCircleTimer)/Manager.IncomeCircleTime);
- useList[circle].UniqueAdd(this);
- }
- }
- }
- else
- {
- UseTimer -= elapse;
- }
- }
- else if (itemStatus == SkillStatus.Cool)
- {
- CoolTimer -= elapse;
- Manager.CoolSkillList.Add(this);
- }
- button.onClick.RemoveAllListeners();
- button.onClick.AddListener(OnClick);
- DescriptionText.text = GetDescription(0);
- ItemStatus = ItemStatus;
- }
- public override void Cool(float amt, bool current, bool buff)
- {
- if (!CoolLock)
- {
- return;
- }
- if (current)
- {
- if (ItemStatus != SkillStatus.Cool)
- {
- return;
- }
- if (buff)
- {
- CoolTimer -= CD * amt;
- }
- else
- {
- CoolTimer -= amt;
- }
- }
- else
- {
- if (buff)
- {
- CdBuff = 1 - amt;
- }
- else
- {
- CD -= amt;
- }
- }
- }
- protected double GetUpgradeAmt(string str)
- {
- if (string.IsNullOrEmpty(str))
- {
- return UnlockAmt;
- }
- else
- {
- return double.Parse(str);
- }
- }
- protected override string GetDescription(int offset)
- {
- float temp;
- string[] strings = Desc.Split(TransferLabel.OpenChar, TransferLabel.CloseChar);
-
- StringBuilder stringBuilder = new StringBuilder();
- for (int i = 0; i < strings.Length; i++)
- {
- if (strings[i].Contains(TransferLabel.Level))
- {
- }
- else if (strings[i].Contains(TransferLabel.Person))
- {
- #region MyRegion
- if (!Person.Equal(0))
- {
- 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 (!PersonBuff.Equal(0))
- {
- temp = NewPersonBuff;
- UpgradeValue(ref temp, UpgradePerson, offset);
- stringBuilder.Append(string.Format("{0:0}%", temp * 100));
- }
- #endregion
- }
- else if (strings[i].Contains(TransferLabel.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(TransferLabel.CoinOnce))
- {
- #region MyRegion
- if (!CoinOnce.Equal(0))
- {
- temp = NewCoinOnce;
- UpgradeValue(ref temp, CoinOnce, UpgradeCoinOnce, offset);
- stringBuilder.Append(temp.ToString("0"));
- }
- else if (!CoinOnceBuff.Equal(0))
- {
- temp = NewCoinOnceBuff;
-
- UpgradeValue(ref temp, UpgradeCoinOnce, offset);
-
- stringBuilder.Append(temp.ToString("0"));
- }
- #endregion
- }
- else if (strings[i].Contains(TransferLabel.DiamondOnce))
- {
- #region MyRegion
- stringBuilder.Append(DiamondOnce.ToString("0"));
- #endregion
- }
- else if (strings[i].Contains(TransferLabel.CoinPerson))
- {
- #region MyRegion
-
- if (!CoinPerson.Equal(0))
- {
- temp = NewCoinPerson;
- UpgradeValue(ref temp, CoinPerson, UpgradePlus, offset);
- float remainder = temp % 1;
- if (remainder > 0)
- {
- stringBuilder.Append(temp.ToString("0") + "+");
- }
- else
- {
- stringBuilder.Append(temp.ToString("0"));
- }
- }
- else if (!Plus.Equal(0))
- {
- temp = NewPlus;
- UpgradeValue(ref temp, UpgradePlus, offset);
- stringBuilder.Append(string.Format("{0:0}%", temp * 100));
- }
- else
- {
- throw new Exception();
- }
- #endregion
- }
- else
- {
- stringBuilder.Append(strings[i]);
- }
- }
- return stringBuilder.ToString();
- }
- }
|