2022-09-06 00:28:23 +10:00
|
|
|
namespace Content.Server.NPC.HTN.PrimitiveTasks.Operators;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Waits the specified amount of time. Removes the key when finished.
|
|
|
|
|
/// </summary>
|
2023-08-22 18:14:33 -07:00
|
|
|
public sealed partial class WaitOperator : HTNOperator
|
2022-09-06 00:28:23 +10:00
|
|
|
{
|
2022-11-19 08:07:52 +11:00
|
|
|
[Dependency] private readonly IEntityManager _entManager = default!;
|
|
|
|
|
|
2022-09-06 00:28:23 +10:00
|
|
|
/// <summary>
|
|
|
|
|
/// Blackboard key for the time we'll wait for.
|
|
|
|
|
/// </summary>
|
2022-11-16 20:22:11 +01:00
|
|
|
[DataField("key", required: true)] public string Key = string.Empty;
|
2022-09-06 00:28:23 +10:00
|
|
|
|
|
|
|
|
public override HTNOperatorStatus Update(NPCBlackboard blackboard, float frameTime)
|
|
|
|
|
{
|
2022-11-19 08:07:52 +11:00
|
|
|
if (!blackboard.TryGetValue<float>(Key, out var timer, _entManager))
|
2022-09-06 00:28:23 +10:00
|
|
|
{
|
|
|
|
|
return HTNOperatorStatus.Finished;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
timer -= frameTime;
|
|
|
|
|
blackboard.SetValue(Key, timer);
|
|
|
|
|
|
|
|
|
|
return timer <= 0f ? HTNOperatorStatus.Finished : HTNOperatorStatus.Continuing;
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-02 10:48:56 +10:00
|
|
|
public override void TaskShutdown(NPCBlackboard blackboard, HTNOperatorStatus status)
|
2022-09-06 00:28:23 +10:00
|
|
|
{
|
2023-08-02 10:48:56 +10:00
|
|
|
base.TaskShutdown(blackboard, status);
|
2022-09-06 00:28:23 +10:00
|
|
|
|
|
|
|
|
// The replacement plan may want this value so only dump it if we're successful.
|
|
|
|
|
if (status != HTNOperatorStatus.BetterPlan)
|
|
|
|
|
{
|
|
|
|
|
blackboard.Remove<float>(Key);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|