mirror of
http://47.107.252.169:3000/Roguelite-Game-Developing-Team/Gen_Hack-and-Slash-Roguelite.git
synced 2025-11-20 09:57:13 +08:00
(client) feat:添加基地界面到游玩界面的过程,添加存档管理,技能树变得可用 (#58)
Co-authored-by: m0_75251201 <m0_75251201@noreply.gitcode.com> Reviewed-on: http://47.107.252.169:3000/Roguelite-Game-Developing-Team/Gen_Hack-and-Slash-Roguelite/pulls/58
This commit is contained in:
76
Client/Assets/Scripts/AI/LeafNodeBase.cs
Normal file
76
Client/Assets/Scripts/AI/LeafNodeBase.cs
Normal file
@@ -0,0 +1,76 @@
|
||||
using System;
|
||||
|
||||
namespace AI
|
||||
{
|
||||
public abstract class LeafNodeBase : BehaviorTreeBase
|
||||
{
|
||||
// 已经运行的帧数
|
||||
protected int _elapsedFrames;
|
||||
// 默认超时帧数
|
||||
protected int _timeoutFrames = 180;
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置该叶节点的超时帧数。确保超时帧数至少为1。
|
||||
/// </summary>
|
||||
public int TimeoutFrames
|
||||
{
|
||||
get => _timeoutFrames;
|
||||
set => _timeoutFrames = Math.Max(1, value);
|
||||
}
|
||||
|
||||
// 剩余帧数
|
||||
public int RemainingFrames => TimeoutFrames - _elapsedFrames;
|
||||
|
||||
/// <summary>
|
||||
/// 抽象方法,由具体的叶节点实现其核心业务逻辑。
|
||||
/// <see cref="LeafNodeBase"/> 会在计时器管理后调用此方法。
|
||||
/// </summary>
|
||||
/// <returns>节点的执行状态(Running, Success, Failure)。</returns>
|
||||
protected abstract Status ExecuteLeafLogic();
|
||||
|
||||
/// <summary>
|
||||
/// <see cref="LeafNodeBase"/> 的 Tick 方法,包含了计时器和状态管理逻辑。
|
||||
/// 此方法被密封,子类应实现 <see cref="ExecuteLeafLogic"/> 而不是重写 Tick。
|
||||
/// </summary>
|
||||
public sealed override Status Tick()
|
||||
{
|
||||
if (CurrentStatus == Status.Ready)
|
||||
{
|
||||
CurrentStatus = Status.Running;
|
||||
_elapsedFrames = 0;
|
||||
}
|
||||
|
||||
if (CurrentStatus == Status.Running)
|
||||
{
|
||||
_elapsedFrames++;
|
||||
|
||||
if (_elapsedFrames > _timeoutFrames)
|
||||
{
|
||||
CurrentStatus = Status.Failure;
|
||||
Reset();
|
||||
return Status.Failure;
|
||||
}
|
||||
|
||||
var logicResult = ExecuteLeafLogic();
|
||||
|
||||
if (logicResult != Status.Running)
|
||||
{
|
||||
CurrentStatus = logicResult;
|
||||
Reset();
|
||||
}
|
||||
return logicResult;
|
||||
}
|
||||
|
||||
return CurrentStatus;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 重置叶节点的状态,包括基类状态和内部计时器。
|
||||
/// </summary>
|
||||
public override void Reset()
|
||||
{
|
||||
base.Reset();
|
||||
_elapsedFrames = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user