tool lock

This commit is contained in:
slarticodefast
2025-08-26 20:04:10 +02:00
parent 4505f61ff2
commit f4056e854b
6 changed files with 95 additions and 13 deletions

View File

@@ -8,7 +8,7 @@ namespace Content.Shared.Tools.Components;
/// <summary>
/// Component responsible for simple tool interactions.
/// Using a tool with the correct quality on an entity with this component will start a doAfter and raise events.
/// Using a tool with the correct quality on an entity with this component will start a DoAfter and raise the <see cref="SimpleToolDoAfterEvent"/> other systems can subscribe to.
/// </summary>
[RegisterComponent, NetworkedComponent]
[Access(typeof(SimpleToolUsageSystem))]
@@ -40,8 +40,15 @@ public sealed partial class SimpleToolUsageComponent : Component
public LocId BlockedMessage = "simple-tool-usage-blocked-message";
}
/// <summary>
/// Cancelable event that can be used to prevent tool interaction.
/// </summary>
[ByRefEvent]
public record struct AttemptSimpleToolUseEvent(EntityUid User, bool Cancelled = false);
/// <summary>
/// Raised after the right tool is used on an entity with <see cref="SimpleToolUsageComponent"/>
/// and the DoAfter has finished.
/// </summary>
[Serializable, NetSerializable]
public sealed partial class SimpleToolDoAfterEvent : SimpleDoAfterEvent;

View File

@@ -0,0 +1,12 @@
using Content.Shared.Tools.Components;
using Robust.Shared.GameStates;
namespace Content.Shared.Trigger.Components.Triggers;
/// <summary>
/// Triggers an entity with <see cref="SimpleToolUsageComponent"/> when the correct tool
/// is used on it and the DoAfter has finished.
/// The user is the player using the tool.
/// </summary>
[RegisterComponent, NetworkedComponent, AutoGenerateComponentState]
public sealed partial class TriggerOnSimpleToolUsageComponent : BaseTriggerOnXComponent;

View File

@@ -0,0 +1,21 @@
using Content.Shared.Tools.Components;
using Content.Shared.Trigger.Components.Triggers;
namespace Content.Shared.Trigger.Systems;
public sealed class TriggerOnToolUseSystem : EntitySystem
{
[Dependency] private readonly TriggerSystem _trigger = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<TriggerOnSimpleToolUsageComponent, SimpleToolDoAfterEvent>(OnToolUse);
}
private void OnToolUse(Entity<TriggerOnSimpleToolUsageComponent> ent, ref SimpleToolDoAfterEvent args)
{
_trigger.Trigger(ent.Owner, args.User, ent.Comp.KeyOut);
}
}