using UnityEngine; using System; using System.Xml; using System.Text; using System.Collections; using System.Collections.Generic; public class Pack : SkillRoot { #region 变量 #region 配置 public override string ID { get { return "Pack" + ID_; } } public override string Name { get { return Language.GetStr("SkillName", ID); } } 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) { ItemBtn.interactable = true; SkillItem.SetActive(true); if (!string.IsNullOrEmpty(Label)) { ManaLan.Add(ItemBtnLab, new LanStr("UI", Label), "\n", Auxiliary.ImageParse(BuyCur), UseAmt.ToString("0")); } else { ManaLan.Add(ItemBtnLab, new LanStr("UI", "Fe_BtnLab3"), "\n", Auxiliary.ImageParse(BuyCur), UseAmt.ToString("0")); } } else if (ItemStatus_ == SkillStatus.Lock) { ItemBtn.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.BoolParse(attribute[17].Value, false); UseAmt = Auxiliary.FloatParse(attribute[12].Value,0); ItemIndex = Auxiliary.IntParse(attribute[3].Value,0); DiamondOnce = Auxiliary.FloatParse(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 AnnulA() { ManaCenter.SkillPlus -= Plus; ManaCenter.SkillPerson -= Person; ManaCenter.SkillPersonBuff -= PersonBuff; ManaCenter.SkillCoinPerson -= CoinPerson; if (!SkillCD.Equal(0)) { for (int j = 0; j < ManaCenter.SkillList.Count; j++) { ManaCenter.SkillList[j].ReceiveCool(-SkillCD, false, false); } } if (!SkillCdBuff.Equal(0)) { for (int j = 0; j < ManaCenter.SkillList.Count; j++) { ManaCenter.SkillList[j].ReceiveCool(-SkillCdBuff, false, true); } } } public override void Reactive() { //for (int i = 0; i < Level; i++) //{ // AnnulA(); //} } public override void RegistValue(bool firstRegist, float elapse, List> useList, XmlAttributeCollection attribute) { if (!firstRegist) { return; } Level = int.Parse(attribute[3].Value); ItemStatus_ = (SkillStatus)Enum.Parse(typeof(SkillStatus), attribute[2].Value); for (int i = 0; i < Level; i++) { UseA(); } ItemBtn.onClick.RemoveAllListeners(); ItemBtn.onClick.AddListener(OnClick); //if (!string.IsNullOrEmpty(Label)) //{ // ItemIcon1.SetActive(true); // ManaLan.Add(IconLab1, new LanStr("UI", Label)); //} ItemLab.text = GetDescription(0); ManaLan.Add(ItemTit, new LanStr("SkillName", ID)); ManaIAP.ProductActionDic.UniqueAdd(ID, PurchaseResult); ItemStatus = ItemStatus; SetActive(!(Lock && ManaServer.PackLock)); } public override void UpdateStatus() { if (!ManaCenter.Complete) { return; } if (Lock && ManaServer.PackLock) { return; } ItemLab.text = GetDescription(0); if (MaxUseLv == MinUseLv) { ItemStatus = SkillStatus.Buy; } else { if (ManaCenter.Level > MaxUseLv || ManaCenter.Level < MinUseLv) { ItemStatus = SkillStatus.Lock; } else { ItemStatus = SkillStatus.Buy; } } } protected void UseA() { Debug.Log(Name + " " + Plus); ManaCenter.SkillPlus += Plus; ManaCenter.SkillPerson += Person; ManaCenter.SkillPersonBuff += PersonBuff; ManaCenter.SkillCoinPerson += CoinPerson; if (!SkillCD.Equal(0)) { for (int i = 0; i < ManaCenter.SkillList.Count; i++) { ManaCenter.SkillList[i].ReceiveCool(SkillCD, false, false); } } if (!SkillCdBuff.Equal(0)) { for (int i = 0; i < ManaCenter.SkillList.Count; i++) { ManaCenter.SkillList[i].ReceiveCool(SkillCdBuff, false, true); } } } public void SetActive(bool active) { if (active) { ItemBtn.interactable = true; ItemStatus = ItemStatus; } else { if (Level > 0) { ItemBtn.interactable = false; ManaLan.Add(ItemBtnLab, Language.GetStr("UI", "Fe_BtnLab9")); } } } protected void OnClick() { ManaAudio.PlayClip(Clip.BtnClip); ManaReso.Get("Fe_Info").TweenForCG(); ManaReso.SetText("Fe_Tit", Name); ManaReso.SetSprite("Fe_Icon", ItemIcon.sprite); if (ItemStatus == SkillStatus.Buy) { ManaReso.SetText("Fe_Lab0", ""); ManaReso.SetText("Fe_Lab1", GetDescription(0)); ManaReso.SetText("Fe_BtnLab", string.Format("{0}({1}{2:0})", Language.GetStr("UI", "Fe_BtnLab3"), Auxiliary.ImageParse(BuyCur), UseAmt)); ManaReso.SetButtonEvent ( "Fe_Btn", () => { Purchase(); ManaReso.Get("Fe_Info").TweenBacCG(); } ); } } protected void Purchase() { ManaAudio.PlayClip(Clip.BtnClip); ManaCenter.Pay(ID, UseAmt, BuyCur, PurchaseResult, StaticsManager.ItemID.购买礼包, StaticsManager.ConsumeModule.Charge); } public void PurchaseResult() { int tempCoin = 0; int tempDiamond = (int) DiamondOnce; ManaCenter.AddDiamond(DiamondOnce, StaticsManager.ItemID.获得钻石, StaticsManager.ConsumeModule.Charge); string tempFlower = ""; if (!string.IsNullOrEmpty(Flower)) { for (int i = 0; i < Flowers.Length; i++) { FlowerInfo flowerInfo = ManaGarden.FlowerInfoDic[int.Parse(Flowers[i])]; if (flowerInfo.Unlock == false) { flowerInfo.Unlock = true; tempFlower += string.Format("{0}{1}{2} ", Language.GetStr("UI", "J_Info0"), "<(花朵)>", flowerInfo.Name); } else { if (flowerInfo.UnlockCur == Current.Coin) { tempCoin = flowerInfo.UnlockAmt/5; ManaCenter.AddCoin(flowerInfo.UnlockAmt / 5, StaticsManager.ItemID.获得金币, StaticsManager.ConsumeModule.Charge); } else if (flowerInfo.UnlockCur == Current.Diamond) { tempDiamond += flowerInfo.UnlockAmt/5; ManaCenter.AddDiamond(flowerInfo.UnlockAmt/5, StaticsManager.ItemID.获得钻石, StaticsManager.ConsumeModule.Charge); } } } } StringBuilder sb = new StringBuilder(); if (!string.IsNullOrEmpty(CoinFml)) { int coin = (int) Auxiliary.FmlParse(CoinFml, "l", ManaCenter.Level.ToString(), "c", ManaCenter.CoinPerson.ToString("0.000")); ManaCenter.AddCoin(coin, StaticsManager.ItemID.获得金币, StaticsManager.ConsumeModule.Shop); tempCoin += coin; } if (!tempCoin.Equal(0)) { sb.AppendFormat("{0}{1}{2} ", Language.GetStr("UI", "J_Info0"), "<(金币)>", Auxiliary.ShrinkNumberStr(tempCoin)); } if (!tempDiamond.Equal(0)) { sb.AppendFormat("{0}{1}{2} ", Language.GetStr("UI", "J_Info0"), "<(钻石)>", Auxiliary.ShrinkNumberStr(tempDiamond)); } if (!string.IsNullOrEmpty(tempFlower)) { sb.Append(tempFlower); } string str = sb.ToString(); if (!string.IsNullOrEmpty(str)) { ManaInfo.Show(str, 10f); } Level++; ManaAudio.PlayClip(Clip.SkillClip); if (BuyCur == Current.Cash) { ManaServer.Save(); } UseA(); SetActive(!(Lock && ManaServer.PackLock)); } #region 解读器 protected int MinLevelParse(string str) { if (string.IsNullOrEmpty(str)) { return 0; } else { return Auxiliary.IntParse(str.Split(',')[0],0); } } protected int MaxLevelParse(string str) { if (string.IsNullOrEmpty(str)) { return 0; } else { return Auxiliary.IntParse(str.Split(',')[1],0); } } protected override string GetDescription(int offset) { 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("&coin&")) { #region MyRegion if (!string.IsNullOrEmpty(CoinFml)) { stringBuilder.Append(Auxiliary.FmlParse(CoinFml, "l", ManaCenter.Level.ToString(), "c", ManaCenter.CoinPerson.ToString("0.000")).ToString("0")); } #endregion } else if (strings[i].Contains("&flower&")) { #region MyRegion if (!string.IsNullOrEmpty(Flower)) { for (int j = 0; j < Flowers.Length; j++) { stringBuilder.Append(Language.GetStr("FlowerName", "Flower" + Flowers[j])); if (j != Flowers.Length - 1) { stringBuilder.Append(","); } } } #endregion } else if (strings[i].Contains("&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("&diamond&")) { #region MyRegion if (!DiamondOnce.Equal(0)) { stringBuilder.Append(DiamondOnce.ToString("0")); } #endregion } else if (strings[i].Contains("&coin_person&")) { #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(); } #endregion }