425 lines
12 KiB
C#
425 lines
12 KiB
C#
using cfg.ActorCfg;
|
||
using cfg.PlayerSkillCfg;
|
||
using cfg.SkillCfg;
|
||
using Framework;
|
||
using Framework.Condition;
|
||
using Gameplay;
|
||
using Gameplay.Net;
|
||
using System;
|
||
using System.Collections.Generic;
|
||
using System.Linq;
|
||
using PhxhSDK;
|
||
using Constants = Framework.Constants;
|
||
|
||
public class PlayerSkillUnlockLevelData : Singlenton<PlayerSkillUnlockLevelData>
|
||
{
|
||
public int unlockLayer;
|
||
public Dictionary<int,int>lockLayerDic= new Dictionary<int,int>();
|
||
}
|
||
|
||
public static class PlayerSkillUpgradeHelper
|
||
{
|
||
public static int GetMaxLevel(int id)
|
||
{
|
||
int maxLevel = 0;
|
||
for (int i = 0; i <TableManager.Instance.Tables.PlayerSkillUpgrade.DataList.Count ; i++)
|
||
{
|
||
DataPlayerSkillUpgrade data = TableManager.Instance.Tables.PlayerSkillUpgrade.DataList[i];
|
||
if (data.Level>maxLevel)
|
||
{
|
||
maxLevel = data.Level;
|
||
}
|
||
}
|
||
return maxLevel;
|
||
}
|
||
|
||
public static int GetSumLevel()
|
||
{
|
||
return Actor.Instance.PlayerSkill.GetSumLevel();
|
||
}
|
||
|
||
|
||
|
||
|
||
}
|
||
|
||
public class SinglePlayerSkillCultivateData
|
||
{
|
||
public int ID;
|
||
//public int Level;
|
||
public string IconPath;
|
||
public DataPlayerSkill SkillCfg;
|
||
public DataPlayerSkillUpgrade UpgradeCfg;
|
||
public int maxLevel = 0;
|
||
public int lineNum = 0;
|
||
|
||
public int[] unLockId => UpgradeCfg.Unlock;
|
||
public List<int> nextLockId;
|
||
public List<int> unLockIndex;
|
||
public string Name => CommonUtils.GetLocalizeText(SkillCfg.NameLocal);
|
||
public string Desc => CommonUtils.GetLocalizeText(SkillCfg.DescLocal);
|
||
|
||
public bool IsUnlock()
|
||
{
|
||
for (int i = 0; i < unLockIndex.Count; i++)
|
||
{
|
||
int level = Actor.Instance.PlayerSkill.GetLevel(unLockIndex[i]);
|
||
if((level==0)||level<PlayerSkillUpgradeHelper.GetMaxLevel(unLockIndex[i]))
|
||
{
|
||
return false;
|
||
}
|
||
}
|
||
return true;
|
||
}
|
||
public SinglePlayerSkillCultivateData(DataPlayerSkillUpgrade cfg)
|
||
{
|
||
ID= cfg.ID;
|
||
UpgradeCfg= cfg;
|
||
//RefreshLevel();
|
||
RefreshMaxLevel(cfg.Level);
|
||
nextLockId = new List<int>();
|
||
unLockIndex = new List<int>();
|
||
//检查上层配置
|
||
if(cfg.LayerID==1)
|
||
{
|
||
lineNum = 0;
|
||
}else
|
||
{
|
||
for (int i = 0; i < cfg.Unlock.Length; i++)
|
||
{
|
||
DataPlayerSkillUpgrade dataPlayerSkillUpgrade= TableManager.Instance.Tables.PlayerSkillUpgrade.Get(cfg.Unlock[i], cfg.LayerID - 1);
|
||
if (dataPlayerSkillUpgrade==null)
|
||
{
|
||
DebugUtil.LogError("playerSkillUpgrade表里,id为{0},等级为{1}的unlockId为{2}在上一层没有配置", cfg.ID, cfg.Level, cfg.Unlock[i]);
|
||
}
|
||
}
|
||
|
||
|
||
}
|
||
SkillCfg = TableManager.GetSingleton().Tables.PlayerSkillConfig.Get(cfg.ID);
|
||
|
||
if(SkillCfg==null)
|
||
{
|
||
DebugUtil.LogError("PlayerSkillConfig没有id为{0}的技能", cfg.ID);
|
||
SkillCfg = TableManager.GetSingleton().Tables.PlayerSkillConfig.DataList[0];
|
||
}
|
||
|
||
IconPath =Constants.UI_PlaySkill_IconPathFolder+ SkillCfg.IconPath+".png";
|
||
|
||
}
|
||
public void AddNextLockID(int ID)
|
||
{
|
||
nextLockId.Add(ID);
|
||
}
|
||
|
||
public void AddUnlockIndexID(int ID)
|
||
{
|
||
unLockIndex.Add(ID);
|
||
}
|
||
public bool IfMaxLevel()
|
||
{
|
||
return Actor.Instance.PlayerSkill.GetLevel(ID) >= maxLevel;
|
||
}
|
||
public void RefreshMaxLevel(int curLv)
|
||
{
|
||
if(curLv>maxLevel)
|
||
{
|
||
maxLevel= curLv;
|
||
}
|
||
|
||
}
|
||
|
||
|
||
}
|
||
|
||
public class PlayerLayerCultivateData
|
||
{
|
||
public List<SinglePlayerSkillCultivateData> dataList;
|
||
|
||
public PlayerLayerCultivateData(DataPlayerSkillUpgrade cfg)
|
||
{
|
||
dataList = new List<SinglePlayerSkillCultivateData>
|
||
{
|
||
new SinglePlayerSkillCultivateData(cfg)
|
||
};
|
||
}
|
||
public void Add(DataPlayerSkillUpgrade cfg)
|
||
{
|
||
bool isContain = false;
|
||
for (int i = 0; i < dataList.Count; i++)
|
||
{
|
||
if (dataList[i].ID==cfg.ID)
|
||
{
|
||
isContain = true;
|
||
dataList[i].RefreshMaxLevel(cfg.Level);
|
||
}
|
||
}
|
||
if(isContain)
|
||
{
|
||
return;
|
||
}
|
||
|
||
SinglePlayerSkillCultivateData data = new SinglePlayerSkillCultivateData(cfg);
|
||
dataList.Add(data);
|
||
}
|
||
}
|
||
|
||
|
||
|
||
public class PlayerSkillTypeData
|
||
{
|
||
public int MaxLayer => maxLayer;
|
||
private int maxLayer;
|
||
|
||
public PlayerSkillType nowType;
|
||
|
||
public Dictionary<int, PlayerLayerCultivateData> layerDataDic = new Dictionary<int, PlayerLayerCultivateData>();
|
||
|
||
public PlayerLayerCultivateData GetDataByLayer(int layer)
|
||
{
|
||
PlayerLayerCultivateData data;
|
||
if (layerDataDic.TryGetValue(layer, out data))
|
||
{
|
||
return data;
|
||
}
|
||
return null;
|
||
}
|
||
public PlayerSkillTypeData()
|
||
{
|
||
InitData();
|
||
}
|
||
void InitData()
|
||
{
|
||
maxLayer = 0;
|
||
}
|
||
|
||
public void Add(DataPlayerSkillUpgrade data)
|
||
{
|
||
PlayerLayerCultivateData player;
|
||
if (layerDataDic.TryGetValue(data.LayerID, out player))
|
||
{
|
||
player.Add(data);
|
||
}
|
||
else
|
||
{
|
||
|
||
PlayerLayerCultivateData temp = new PlayerLayerCultivateData(data);
|
||
temp.Add(data);
|
||
layerDataDic.Add(data.LayerID, temp);
|
||
RefreshMaxLayer(data.LayerID);
|
||
}
|
||
}
|
||
|
||
private void RefreshMaxLayer(int layerID)
|
||
{
|
||
if(layerID>maxLayer)
|
||
{
|
||
maxLayer = layerID;
|
||
}
|
||
}
|
||
}
|
||
|
||
public class AllPlayerSkillCultivateData
|
||
{
|
||
//layer 的dic
|
||
private Dictionary<PlayerSkillType, PlayerSkillTypeData> playerTypeDic;
|
||
public Dictionary<int, SinglePlayerSkillCultivateData> allSinglePlayerDic;
|
||
|
||
public int maxLayer;
|
||
|
||
public PlayerSkillTypeData GetDataBySkillType(PlayerSkillType playerSkillType)
|
||
{
|
||
PlayerSkillTypeData data;
|
||
if(playerTypeDic.TryGetValue(playerSkillType,out data))
|
||
{
|
||
return data;
|
||
}
|
||
DebugUtil.LogError("数据有问题");
|
||
return null;
|
||
}
|
||
public AllPlayerSkillCultivateData()
|
||
{
|
||
playerTypeDic = new Dictionary<PlayerSkillType, PlayerSkillTypeData>();
|
||
allSinglePlayerDic = new Dictionary<int, SinglePlayerSkillCultivateData>();
|
||
for (int i = 0; i < TableManager.Instance.Tables.PlayerSkillUpgrade.DataList.Count; i++)
|
||
{
|
||
DataPlayerSkillUpgrade data = TableManager.Instance.Tables.PlayerSkillUpgrade.DataList[i];
|
||
PlayerSkillTypeData player;
|
||
if(playerTypeDic.TryGetValue(data.SkillType,out player))
|
||
{
|
||
player.Add(data);
|
||
}else
|
||
{
|
||
PlayerSkillTypeData temp = new PlayerSkillTypeData();
|
||
temp.Add(data);
|
||
playerTypeDic.Add(data.SkillType, temp);
|
||
|
||
}
|
||
|
||
SinglePlayerSkillCultivateData data1 = new SinglePlayerSkillCultivateData(data);
|
||
if(!allSinglePlayerDic.ContainsKey(data.ID))
|
||
{
|
||
allSinglePlayerDic.Add(data.ID, data1);
|
||
|
||
}
|
||
}
|
||
|
||
TidyData();
|
||
AddCondition();
|
||
}
|
||
|
||
private void AddCondition()
|
||
{
|
||
for (int i = 1; i < GetMaxLayer(); i++)
|
||
{
|
||
AddLockConditionReaction(i);
|
||
}
|
||
}
|
||
class conditionParamInt
|
||
{
|
||
public int layerid;
|
||
}
|
||
|
||
private void AddLockConditionReaction(int layerId)
|
||
{
|
||
|
||
int[] UnLockCondition = TableManager.Instance.Tables.PlayerSkillLayer.Get(layerId).Unlock;
|
||
conditionParamInt temp = new conditionParamInt();
|
||
temp.layerid = layerId;
|
||
ConditionReactor.Instance.AddReaction(UnLockCondition, OnUnlockConditionChanged,temp);
|
||
}
|
||
|
||
private void OnUnlockConditionChanged(bool result, object callBackParam, int reactionID)
|
||
{
|
||
if (result)
|
||
{
|
||
conditionParamInt temp = callBackParam as conditionParamInt;
|
||
if(temp.layerid> PlayerSkillUnlockLevelData.GetSingleton().unlockLayer)
|
||
{
|
||
PlayerSkillUnlockLevelData.GetSingleton().unlockLayer = temp.layerid;
|
||
}
|
||
|
||
EventManager.Instance.Send<int>(EventManager.EventName.CultivatePlayerSkillUpgradeChangeLockLayer, temp.layerid);
|
||
ConditionReactor.Instance.RemoveReaction(reactionID);
|
||
}else
|
||
{
|
||
// PlayerSkillUnlockLevelData.GetSingleton().lockLayerDic[]
|
||
}
|
||
}
|
||
private void TidyData()
|
||
{
|
||
GetAllNextLockId();
|
||
TidyAllData();
|
||
}
|
||
|
||
private void GetUpIndexData(PlayerSkillTypeData data)
|
||
{
|
||
for (int i = 1; i <= data.MaxLayer; i++)
|
||
{
|
||
if (i != 1)
|
||
{
|
||
for (int j = 0; j < data.layerDataDic[i].dataList.Count; j++)
|
||
{
|
||
var nowdata = data.layerDataDic[i].dataList[j];
|
||
for (int k = 0; k < data.layerDataDic[i - 1].dataList.Count; k++)
|
||
{
|
||
if (nowdata.unLockId.Contains(data.layerDataDic[i - 1].dataList[k].ID))
|
||
{
|
||
nowdata.unLockIndex.Add(k);
|
||
}
|
||
}
|
||
|
||
}
|
||
}
|
||
}
|
||
|
||
|
||
}
|
||
|
||
|
||
private void TidyAllData()
|
||
{
|
||
TidySingleData(playerTypeDic[PlayerSkillType.Conduct]);
|
||
TidySingleData(playerTypeDic[PlayerSkillType.Support]);
|
||
TidySingleData(playerTypeDic[PlayerSkillType.Attack]);
|
||
}
|
||
private void TidySingleData(PlayerSkillTypeData data)
|
||
{
|
||
for (int i = 1; i < data.MaxLayer; i++)
|
||
{
|
||
if (data.layerDataDic[i].dataList.Count ==3)
|
||
{
|
||
|
||
for (int j = 0; j < data.layerDataDic[i].dataList.Count; j++)
|
||
{
|
||
|
||
SinglePlayerSkillCultivateData singleData = data.layerDataDic[i].dataList[j];
|
||
SinglePlayerSkillCultivateData maxChildData=null;
|
||
int maxChildCount = 0;
|
||
if (singleData.nextLockId.Count > maxChildCount)
|
||
{
|
||
maxChildCount = singleData.nextLockId.Count;
|
||
maxChildData = singleData;
|
||
}
|
||
|
||
List<SinglePlayerSkillCultivateData> tempList = new List<SinglePlayerSkillCultivateData>();
|
||
tempList.AddRange(data.layerDataDic[i].dataList);
|
||
tempList.Remove(maxChildData);
|
||
data.layerDataDic[i].dataList.Clear();
|
||
|
||
data.layerDataDic[i].dataList.Add(tempList[0]);
|
||
data.layerDataDic[i].dataList.Add(maxChildData);
|
||
data.layerDataDic[i].dataList.Add(tempList[1]);
|
||
|
||
}
|
||
|
||
|
||
}
|
||
|
||
}
|
||
|
||
GetUpIndexData(data);
|
||
}
|
||
private void GetAllNextLockId()
|
||
{
|
||
GetSingleNextLockId(playerTypeDic[PlayerSkillType.Conduct]);
|
||
GetSingleNextLockId(playerTypeDic[PlayerSkillType.Support]);
|
||
GetSingleNextLockId(playerTypeDic[PlayerSkillType.Attack]);
|
||
|
||
}
|
||
private void GetSingleNextLockId(PlayerSkillTypeData data)
|
||
{
|
||
for (int i = 1; i <= data.MaxLayer; i++)
|
||
{
|
||
for (int j = 0; j < data.layerDataDic[i].dataList.Count; j++)
|
||
{
|
||
if (i != data.MaxLayer)
|
||
{
|
||
foreach (var val1 in allSinglePlayerDic.Keys)
|
||
{
|
||
if (allSinglePlayerDic[val1].unLockId.Contains( data.layerDataDic[i].dataList[j].ID))
|
||
{
|
||
data.layerDataDic[i].dataList[j].AddNextLockID(val1);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
}
|
||
}
|
||
|
||
|
||
public int GetMaxLayer()
|
||
{
|
||
int maxLayer = 0;
|
||
for (int i = 0; i < TableManager.Instance.Tables.PlayerSkillUpgrade.DataList.Count; i++)
|
||
{
|
||
if (TableManager.Instance.Tables.PlayerSkillUpgrade.DataList[i].LayerID>maxLayer)
|
||
{
|
||
maxLayer = TableManager.Instance.Tables.PlayerSkillUpgrade.DataList[i].LayerID;
|
||
}
|
||
}
|
||
return maxLayer;
|
||
}
|
||
}
|