NLDClient-yudde/ProjectNLD/Assets/Code/Scripts/Gameplay/PlayerSkill/PlayerSkillManager.cs

102 lines
2.6 KiB
C#
Raw Normal View History

2023-12-06 15:32:45 +08:00
using cfg.SkillCfg;
using Framework;
2023-12-08 13:28:03 +08:00
using Gameplay.Character;
2023-12-06 15:32:45 +08:00
using Gameplay.PlayerSkill.State;
2023-12-08 13:28:03 +08:00
using Gameplay.PlayerSkill.Unit;
2023-12-06 12:22:59 +08:00
using LTGame;
2023-12-08 13:28:03 +08:00
using UnityEngine;
2023-12-06 12:22:59 +08:00
namespace Gameplay.PlayerSkill
{
public class PlayerSkillManager
{
private NStateMachine<BasePlayerSkillState> _fsm;
2023-12-06 15:32:45 +08:00
public int readySkillId { get; private set; }
public DataPlayerSkill readySkillConfig { get; private set; }
2023-12-08 13:28:03 +08:00
public int selectedCellIndex;
public FakePlayerUnit playerUnit;
2023-12-06 18:36:15 +08:00
private float _maxCd;
private float _curCd;
public bool isInCD
{
get
{
return _curCd > 0;
}
}
2023-12-06 12:22:59 +08:00
public void Init()
{
2023-12-08 13:28:03 +08:00
// TODO: 这里临时用己方的troopId
var fakeId = GUIDManager.GenGuid();
playerUnit = new FakePlayerUnit(fakeId, ETroopsId.Self);
2023-12-06 14:08:57 +08:00
_InitFsm();
2023-12-06 12:22:59 +08:00
}
2023-12-08 13:28:03 +08:00
public float ReadParamFloat(int index)
{
if (readySkillConfig.FloatParams.Count <= index)
{
DebugUtil.LogError("技能参数不足: " + readySkillConfig.ID + " " + index);
return 0;
}
return readySkillConfig.FloatParams[index];
}
public int ReadParamInt(int index)
{
var floatVal = ReadParamFloat(index);
return Mathf.RoundToInt(floatVal);
}
2023-12-06 12:22:59 +08:00
private void _InitFsm()
{
_fsm = new NStateMachine<BasePlayerSkillState>();
2023-12-06 15:32:45 +08:00
_fsm.Add(new PlayerSkillStateIdle(this));
_fsm.Add(new PlayerSkillStateChoosePos(this));
_fsm.Add(new PlayerSkillStateRelease(this));
2023-12-11 16:25:13 +08:00
_fsm.Add(new PlayerSkillShowGlobalEffect(this));
2023-12-19 15:01:19 +08:00
_fsm.Add(new PlayerSkillPreNoEffect(this));
2023-12-06 12:22:59 +08:00
_fsm.ChangeState(EPlayerSkillState.Idle);
}
public void LogicUpdate(float dt)
{
2023-12-06 18:36:15 +08:00
_curCd -= dt;
2023-12-06 12:22:59 +08:00
_fsm.LogicUpdate(dt);
}
public void Dispose()
{
2023-12-19 15:01:19 +08:00
2023-12-06 12:22:59 +08:00
}
2023-12-06 14:08:57 +08:00
public float GetCDProgress(int id)
{
2023-12-06 18:36:15 +08:00
if (_curCd <= 0) return 0;
return _curCd / _maxCd;
2023-12-06 14:08:57 +08:00
}
2023-12-06 15:32:45 +08:00
public void ReadySkill(int skillId)
{
readySkillId = skillId;
readySkillConfig = TableManager.Instance.Tables.PlayerSkillConfig.Get(skillId);
2024-07-04 19:24:55 +08:00
DebugUtil.LogG("[指挥官技能] 准备技能: " + readySkillConfig.ID + " " + readySkillConfig.NameLocal);
2023-12-06 15:32:45 +08:00
}
2023-12-06 18:36:15 +08:00
public void ResetCD(float cdTime)
{
_maxCd = cdTime;
_curCd = _maxCd;
}
2023-12-19 15:01:19 +08:00
2023-12-06 12:22:59 +08:00
}
}