Skip to content

Commit

Permalink
Make NPC stand up for real (#101)
Browse files Browse the repository at this point in the history
  • Loading branch information
Lokilife authored Oct 20, 2024
1 parent 7ff67b2 commit 64b6415
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 2 deletions.
13 changes: 13 additions & 0 deletions Content.Server/NPC/Components/NPCStandsUpComponent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using Content.Shared.DoAfter;

namespace Content.Server.NPC.Components;

/// <summary>
/// Added to NPC when it's trying to get up (while do after is active)
/// </summary>
[RegisterComponent]
public sealed partial class NPCStandsUpComponent : Component
{
[DataField]
public DoAfterId DoAfter;
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Exodus-Crawling
using Content.Server.DoAfter;
using Content.Server.NPC.Components;
using Content.Shared.DoAfter;
using Content.Shared.Standing;

Expand Down Expand Up @@ -32,11 +33,26 @@ public override void Startup(NPCBlackboard blackboard)
CancelDuplicate = true,
BreakOnDamage = true,
};
_doAfter.TryStartDoAfter(doAfterArgs);
if (_doAfter.TryStartDoAfter(doAfterArgs, out var doAfterId))
{
var standsUp = _entManager.EnsureComponent<NPCStandsUpComponent>(owner);
standsUp.DoAfter = doAfterId.Value;
}
}

public override HTNOperatorStatus Update(NPCBlackboard blackboard, float frameTime)
{
var owner = blackboard.GetValue<EntityUid>(NPCBlackboard.Owner);

if (_entManager.TryGetComponent<NPCStandsUpComponent>(owner, out var standsUp) && _doAfter.IsRunning(standsUp.DoAfter))
return HTNOperatorStatus.Continuing;
return HTNOperatorStatus.Finished;
}

public override void TaskShutdown(NPCBlackboard blackboard, HTNOperatorStatus status)
{
var owner = blackboard.GetValue<EntityUid>(NPCBlackboard.Owner);
if (_entManager.HasComponent<NPCStandsUpComponent>(owner))
_entManager.RemoveComponentDeferred<NPCStandsUpComponent>(owner);
}
}
1 change: 0 additions & 1 deletion Resources/Prototypes/NPCs/Combat/melee.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
tasks:
- !type:HTNPrimitiveTask
operator: !type:StandUpOperator
shutdownState: TaskFinished
# Exodus-MRP NPC-End

- preconditions:
Expand Down
9 changes: 9 additions & 0 deletions Resources/Prototypes/NPCs/idle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,15 @@
- !type:KeyExistsPrecondition
key: IdleTime

# Exodus-MRP NPC-Start
- preconditions:
- !type:StandingPrecondition
isStanding: false
tasks:
- !type:HTNPrimitiveTask
operator: !type:StandUpOperator
# Exodus-MRP NPC-End

# Pick a new spot and wait there.
- preconditions:
- !type:BuckledPrecondition
Expand Down

0 comments on commit 64b6415

Please sign in to comment.