Shards damage barefoot users + steptrigger-related general cleanup (#9585)

This commit is contained in:
Kara
2022-07-10 02:28:37 -07:00
committed by GitHub
parent 37bf333674
commit 459f8d23eb
22 changed files with 220 additions and 92 deletions

View File

@@ -0,0 +1,11 @@
using Robust.Shared.GameStates;
namespace Content.Shared.StepTrigger.Components;
/// <summary>
/// This is used for cancelling step trigger events if the user is wearing shoes, such as for glass shards.
/// </summary>
[RegisterComponent, NetworkedComponent]
public sealed class ShoesRequiredStepTriggerComponent : Component
{
}

View File

@@ -1,7 +1,8 @@
using Content.Shared.StepTrigger.Systems;
using Robust.Shared.GameStates;
using Robust.Shared.Serialization;
namespace Content.Shared.StepTrigger;
namespace Content.Shared.StepTrigger.Components;
[RegisterComponent]
[NetworkedComponent]

View File

@@ -0,0 +1,33 @@
using Content.Shared.Examine;
using Content.Shared.Inventory;
using Content.Shared.StepTrigger.Components;
namespace Content.Shared.StepTrigger.Systems;
public sealed class ShoesRequiredStepTriggerSystem : EntitySystem
{
[Dependency] private readonly InventorySystem _inventory = default!;
/// <inheritdoc/>
public override void Initialize()
{
SubscribeLocalEvent<ShoesRequiredStepTriggerComponent, StepTriggerAttemptEvent>(OnStepTriggerAttempt);
SubscribeLocalEvent<ShoesRequiredStepTriggerComponent, ExaminedEvent>(OnExamined);
}
private void OnStepTriggerAttempt(EntityUid uid, ShoesRequiredStepTriggerComponent component, ref StepTriggerAttemptEvent args)
{
if (!TryComp<InventoryComponent>(args.Tripper, out var inventory))
return;
if (_inventory.TryGetSlotEntity(args.Tripper, "shoes", out _, inventory))
{
args.Cancelled = true;
}
}
private void OnExamined(EntityUid uid, ShoesRequiredStepTriggerComponent component, ExaminedEvent args)
{
args.PushMarkup(Loc.GetString("shoes-required-step-trigger-examine"));
}
}

View File

@@ -1,8 +1,9 @@
using Content.Shared.StepTrigger.Components;
using Robust.Shared.Collections;
using Robust.Shared.GameStates;
using Robust.Shared.Physics.Dynamics;
namespace Content.Shared.StepTrigger;
namespace Content.Shared.StepTrigger.Systems;
public sealed class StepTriggerSystem : EntitySystem
{
@@ -93,7 +94,7 @@ public sealed class StepTriggerSystem : EntitySystem
RaiseLocalEvent(uid, ref msg, true);
return msg.Continue;
return msg.Continue && !msg.Cancelled;
}
private void HandleCollide(EntityUid uid, StepTriggerComponent component, StartCollideEvent args)
@@ -177,6 +178,10 @@ public struct StepTriggerAttemptEvent
public EntityUid Source;
public EntityUid Tripper;
public bool Continue;
/// <summary>
/// Set by systems which wish to cancel the step trigger event, regardless of event ordering.
/// </summary>
public bool Cancelled;
}
[ByRefEvent]