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); } } protected int MinUseLv; protected int MaxUseLv; protected float Person; protected float SkillCD; protected float UseAmt; protected float CoinPerson; protected float DiamondOnce; protected string CoinFml; protected float Plus; protected float PersonBuff; protected float SkillCdBuff; protected string Label; protected string Anim; protected string Flower; protected Current BuyCur; #endregion public override int Level { get; set; } public SkillStatus ItemStatus { get { return ItemStatus_; } set { ItemStatus_ = value; if (ItemStatus_ == SkillStatus.Buy) { ItemBtn.interactable = true; SkillItem.SetActive(true); ManaLan.Add(ItemBtnLab, new LanStr("UI", "Fe_BtnLab3"), "\n", ImageParse(BuyCur), UseAmt.ToString("0")); } else if (ItemStatus_ == SkillStatus.Lock) { ItemBtn.interactable = false; SkillItem.SetActive(false); } } } public SkillStatus ItemStatus_; #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; ItemIndex = Auxiliary.IntParse(attribute[3].Value,0); UseAmt = Auxiliary.FloatParse(attribute[12].Value,0); DiamondOnce = Auxiliary.FloatParse(attribute[8].Value,0); SkillTab = SkillClassParse(attribute[2].Value); BuyCur = CurrentParse(attribute[11].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); #endregion SkillType = SkillType.Pack; } public override void Annul() { for (int i = 0; i < Level; i++) { ManaCenter.SkillPlus -= Plus; ManaCenter.SkillPerson -= Person; ManaCenter.SkillPersonBuff -= PersonBuff; ManaCenter.SkillCoinPerson -= CoinPerson; if (Math.Abs(SkillCD) > 0.0005f) { for (int j = 0; j < ManaCenter.SkillList.Count; j++) { ManaCenter.SkillList[j].ReceiveCool(-SkillCD, false, false); } } if (Math.Abs(SkillCdBuff) > 0.0005f) { 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++) { Annul(); } } public override void RegistValue(float elapse, List> useList, XmlAttributeCollection attribute) { Level = int.Parse(attribute[3].Value); for (int i = 0; i < Level; i++) { UseA(); } ItemStatus_ = (SkillStatus)Enum.Parse(typeof(SkillStatus), attribute[2].Value); ItemBtn.onClick.RemoveAllListeners(); ItemBtn.onClick.AddListener(OnClick); ItemLab.text = GetDescription(0); ManaLan.Add(ItemTit, new LanStr("SkillName", ID)); ItemStatus = ItemStatus; ManaIAP.ProductDic.UniqueAdd(ID, PurchaseResult); } public override void UpdateStatus() { if (!ManaCenter.Complete) { 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 UseB() { if (!string.IsNullOrEmpty(CoinFml)) { ManaCenter.Coin += Auxiliary.FmlParse(CoinFml, "l", ManaCenter.Level.ToString(), "c", ManaCenter.CoinPerson.ToString("0.000")); } ManaCenter.Diamond += DiamondOnce; } protected void UseA() { if (!string.IsNullOrEmpty(Flower)) { string[] strings = Flower.Split(' '); for (int i = 0; i < strings.Length; i++) { FlowerInfo flowerInfo = ManaGarden.FlowerInfoDic[int.Parse(strings[i])]; if (flowerInfo.Unlock == false) { flowerInfo.Unlock = true; } } } ManaCenter.SkillPlus += Plus; ManaCenter.SkillPerson += Person; ManaCenter.SkillPersonBuff += PersonBuff; ManaCenter.SkillCoinPerson += CoinPerson; if (Math.Abs(SkillCD) > 0.0005f) { for (int i = 0; i < ManaCenter.SkillList.Count; i++) { ManaCenter.SkillList[i].ReceiveCool(SkillCD, false, false); } } if (Math.Abs(SkillCdBuff) > 0.0005f) { for (int i = 0; i < ManaCenter.SkillList.Count; i++) { ManaCenter.SkillList[i].ReceiveCool(SkillCdBuff, false, true); } } } protected void OnClick() { ManaAudio.PlayClip(Clip.BtnClip); ManaReso.Get("Fe_Info").TweenForCG(); ManaReso.SetText("Fe_Tit", Name); ManaReso.SetSprite("Fe_Icon", ItemIcon.sprite); ManaReso.SetText("Fe_Lab0", ""); if (ItemStatus == SkillStatus.Buy) { ManaReso.SetText("Fe_Lab1", GetDescription(0)); ManaReso.SetText("Fe_BtnLab", string.Format("{0}({1}{2:0})", Language.GetStr("UI", "Fe_BtnLab3"), ImageParse(BuyCur), UseAmt)); ManaReso.SetButtonEvent ( "Fe_Btn", () => { Purchase(); ManaReso.Get("Fe_Info").TweenBacCG(); } ); } } protected void Purchase() { ManaAudio.PlayClip(Clip.BtnClip); ManaCenter.Pay(ID, UseAmt, Current.Cash, PurchaseResult); } protected void PurchaseResult() { UseA(); UseB(); StringBuilder sb = new StringBuilder(); if (!string.IsNullOrEmpty(CoinFml)) { sb.AppendFormat("{0}{1}{2} ", Language.GetStr("UI", "J_Info0"), "<(金币)>", Auxiliary.FmlParse(CoinFml, "l", ManaCenter.Level.ToString(), "c", ManaCenter.CoinPerson.ToString("0.000")).ToString("0")); } if (!DiamondOnce.Equal(0)) { sb.AppendFormat("{0}{1}{2} ", Language.GetStr("UI", "J_Info0"), "<(钻石)>", DiamondOnce); } if (!string.IsNullOrEmpty(Flower)) { string[] strings = Flower.Split(' '); for (int i = 0; i < strings.Length; i++) { FlowerInfo flowerInfo = ManaGarden.FlowerInfoDic[int.Parse(strings[i])]; if (flowerInfo.Unlock == false) { flowerInfo.Unlock = true; } sb.AppendFormat("{0}{1}{2}", Language.GetStr("UI", "J_Info0"), "<(花朵)>", flowerInfo.Name); } } string str = sb.ToString(); if (!string.IsNullOrEmpty(str)) { ManaInfo.Show(str, 10f); } Level++; ManaAudio.PlayClip(Clip.SkillClip); if (BuyCur == Current.Cash) { ManaServer.Save(); } } #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)) { string[] strings1 = Flower.Split(' '); for (int j = 0; j < strings1.Length; j++) { stringBuilder.Append(Language.GetStr("FlowerName", "Flower" + strings1[j])); if (j != strings1.Length - 1) { stringBuilder.Append(","); } } } #endregion } else if (strings[i].Contains("&diamond&")) { #region MyRegion if (Math.Abs(DiamondOnce) > 0.0005f) { stringBuilder.Append(DiamondOnce.ToString("0")); } #endregion } else if (strings[i].Contains("&coin_person&")) { #region MyRegion if (Math.Abs(Plus) > 0.0005f) { stringBuilder.Append(string.Format("{0:0}%", Plus*100)); } else if (Math.Abs(CoinPerson) > 0.0005f) { stringBuilder.Append(CoinPerson.ToString("0")); } #endregion } else { stringBuilder.Append(strings[i]); } } return stringBuilder.ToString(); } #endregion }