forked from space-wizards/space-station-14
-
-
Notifications
You must be signed in to change notification settings - Fork 87
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Animated handcuffs now chase down and restrain people
Sentient handcuffs can now restain people using themselves
- Loading branch information
Showing
10 changed files
with
239 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
Content.Server/NPC/HTN/PrimitiveTasks/Operators/Interactions/InteractionActivateOperator.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
using System.Linq; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Content.Shared.DoAfter; | ||
using Content.Shared.Interaction; | ||
|
||
namespace Content.Server.NPC.HTN.PrimitiveTasks.Operators.Interactions; | ||
|
||
public sealed partial class InteractionActivateOperator : HTNOperator | ||
{ | ||
[Dependency] private readonly IEntityManager _entManager = default!; | ||
|
||
[DataField("targetKey")] | ||
public string Key = "Target"; | ||
|
||
/// <summary> | ||
/// If this alt-interaction started a do_after where does the key get stored. | ||
/// </summary> | ||
[DataField("idleKey")] | ||
public string IdleKey = "IdleTime"; | ||
|
||
public override async Task<(bool Valid, Dictionary<string, object>? Effects)> Plan(NPCBlackboard blackboard, CancellationToken cancelToken) | ||
{ | ||
return new(true, new Dictionary<string, object>() | ||
{ | ||
{ IdleKey, 1f } | ||
}); | ||
} | ||
|
||
public override HTNOperatorStatus Update(NPCBlackboard blackboard, float frameTime) | ||
{ | ||
var owner = blackboard.GetValue<EntityUid>(NPCBlackboard.Owner); | ||
var target = blackboard.GetValue<EntityUid>(Key); | ||
var intSystem = _entManager.System<SharedInteractionSystem>(); | ||
var count = 0; | ||
|
||
if (_entManager.TryGetComponent<DoAfterComponent>(owner, out var doAfter)) | ||
{ | ||
count = doAfter.DoAfters.Count; | ||
} | ||
|
||
var result = intSystem.InteractionActivate(owner, target); | ||
|
||
// Interaction started a doafter so set the idle time to it. | ||
if (result && doAfter != null && count != doAfter.DoAfters.Count) | ||
{ | ||
var wait = doAfter.DoAfters.First().Value.Args.Delay; | ||
blackboard.SetValue(IdleKey, (float) wait.TotalSeconds + 0.5f); | ||
} | ||
else | ||
{ | ||
blackboard.SetValue(IdleKey, 1f); | ||
} | ||
|
||
return result ? HTNOperatorStatus.Finished : HTNOperatorStatus.Failed; | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
Content.Server/NPC/Queries/Considerations/TargetIsCuffableCon.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
namespace Content.Server.NPC.Queries.Considerations; | ||
|
||
/// <summary> | ||
/// Returns 1f if the target can be cuffed or 0f if not. | ||
/// </summary> | ||
|
||
public sealed partial class TargetIsCuffableCon : UtilityConsideration | ||
{ | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
84 changes: 84 additions & 0 deletions
84
Content.Server/Revenant/EntitySystems/RevenantAnimatedSystem.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
using Content.Shared.Cuffs; | ||
using Content.Shared.Cuffs.Components; | ||
using Content.Shared.Hands.EntitySystems; | ||
using Content.Shared.Inventory; | ||
using Content.Shared.Weapons.Melee.Events; | ||
using Robust.Shared.Containers; | ||
using Content.Server.Revenant.Components; | ||
using Content.Shared.Interaction; | ||
using Content.Shared.Popups; | ||
|
||
namespace Content.Server.Revenant.EntitySystems; | ||
|
||
public sealed class RevenantAnimatedSystem : EntitySystem | ||
{ | ||
[Dependency] private readonly SharedHandsSystem _hands = default!; | ||
[Dependency] private readonly InventorySystem _inventory = default!; | ||
[Dependency] private readonly SharedContainerSystem _container = default!; | ||
[Dependency] private readonly SharedPopupSystem _popup = default!; | ||
|
||
public override void Initialize() | ||
{ | ||
base.Initialize(); | ||
|
||
SubscribeLocalEvent<RevenantAnimatedComponent, MeleeHitEvent>(OnMeleeHit, before: [typeof(SharedCuffableSystem)]); | ||
SubscribeLocalEvent<RevenantAnimatedComponent, UserActivateInWorldEvent>(OnCuffInteract, before: [typeof(SharedCuffableSystem)]); | ||
} | ||
|
||
private void OnMeleeHit(EntityUid uid, RevenantAnimatedComponent comp, MeleeHitEvent args) | ||
{ | ||
if (args.Handled) | ||
return; | ||
|
||
if (args.HitEntities.Count == 0) | ||
return; | ||
|
||
var hitEntity = args.HitEntities[0]; | ||
|
||
// Handcuffs will attempt to jump into the victim's hands/pockets before trying to cuff them | ||
if (HasComp<HandcuffComponent>(uid) && HasComp<CuffableComponent>(hitEntity)) | ||
TryJumpIntoSlots(uid, hitEntity); | ||
} | ||
|
||
private void OnCuffInteract(EntityUid uid, RevenantAnimatedComponent comp, UserActivateInWorldEvent args) | ||
{ | ||
if (args.Handled) | ||
return; | ||
|
||
if (HasComp<HandcuffComponent>(uid) && HasComp<CuffableComponent>(args.Target)) | ||
TryJumpIntoSlots(uid, args.Target); | ||
} | ||
|
||
private void TryJumpIntoSlots(EntityUid uid, EntityUid target) | ||
{ | ||
if (_container.ContainsEntity(target, uid)) | ||
return; | ||
|
||
Log.Debug($"{uid} trying to jump into {target} pocket1"); | ||
|
||
if (_inventory.TryGetSlotContainer(target, "pocket1", out var pocket1, out _) | ||
&& _container.Insert(uid, pocket1) | ||
) | ||
{ | ||
_popup.PopupEntity(Loc.GetString("item-jump-into-pocket", ("name", Comp<MetaDataComponent>(uid).EntityName)), target, target); | ||
return; | ||
} | ||
|
||
Log.Debug($"{uid} trying to jump into {target} pocket2"); | ||
|
||
if (_inventory.TryGetSlotContainer(target, "pocket2", out var pocket2, out _) | ||
&& _container.Insert(uid, pocket2) | ||
) | ||
{ | ||
_popup.PopupEntity(Loc.GetString("item-jump-into-pocket", ("name", Comp<MetaDataComponent>(uid).EntityName)), target, target); | ||
return; | ||
} | ||
|
||
Log.Debug($"{uid} trying to jump into {target} hands"); | ||
if (_hands.TryPickupAnyHand(target, uid)) | ||
{ | ||
_popup.PopupEntity(Loc.GetString("item-jump-into-hands", ("name", Comp<MetaDataComponent>(uid).EntityName)), target, target); | ||
return; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
- type: htnCompound | ||
id: AnimatedHandcuffsCompound | ||
branches: | ||
- tasks: | ||
- !type:HTNPrimitiveTask | ||
operator: !type:UtilityOperator | ||
proto: NearbyCuffableTargets | ||
|
||
- !type:HTNPrimitiveTask | ||
operator: !type:MoveToOperator | ||
pathfindInPlanning: true | ||
removeKeyOnFinish: false | ||
targetKey: TargetCoordinates | ||
pathfindKey: TargetPathfind | ||
rangeKey: MeleeRange | ||
|
||
- !type:PrimitiveTask | ||
preconditions: | ||
- !type:KeyExistsPrecondition | ||
key: Target | ||
operator: !type:InteractionActivateOperator | ||
|
||
- !type:HTNPrimitiveTask | ||
preconditions: | ||
- !type:KeyExistsPrecondition | ||
key: IdleTime | ||
operator: !type:WaitOperator | ||
key: IdleTime | ||
|
||
- tasks: | ||
- !type:HTNCompoundTask | ||
task: IdleCompound | ||
|
||
- type: utilityQuery | ||
id: NearbyCuffableTargets | ||
query: | ||
- !type:NearbyHostilesQuery | ||
considerations: | ||
- !type:TargetIsAliveCon | ||
curve: !type:BoolCurve | ||
- !type:TargetDistanceCon | ||
curve: !type:PresetCurve | ||
preset: TargetDistance | ||
- !type:TargetAccessibleCon | ||
curve: !type:BoolCurve | ||
- !type:TargetInLOSOrCurrentCon | ||
curve: !type:BoolCurve | ||
- !type:TargetIsCuffableCon | ||
curve: !type:BoolCurve |