using UnityEngine; using System; using System.Xml; using System.Text; using System.Collections; using System.Collections.Generic; public class Pack : SkillRoot { #region Config #region 配置 public override string FullID { get { return PackFullIDPrefix + ID; } } public override string Name { get { return Language.GetStr(LanguageLabel.CombineLanguageLabel(LanguageLabel.SkillName, FullID)); } } public int MinUseLv; public int MaxUseLv; public float Person; public float SkillCD; public float UseAmt; public float CoinPerson; public float DiamondOnce; public bool Lock; public string CoinFml; public float Plus; public float PersonBuff; public float SkillCdBuff; public string Label; public string Anim; public string Flower; public string[] Flowers; public Current BuyCur; #endregion public override int Level { get; set; } public override SkillStatus ItemStatus { get { return itemStatus; } set { itemStatus = value; if (itemStatus == SkillStatus.Buy) { button.interactable = true; SkillItem.SetActive(true); if (!string.IsNullOrEmpty(Label)) { LanguageManager.Add(ButtonTitle, new MulLanStr(LanguageLabel.CombineLanguageLabel(LanguageLabel.UI, Label)), "\n", Auxiliary.ImageParse(BuyCur), UseAmt.ToString("0")); } else { LanguageManager.Add(ButtonTitle, new MulLanStr(LanguageLabel.UI__Fe_BtnLab3), "\n", Auxiliary.ImageParse(BuyCur), UseAmt.ToString("0")); } } else if (itemStatus == SkillStatus.Lock) { button.interactable = false; SkillItem.SetActive(false); } } } #endregion public Pack(XmlAttributeCollection attribute) { #region 配置 ID = int.Parse(attribute[0].Value); icon = attribute[14].Value; Anim = attribute[15].Value; Label = attribute[16].Value; Flower = attribute[9].Value; CoinFml = attribute[7].Value; Lock = Auxiliary.StringToBool(attribute[17].Value, false); UseAmt = Auxiliary.StringToFloat(attribute[12].Value,0); ItemIndex = Auxiliary.StringToInt(attribute[3].Value,0); DiamondOnce = Auxiliary.StringToFloat(attribute[8].Value,0); BuyCur = Auxiliary.CurrentParse(attribute[11].Value); SkillTab = SkillClassParse(attribute[2].Value); MinUseLv = MinLevelParse(attribute[10].Value); MaxUseLv = MaxLevelParse(attribute[10].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); if (!string.IsNullOrEmpty(Flower)) { Flowers = Flower.Split(' ')[0].Split(','); } #endregion SkillType = SkillType.Pack; } public override void AnnulEffect() { Manager.SkillPlus -= Plus; Manager.SkillPerson -= Person; Manager.SkillPersonBuff -= PersonBuff; Manager.SkillCoinPerson -= CoinPerson; if (!SkillCD.Equal(0)) { for (int j = 0; j < Manager.SkillList.Count; j++) { Manager.SkillList[j].Cool(-SkillCD, false, false); } } if (!SkillCdBuff.Equal(0)) { for (int j = 0; j < Manager.SkillList.Count; j++) { Manager.SkillList[j].Cool(-SkillCdBuff, false, true); } } } public override void Reactive() { //for (int i = 0; i < Level; i++) //{ // AnnulA(); //} } public override void Init(bool firstInit, float elapse, List> useList, XmlAttributeCollection attribute) { if (!firstInit) { return; } Level = int.Parse(attribute[3].Value); itemStatus = (SkillStatus)Enum.Parse(typeof(SkillStatus), attribute[2].Value); for (int i = 0; i < Level; i++) { GetBuff(); } button.onClick.RemoveAllListeners(); button.onClick.AddListener(OnClick); //if (!string.IsNullOrEmpty(Label)) //{ // ItemIcon1.SetActive(true); // ManaLan.Add(IconLab1, new LanStr("UI", Label)); //} DescriptionText.text = GetDescription(0); LanguageManager.Add(TitleText, new MulLanStr(LanguageLabel.CombineLanguageLabel(LanguageLabel.SkillName, FullID))); IAPManager.BuyProductCallbackDictionary.UniqueAdd(FullID, ()=>OnBuySucceed()); ItemStatus = ItemStatus; SetActive(); } public override void UpdateStatus() { if (!Manager.Inited) { return; } if (Lock && HttpManager.BuyPackLimitFlag && Level >= 1) { return; } DescriptionText.text = GetDescription(0); if (MaxUseLv == MinUseLv) { ItemStatus = SkillStatus.Buy; } else { if (Manager.GardenLevel > MaxUseLv || Manager.GardenLevel < MinUseLv) { ItemStatus = SkillStatus.Lock; } else { ItemStatus = SkillStatus.Buy; } } } protected void GetBuff() { Manager.SkillPlus += Plus; Manager.SkillPerson += Person; Manager.SkillPersonBuff += PersonBuff; Manager.SkillCoinPerson += CoinPerson; if (!SkillCD.Equal(0)) { for (int i = 0; i < Manager.SkillList.Count; i++) { Manager.SkillList[i].Cool(SkillCD, false, false); } } if (!SkillCdBuff.Equal(0)) { for (int i = 0; i < Manager.SkillList.Count; i++) { Manager.SkillList[i].Cool(SkillCdBuff, false, true); } } } public void SetActive() { bool active = !(Lock && HttpManager.BuyPackLimitFlag); if (active) { button.interactable = true; ItemStatus = ItemStatus; } else { if (Level > 0) { button.interactable = false; LanguageManager.Add(ButtonTitle, Language.GetStr(LanguageLabel.UI__Fe_BtnLab9)); } } } protected void OnClick() { AudioManager.PlayClip(AudioLabel.ClickButton); ResourceManager.Get(CanvasLabel.Fe_Info).TweenForCG(); ResourceManager.SetText(CanvasLabel.Fe_Tit, Name); ResourceManager.SetSprite(CanvasLabel.Fe_Icon, SkillIcon.sprite); if (ItemStatus == SkillStatus.Buy) { 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, () => { OnBuy(); ResourceManager.Get(CanvasLabel.Fe_Info).TweenBacCG(); } ); } } protected void OnBuy() { AudioManager.PlayClip(AudioLabel.ClickButton); Manager.Pay(FullID, UseAmt, BuyCur, ()=> OnBuySucceed(), StaticsManager.ItemID.购买礼包, StaticsManager.ConsumeModule.Charge); } public void OnBuySucceed(bool getGift = true) { int tempCoin = 0; int tempDiamond = (int) DiamondOnce; Manager.AddDiamond(DiamondOnce, StaticsManager.ItemID.获得钻石, StaticsManager.ConsumeModule.Charge); string tempFlower = ""; if (!string.IsNullOrEmpty(Flower)) { for (int i = 0; i < Flowers.Length; i++) { FlowerInfo flowerInfo = GardenManager.FlowerInfoDictionary[int.Parse(Flowers[i])]; flowerInfo.Add(); tempFlower += string.Format("{0}{1}{2} ", Language.GetStr(LanguageLabel.UI__J_Info0), TransferLabel.FlowerSprite, flowerInfo.Name); } } StringBuilder sb = new StringBuilder(); if (!string.IsNullOrEmpty(CoinFml)) { int coin = (int) Auxiliary.FmlParse(CoinFml, "l", Manager.GardenLevel.ToString(), "c", Manager.CoinPerson.ToString("0.000")); Manager.AddCoin(coin, StaticsManager.ItemID.获得金币, StaticsManager.ConsumeModule.Shop); tempCoin += coin; } if (!tempCoin.Equal(0)) { sb.AppendFormat("{0}{1}{2} ", Language.GetStr(LanguageLabel.UI__J_Info0), TransferLabel.CoinSprite, Auxiliary.ShrinkNumberStr(tempCoin)); } if (!tempDiamond.Equal(0)) { sb.AppendFormat("{0}{1}{2} ", Language.GetStr(LanguageLabel.UI__J_Info0), TransferLabel.DiamondSprite, Auxiliary.ShrinkNumberStr(tempDiamond)); } if (!string.IsNullOrEmpty(tempFlower)) { sb.Append(tempFlower); } string str = sb.ToString(); if (!string.IsNullOrEmpty(str)) { InfoBoxManager.GardenInfoBox.Display(str, 10f, Color.white, ResourceManager.LoadSprite("Atlas", Folder.Atlas)); } Level++; AudioManager.PlayClip(AudioLabel.UseSkill); //if (BuyCur == Current.Cash) //{ // HttpManager.UploadConfig(); //} GetBuff(); SetActive(); if (getGift) { RechargeGiftManager.GetAllRechargeGiftAward(ID); } } protected int MinLevelParse(string str) { if (string.IsNullOrEmpty(str)) { return 0; } else { return Auxiliary.StringToInt(str.Split(',')[0],0); } } protected int MaxLevelParse(string str) { if (string.IsNullOrEmpty(str)) { return 0; } else { return Auxiliary.StringToInt(str.Split(',')[1],0); } } protected override string GetDescription(int offset) { 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.Coin)) { #region MyRegion if (!string.IsNullOrEmpty(CoinFml)) { stringBuilder.Append(Auxiliary.FmlParse(CoinFml, "l", Manager.GardenLevel.ToString(), "c", Manager.CoinPerson.ToString("0.000")).ToString("0")); } #endregion } else if (strings[i].Contains(TransferLabel.Flower)) { #region MyRegion if (!string.IsNullOrEmpty(Flower)) { for (int j = 0; j < Flowers.Length; j++) { FlowerInfo flowerInfo = GardenManager.FlowerInfoDictionary[int.Parse(Flowers[j])]; stringBuilder.Append(Language.GetStr(LanguageLabel.CombineLanguageLabel(LanguageLabel.FlowerName, flowerInfo.FullID))); if (j != Flowers.Length - 1) { stringBuilder.Append(","); } } } #endregion } else if (strings[i].Contains(TransferLabel.Replace)) { #region MyRegion //if (!string.IsNullOrEmpty(Flower)) //{ // for (int j = 0; j < Diamonds.Length; j++) // { // stringBuilder.Append(int.Parse(Diamonds[j])); // if (j != Diamonds.Length - 1) // { // stringBuilder.Append(","); // } // } //} #endregion } else if (strings[i].Contains(TransferLabel.Diamond)) { #region MyRegion if (!DiamondOnce.Equal(0)) { stringBuilder.Append(DiamondOnce.ToString("0")); } #endregion } else if (strings[i].Contains(TransferLabel.CoinPerson)) { #region MyRegion if (!Plus.Equal(0)) { stringBuilder.Append(string.Format("{0:0}%", Plus*100)); } else if (!CoinPerson.Equal(0)) { stringBuilder.Append(CoinPerson.ToString("0")); } #endregion } else { stringBuilder.Append(strings[i]); } } return stringBuilder.ToString(); } }