Turn interaction related attempt events into structs (#29168)
* Turn InteractionAttemptEvent into a struct event * readonly * GettingInteractedWithAttemptEvent * ConsciousAttemptEvent
This commit is contained in:
@@ -495,7 +495,7 @@ public sealed class DragDropSystem : SharedDragDropSystem
|
||||
// CanInteract() doesn't support checking a second "target" entity.
|
||||
// Doing so manually:
|
||||
var ev = new GettingInteractedWithAttemptEvent(user, dragged);
|
||||
RaiseLocalEvent(dragged, ev, true);
|
||||
RaiseLocalEvent(dragged, ref ev);
|
||||
|
||||
if (ev.Cancelled)
|
||||
return false;
|
||||
|
||||
@@ -17,7 +17,7 @@ public sealed partial class ReplaySpectatorSystem
|
||||
SubscribeLocalEvent<ReplaySpectatorComponent, UseAttemptEvent>(OnAttempt);
|
||||
SubscribeLocalEvent<ReplaySpectatorComponent, PickupAttemptEvent>(OnAttempt);
|
||||
SubscribeLocalEvent<ReplaySpectatorComponent, ThrowAttemptEvent>(OnAttempt);
|
||||
SubscribeLocalEvent<ReplaySpectatorComponent, InteractionAttemptEvent>(OnAttempt);
|
||||
SubscribeLocalEvent<ReplaySpectatorComponent, InteractionAttemptEvent>(OnInteractAttempt);
|
||||
SubscribeLocalEvent<ReplaySpectatorComponent, AttackAttemptEvent>(OnAttempt);
|
||||
SubscribeLocalEvent<ReplaySpectatorComponent, DropAttemptEvent>(OnAttempt);
|
||||
SubscribeLocalEvent<ReplaySpectatorComponent, IsEquippingAttemptEvent>(OnAttempt);
|
||||
@@ -27,6 +27,11 @@ public sealed partial class ReplaySpectatorSystem
|
||||
SubscribeLocalEvent<ReplaySpectatorComponent, PullAttemptEvent>(OnPullAttempt);
|
||||
}
|
||||
|
||||
private void OnInteractAttempt(Entity<ReplaySpectatorComponent> ent, ref InteractionAttemptEvent args)
|
||||
{
|
||||
args.Cancelled = true;
|
||||
}
|
||||
|
||||
private void OnAttempt(EntityUid uid, ReplaySpectatorComponent component, CancellableEntityEventArgs args)
|
||||
{
|
||||
args.Cancel();
|
||||
|
||||
@@ -70,7 +70,7 @@ namespace Content.Shared.ActionBlocker
|
||||
return false;
|
||||
|
||||
var ev = new InteractionAttemptEvent(user, target);
|
||||
RaiseLocalEvent(user, ev);
|
||||
RaiseLocalEvent(user, ref ev);
|
||||
|
||||
if (ev.Cancelled)
|
||||
return false;
|
||||
@@ -79,7 +79,7 @@ namespace Content.Shared.ActionBlocker
|
||||
return true;
|
||||
|
||||
var targetEv = new GettingInteractedWithAttemptEvent(user, target);
|
||||
RaiseLocalEvent(target.Value, targetEv);
|
||||
RaiseLocalEvent(target.Value, ref targetEv);
|
||||
|
||||
return !targetEv.Cancelled;
|
||||
}
|
||||
@@ -110,7 +110,7 @@ namespace Content.Shared.ActionBlocker
|
||||
public bool CanConsciouslyPerformAction(EntityUid user)
|
||||
{
|
||||
var ev = new ConsciousAttemptEvent(user);
|
||||
RaiseLocalEvent(user, ev);
|
||||
RaiseLocalEvent(user, ref ev);
|
||||
|
||||
return !ev.Cancelled;
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ using Content.Shared.Throwing;
|
||||
|
||||
namespace Content.Shared.Administration;
|
||||
|
||||
// TODO deduplicate with BlockMovementComponent
|
||||
public abstract class SharedAdminFrozenSystem : EntitySystem
|
||||
{
|
||||
[Dependency] private readonly ActionBlockerSystem _blocker = default!;
|
||||
@@ -23,7 +24,7 @@ public abstract class SharedAdminFrozenSystem : EntitySystem
|
||||
SubscribeLocalEvent<AdminFrozenComponent, UseAttemptEvent>(OnAttempt);
|
||||
SubscribeLocalEvent<AdminFrozenComponent, PickupAttemptEvent>(OnAttempt);
|
||||
SubscribeLocalEvent<AdminFrozenComponent, ThrowAttemptEvent>(OnAttempt);
|
||||
SubscribeLocalEvent<AdminFrozenComponent, InteractionAttemptEvent>(OnAttempt);
|
||||
SubscribeLocalEvent<AdminFrozenComponent, InteractionAttemptEvent>(OnInteractAttempt);
|
||||
SubscribeLocalEvent<AdminFrozenComponent, ComponentStartup>(OnStartup);
|
||||
SubscribeLocalEvent<AdminFrozenComponent, ComponentShutdown>(UpdateCanMove);
|
||||
SubscribeLocalEvent<AdminFrozenComponent, UpdateCanMoveEvent>(OnUpdateCanMove);
|
||||
@@ -34,6 +35,11 @@ public abstract class SharedAdminFrozenSystem : EntitySystem
|
||||
SubscribeLocalEvent<AdminFrozenComponent, SpeakAttemptEvent>(OnSpeakAttempt);
|
||||
}
|
||||
|
||||
private void OnInteractAttempt(Entity<AdminFrozenComponent> ent, ref InteractionAttemptEvent args)
|
||||
{
|
||||
args.Cancelled = true;
|
||||
}
|
||||
|
||||
private void OnSpeakAttempt(EntityUid uid, AdminFrozenComponent component, SpeakAttemptEvent args)
|
||||
{
|
||||
if (!component.Muted)
|
||||
|
||||
@@ -153,7 +153,7 @@ public sealed partial class SleepingSystem : EntitySystem
|
||||
|
||||
private void OnConsciousAttempt(Entity<SleepingComponent> ent, ref ConsciousAttemptEvent args)
|
||||
{
|
||||
args.Cancel();
|
||||
args.Cancelled = true;
|
||||
}
|
||||
|
||||
private void OnExamined(Entity<SleepingComponent> ent, ref ExaminedEvent args)
|
||||
|
||||
@@ -79,7 +79,7 @@ namespace Content.Shared.Cuffs
|
||||
SubscribeLocalEvent<CuffableComponent, PickupAttemptEvent>(CheckAct);
|
||||
SubscribeLocalEvent<CuffableComponent, AttackAttemptEvent>(CheckAct);
|
||||
SubscribeLocalEvent<CuffableComponent, UseAttemptEvent>(CheckAct);
|
||||
SubscribeLocalEvent<CuffableComponent, InteractionAttemptEvent>(CheckAct);
|
||||
SubscribeLocalEvent<CuffableComponent, InteractionAttemptEvent>(CheckInteract);
|
||||
|
||||
SubscribeLocalEvent<HandcuffComponent, AfterInteractEvent>(OnCuffAfterInteract);
|
||||
SubscribeLocalEvent<HandcuffComponent, MeleeHitEvent>(OnCuffMeleeHit);
|
||||
@@ -87,6 +87,12 @@ namespace Content.Shared.Cuffs
|
||||
SubscribeLocalEvent<HandcuffComponent, VirtualItemDeletedEvent>(OnCuffVirtualItemDeleted);
|
||||
}
|
||||
|
||||
private void CheckInteract(Entity<CuffableComponent> ent, ref InteractionAttemptEvent args)
|
||||
{
|
||||
if (!ent.Comp.CanStillInteract)
|
||||
args.Cancelled = true;
|
||||
}
|
||||
|
||||
private void OnUncuffAttempt(ref UncuffAttemptEvent args)
|
||||
{
|
||||
if (args.Cancelled)
|
||||
|
||||
@@ -19,12 +19,18 @@ namespace Content.Shared.Ghost
|
||||
{
|
||||
base.Initialize();
|
||||
SubscribeLocalEvent<GhostComponent, UseAttemptEvent>(OnAttempt);
|
||||
SubscribeLocalEvent<GhostComponent, InteractionAttemptEvent>(OnAttempt);
|
||||
SubscribeLocalEvent<GhostComponent, InteractionAttemptEvent>(OnAttemptInteract);
|
||||
SubscribeLocalEvent<GhostComponent, EmoteAttemptEvent>(OnAttempt);
|
||||
SubscribeLocalEvent<GhostComponent, DropAttemptEvent>(OnAttempt);
|
||||
SubscribeLocalEvent<GhostComponent, PickupAttemptEvent>(OnAttempt);
|
||||
}
|
||||
|
||||
private void OnAttemptInteract(Entity<GhostComponent> ent, ref InteractionAttemptEvent args)
|
||||
{
|
||||
if (!ent.Comp.CanGhostInteract)
|
||||
args.Cancelled = true;
|
||||
}
|
||||
|
||||
private void OnAttempt(EntityUid uid, GhostComponent component, CancellableEntityEventArgs args)
|
||||
{
|
||||
if (!component.CanGhostInteract)
|
||||
|
||||
@@ -3,39 +3,33 @@
|
||||
/// <summary>
|
||||
/// Event raised directed at a user to see if they can perform a generic interaction.
|
||||
/// </summary>
|
||||
public sealed class InteractionAttemptEvent : CancellableEntityEventArgs
|
||||
[ByRefEvent]
|
||||
public struct InteractionAttemptEvent(EntityUid uid, EntityUid? target)
|
||||
{
|
||||
public InteractionAttemptEvent(EntityUid uid, EntityUid? target)
|
||||
{
|
||||
Uid = uid;
|
||||
Target = target;
|
||||
}
|
||||
|
||||
public EntityUid Uid { get; }
|
||||
public EntityUid? Target { get; }
|
||||
public bool Cancelled;
|
||||
public readonly EntityUid Uid = uid;
|
||||
public readonly EntityUid? Target = target;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Raised to determine whether an entity is conscious to perform an action.
|
||||
/// </summary>
|
||||
public sealed class ConsciousAttemptEvent(EntityUid Uid) : CancellableEntityEventArgs
|
||||
[ByRefEvent]
|
||||
public struct ConsciousAttemptEvent(EntityUid uid)
|
||||
{
|
||||
public EntityUid Uid { get; } = Uid;
|
||||
public bool Cancelled;
|
||||
public readonly EntityUid Uid = uid;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Event raised directed at the target entity of an interaction to see if the user is allowed to perform some
|
||||
/// generic interaction.
|
||||
/// </summary>
|
||||
public sealed class GettingInteractedWithAttemptEvent : CancellableEntityEventArgs
|
||||
[ByRefEvent]
|
||||
public struct GettingInteractedWithAttemptEvent(EntityUid uid, EntityUid? target)
|
||||
{
|
||||
public GettingInteractedWithAttemptEvent(EntityUid uid, EntityUid? target)
|
||||
{
|
||||
Uid = uid;
|
||||
Target = target;
|
||||
}
|
||||
|
||||
public EntityUid Uid { get; }
|
||||
public EntityUid? Target { get; }
|
||||
public bool Cancelled;
|
||||
public readonly EntityUid Uid = uid;
|
||||
public readonly EntityUid? Target = target;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ using Content.Shared.Movement.Events;
|
||||
|
||||
namespace Content.Shared.Interaction;
|
||||
|
||||
// TODO deduplicate with AdminFrozenComponent
|
||||
/// <summary>
|
||||
/// Handles <see cref="BlockMovementComponent"/>, which prevents various
|
||||
/// kinds of movement and interactions when attached to an entity.
|
||||
@@ -16,7 +17,7 @@ public partial class SharedInteractionSystem
|
||||
{
|
||||
SubscribeLocalEvent<BlockMovementComponent, UpdateCanMoveEvent>(OnMoveAttempt);
|
||||
SubscribeLocalEvent<BlockMovementComponent, UseAttemptEvent>(CancelEvent);
|
||||
SubscribeLocalEvent<BlockMovementComponent, InteractionAttemptEvent>(CancelEvent);
|
||||
SubscribeLocalEvent<BlockMovementComponent, InteractionAttemptEvent>(CancelInteractEvent);
|
||||
SubscribeLocalEvent<BlockMovementComponent, DropAttemptEvent>(CancelEvent);
|
||||
SubscribeLocalEvent<BlockMovementComponent, PickupAttemptEvent>(CancelEvent);
|
||||
SubscribeLocalEvent<BlockMovementComponent, ChangeDirectionAttemptEvent>(CancelEvent);
|
||||
@@ -25,6 +26,11 @@ public partial class SharedInteractionSystem
|
||||
SubscribeLocalEvent<BlockMovementComponent, ComponentShutdown>(OnBlockingShutdown);
|
||||
}
|
||||
|
||||
private void CancelInteractEvent(Entity<BlockMovementComponent> ent, ref InteractionAttemptEvent args)
|
||||
{
|
||||
args.Cancelled = true;
|
||||
}
|
||||
|
||||
private void OnMoveAttempt(EntityUid uid, BlockMovementComponent component, UpdateCanMoveEvent args)
|
||||
{
|
||||
if (component.LifeStage > ComponentLifeStage.Running)
|
||||
|
||||
@@ -31,7 +31,7 @@ public partial class MobStateSystem
|
||||
SubscribeLocalEvent<MobStateComponent, ChangeDirectionAttemptEvent>(CheckAct);
|
||||
SubscribeLocalEvent<MobStateComponent, UseAttemptEvent>(CheckAct);
|
||||
SubscribeLocalEvent<MobStateComponent, AttackAttemptEvent>(CheckAct);
|
||||
SubscribeLocalEvent<MobStateComponent, ConsciousAttemptEvent>(CheckAct);
|
||||
SubscribeLocalEvent<MobStateComponent, ConsciousAttemptEvent>(CheckConcious);
|
||||
SubscribeLocalEvent<MobStateComponent, ThrowAttemptEvent>(CheckAct);
|
||||
SubscribeLocalEvent<MobStateComponent, SpeakAttemptEvent>(OnSpeakAttempt);
|
||||
SubscribeLocalEvent<MobStateComponent, IsEquippingAttemptEvent>(OnEquipAttempt);
|
||||
@@ -48,6 +48,17 @@ public partial class MobStateSystem
|
||||
SubscribeLocalEvent<MobStateComponent, AttemptPacifiedAttackEvent>(OnAttemptPacifiedAttack);
|
||||
}
|
||||
|
||||
private void CheckConcious(Entity<MobStateComponent> ent, ref ConsciousAttemptEvent args)
|
||||
{
|
||||
switch (ent.Comp.CurrentState)
|
||||
{
|
||||
case MobState.Dead:
|
||||
case MobState.Critical:
|
||||
args.Cancelled = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void OnStateExitSubscribers(EntityUid target, MobStateComponent component, MobState state)
|
||||
{
|
||||
switch (state)
|
||||
|
||||
@@ -7,6 +7,7 @@ using Content.Shared.Movement.Events;
|
||||
|
||||
namespace Content.Shared.Puppet;
|
||||
|
||||
// TODO deduplicate with BlockMovementComponent
|
||||
public abstract class SharedVentriloquistPuppetSystem : EntitySystem
|
||||
{
|
||||
[Dependency] private readonly ActionBlockerSystem _blocker = default!;
|
||||
@@ -15,7 +16,7 @@ public abstract class SharedVentriloquistPuppetSystem : EntitySystem
|
||||
{
|
||||
base.Initialize();
|
||||
SubscribeLocalEvent<VentriloquistPuppetComponent, UseAttemptEvent>(Cancel);
|
||||
SubscribeLocalEvent<VentriloquistPuppetComponent, InteractionAttemptEvent>(Cancel);
|
||||
SubscribeLocalEvent<VentriloquistPuppetComponent, InteractionAttemptEvent>(CancelInteract);
|
||||
SubscribeLocalEvent<VentriloquistPuppetComponent, DropAttemptEvent>(Cancel);
|
||||
SubscribeLocalEvent<VentriloquistPuppetComponent, PickupAttemptEvent>(Cancel);
|
||||
SubscribeLocalEvent<VentriloquistPuppetComponent, UpdateCanMoveEvent>(Cancel);
|
||||
@@ -24,6 +25,11 @@ public abstract class SharedVentriloquistPuppetSystem : EntitySystem
|
||||
SubscribeLocalEvent<VentriloquistPuppetComponent, ComponentStartup>(OnStartup);
|
||||
}
|
||||
|
||||
private void CancelInteract(Entity<VentriloquistPuppetComponent> ent, ref InteractionAttemptEvent args)
|
||||
{
|
||||
args.Cancelled = true;
|
||||
}
|
||||
|
||||
private void OnStartup(EntityUid uid, VentriloquistPuppetComponent component, ComponentStartup args)
|
||||
{
|
||||
_blocker.UpdateCanMove(uid);
|
||||
|
||||
@@ -54,7 +54,7 @@ public abstract class SharedStunSystem : EntitySystem
|
||||
// Attempt event subscriptions.
|
||||
SubscribeLocalEvent<StunnedComponent, ChangeDirectionAttemptEvent>(OnAttempt);
|
||||
SubscribeLocalEvent<StunnedComponent, UpdateCanMoveEvent>(OnMoveAttempt);
|
||||
SubscribeLocalEvent<StunnedComponent, InteractionAttemptEvent>(OnAttempt);
|
||||
SubscribeLocalEvent<StunnedComponent, InteractionAttemptEvent>(OnAttemptInteract);
|
||||
SubscribeLocalEvent<StunnedComponent, UseAttemptEvent>(OnAttempt);
|
||||
SubscribeLocalEvent<StunnedComponent, ThrowAttemptEvent>(OnAttempt);
|
||||
SubscribeLocalEvent<StunnedComponent, DropAttemptEvent>(OnAttempt);
|
||||
@@ -65,7 +65,10 @@ public abstract class SharedStunSystem : EntitySystem
|
||||
SubscribeLocalEvent<MobStateComponent, MobStateChangedEvent>(OnMobStateChanged);
|
||||
}
|
||||
|
||||
|
||||
private void OnAttemptInteract(Entity<StunnedComponent> ent, ref InteractionAttemptEvent args)
|
||||
{
|
||||
args.Cancelled = true;
|
||||
}
|
||||
|
||||
private void OnMobStateChanged(EntityUid uid, MobStateComponent component, MobStateChangedEvent args)
|
||||
{
|
||||
|
||||
@@ -45,11 +45,11 @@ namespace Content.Shared.SubFloor
|
||||
args.Cancelled = true;
|
||||
}
|
||||
|
||||
private void OnInteractionAttempt(EntityUid uid, SubFloorHideComponent component, GettingInteractedWithAttemptEvent args)
|
||||
private void OnInteractionAttempt(EntityUid uid, SubFloorHideComponent component, ref GettingInteractedWithAttemptEvent args)
|
||||
{
|
||||
// No interactions with entities hidden under floor tiles.
|
||||
if (component.BlockInteractions && component.IsUnderCover)
|
||||
args.Cancel();
|
||||
args.Cancelled = true;
|
||||
}
|
||||
|
||||
private void OnSubFloorStarted(EntityUid uid, SubFloorHideComponent component, ComponentStartup _)
|
||||
|
||||
Reference in New Issue
Block a user