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
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 = true;

/// <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
5 changes: 4 additions & 1 deletion Resources/Prototypes/Actions/crit.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Actions added to mobs in crit.
# Actions added to mobs in crit.
- type: entity
id: ActionCritSuccumb
name: Succumb
Expand All @@ -8,6 +8,7 @@
- type: InstantAction
itemIconStyle: NoItem
checkCanInteract: false
checkConsciousness: false
icon:
sprite: Mobs/Ghosts/ghost_human.rsi
state: icon
Expand All @@ -22,6 +23,7 @@
- type: InstantAction
itemIconStyle: NoItem
checkCanInteract: false
checkConsciousness: false
icon:
sprite: Interface/Actions/actions_crit.rsi
state: fakedeath
Expand All @@ -37,6 +39,7 @@
- type: InstantAction
itemIconStyle: NoItem
checkCanInteract: false
checkConsciousness: false
icon:
sprite: Interface/Actions/actions_crit.rsi
state: lastwords
Expand Down
1 change: 1 addition & 0 deletions Resources/Prototypes/Actions/diona.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
icon: Mobs/Species/Diona/organs.rsi/brain.png
event: !type:GibActionEvent {}
checkCanInteract: false
checkConsciousness: false

- type: entity
id: DionaReformAction
Expand Down
9 changes: 9 additions & 0 deletions Resources/Prototypes/Actions/types.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
components:
- type: InstantAction
checkCanInteract: false
checkConsciousness: false
icon: Interface/Actions/zombie-turn.png
event: !type:ZombifySelfActionEvent

Expand Down Expand Up @@ -66,6 +67,7 @@
components:
- type: InstantAction
checkCanInteract: false
checkConsciousness: false
itemIconStyle: BigAction
priority: -20
icon:
Expand All @@ -82,6 +84,7 @@
components:
- type: InstantAction
checkCanInteract: false
checkConsciousness: false
itemIconStyle: BigAction
priority: -20
icon:
Expand Down Expand Up @@ -143,6 +146,7 @@
noSpawn: true
components:
- type: InstantAction
checkCanInteract: false
charges: 2
useDelay: 5
itemIconStyle: BigAction
Expand Down Expand Up @@ -186,6 +190,7 @@
components:
- type: InstantAction
checkCanInteract: false
checkConsciousness: false
icon: Interface/Actions/harmOff.png
iconOn: Interface/Actions/harm.png
event: !type:ToggleCombatActionEvent
Expand Down Expand Up @@ -256,6 +261,7 @@
- type: InstantAction
clientExclusive: true
checkCanInteract: false
checkConsciousness: false
temporary: true
icon: { sprite: Objects/Tools/multitool.rsi, state: icon }
event: !type:ClearAllOverlaysEvent
Expand All @@ -279,6 +285,7 @@
components:
- type: InstantAction
checkCanInteract: false
checkConsciousness: false
icon: { sprite: Clothing/Head/Hats/pyjamasyndicatered.rsi, state: icon }
event: !type:SleepActionEvent

Expand All @@ -291,6 +298,7 @@
- type: InstantAction
icon: { sprite: Clothing/Head/Hats/pyjamasyndicatered.rsi, state: icon }
checkCanInteract: false
checkConsciousness: false
event: !type:WakeActionEvent

- type: entity
Expand Down Expand Up @@ -328,6 +336,7 @@
event: !type:ToggleEyesActionEvent
useDelay: 1 # so u cant give yourself and observers eyestrain by rapidly spamming the action
checkCanInteract: false
checkConsciousness: false

- type: entity
id: ActionToggleWagging
Expand Down
1 change: 1 addition & 0 deletions Resources/Prototypes/Entities/Mobs/Player/guardian.yml
Original file line number Diff line number Diff line change
Expand Up @@ -253,3 +253,4 @@
event: !type:GuardianToggleActionEvent
useDelay: 2
checkCanInteract: false
checkConsciousness: false
2 changes: 2 additions & 0 deletions Resources/Prototypes/Entities/Objects/Fun/pai.yml
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@
components:
- type: InstantAction
checkCanInteract: false
checkConsciousness: false
icon: Interface/Actions/pai-midi.png
event: !type:OpenUiActionEvent
key: enum.InstrumentUiKey.Key
Expand All @@ -150,6 +151,7 @@
components:
- type: InstantAction
checkCanInteract: false
checkConsciousness: false
icon: { sprite: Interface/Actions/pai-map.rsi, state: icon }
event: !type:OpenUiActionEvent
key: enum.StationMapUiKey.Key
Loading
Loading