Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix SCRAM implant not working while cuffed. Incidentally fix freedom implant working while dead/crit #25978

Merged
merged 6 commits into from
Mar 18, 2024
Merged
1 change: 1 addition & 0 deletions Content.Client/Actions/ActionsSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ private void BaseHandleState<T>(EntityUid uid, BaseActionComponent component, Ba
component.Container = EnsureEntity<T>(state.Container, uid);
component.EntityIcon = EnsureEntity<T>(state.EntityIcon, uid);
component.CheckCanInteract = state.CheckCanInteract;
component.CheckConsciousness = state.CheckConsciousness;
component.ClientExclusive = state.ClientExclusive;
component.Priority = state.Priority;
component.AttachedEntity = EnsureEntity<T>(state.AttachedEntity, uid);
Expand Down
8 changes: 8 additions & 0 deletions Content.Server/Bed/Sleep/SleepingSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using Content.Shared.Examine;
using Content.Shared.IdentityManagement;
using Content.Shared.Interaction;
using Content.Shared.Interaction.Events;
using Content.Shared.Mobs;
using Content.Shared.Mobs.Components;
using Content.Shared.Slippery;
Expand Down Expand Up @@ -45,6 +46,7 @@ public override void Initialize()
SubscribeLocalEvent<SleepingComponent, InteractHandEvent>(OnInteractHand);
SubscribeLocalEvent<SleepingComponent, ExaminedEvent>(OnExamined);
SubscribeLocalEvent<SleepingComponent, SlipAttemptEvent>(OnSlip);
SubscribeLocalEvent<SleepingComponent, ConsciousAttemptEvent>(OnConsciousAttempt);
SubscribeLocalEvent<ForcedSleepingComponent, ComponentInit>(OnInit);
}

Expand Down Expand Up @@ -173,6 +175,12 @@ private void OnSlip(EntityUid uid, SleepingComponent component, SlipAttemptEvent
args.Cancel();
}

private void OnConsciousAttempt(EntityUid uid, SleepingComponent component, ConsciousAttemptEvent args)
{
args.Cancel();
}


