using System;
|
using System.Collections.Generic;
|
using System.Linq;
|
using System.Text;
|
using TableConfig;
|
using LitJson;
|
|
namespace Snxxz.UI
|
{
|
public class JadeDynastyEquipModel : Model,IBeforePlayerDataInitialize,IAfterPlayerDataInitialize,IPlayerLoginOk
|
{
|
public int UnlockTowerLayer
|
{
|
get { return 0; }
|
}
|
|
PlayerPackModel playerPack { get { return ModelCenter.Instance.GetModel<PlayerPackModel>(); } }
|
|
public override void Init()
|
{
|
ParseFuncConfig();
|
ParseSuitAttrConfig();
|
}
|
|
public void OnBeforePlayerDataInitialize()
|
{
|
|
}
|
|
public void OnAfterPlayerDataInitialize()
|
{
|
|
}
|
|
public void OnPlayerLoginOk()
|
{
|
|
}
|
|
public override void UnInit()
|
{
|
|
}
|
|
#region 解析表数据
|
public Dictionary<int, int> lockEquipLayerDict { get; private set; }
|
public Dictionary<int, List<int>> suitTypeDict { get; private set;}
|
public void ParseFuncConfig()
|
{
|
lockEquipLayerDict = new Dictionary<int, int>();
|
suitTypeDict = new Dictionary<int, List<int>>();
|
var equipZhuXian = Config.Instance.Get<FuncConfigConfig>("EquipZhuXian");
|
var lockEquipData = JsonMapper.ToObject(equipZhuXian.Numerical1);
|
foreach(var key in lockEquipData.Keys)
|
{
|
int equipPlace = int.Parse(key);
|
int towerLayer = int.Parse(lockEquipData[key].ToString());
|
lockEquipLayerDict.Add(equipPlace,towerLayer);
|
}
|
|
var suitGroupData = JsonMapper.ToObject(equipZhuXian.Numerical2);
|
foreach(var key in suitGroupData.Keys)
|
{
|
int groupType = int.Parse(key);
|
var equipPlaces = suitGroupData[key];
|
if(equipPlaces.IsArray)
|
{
|
List<int> list = new List<int>();
|
suitTypeDict.Add(groupType,list);
|
for(int i = 0; i < equipPlaces.Count; i++)
|
{
|
var equipPlace = equipPlaces[i];
|
list.Add(int.Parse(equipPlace.ToString()));
|
}
|
}
|
}
|
}
|
|
public Dictionary<int, Dictionary<int, JadeDynastySuitAttrData>> suitAttrDict { get; private set; }
|
public void ParseSuitAttrConfig()
|
{
|
suitAttrDict = new Dictionary<int, Dictionary<int, JadeDynastySuitAttrData>>();
|
var suitConfigs = Config.Instance.GetAllValues<JadeDynastySuitAttrConfig>();
|
foreach(var config in suitConfigs)
|
{
|
int suitLv = config.suiteLV;
|
int type = config.suiteType;
|
var suitAttrData = new JadeDynastySuitAttrData(config.id);
|
if (!suitAttrDict.ContainsKey(type))
|
{
|
var dict = new Dictionary<int, JadeDynastySuitAttrData>();
|
dict.Add(suitLv,suitAttrData);
|
suitAttrDict.Add(type,dict);
|
}
|
else
|
{
|
var dict = suitAttrDict[type];
|
if(!dict.ContainsKey(suitLv))
|
{
|
dict.Add(suitLv, suitAttrData);
|
}
|
}
|
}
|
}
|
|
public class JadeDynastySuitAttrData
|
{
|
public int suitLv { get; private set; }
|
public Dictionary<int, int> attrDict { get; private set; }
|
public JadeDynastySuitAttrConfig suitAttrConfig { get; private set; }
|
|
public JadeDynastySuitAttrData(int id)
|
{
|
suitLv = 0;
|
attrDict = new Dictionary<int, int>();
|
suitAttrConfig = Config.Instance.Get<JadeDynastySuitAttrConfig>(id);
|
if(suitAttrConfig != null)
|
{
|
suitLv = suitAttrConfig.suiteLV;
|
int[] attrIds = suitAttrConfig.attrIDList;
|
int[] attrValues = suitAttrConfig.attrValueList;
|
if(attrIds != null && attrValues != null)
|
{
|
for(int i = 0; i < attrIds.Length; i++)
|
{
|
int attrId = attrIds[i];
|
int attrValue = attrValues[i];
|
if(!attrDict.ContainsKey(attrId))
|
{
|
attrDict.Add(attrId, attrValue);
|
}
|
else
|
{
|
attrDict[attrId] += attrValue;
|
}
|
}
|
}
|
}
|
}
|
}
|
#endregion
|
|
#region 封包
|
#endregion
|
|
public bool TryGetJadeDynastyEquipIndex(int equipPlace,out int equipIndex)
|
{
|
equipIndex = 0;
|
if(equipPlace >= (int)RoleEquipType.JadeDynasty_Cloak && equipPlace <= (int)RoleEquipType.JadeDynasty_Sword4)
|
{
|
equipIndex = equipPlace - 121;
|
return true;
|
}
|
return false;
|
}
|
|
public bool TryGetLockTowerLayer(int equipPlace,out int towerLayer)
|
{
|
towerLayer = 0;
|
return lockEquipLayerDict.TryGetValue(equipPlace,out towerLayer);
|
}
|
|
public bool TryGetSuitType(int equipPlace,out int suitType)
|
{
|
suitType = 0;
|
foreach(var type in suitTypeDict.Keys)
|
{
|
var equipPlaces = suitTypeDict[type];
|
if(equipPlaces.Contains(equipPlace))
|
{
|
suitType = type;
|
return true;
|
}
|
}
|
return false;
|
}
|
|
public bool TryGetEquipPlaces(int equipPlace,out List<int> equipPlaces)
|
{
|
int suitType = 0;
|
equipPlaces = null;
|
bool isSuit = TryGetSuitType(equipPlace,out suitType);
|
if(isSuit)
|
{
|
equipPlaces = suitTypeDict[suitType];
|
return true;
|
}
|
return false;
|
}
|
|
public bool TryGetSuitAttrData(int equipPlace,int suitLv,out JadeDynastySuitAttrData suitAttrData)
|
{
|
suitAttrData = null;
|
int suitType = 0;
|
TryGetSuitType(equipPlace,out suitType);
|
if(suitAttrDict.ContainsKey(suitType))
|
{
|
var dict = suitAttrDict[suitType];
|
return dict.TryGetValue(suitLv,out suitAttrData);
|
}
|
return false;
|
}
|
|
public bool IsWillUnlockEquipPlace(int equipPlace)
|
{
|
int willUnlockPlace = 0;
|
int unlockTowerLayer = UnlockTowerLayer;
|
int minTowerLayer = 0;
|
foreach(var key in lockEquipLayerDict.Keys)
|
{
|
int lockTowerLayer = lockEquipLayerDict[key];
|
if (lockTowerLayer > unlockTowerLayer
|
&& (minTowerLayer > lockTowerLayer || minTowerLayer == 0))
|
{
|
willUnlockPlace = key;
|
minTowerLayer = lockTowerLayer;
|
}
|
}
|
|
return willUnlockPlace == equipPlace && willUnlockPlace != 0;
|
}
|
|
public bool IsLockEquipPlace(int equipPlace)
|
{
|
int unlockTowerLayer = UnlockTowerLayer;
|
int towerLayer = 0;
|
bool isLock = TryGetLockTowerLayer(equipPlace,out towerLayer);
|
if(isLock && towerLayer > unlockTowerLayer)
|
{
|
return true;
|
}
|
return false;
|
}
|
|
public bool TryGetMaxSuitLV(int equipPlace,out int maxSuitLv)
|
{
|
maxSuitLv = 0;
|
var suitLvs = GetSuitLvList(equipPlace);
|
if(suitLvs != null && suitLvs.Count > 0)
|
{
|
maxSuitLv = suitLvs[suitLvs.Count - 1];
|
return true;
|
}
|
return false;
|
}
|
|
public List<int> GetSuitLvList(int equipPlace)
|
{
|
int suitType = 0;
|
bool isSuit = TryGetSuitType(equipPlace,out suitType);
|
if(suitAttrDict.ContainsKey(suitType))
|
{
|
var dict = suitAttrDict[suitType];
|
return dict.Keys.ToList();
|
}
|
return null;
|
}
|
|
public bool TryGetIsActiveSuit(int equipPlace,int suitLV,out List<int> activeEquips)
|
{
|
activeEquips = new List<int>();
|
List<int> equipPlaces = null;
|
bool isSuit = TryGetEquipPlaces(equipPlace, out equipPlaces);
|
var itemModel = playerPack.GetItemModelByIndex(PackType.rptJadeDynastyEquip,equipPlace);
|
if(itemModel != null)
|
{
|
int equipLv = itemModel.chinItemModel.LV;
|
if(equipLv >= suitLV)
|
{
|
activeEquips = equipPlaces;
|
return true;
|
}
|
}
|
|
if(equipPlaces != null)
|
{
|
foreach(var key in equipPlaces)
|
{
|
var model = playerPack.GetItemModelByIndex(PackType.rptJadeDynastyEquip,key);
|
if(model != null)
|
{
|
int equipLv = model.chinItemModel.LV;
|
if (equipLv >= suitLV)
|
{
|
activeEquips.Add(key);
|
}
|
}
|
}
|
}
|
return false;
|
}
|
|
public bool TryGetSuitLV(int equipPlace,PackType type,out int curSuitLv,out int nextSuitLV)
|
{
|
curSuitLv = 0;
|
nextSuitLV = 0;
|
int maxSuitLv = 0;
|
bool isMax = TryGetMaxSuitLV(equipPlace,out maxSuitLv);
|
switch(type)
|
{
|
case PackType.rptJadeDynastyItem:
|
if(isMax)
|
{
|
curSuitLv = maxSuitLv;
|
return true;
|
}
|
break;
|
case PackType.rptJadeDynastyEquip:
|
int minEquipLv = 0;
|
var suitLvs = GetSuitLvList(equipPlace);
|
List<int> equipPlaces = null;
|
bool isSuit = TryGetEquipPlaces(equipPlace, out equipPlaces);
|
if (isSuit && equipPlaces != null)
|
{
|
foreach (var key in equipPlaces)
|
{
|
var model = playerPack.GetItemModelByIndex(type,key);
|
if(model != null
|
&& (minEquipLv > model.chinItemModel.LV
|
|| minEquipLv == 0))
|
{
|
minEquipLv = model.chinItemModel.LV;
|
}
|
else if(model == null)
|
{
|
minEquipLv = 0;
|
break;
|
}
|
}
|
}
|
|
if(minEquipLv != 0 && suitLvs != null)
|
{
|
for(int i = suitLvs.Count - 1; i > -1; i++)
|
{
|
int suitLv = suitLvs[i];
|
if(minEquipLv >= suitLv)
|
{
|
curSuitLv = suitLv;
|
break;
|
}
|
}
|
|
foreach(var suitLv in suitLvs)
|
{
|
if(suitLv > minEquipLv)
|
{
|
nextSuitLV = suitLv;
|
break;
|
}
|
}
|
}
|
|
if(curSuitLv != 0 || nextSuitLV != 0)
|
{
|
return true;
|
}
|
break;
|
}
|
|
return false;
|
|
}
|
|
public bool TryGetSumSuitAttr(int suitType,PackType type,out JadeDynastySuitAttrData activeSuit,out JadeDynastySuitAttrData nextSuit)
|
{
|
activeSuit = null;
|
nextSuit = null;
|
if (!suitTypeDict.ContainsKey(suitType)) return false;
|
|
int equipPlace = suitTypeDict[suitType][0];
|
int curSuitLv = 0;
|
int nextSuitLv = 0;
|
bool isSuitLv = TryGetSuitLV(equipPlace,type,out curSuitLv,out nextSuitLv);
|
|
TryGetSuitAttrData(equipPlace,curSuitLv,out activeSuit);
|
TryGetSuitAttrData(equipPlace,nextSuitLv,out nextSuit);
|
|
return activeSuit != null || nextSuit != null;
|
}
|
}
|
}
|