// 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;
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);
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();
return false;
var ev = new InteractionAttemptEvent(user, target);
- RaiseLocalEvent(user, ev);
+ RaiseLocalEvent(user, ref ev);
if (ev.Cancelled)
return false;
return true;
var targetEv = new GettingInteractedWithAttemptEvent(user, target);
- RaiseLocalEvent(target.Value, targetEv);
+ RaiseLocalEvent(target.Value, ref targetEv);
return !targetEv.Cancelled;
}
public bool CanConsciouslyPerformAction(EntityUid user)
{
var ev = new ConsciousAttemptEvent(user);
- RaiseLocalEvent(user, ev);
+ RaiseLocalEvent(user, ref ev);
return !ev.Cancelled;
}
namespace Content.Shared.Administration;
+// TODO deduplicate with BlockMovementComponent
public abstract class SharedAdminFrozenSystem : EntitySystem
{
[Dependency] private readonly ActionBlockerSystem _blocker = default!;
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);
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)
private void OnConsciousAttempt(Entity<SleepingComponent> ent, ref ConsciousAttemptEvent args)
{
- args.Cancel();
+ args.Cancelled = true;
}
private void OnExamined(Entity<SleepingComponent> ent, ref ExaminedEvent args)
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);
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)
{
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)
/// <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;
}
}
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.
{
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);
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)
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);
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)
namespace Content.Shared.Puppet;
+// TODO deduplicate with BlockMovementComponent
public abstract class SharedVentriloquistPuppetSystem : EntitySystem
{
[Dependency] private readonly ActionBlockerSystem _blocker = default!;
{
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);
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);
{
args.Cancel();
}
-}
\ No newline at end of file
+}
// 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);
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)
{
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 _)