private void OnInit(EntityUid uid, ForcedSleepingComponent component, ComponentInit args)
{
TrySleeping(uid);
Expand Down
21 changes: 21 additions & 0 deletions Content.Shared/ActionBlocker/ActionBlockerSystem.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
using Content.Shared.Bed.Sleep;
using Content.Shared.Body.Events;
using Content.Shared.DragDrop;
using Content.Shared.Emoting;
using Content.Shared.Hands;
using Content.Shared.Interaction;
using Content.Shared.Interaction.Events;
using Content.Shared.Item;
using Content.Shared.Mobs;
using Content.Shared.Mobs.Components;
using Content.Shared.Movement.Components;
using Content.Shared.Movement.Events;
using Content.Shared.Speech;
Expand Down Expand Up @@ -67,6 +70,9 @@ public bool UpdateCanMove(EntityUid uid, InputMoverComponent? component = null)
/// <returns></returns>
public bool CanInteract(EntityUid user, EntityUid? target)
{
if (!CanConsciouslyPerformAction(user))
return false;

var ev = new InteractionAttemptEvent(user, target);
RaiseLocalEvent(user, ev);

Expand Down Expand Up @@ -98,6 +104,21 @@ public bool CanUseHeldEntity(EntityUid user)
return !ev.Cancelled;
}


/// <summary>
/// Whether a user conscious to perform an action.
/// </summary>
/// <remarks>
/// This should be used when you want a much more permissive check than <see cref="CanInteract"/>
/// </remarks>
public bool CanConsciouslyPerformAction(EntityUid user)
{
var ev = new ConsciousAttemptEvent(user);
RaiseLocalEvent(user, ev);

return !ev.Cancelled;
}

public bool CanThrow(EntityUid user, EntityUid itemUid)
{
var ev = new ThrowAttemptEvent(user, itemUid);
Expand Down
11 changes: 10 additions & 1 deletion Content.Shared/Actions/BaseActionComponent.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Robust.Shared.Audio;
using Content.Shared.Mobs;
using Robust.Shared.Audio;
using Robust.Shared.Serialization;
using Robust.Shared.Utility;

Expand Down Expand Up @@ -118,6 +119,12 @@ public EntityUid? EntityIcon
/// </summary>
[DataField("checkCanInteract")] public bool CheckCanInteract = true;

/// <summary>
/// Whether to check if the user is conscious or not. Can be used instead of <see cref="CheckCanInteract"/>
/// for a more permissive check.
/// </summary>
[DataField] public bool CheckConsciousness;

/// <summary>
/// If true, this will cause the action to only execute locally without ever notifying the server.
/// </summary>
Expand Down Expand Up @@ -177,6 +184,7 @@ public abstract class BaseActionComponentState : ComponentState
public NetEntity? Container;
public NetEntity? EntityIcon;
public bool CheckCanInteract;
public bool CheckConsciousness;
public bool ClientExclusive;
public int Priority;
public NetEntity? AttachedEntity;
Expand Down Expand Up @@ -204,6 +212,7 @@ protected BaseActionComponentState(BaseActionComponent component, IEntityManager
MaxCharges = component.MaxCharges;
RenewCharges = component.RenewCharges;
CheckCanInteract = component.CheckCanInteract;
CheckConsciousness = component.CheckConsciousness;
ClientExclusive = component.ClientExclusive;
Priority = component.Priority;
AutoPopulate = component.AutoPopulate;
Expand Down
4 changes: 4 additions & 0 deletions Content.Shared/Actions/SharedActionsSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using Content.Shared.Interaction;
using Content.Shared.Inventory.Events;
using Content.Shared.Mind;
using Content.Shared.Mobs.Components;
using Robust.Shared.Audio.Systems;
using Robust.Shared.Containers;
using Robust.Shared.GameStates;
Expand Down Expand Up @@ -370,6 +371,9 @@ private void OnActionRequest(RequestPerformActionEvent ev, EntitySessionEventArg

BaseActionEvent? performEvent = null;

if (action.CheckConsciousness && !_actionBlockerSystem.CanConsciouslyPerformAction(user))
return;

// Validate request by checking action blockers and the like:
switch (action)
{
Expand Down
8 changes: 8 additions & 0 deletions Content.Shared/Interaction/Events/InteractionAttemptEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@ public InteractionAttemptEvent(EntityUid uid, EntityUid? target)
public EntityUid? Target { get; }
}

/// <summary>
/// Raised to determine whether an entity is conscious to perform an action.
/// </summary>
public sealed class ConsciousAttemptEvent(EntityUid Uid) : CancellableEntityEventArgs
{
public EntityUid Uid { get; } = Uid;
}

/// <summary>
/// Event raised directed at the target entity of an interaction to see if the user is allowed to perform some
/// generic interaction.
Expand Down
2 changes: 1 addition & 1 deletion Content.Shared/Mobs/Systems/MobStateSystem.Subscribers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ private void SubscribeEvents()
SubscribeLocalEvent<MobStateComponent, ChangeDirectionAttemptEvent>(CheckAct);
SubscribeLocalEvent<MobStateComponent, UseAttemptEvent>(CheckAct);
SubscribeLocalEvent<MobStateComponent, AttackAttemptEvent>(CheckAct);
SubscribeLocalEvent<MobStateComponent, InteractionAttemptEvent>(CheckAct);
SubscribeLocalEvent<MobStateComponent, ConsciousAttemptEvent>(CheckAct);
SubscribeLocalEvent<MobStateComponent, ThrowAttemptEvent>(CheckAct);
SubscribeLocalEvent<MobStateComponent, SpeakAttemptEvent>(OnSpeakAttempt);
SubscribeLocalEvent<MobStateComponent, IsEquippingAttemptEvent>(OnEquipAttempt);
Expand Down
3 changes: 3 additions & 0 deletions Resources/Prototypes/Actions/types.yml
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@
- type: InstantAction
charges: 3
checkCanInteract: false
checkConsciousness: true
itemIconStyle: BigAction
priority: -20
icon:
Expand Down Expand Up @@ -143,6 +144,8 @@
noSpawn: true
components:
- type: InstantAction
checkCanInteract: false
checkConsciousness: true
charges: 2
useDelay: 5
itemIconStyle: BigAction
Expand Down
Loading