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> 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(); } }