674 lines
18 KiB
C#
674 lines
18 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;
|
||
using cfg.CharacterCfg;
|
||
|
||
/// <summary>
|
||
/// 玩家技能等级解锁数据
|
||
/// </summary>
|
||
public class PlayerSkillUnlockLevelData : Singlenton<PlayerSkillUnlockLevelData>
|
||
{
|
||
public int unlockLayer;
|
||
public Dictionary<int, int> lockLayerDic = new();
|
||
}
|
||
|
||
/// <summary>
|
||
/// 玩家技能升级帮助类
|
||
/// </summary>
|
||
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();
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 单个玩家技能养成数据
|
||
/// </summary>
|
||
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;
|
||
}
|
||
|
||
}
|
||
|
||
|
||
}
|
||
|
||
/// <summary>
|
||
/// 玩家每层养成数据
|
||
/// </summary>
|
||
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);
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 玩家技能类型数据
|
||
/// </summary>
|
||
public class PlayerSkillTypeData
|
||
{
|
||
/// <summary>
|
||
/// 最大层数
|
||
/// </summary>
|
||
private int maxLayer;
|
||
/// <summary>
|
||
/// 玩家技能类型
|
||
/// </summary>
|
||
private PlayerSkillType playerSkillType;
|
||
|
||
/// <summary>
|
||
/// 玩家技能类型
|
||
/// </summary>
|
||
public PlayerSkillType SkillType
|
||
{
|
||
get { return playerSkillType; }
|
||
}
|
||
|
||
/// <summary>
|
||
/// 最大层数
|
||
/// </summary>
|
||
public int MaxLayer
|
||
{
|
||
get { return maxLayer; }
|
||
}
|
||
|
||
/// <summary>
|
||
/// 层数据字典,key:第几层 value:该层数据
|
||
/// </summary>
|
||
public Dictionary<int, PlayerLayerCultivateData> dicLayerData = new();
|
||
|
||
/// <summary>
|
||
/// 根据层数获取该层数据
|
||
/// </summary>
|
||
/// <param name="layer"></param>
|
||
/// <returns></returns>
|
||
public PlayerLayerCultivateData GetDataByLayer(int layer)
|
||
{
|
||
if (dicLayerData.TryGetValue(layer, out PlayerLayerCultivateData data))
|
||
return data;
|
||
|
||
return null;
|
||
}
|
||
|
||
public PlayerSkillTypeData()
|
||
{
|
||
maxLayer = 0;
|
||
}
|
||
|
||
public void Add(DataPlayerSkillUpgrade data)
|
||
{
|
||
if (dicLayerData.TryGetValue(data.LayerID, out PlayerLayerCultivateData playerLayerCultivateData))
|
||
playerLayerCultivateData.Add(data);
|
||
else
|
||
{
|
||
|
||
playerLayerCultivateData = new PlayerLayerCultivateData(data);
|
||
playerLayerCultivateData.Add(data);
|
||
dicLayerData.Add(data.LayerID, playerLayerCultivateData);
|
||
RefreshMaxLayer(data.LayerID);
|
||
}
|
||
}
|
||
|
||
private void RefreshMaxLayer(int layerID)
|
||
{
|
||
if (layerID > maxLayer)
|
||
maxLayer = layerID;
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 所有玩家技能养成数据
|
||
/// </summary>
|
||
public class AllPlayerSkillCultivateData
|
||
{
|
||
/// <summary>
|
||
/// 玩家技能类型对应技能数据字典
|
||
/// </summary>
|
||
private readonly Dictionary<PlayerSkillType, PlayerSkillTypeData> dicPlayerSkillTypeData;
|
||
public Dictionary<int, SinglePlayerSkillCultivateData> allSinglePlayerDic;
|
||
|
||
public int maxLayer;
|
||
|
||
public PlayerSkillTypeData GetDataBySkillType(PlayerSkillType playerSkillType)
|
||
{
|
||
if (dicPlayerSkillTypeData.TryGetValue(playerSkillType, out PlayerSkillTypeData data))
|
||
return data;
|
||
|
||
DebugUtil.LogError("数据有问题");
|
||
return null;
|
||
}
|
||
|
||
public AllPlayerSkillCultivateData()
|
||
{
|
||
dicPlayerSkillTypeData = new Dictionary<PlayerSkillType, PlayerSkillTypeData>();
|
||
allSinglePlayerDic = new Dictionary<int, SinglePlayerSkillCultivateData>();
|
||
foreach (DataPlayerSkillUpgrade skillUpgradeData in TableManager.Instance.Tables.PlayerSkillUpgrade.DataList)
|
||
{
|
||
if (dicPlayerSkillTypeData.TryGetValue(skillUpgradeData.SkillType, out PlayerSkillTypeData player))
|
||
player.Add(skillUpgradeData);
|
||
else
|
||
{
|
||
PlayerSkillTypeData temp = new();
|
||
temp.Add(skillUpgradeData);
|
||
dicPlayerSkillTypeData.Add(skillUpgradeData.SkillType, temp);
|
||
}
|
||
|
||
SinglePlayerSkillCultivateData data = new(skillUpgradeData);
|
||
if(!allSinglePlayerDic.ContainsKey(skillUpgradeData.ID))
|
||
allSinglePlayerDic.Add(skillUpgradeData.ID, data);
|
||
}
|
||
|
||
TidyData();
|
||
AddCondition();
|
||
}
|
||
|
||
private void AddCondition()
|
||
{
|
||
for (int i = 1; i < GetMaxLayer(); i++)
|
||
{
|
||
AddLockConditionReaction(i);
|
||
}
|
||
}
|
||
|
||
private class ConditionParamInt
|
||
{
|
||
public int layerid;
|
||
}
|
||
|
||
private void AddLockConditionReaction(int layerId)
|
||
{
|
||
|
||
int[] UnLockCondition = TableManager.Instance.Tables.PlayerSkillLayer.Get(layerId).Unlock;
|
||
ConditionParamInt temp = new()
|
||
{
|
||
layerid = layerId
|
||
};
|
||
ConditionReactor.Instance.AddReaction(UnLockCondition, OnUnlockConditionChanged, temp);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 解锁条件变化回调
|
||
/// </summary>
|
||
/// <param name="result"></param>
|
||
/// <param name="callBackParam"></param>
|
||
/// <param name="reactionID"></param>
|
||
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.dicLayerData[i].dataList.Count; j++)
|
||
{
|
||
var nowdata = data.dicLayerData[i].dataList[j];
|
||
for (int k = 0; k < data.dicLayerData[i - 1].dataList.Count; k++)
|
||
{
|
||
if (nowdata.unLockId.Contains(data.dicLayerData[i - 1].dataList[k].ID))
|
||
{
|
||
nowdata.unLockIndex.Add(k);
|
||
}
|
||
}
|
||
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
private void TidyAllData()
|
||
{
|
||
TidySingleData(dicPlayerSkillTypeData[PlayerSkillType.Conduct]);
|
||
TidySingleData(dicPlayerSkillTypeData[PlayerSkillType.Support]);
|
||
TidySingleData(dicPlayerSkillTypeData[PlayerSkillType.Attack]);
|
||
}
|
||
|
||
private void TidySingleData(PlayerSkillTypeData data)
|
||
{
|
||
for (int i = 1; i < data.MaxLayer; i++)
|
||
{
|
||
if (data.dicLayerData[i].dataList.Count == 3)
|
||
{
|
||
for (int j = 0; j < data.dicLayerData[i].dataList.Count; j++)
|
||
{
|
||
SinglePlayerSkillCultivateData singleData = data.dicLayerData[i].dataList[j];
|
||
SinglePlayerSkillCultivateData maxChildData = null;
|
||
int maxChildCount = 0;
|
||
if (singleData.nextLockId.Count > maxChildCount)
|
||
{
|
||
maxChildCount = singleData.nextLockId.Count;
|
||
maxChildData = singleData;
|
||
}
|
||
|
||
List<SinglePlayerSkillCultivateData> tempList = new();
|
||
tempList.AddRange(data.dicLayerData[i].dataList);
|
||
tempList.Remove(maxChildData);
|
||
data.dicLayerData[i].dataList.Clear();
|
||
|
||
data.dicLayerData[i].dataList.Add(tempList[0]);
|
||
data.dicLayerData[i].dataList.Add(maxChildData);
|
||
data.dicLayerData[i].dataList.Add(tempList[1]);
|
||
}
|
||
}
|
||
}
|
||
|
||
GetUpIndexData(data);
|
||
}
|
||
|
||
private void GetAllNextLockId()
|
||
{
|
||
GetSingleNextLockId(dicPlayerSkillTypeData[PlayerSkillType.Conduct]);
|
||
GetSingleNextLockId(dicPlayerSkillTypeData[PlayerSkillType.Support]);
|
||
GetSingleNextLockId(dicPlayerSkillTypeData[PlayerSkillType.Attack]);
|
||
|
||
}
|
||
|
||
private void GetSingleNextLockId(PlayerSkillTypeData data)
|
||
{
|
||
for (int i = 1; i <= data.MaxLayer; i++)
|
||
{
|
||
for (int j = 0; j < data.dicLayerData[i].dataList.Count; j++)
|
||
{
|
||
if (i != data.MaxLayer)
|
||
{
|
||
foreach (var val1 in allSinglePlayerDic.Keys)
|
||
{
|
||
if (allSinglePlayerDic[val1].unLockId.Contains( data.dicLayerData[i].dataList[j].ID))
|
||
{
|
||
data.dicLayerData[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;
|
||
}
|
||
}
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
/// <summary>
|
||
/// 指挥官所有技能树数据
|
||
/// </summary>
|
||
public class AllCommandSkillTreeData
|
||
{
|
||
/// <summary>
|
||
/// 指挥官技能树字典,key:技能类型 value:技能树数据
|
||
/// </summary>
|
||
private readonly Dictionary<PlayerSkillType, CommandSkillTreeData> dicSkillTree = new();
|
||
|
||
public AllCommandSkillTreeData()
|
||
{
|
||
foreach (DataPlayerSkillUpgrade skillUpgradeData in TableManager.Instance.Tables.PlayerSkillUpgrade.DataList)
|
||
{
|
||
if (!dicSkillTree.TryGetValue(skillUpgradeData.SkillType, out CommandSkillTreeData skillTreeData))
|
||
{
|
||
skillTreeData = new();
|
||
dicSkillTree[skillUpgradeData.SkillType] = skillTreeData;
|
||
}
|
||
|
||
skillTreeData.Add(skillUpgradeData);
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 根据技能类型获取技能树数据
|
||
/// </summary>
|
||
/// <param name="type"></param>
|
||
/// <returns></returns>
|
||
public CommandSkillTreeData GetSkillTreeDataByType(PlayerSkillType type)
|
||
{
|
||
dicSkillTree.TryGetValue(type, out CommandSkillTreeData data);
|
||
|
||
return data;
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 指挥官技能树数据
|
||
/// </summary>
|
||
public class CommandSkillTreeData
|
||
{
|
||
/// <summary>
|
||
/// 每层指挥官技能
|
||
/// </summary>
|
||
private readonly List<HashSet<int>> listSetSkillId = new();
|
||
|
||
/// <summary>
|
||
/// 获取技能树层数
|
||
/// </summary>
|
||
public int FloorCount
|
||
{
|
||
get { return listSetSkillId.Count; }
|
||
}
|
||
|
||
public void Add(DataPlayerSkillUpgrade data)
|
||
{
|
||
int index = data.LayerID - 1;
|
||
while (listSetSkillId.Count <= index)
|
||
{
|
||
listSetSkillId.Add(new());
|
||
}
|
||
|
||
listSetSkillId[index].Add(data.ID);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 获取该层的技能配置数据列表
|
||
/// </summary>
|
||
/// <param name="index"></param>
|
||
/// <returns></returns>
|
||
public List<CommandSkillData> GetSkillIDs(int index)
|
||
{
|
||
if (index > listSetSkillId.Count)
|
||
{
|
||
DebugUtil.LogError("数组越界");
|
||
return null;
|
||
}
|
||
|
||
HashSet<int> setId = listSetSkillId[index];
|
||
List<CommandSkillData> listSkillData = new(setId.Count);
|
||
foreach (int skillID in setId)
|
||
{
|
||
listSkillData.Add(new CommandSkillData(skillID));
|
||
}
|
||
|
||
return listSkillData;
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 指挥官技能数据
|
||
/// </summary>
|
||
public class CommandSkillData
|
||
{
|
||
/// <summary>
|
||
/// 技能id
|
||
/// </summary>
|
||
private int skillID;
|
||
/// <summary>
|
||
/// 技能等级
|
||
/// </summary>
|
||
private int skillLevel;
|
||
/// <summary>
|
||
/// 指挥官技能养成配置数据
|
||
/// </summary>
|
||
private DataPlayerSkillUpgrade skillUpgradeData;
|
||
/// <summary>
|
||
/// 指挥官技能配置数据
|
||
/// </summary>
|
||
private DataPlayerSkill playerSkill;
|
||
|
||
#region 属性
|
||
/// <summary>
|
||
/// 技能ID
|
||
/// </summary>
|
||
public int SkillID
|
||
{
|
||
get { return skillID; }
|
||
}
|
||
|
||
/// <summary>
|
||
/// 解锁条件列表(配置的id升一级就解锁)
|
||
/// </summary>
|
||
public int[] ListUnLock
|
||
{
|
||
get { return skillUpgradeData.Unlock; }
|
||
}
|
||
|
||
/// <summary>
|
||
/// 技能名
|
||
/// </summary>
|
||
public string Name
|
||
{
|
||
get { return CommonUtils.GetLocalizeText(playerSkill.NameLocal); }
|
||
}
|
||
|
||
/// <summary>
|
||
/// 技能描述
|
||
/// </summary>
|
||
public string Desc
|
||
{
|
||
get { return CommonUtils.GetLocalizeText(playerSkill.DescLocal); }
|
||
}
|
||
|
||
/// <summary>
|
||
/// 图标路径
|
||
/// </summary>
|
||
public string IconPath
|
||
{
|
||
get { return $"{Constants.UI_PlaySkill_IconPathFolder}{playerSkill.IconPath}.png"; }
|
||
}
|
||
|
||
/// <summary>
|
||
/// 当前等级
|
||
/// </summary>
|
||
public int Level
|
||
{
|
||
get { return skillUpgradeData.Level; }
|
||
}
|
||
|
||
/// <summary>
|
||
/// 最大等级
|
||
/// </summary>
|
||
public int MaxLevel
|
||
{
|
||
get { return skillUpgradeData.MaxLevel; }
|
||
}
|
||
|
||
/// <summary>
|
||
/// 所在第几层
|
||
/// </summary>
|
||
public int Floor
|
||
{
|
||
get { return skillUpgradeData.LayerID; }
|
||
}
|
||
|
||
/// <summary>
|
||
/// 是否锁住
|
||
/// </summary>
|
||
public bool IsLock
|
||
{
|
||
get
|
||
{
|
||
for (int i = 0; i < skillUpgradeData.Unlock.Length; i++)
|
||
{
|
||
int level = Actor.Instance.PlayerSkill.GetLevel(skillUpgradeData.Unlock[i]);
|
||
if (level < 1)
|
||
return true;
|
||
}
|
||
|
||
return false;
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 是否满级
|
||
/// </summary>
|
||
public bool IsFullLevel
|
||
{
|
||
get { return Level >= MaxLevel; }
|
||
}
|
||
#endregion
|
||
|
||
public CommandSkillData(int id)
|
||
{
|
||
skillID = id;
|
||
skillLevel = Actor.Instance.PlayerSkill.GetLevel(id);
|
||
skillUpgradeData = TableManager.Instance.Tables.PlayerSkillUpgrade.Get(skillID, skillLevel);
|
||
playerSkill = TableManager.Instance.Tables.PlayerSkillConfig.Get(skillID);
|
||
|
||
}
|
||
} |