Skip to content

Commit

Permalink
Merge pull request #266 from TGRCdev/cyborg-self-exploding-fix
Browse files Browse the repository at this point in the history
Fixed cyborgs being able to explode by clicking on themselves
  • Loading branch information
formlessnameless authored Sep 16, 2024
2 parents ffd2bcc + 1011d77 commit f8ff578
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 15 deletions.
14 changes: 0 additions & 14 deletions Content.Server/Explosion/EntitySystems/TriggerSystem.OnUse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,26 +16,12 @@ public sealed partial class TriggerSystem
private void InitializeOnUse()
{
SubscribeLocalEvent<OnUseTimerTriggerComponent, UseInHandEvent>(OnTimerUse);
SubscribeLocalEvent<OnUseTimerTriggerComponent, UserActivateInWorldEvent>(OnUseSelf);
SubscribeLocalEvent<OnUseTimerTriggerComponent, ExaminedEvent>(OnExamined);
SubscribeLocalEvent<OnUseTimerTriggerComponent, GetVerbsEvent<AlternativeVerb>>(OnGetAltVerbs);
SubscribeLocalEvent<OnUseTimerTriggerComponent, EntityStuckEvent>(OnStuck);
SubscribeLocalEvent<RandomTimerTriggerComponent, MapInitEvent>(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)
Expand Down
Original file line number Diff line number Diff line change
@@ -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<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 trigger = _entManager.System<TriggerSystem>();
if (!_entManager.TryGetComponent<OnUseTimerTriggerComponent>(owner, out var timer))
return HTNOperatorStatus.Failed;

trigger.StartTimer((owner, timer), owner);
blackboard.SetValue(IdleKey, timer.Delay);

return HTNOperatorStatus.Finished;
}
}
2 changes: 1 addition & 1 deletion Resources/Prototypes/NPCs/Animated/grenades.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
- !type:TargetInRangePrecondition
targetKey: Target
rangeKey: MeleeRange
operator: !type:InteractionActivateSelfOperator
operator: !type:StartTimerOperator
- tasks:
- !type:HTNCompoundTask
task: IdleCompound

0 comments on commit f8ff578

Please sign in to comment.