using vnxbqy.UI;
|
using System;
|
using System.Collections.Generic;
|
using System.Linq;
|
using LitJson;
|
using UnityEngine;
|
|
public class ShentongModel : ILModel<ShentongModel>
|
{
|
public Dictionary<int, structShentongLV> shentongDict = new Dictionary<int, structShentongLV>();
|
public List<int> shentongSetSkillIDs = new List<int>(); //已放置的神通技能
|
public List<int> shentongIDSortBySkillID = new List<int>(); //已出战神通的顺序
|
public List<int> shentongIDList = new List<int>(); //神通列表(排序)
|
Dictionary<int, int> gubaoToShentong = new Dictionary<int, int>();
|
public Dictionary<int, int> shentongIDToSkillID = new Dictionary<int, int>(); //已学的神通对应技能
|
public event Action UpdateShentongEvent;
|
public event Action UpdateShentongSkillEvent;
|
Dictionary<int, int> skillIDToShentongIDDict = new Dictionary<int, int>(); //所有神通技能(含不同等级)对应神通ID
|
Dictionary<int, Redpoint> redpoints = new Dictionary<int, Redpoint>();
|
public int[] skillSetLimitLV;
|
|
public bool isShowShentongSkill;
|
|
public event Action SelectEvent;
|
|
private int m_SelectType;
|
public int selectShentong
|
{
|
get { return m_SelectType; }
|
set
|
{
|
m_SelectType = value;
|
m_SelectShentongSkillID = 0;
|
SelectEvent?.Invoke();
|
}
|
|
}
|
|
public event Action SelectShentongSkillIDEvent;
|
private int m_SelectShentongSkillID;
|
public int selectShentongSkillID
|
{
|
get { return m_SelectShentongSkillID; }
|
set
|
{
|
m_SelectShentongSkillID = value;
|
SelectShentongSkillIDEvent?.Invoke();
|
}
|
|
}
|
|
public event Action OnSkillPositionStateEvent;
|
private int m_SkillPositionState;
|
public int skillPositionState
|
{
|
get { return m_SkillPositionState; }
|
set
|
{
|
m_SkillPositionState = value;
|
OnSkillPositionStateEvent?.Invoke();
|
}
|
|
}
|
|
|
public int shentongPoint = MainRedPoint.faqiRedPoint * 10 + 2;
|
public Redpoint redpoint1 = new Redpoint(MainRedPoint.faqiRedPoint, MainRedPoint.faqiRedPoint * 10 + 2);
|
|
PackModel packModel { get { return ModelCenter.Instance.GetModel<PackModel>(); } }
|
|
protected override void Init()
|
{
|
ParseConfig();
|
GameEvent.beforePlayerDataInitializeEvent += OnBeforePlayerDataInitializeEvent;
|
GameEvent.playerLoginOkEvent += OnPlayerLoginOkEvent;
|
packModel.refreshItemCountEvent += OnRefreshItem;
|
|
}
|
|
protected override void UnInit()
|
{
|
GameEvent.beforePlayerDataInitializeEvent -= OnBeforePlayerDataInitializeEvent;
|
packModel.refreshItemCountEvent -= OnRefreshItem;
|
GameEvent.playerLoginOkEvent -= OnPlayerLoginOkEvent;
|
}
|
|
|
void ParseConfig()
|
{
|
var keys = ILShentongConfig.GetKeys();
|
for (int i = 0; i < keys.Count; i++)
|
{
|
var id = int.Parse(keys[i]);
|
shentongIDList.Add(id);
|
redpoints.Add(id, new Redpoint(shentongPoint, shentongPoint * 1000 + id));
|
gubaoToShentong[ILShentongConfig.Get(id).NeedGubaoID] = id;
|
}
|
|
keys = ILShentongLVConfig.GetKeys();
|
for (int i = 0; i < keys.Count; i++)
|
{
|
var config = ILShentongLVConfig.Get(keys[i]);
|
skillIDToShentongIDDict[config.LVSkillID] = config.ShentongID;
|
}
|
|
var configFunc = FuncConfigConfig.Get("Shentong");
|
|
skillSetLimitLV = JsonMapper.ToObject<int[]>(configFunc.Numerical1);
|
for (int i = 0; i < skillSetLimitLV.Length; i++)
|
{
|
shentongSetSkillIDs.Add(0);
|
shentongIDSortBySkillID.Add(0);
|
}
|
|
}
|
|
void OnBeforePlayerDataInitializeEvent()
|
{
|
shentongDict.Clear();
|
shentongSetSkillIDs.Clear();
|
shentongIDSortBySkillID.Clear();
|
for (int i = 0; i < skillSetLimitLV.Length; i++)
|
{
|
shentongSetSkillIDs.Add(0);
|
shentongIDSortBySkillID.Add(0);
|
}
|
shentongIDToSkillID.Clear();
|
}
|
|
void OnPlayerLoginOkEvent()
|
{
|
isShowShentongSkill = PlayerPrefs.GetInt("hidestskill" + PlayerDatas.Instance.baseData.PlayerID) == 0;
|
UpdateRedpoint();
|
}
|
|
public void UpdateShentongLVInfo(IL_HA3C8_tagMCShentongLVInfo netPack)
|
{
|
for (int i = 0; i < netPack.ShentongLVList.Length; i++)
|
{
|
var info = netPack.ShentongLVList[i];
|
shentongDict[info.ShentongID] = new structShentongLV()
|
{
|
ClassLV = info.ClassLV,
|
LV = info.LV
|
};
|
|
}
|
|
UpdateShentongSkill();
|
SortShentong();
|
UpdateShentongEvent?.Invoke();
|
UpdateRedpoint();
|
}
|
|
public void UpdateShentongSkill(IL_HA3C9_tagMCShentongSkillInfo netPack)
|
{
|
for (int i = 0; i < netPack.SkillIDList.Length; i++)
|
{
|
shentongSetSkillIDs[i] = (int)netPack.SkillIDList[i];
|
}
|
|
for (int i = 0; i < shentongSetSkillIDs.Count; i++)
|
{
|
if (shentongSetSkillIDs[i] != 0)
|
{
|
shentongIDSortBySkillID[i] = skillIDToShentongIDDict[shentongSetSkillIDs[i]];
|
}
|
}
|
|
SortShentong();
|
ILSkillManager.Instance.InitSkill();
|
UpdateShentongSkillEvent?.Invoke();
|
}
|
|
public void UpdateShentongSkill()
|
{
|
var keyList = shentongDict.Keys.ToList();
|
for (int k = 0; k < keyList.Count; k++)
|
{
|
var shentongID = keyList[k];
|
var classLV = shentongDict.ContainsKey(shentongID) ? shentongDict[shentongID].ClassLV : 0;
|
var lv = shentongDict.ContainsKey(shentongID) ? shentongDict[shentongID].LV : 0;
|
for (int i = 1; i <= classLV; i++)
|
{
|
for (int j = 1; j <= 10; j++)
|
{
|
if (classLV == i && j > lv)
|
{
|
break;
|
}
|
var id = ILShentongLVConfig.GetShentongLVID(shentongID, i, j);
|
var config = ILShentongLVConfig.Get(id);
|
if (config.LVSkillID != 0)
|
shentongIDToSkillID[shentongID] = config.LVSkillID;
|
}
|
}
|
}
|
}
|
|
//根据技能排序 优先已放置技能ID - 已激活神通 - 排序
|
public void SortShentong()
|
{
|
shentongIDList.Sort(CmpShentong);
|
}
|
|
int CmpShentong(int x, int y)
|
{
|
int indexX = shentongIDSortBySkillID.IndexOf(x);
|
indexX = indexX == -1 ? 10 : indexX;
|
int indexY = shentongIDSortBySkillID.IndexOf(y);
|
indexY = indexY == -1 ? 10 : indexY;
|
|
if (indexX != indexY)
|
{
|
return indexX.CompareTo(indexY);
|
}
|
|
//古宝解锁问题
|
bool isActiveX = shentongDict.ContainsKey(x) || IsGubaoActive(x);
|
bool isActiveY = shentongDict.ContainsKey(y) || IsGubaoActive(y);
|
if (isActiveX != isActiveY)
|
{
|
return isActiveY.CompareTo(isActiveX);
|
}
|
|
return ILShentongConfig.Get(x).SortIndex.CompareTo(ILShentongConfig.Get(y).SortIndex);
|
}
|
|
public bool IsGubaoActive(int id)
|
{
|
return TreasurePavilionModel.Instance.TryGetGubaoInfo(ILShentongConfig.Get(id).NeedGubaoID).Count != 0;
|
}
|
|
public struct structShentongLV
|
{
|
public int ClassLV;
|
public int LV;
|
}
|
|
|
void UpdateRedpoint()
|
{
|
var keys = redpoints.Keys.ToList();
|
for (int i = 0; i < keys.Count; i++)
|
{
|
var shentongID = keys[i];
|
redpoints[shentongID].state = RedPointState.None;
|
if (!IsGubaoActive(shentongID))
|
continue;
|
|
var nextID = GetNextShentongIndex(shentongID);
|
if (nextID == -1) continue;
|
var items = ILShentongLVConfig.GetUseItems(nextID);
|
var isEnough = true;
|
for (int j = 0; j < items.Count; j++)
|
{
|
var cnt = packModel.GetItemCountByID(PackType.Item, items[j].x);
|
if (cnt < items[j].y)
|
{
|
isEnough = false;
|
break;
|
}
|
}
|
if (isEnough)
|
{
|
redpoints[shentongID].state = RedPointState.Simple;
|
}
|
}
|
|
|
}
|
|
void OnRefreshItem(PackType type, int index, int id)
|
{
|
if (type == PackType.Item && ILShentongLVConfig.needItemIDs.Contains(id))
|
{
|
UpdateRedpoint();
|
}
|
}
|
|
public void SetShentongSkill()
|
{
|
var pack = new IL_CB220_tagCMShentongSkillSet();
|
pack.SkillIDList = new uint[skillSetLimitLV.Length] ;
|
for (int i = 0; i < shentongSetSkillIDs.Count; i++)
|
{
|
pack.SkillIDList[i] = (uint)shentongSetSkillIDs[i];
|
}
|
pack.Count = (byte)pack.SkillIDList.Length;
|
GameNetSystem.Instance.SendInfo(pack);
|
}
|
|
public Dictionary<int, int> shentongAttrDict = new Dictionary<int, int>();
|
|
public void CalcAttr()
|
{
|
shentongAttrDict.Clear();
|
var classLV = shentongDict.ContainsKey(selectShentong) ? shentongDict[selectShentong].ClassLV : 0;
|
var lv = shentongDict.ContainsKey(selectShentong) ? shentongDict[selectShentong].LV : 0;
|
for (int i = 1; i <= classLV; i++)
|
{
|
for (int j = 1; j <= 10; j++)
|
{
|
if (classLV == i && j > lv)
|
{
|
break;
|
}
|
var id = ILShentongLVConfig.GetShentongLVID(selectShentong, classLV, j);
|
var config = ILShentongLVConfig.Get(id);
|
for (int k = 0; k < config.LVAttrTypeList.Length; k++)
|
{
|
if (!shentongAttrDict.ContainsKey(config.LVAttrTypeList[k]))
|
shentongAttrDict[config.LVAttrTypeList[k]] = 0;
|
shentongAttrDict[config.LVAttrTypeList[k]] = shentongAttrDict[config.LVAttrTypeList[k]] + config.LVAttrValueList[k];
|
}
|
}
|
}
|
}
|
|
public int GetNextShentongIndex(int id = 0)
|
{
|
if (id == 0)
|
id = selectShentong;
|
var classLV = shentongDict.ContainsKey(id) ? shentongDict[id].ClassLV : 0;
|
var lv = shentongDict.ContainsKey(id) ? shentongDict[id].LV : 0;
|
|
if (classLV == 0)
|
{
|
classLV = 1;
|
lv = 1;
|
}
|
else if (lv == 10)
|
{
|
classLV = classLV + 1;
|
lv = 1;
|
}
|
else
|
{
|
lv = lv + 1;
|
}
|
return ILShentongLVConfig.GetShentongLVID(id, classLV, lv);
|
}
|
|
|
public void SetSkillPositionState(int state)
|
{
|
skillPositionState = state;
|
}
|
|
public int GetShentongIDByGubaoID(int gubaoID)
|
{
|
if (gubaoToShentong.ContainsKey(gubaoID))
|
return gubaoToShentong[gubaoID];
|
return 0;
|
}
|
}
|