From 1011d77ec8e2c9c205e8bdf3192c9a6622950090 Mon Sep 17 00:00:00 2001 From: TGRCDev Date: Sun, 15 Sep 2024 18:15:24 -0700 Subject: [PATCH] Fixed cyborgs being able to explode by clicking on themselves --- .../EntitySystems/TriggerSystem.OnUse.cs | 14 -------- .../Interactions/StartTimerOperator.cs | 35 +++++++++++++++++++ .../Prototypes/NPCs/Animated/grenades.yml | 2 +- 3 files changed, 36 insertions(+), 15 deletions(-) create mode 100644 Content.Server/NPC/HTN/PrimitiveTasks/Operators/Interactions/StartTimerOperator.cs diff --git a/Content.Server/Explosion/EntitySystems/TriggerSystem.OnUse.cs b/Content.Server/Explosion/EntitySystems/TriggerSystem.OnUse.cs index 5337460b299..d8a98027f55 100644 --- a/Content.Server/Explosion/EntitySystems/TriggerSystem.OnUse.cs +++ b/Content.Server/Explosion/EntitySystems/TriggerSystem.OnUse.cs @@ -16,26 +16,12 @@ public sealed partial class TriggerSystem private void InitializeOnUse() { SubscribeLocalEvent(OnTimerUse); - SubscribeLocalEvent(OnUseSelf); SubscribeLocalEvent(OnExamined); SubscribeLocalEvent>(OnGetAltVerbs); SubscribeLocalEvent(OnStuck); SubscribeLocalEvent(OnRandomTimerTriggerMapInit); } - private void OnUseSelf(EntityUid uid, OnUseTimerTriggerComponent comp, UserActivateInWorldEvent args) - { - // Allow grenades to activate themselves (if they're posessed or ghost role) - - if (args.Handled) - return; - - if (args.Target != uid) - return; - - StartTimer((uid, comp), uid); - } - private void OnStuck(EntityUid uid, OnUseTimerTriggerComponent component, ref EntityStuckEvent args) { if (!component.StartOnStick) diff --git a/Content.Server/NPC/HTN/PrimitiveTasks/Operators/Interactions/StartTimerOperator.cs b/Content.Server/NPC/HTN/PrimitiveTasks/Operators/Interactions/StartTimerOperator.cs new file mode 100644 index 00000000000..fe72e16e3e5 --- /dev/null +++ b/Content.Server/NPC/HTN/PrimitiveTasks/Operators/Interactions/StartTimerOperator.cs @@ -0,0 +1,35 @@ +using System.Threading; +using System.Threading.Tasks; +using Content.Server.Explosion.EntitySystems; +using Content.Shared.Explosion.Components; + +namespace Content.Server.NPC.HTN.PrimitiveTasks.Operators.Interactions; + +public sealed partial class StartTimerOperator : HTNOperator +{ + [Dependency] private readonly IEntityManager _entManager = default!; + + [DataField("idleKey")] + public string IdleKey = "IdleTime"; + + public override async Task<(bool Valid, Dictionary? Effects)> Plan(NPCBlackboard blackboard, CancellationToken cancelToken) + { + return new(true, new Dictionary() + { + { IdleKey, 1f } + }); + } + + public override HTNOperatorStatus Update(NPCBlackboard blackboard, float frameTime) + { + var owner = blackboard.GetValue(NPCBlackboard.Owner); + var trigger = _entManager.System(); + if (!_entManager.TryGetComponent(owner, out var timer)) + return HTNOperatorStatus.Failed; + + trigger.StartTimer((owner, timer), owner); + blackboard.SetValue(IdleKey, timer.Delay); + + return HTNOperatorStatus.Finished; + } +} diff --git a/Resources/Prototypes/NPCs/Animated/grenades.yml b/Resources/Prototypes/NPCs/Animated/grenades.yml index dc1bbb1c2ad..39de114a775 100644 --- a/Resources/Prototypes/NPCs/Animated/grenades.yml +++ b/Resources/Prototypes/NPCs/Animated/grenades.yml @@ -37,7 +37,7 @@ - !type:TargetInRangePrecondition targetKey: Target rangeKey: MeleeRange - operator: !type:InteractionActivateSelfOperator + operator: !type:StartTimerOperator - tasks: - !type:HTNCompoundTask task: IdleCompound \ No newline at end of file