403 lines
12 KiB
C#
403 lines
12 KiB
C#
using System.Collections.Generic;
|
|
using Code.Scripts.Gameplay.Enviorment;
|
|
using Cysharp.Threading.Tasks;
|
|
using Gameplay.PlayerSkill;
|
|
using Gameplay.Unit;
|
|
using Gameplay.Vehicle.Impl;
|
|
using PhxhSDK;
|
|
using UnityEngine;
|
|
|
|
namespace Gameplay.Skill
|
|
{
|
|
using cfg.SkillCfg;
|
|
using Character;
|
|
using Framework;
|
|
using System;
|
|
|
|
public class SkillManager
|
|
{
|
|
|
|
private static SkillManager _instance;
|
|
public static SkillManager instance
|
|
{
|
|
get
|
|
{
|
|
if (_instance == null)
|
|
{
|
|
// DebugUtil.LogError("Skill尚未初始化,请先初始化");
|
|
return null;
|
|
}
|
|
return _instance;
|
|
}
|
|
}
|
|
|
|
public static void CreateInstance()
|
|
{
|
|
if (_instance != null)
|
|
{
|
|
DebugUtil.LogError("请勿重复创建SkillManager");
|
|
return;
|
|
}
|
|
_instance = new SkillManager();
|
|
}
|
|
|
|
private List<UnitSkillManager> _handles;
|
|
private readonly Dictionary<GameUnit, UnitSkillManager> _handleDict;
|
|
|
|
private readonly List<EventDataUseSkill> _useSkillList;
|
|
|
|
public bool needSkillPaused;
|
|
public bool waitSkillEnd;
|
|
/// <summary>
|
|
/// 当前正在释放技能的单位,仅限玩家操作的单位
|
|
/// </summary>
|
|
public GameUnit inSkillingUnit;
|
|
/// <summary>
|
|
/// 当前正在释放技能的单位,仅限AI操作的单位-敌方
|
|
/// </summary>
|
|
public GameUnit inSkillingUnitAI;
|
|
public readonly SkillScreenEffect screenEffect;
|
|
|
|
public PlayerSkillManager playerSkillManager;
|
|
|
|
private SkillManager()
|
|
{
|
|
_handles = new List<UnitSkillManager>();
|
|
_handleDict = new Dictionary<GameUnit, UnitSkillManager>();
|
|
_useSkillList = new List<EventDataUseSkill>();
|
|
screenEffect = new SkillScreenEffect();
|
|
playerSkillManager = new PlayerSkillManager();
|
|
}
|
|
|
|
public void Init()
|
|
{
|
|
DebugUtil.Log("[Init]------SkillManager");
|
|
playerSkillManager.Init();
|
|
screenEffect.Init();
|
|
_RegistEvents();
|
|
}
|
|
|
|
private void _RegistEvents()
|
|
{
|
|
EventManager.Instance.Register(EventManager.EventName.UI_USE_SKILL, (Action<EventDataUseSkill>)_OnUIUseSkill);
|
|
}
|
|
|
|
private void _OnUIUseSkill(EventDataUseSkill eventData)
|
|
{
|
|
_useSkillList.Add(eventData);
|
|
}
|
|
|
|
private void _UnRegistEvents()
|
|
{
|
|
EventManager.Instance.Unregister(EventManager.EventName.UI_USE_SKILL, (Action<EventDataUseSkill>)_OnUIUseSkill);
|
|
}
|
|
|
|
public void Dispose()
|
|
{
|
|
DebugUtil.Log("[Dispose]------SkillManager");
|
|
_UnRegistEvents();
|
|
playerSkillManager.Dispose();
|
|
screenEffect.Restore();
|
|
screenEffect.Dispose();
|
|
_handles = null;
|
|
_instance = null;
|
|
}
|
|
|
|
public static DataSkill GetSkillConfigById(int skillId)
|
|
{
|
|
return TableManager.Instance.Tables.SkillConfig.Get(skillId);
|
|
}
|
|
|
|
public async UniTask<SkillLogicData> GetSkillLogicById(int logicId)
|
|
{
|
|
var combinePath = string.Format(Constants.SKILL_CONFIG_FORMAT_PATH, logicId);
|
|
var loadAsset = await AssetManager.Instance.LoadAssetAsync<TextAsset>(combinePath);
|
|
if (loadAsset == null)
|
|
{
|
|
DebugUtil.LogError("无效的logicId:{0}", logicId);
|
|
return null;
|
|
}
|
|
var json = loadAsset.text;
|
|
var result = JsonUtility.FromJson<SkillLogicData>(json);
|
|
// 立即释放资源
|
|
AssetManager.Instance.Unload(combinePath);
|
|
return result;
|
|
}
|
|
|
|
public async UniTask InitCharacter(Character charactor)
|
|
{
|
|
// 增加主动技能
|
|
if (charactor.runtimeData.configData.skillId == 0)
|
|
{
|
|
charactor.aiManager.Init();
|
|
return;
|
|
}
|
|
|
|
var addUnit = new UnitSkillManager(charactor);
|
|
var result = await addUnit.AddSkill(charactor.runtimeData.configData.skillId);
|
|
if (!result)
|
|
{
|
|
DebugUtil.LogError("角色:{0} 初始化技能:{1}失败", charactor.GetUnitDesc(), charactor.runtimeData.configData.skillId);
|
|
return;
|
|
}
|
|
_AddToManager(charactor, addUnit);
|
|
charactor.aiManager.Init();
|
|
}
|
|
|
|
public void AutoAddPassiveBuffs(Character character)
|
|
{
|
|
var addUnit = GetUnitSkillManager(character);
|
|
if (addUnit == null)
|
|
{
|
|
if (character.commonData.troopId != ETroopsId.Self)
|
|
{
|
|
// 敌方角色允许没有技能
|
|
return;
|
|
}
|
|
DebugUtil.LogError("角色:{0} 未初始化技能", character.GetUnitDesc());
|
|
return;
|
|
}
|
|
// 获取主动技能
|
|
var skill = addUnit.positiveSkill;
|
|
// 增加附带的被动buff技能
|
|
addUnit.AddPassiveBuffIds(skill.runtimeData.configData.PassiveBuffIds);
|
|
|
|
_AddBreakPassiveSkill(character);
|
|
_AddAwakePassiveSkill(character);
|
|
}
|
|
|
|
private void _AddBreakPassiveSkill(Character character)
|
|
{
|
|
var addUnit = GetUnitSkillManager(character);
|
|
if (addUnit == null)
|
|
{
|
|
DebugUtil.LogError("角色:{0} 未初始化技能", character.GetUnitDesc());
|
|
return;
|
|
}
|
|
|
|
var breakSkillId = character.runtimeData.configData.breakPassiveSkillId;
|
|
if (breakSkillId == 0)
|
|
{
|
|
// 0 为默认值,代表无需添加
|
|
DebugUtil.Log($"[被动技能]--角色:{character.GetID()} 无需添加break被动技能");
|
|
return;
|
|
}
|
|
|
|
_AddPassiveSkill(breakSkillId, addUnit);
|
|
|
|
DebugUtil.Log($"[被动技能]--角色:{character.GetID()} 添加break被动技能:{breakSkillId}");
|
|
}
|
|
|
|
private void _AddAwakePassiveSkill(Character character)
|
|
{
|
|
var addUnit = GetUnitSkillManager(character);
|
|
if (addUnit == null)
|
|
{
|
|
DebugUtil.LogError("角色:{0} 未初始化技能", character.GetUnitDesc());
|
|
return;
|
|
}
|
|
|
|
var awakeSkillId = character.runtimeData.configData.awakePassiveSkillId;
|
|
if (awakeSkillId == 0)
|
|
{
|
|
// 0 为默认值,代表无需添加
|
|
return;
|
|
}
|
|
|
|
_AddPassiveSkill(awakeSkillId, addUnit);
|
|
|
|
DebugUtil.Log($"[被动技能]--角色:{character.GetID()} 添加awake被动技能:{awakeSkillId}");
|
|
}
|
|
|
|
private void _AddPassiveSkill(int passiveSkillId, UnitSkillManager addUnit)
|
|
{
|
|
var passiveSkill = TableManager.Instance.Tables.PassiveSkillConfig.Get(passiveSkillId);
|
|
if (passiveSkill == null)
|
|
{
|
|
DebugUtil.LogError("无效的被动技能:{0}", passiveSkillId);
|
|
return;
|
|
}
|
|
if (passiveSkill.BuffIds.Count == 0)
|
|
{
|
|
// 空壳技能,不需要添加
|
|
return;
|
|
}
|
|
var matchEnviormentIds = passiveSkill.EnviormentIds;
|
|
if (matchEnviormentIds.Count > 0)
|
|
{
|
|
// 需要判断环境
|
|
var currentEnviormentId = EnviormentManager.instance.currentEnviormentId;
|
|
if (!matchEnviormentIds.Contains(currentEnviormentId))
|
|
{
|
|
return;
|
|
}
|
|
}
|
|
var matchWeatherIds = passiveSkill.WeatherIds;
|
|
if (matchWeatherIds.Count > 0)
|
|
{
|
|
// 需要判断天气
|
|
var currentWeatherId = EnviormentManager.instance.currentWeatherId;
|
|
if (!matchWeatherIds.Contains(currentWeatherId))
|
|
{
|
|
return;
|
|
}
|
|
}
|
|
addUnit.AddPassiveBuffIds(passiveSkill.BuffIds);
|
|
}
|
|
|
|
public async UniTask InitVehicle(NormalVehicle vehicle)
|
|
{
|
|
var addUnit = new UnitSkillManager(vehicle);
|
|
|
|
// 增加主动技能
|
|
await addUnit.AddSkill(vehicle.runtimeData.configData.skillId);
|
|
|
|
// 获取主动技能
|
|
var skill = addUnit.positiveSkill;
|
|
if (skill != null)
|
|
{
|
|
// 增加附带的被动buff技能
|
|
addUnit.AddPassiveBuffIds(skill.runtimeData.configData.PassiveBuffIds);
|
|
}
|
|
|
|
_AddToManager(vehicle, addUnit);
|
|
vehicle.aiManager.Init();
|
|
}
|
|
|
|
private void _AddToManager(GameUnit u, UnitSkillManager unit)
|
|
{
|
|
_handles.Add(unit);
|
|
_handleDict.Add(u, unit);
|
|
}
|
|
|
|
public UnitSkillManager GetUnitSkillManager(GameUnit unit)
|
|
{
|
|
if (_handleDict.TryGetValue(unit, out var result))
|
|
{
|
|
return result;
|
|
}
|
|
return null;
|
|
}
|
|
|
|
public void LogicUpdate(float dt)
|
|
{
|
|
|
|
if (inSkillingUnitAI != null)
|
|
{
|
|
// 监听状态
|
|
if (inSkillingUnitAI.statusData == null)
|
|
{
|
|
inSkillingUnitAI = null;
|
|
}
|
|
else if (!inSkillingUnitAI.statusData.isInSkilling)
|
|
{
|
|
inSkillingUnitAI = null;
|
|
}
|
|
}
|
|
|
|
if (_handles == null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (needSkillPaused)
|
|
{
|
|
if (waitSkillEnd)
|
|
{
|
|
_WaitSkillEnd();
|
|
}
|
|
else
|
|
{
|
|
_InSkilling(dt);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
playerSkillManager.LogicUpdate(dt);
|
|
_NoInSkilling(dt);
|
|
}
|
|
|
|
}
|
|
|
|
private void _InSkilling(float dt)
|
|
{
|
|
if (inSkillingUnit.statusData.needSkillPaused)
|
|
{
|
|
// 等待技能使用完成
|
|
return;
|
|
}
|
|
|
|
waitSkillEnd = true;
|
|
screenEffect.StartHide();
|
|
}
|
|
|
|
private void _WaitSkillEnd()
|
|
{
|
|
// 判断动画是否结束
|
|
if (!screenEffect.isHide)
|
|
{
|
|
return;
|
|
}
|
|
_OnSkillEnd();
|
|
}
|
|
|
|
private void _NoInSkilling(float dt)
|
|
{
|
|
if (_useSkillList.Count > 0)
|
|
{
|
|
// 进行技能释放
|
|
var skillData = _useSkillList[0];
|
|
_useSkillList.RemoveAt(0);
|
|
|
|
var unit = GetUnitSkillManager(skillData.sender);
|
|
unit.positiveSkill.Use(skillData.pointCellIndex);
|
|
|
|
inSkillingUnit = skillData.sender;
|
|
needSkillPaused = inSkillingUnit.statusData.needSkillPaused;
|
|
}
|
|
|
|
if (needSkillPaused)
|
|
{
|
|
_OnSkillStart();
|
|
return;
|
|
}
|
|
|
|
for (var i = 0; i < _handles.Count; ++i)
|
|
{
|
|
var handle = _handles[i];
|
|
if (handle.owner.isDisposed || handle.owner.statusData.isDead)
|
|
{
|
|
continue;
|
|
}
|
|
handle.LogicUpdate(dt);
|
|
}
|
|
}
|
|
|
|
private void _OnSkillEnd()
|
|
{
|
|
|
|
needSkillPaused = false;
|
|
|
|
EventManager.Instance.Send(EventManager.EventName.INFIGHT_SKILL_END_PAUSE);
|
|
|
|
CameraManager.Instance.MainCamera.GetComponent<CameraController>().enabled = true;
|
|
}
|
|
|
|
private void _OnSkillStart()
|
|
{
|
|
waitSkillEnd = false;
|
|
|
|
screenEffect.Show();
|
|
|
|
EventManager.Instance.Send(EventManager.EventName.INFIGHT_SKILL_START_PAUSE);
|
|
|
|
CameraManager.Instance.MainCamera.GetComponent<CameraController>().enabled = false;
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|