//-------------------------------------------------------- // [Author]: 第二世界 // [ Date ]: Monday, March 11, 2019 //-------------------------------------------------------- using UnityEngine; using System.Collections; using System.Collections.Generic; using Snxxz.UI; using System; //装备强化 public struct EquipStrength { public int EquipIndex;//强化部位 public int StrengthLevel;//等级 public int Exp;//经验 public int EvolveLV;//进化等级 public int Type;//强化类型 } public class EquipTypeClass { public int AttType;//属性类型 public int AttValue;//属性值 public string StrName;//属性名 } public class EquipMaxLvClass { public int MaxLv; public int MaxStar; } public class EquipPlusEvolveClass { public int EquipType;//装备类型 public int EvolveLV;//进化等级 public int NeedPlusLV;//需要强化等级 public int CostItemID;//所需物品ID public int CostItemCount;//所需物品数量 public ItemConfig Item; public int AttrType; public string AttrValue; public string AttrName; } public class EquipStrengthModel : Model, IBeforePlayerDataInitialize, IPlayerLoginOk { public Dictionary EquipStrengthDic = new Dictionary();//强化数据 public Dictionary> EquipLevelMaxDic = new Dictionary>();//强化类型的最大等级上限 static Dictionary PartTypeDic = new Dictionary();//强化的部位类型 public Dictionary EvolutionTypeMaxDic = new Dictionary(); public event Action EquipStrengthUpdate;//强化数据刷新 public event Action EquipStrengthLvUpdate;//强化升级成功 public event Action EquipStrngthEvolutionLv;//进阶成功 public event Action SelectEquipRefresh;//二级页签刷新 public event Action SelectLevelRefresh;//一级页签刷新 private bool isChangeBool = true; public bool IsChangeBool { get { return isChangeBool; } set { isChangeBool = value; } } private int selectLevel = 0; public int SelectLevel//装备类别 { get { return selectLevel; } set { if (selectLevel != value) { selectLevel = value; if (SelectLevelRefresh != null) { SelectLevelRefresh(); } } } } private int selectEquipPlace = -1;//装备部位 public int SelectEquipPlace//装备类别 { get { return selectEquipPlace; } set { if (selectEquipPlace != value) { selectEquipPlace = value; if (SelectEquipRefresh != null) { SelectEquipRefresh(); } } } } public Int2 jumpEquipPosition { get; set; } public override void Init() { var strengthenLevelLimit = FuncConfigConfig.Get("StrengthenLevelLimit").Numerical1; PartTypeDic = ConfigParse.GetDic(strengthenLevelLimit); GetEquipLevelMax(); GetEvolutionTypeMax(); } public void OnBeforePlayerDataInitialize() { } public void OnPlayerLoginOk() { } public override void UnInit() { } public void UpdateEuipPartPlusInfo(HA3B3_tagMCEquipPartPlusInfo info) { for (int i = 0; i < info.Count; i++) { var equipPartPlus = info.InfoList[i]; EquipStrength equipStrength = new EquipStrength(); equipStrength.Type = equipPartPlus.PackType; equipStrength.EquipIndex = equipPartPlus.EquipIndex; equipStrength.StrengthLevel = equipPartPlus.EquipPartStarLV; equipStrength.Exp = (int)equipPartPlus.Proficiency; equipStrength.EvolveLV = equipPartPlus.EvolveLV; if (EquipStrengthDic.ContainsKey(equipPartPlus.EquipIndex)) { var equip = EquipStrengthDic[equipPartPlus.EquipIndex]; EquipStrengthDic[equipPartPlus.EquipIndex] = equipStrength; if (equip.StrengthLevel != equipPartPlus.EquipPartStarLV && EquipStrengthLvUpdate != null) { EquipStrengthLvUpdate(); } if (equip.EvolveLV != equipPartPlus.EvolveLV && EquipStrngthEvolutionLv != null) { EquipStrngthEvolutionLv(); } } else { EquipStrengthDic.Add(equipPartPlus.EquipIndex, equipStrength); } } if (EquipStrengthUpdate != null) { EquipStrengthUpdate(); } } public void SendEquip(int equipIndex, int packTyp = 1) { CA301_tagEquipPlus CA301 = new CA301_tagEquipPlus(); CA301.PackType = (byte)packTyp; CA301.ItemIndex = (ushort)equipIndex; GameNetSystem.Instance.SendInfo(CA301); } public void SendEquipPlusEvolve(int equipIndex) { CA316_tagCMEquipPlusEvolve CA316 = new CA316_tagCMEquipPlusEvolve(); CA316.ItemIndex = (ushort)equipIndex; GameNetSystem.Instance.SendInfo(CA316); } private void GetEquipLevelMax() { var itemPlusMax = ItemPlusMaxConfig.GetValues(); foreach (var value in itemPlusMax) { Dictionary starLevelDict = null; if (!EquipLevelMaxDic.TryGetValue(value.EquipType, out starLevelDict)) { starLevelDict = new Dictionary(); EquipLevelMaxDic.Add(value.EquipType, starLevelDict); } starLevelDict.Add(value.equipStar, value.levelMax); } } public static int GetEquipStrengthType(int equipPlace)//获取装备类型 { int type = 1; if (PartTypeDic.ContainsKey(equipPlace)) { type = PartTypeDic[equipPlace]; } return type; } public int GetEquipLevelMax(int type, int star)//获取某一类型的最大强化等级 { int lv = 0; if (EquipLevelMaxDic.ContainsKey(type)) { var starLevelDict = EquipLevelMaxDic[type]; if (starLevelDict.ContainsKey(star)) { return starLevelDict[star]; } } return lv; } public List GetEquipValueList(int level, int equipPlace, int addlv = 0)//当前获得的强化属性 { List EquipTypeList = new List(); int type = GetEquipStrengthType(equipPlace); int equiplv = 0; int equipIndex = EquipPlaceMapConfig.GetServerPlace(level, equipPlace); if (EquipStrengthDic.ContainsKey(equipIndex)) { equiplv = EquipStrengthDic[equipIndex].StrengthLevel; } equiplv += addlv; var itemPlus = ItemPlusConfig.GetTypeAndLevel(type, equiplv); if (itemPlus != null) { int[] attType = itemPlus.attType; int[] attValue = itemPlus.attValue; for (int i = 0; i < attType.Length; i++) { EquipTypeClass equipType = new EquipTypeClass(); equipType.AttType = attType[i]; equipType.AttValue = attValue[i]; var config = PlayerPropertyConfig.Get(attType[i]); if (config != null) { equipType.StrName = config.Name; } EquipTypeList.Add(equipType); } } return EquipTypeList; } public ItemPlusConfig GetEquipConfig(int level, int equipPlace) { ItemPlusConfig itemPlusConfig = new ItemPlusConfig(); int type = GetEquipStrengthType(equipPlace); int equiplv = 0; int equipIndex = EquipPlaceMapConfig.GetServerPlace(level, equipPlace); if (EquipStrengthDic.ContainsKey(equipIndex)) { equiplv = EquipStrengthDic[equipIndex].StrengthLevel; } itemPlusConfig = ItemPlusConfig.GetTypeAndLevel(type, equiplv); return itemPlusConfig; } public EquipPlusEvolveClass GetEquipPlusEvolve(int equipPlace, int equipLv)//获取装备进化数据 { EquipPlusEvolveClass equipPlusEvolve = new EquipPlusEvolveClass(); int lvType = 1; if (equipLv != 0) { lvType = equipLv; } var equipPlusEvolveConfig = EquipPlusEvolveConfig.GetEquipPlaceAndEvolveLV(equipPlace, lvType); if (equipPlusEvolveConfig != null) { equipPlusEvolve.EquipType = equipPlusEvolveConfig.EquipPlace; equipPlusEvolve.EvolveLV = equipPlusEvolveConfig.EvolveLV; equipPlusEvolve.NeedPlusLV = equipPlusEvolveConfig.NeedPlusLV; var Dic1 = ConfigParse.GetDic(equipPlusEvolveConfig.CostItem); foreach (var key in Dic1.Keys) { equipPlusEvolve.CostItemID = key; equipPlusEvolve.CostItemCount = Dic1[key]; } var Dic2 = ConfigParse.GetDic(equipPlusEvolveConfig.Attr); foreach (var key in Dic2.Keys) { equipPlusEvolve.AttrType = key; var config = PlayerPropertyConfig.Get(key); if (config != null) { equipPlusEvolve.AttrName = config.Name; float value = Dic2[key]; switch (config.ISPercentage) { case 0: equipPlusEvolve.AttrValue = value.ToString(); if (equipLv == 0) { equipPlusEvolve.AttrValue = 0.ToString(); } break; case 1: equipPlusEvolve.AttrValue = (value / 100).ToString() + "%"; if (equipLv == 0) { equipPlusEvolve.AttrValue = 0.ToString() + "%"; } break; case 2: equipPlusEvolve.AttrValue = value.ToString() + "%"; if (equipLv == 0) { equipPlusEvolve.AttrValue = 0.ToString() + "%"; } break; } } } } return equipPlusEvolve; } private void GetEvolutionTypeMax() { var evolveValues = EquipPlusEvolveConfig.GetValues(); foreach (var value in evolveValues) { if (EvolutionTypeMaxDic.ContainsKey(value.EquipPlace)) { var lv = EvolutionTypeMaxDic[value.EquipPlace]; if (value.EvolveLV > lv) { EvolutionTypeMaxDic[value.EquipPlace] = value.EvolveLV; } } else { EvolutionTypeMaxDic.Add(value.EquipPlace, value.EvolveLV); } } } public EquipStrength GetEquipStrength(int level, int equipPlace) { EquipStrength equipStrength = new EquipStrength(); int equipIndex = EquipPlaceMapConfig.GetServerPlace(level, equipPlace); if (EquipStrengthDic.ContainsKey(equipIndex)) { equipStrength = EquipStrengthDic[equipIndex]; } return equipStrength; } public int GetStrengthLevel(int level, int equipPlace) { int lv = 0; int equipIndex = EquipPlaceMapConfig.GetServerPlace(level, equipPlace); if (EquipStrengthDic.ContainsKey(equipIndex)) { lv = EquipStrengthDic[equipIndex].StrengthLevel; } return lv; } }