Skip to content

Commit

Permalink
Deprecate IActionBlocker in favour of cancellable events (#4193)
Browse files Browse the repository at this point in the history
* Deprecate IActionBlocker in favour of cancellable events

* Bring back old speech/emoting component restrictions

* Rename action blocker listener methods

* Use Entity System public methods instead of extension methods

Co-authored-by: Vera Aguilera Puerto <[email protected]>
  • Loading branch information
DrSmugleaf and gradientvera authored Jun 19, 2021
1 parent e1e54e9 commit 9b8185d
Show file tree
Hide file tree
Showing 98 changed files with 669 additions and 361 deletions.
3 changes: 1 addition & 2 deletions Content.Client/Physics/Controllers/MoverController.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
#nullable enable
using Content.Shared.Movement;
using Content.Shared.Movement.Components;
using Content.Shared.Physics.Controllers;
using Robust.Client.Player;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Physics.Dynamics;

namespace Content.Client.Physics.Controllers
{
Expand Down
23 changes: 15 additions & 8 deletions Content.IntegrationTests/Tests/Buckle/BuckleTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
using Content.Shared.Buckle.Components;
using Content.Shared.Coordinates;
using Content.Shared.EffectBlocker;
using Content.Shared.Interaction.Events;
using Content.Shared.Movement;
using NUnit.Framework;
using Robust.Server.Player;
using Robust.Shared.GameObjects;
Expand Down Expand Up @@ -66,6 +68,7 @@ await server.WaitAssertion(() =>
{
var mapManager = IoCManager.Resolve<IMapManager>();
var entityManager = IoCManager.Resolve<IEntityManager>();
var actionBlocker = EntitySystem.Get<ActionBlockerSystem>();

var gridId = new GridId(1);
var grid = mapManager.GetGrid(gridId);
Expand All @@ -79,8 +82,8 @@ await server.WaitAssertion(() =>
Assert.NotNull(buckle);
Assert.Null(buckle.BuckledTo);
Assert.False(buckle.Buckled);
Assert.True(ActionBlockerSystem.CanMove(human));
Assert.True(ActionBlockerSystem.CanChangeDirection(human));
Assert.True(actionBlocker.CanMove(human));
Assert.True(actionBlocker.CanChangeDirection(human));
Assert.True(EffectBlockerSystem.CanFall(human));

// Default state, no buckled entities, strap
Expand All @@ -96,8 +99,8 @@ await server.WaitAssertion(() =>

var player = IoCManager.Resolve<IPlayerManager>().GetAllPlayers().Single();
Assert.True(((BuckleComponentState) buckle.GetComponentState(player)).Buckled);
Assert.False(ActionBlockerSystem.CanMove(human));
Assert.False(ActionBlockerSystem.CanChangeDirection(human));
Assert.False(actionBlocker.CanMove(human));
Assert.False(actionBlocker.CanChangeDirection(human));
Assert.False(EffectBlockerSystem.CanFall(human));
Assert.That(human.Transform.WorldPosition, Is.EqualTo(chair.Transform.WorldPosition));

Expand All @@ -120,15 +123,17 @@ await server.WaitAssertion(() =>

await server.WaitAssertion(() =>
{
var actionBlocker = EntitySystem.Get<ActionBlockerSystem>();

// Still buckled
Assert.True(buckle.Buckled);

// Unbuckle
Assert.True(buckle.TryUnbuckle(human));
Assert.Null(buckle.BuckledTo);
Assert.False(buckle.Buckled);
Assert.True(ActionBlockerSystem.CanMove(human));
Assert.True(ActionBlockerSystem.CanChangeDirection(human));
Assert.True(actionBlocker.CanMove(human));
Assert.True(actionBlocker.CanChangeDirection(human));
Assert.True(EffectBlockerSystem.CanFall(human));

// Unbuckle, strap
Expand All @@ -153,6 +158,8 @@ await server.WaitAssertion(() =>

await server.WaitAssertion(() =>
{
var actionBlocker = EntitySystem.Get<ActionBlockerSystem>();

// Still buckled
Assert.True(buckle.Buckled);

Expand Down Expand Up @@ -182,8 +189,8 @@ await server.WaitAssertion(() =>
// Force unbuckle
Assert.True(buckle.TryUnbuckle(human, true));
Assert.False(buckle.Buckled);
Assert.True(ActionBlockerSystem.CanMove(human));
Assert.True(ActionBlockerSystem.CanChangeDirection(human));
Assert.True(actionBlocker.CanMove(human));
Assert.True(actionBlocker.CanChangeDirection(human));
Assert.True(EffectBlockerSystem.CanFall(human));

// Re-buckle
Expand Down
3 changes: 2 additions & 1 deletion Content.Server/AI/Steering/AiSteeringSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using Content.Server.CPUJob.JobQueues;
using Content.Shared.ActionBlocker;
using Content.Shared.Interaction.Helpers;
using Content.Shared.Movement;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Map;
Expand Down Expand Up @@ -249,7 +250,7 @@ private SteeringStatus Steer(IEntity entity, IAiSteeringRequest steeringRequest,
// Main optimisation to be done below is the redundant calls and adding more variables
if (entity.Deleted ||
!entity.TryGetComponent(out AiControllerComponent? controller) ||
!ActionBlockerSystem.CanMove(entity) ||
!EntitySystem.Get<ActionBlockerSystem>().CanMove(entity) ||
!entity.Transform.GridID.IsValid())
{
return SteeringStatus.NoPath;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using Content.Server.AI.WorldState;
using Content.Server.AI.WorldState.States;
using Content.Shared.ActionBlocker;
using Content.Shared.Movement;
using Robust.Shared.GameObjects;

namespace Content.Server.AI.Utility.Considerations.ActionBlocker
{
Expand All @@ -10,7 +12,7 @@ protected override float GetScore(Blackboard context)
{
var self = context.GetState<SelfState>().GetValue();

if (self == null || !ActionBlockerSystem.CanMove(self))
if (self == null || !EntitySystem.Get<ActionBlockerSystem>().CanMove(self))
{
return 0.0f;
}
Expand Down
7 changes: 5 additions & 2 deletions Content.Server/AME/Components/AMEControllerComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
using Content.Shared.ActionBlocker;
using Content.Shared.AME;
using Content.Shared.Interaction;
using Content.Shared.Notification;
using Content.Shared.Interaction.Events;
using Content.Shared.Notification.Managers;
using Robust.Server.GameObjects;
using Robust.Shared.Audio;
Expand Down Expand Up @@ -157,8 +157,11 @@ private bool PlayerCanUseController(IEntity playerEntity, bool needsPower = true
//Need player entity to check if they are still able to use the dispenser
if (playerEntity == null)
return false;

var actionBlocker = EntitySystem.Get<ActionBlockerSystem>();

//Check if player can interact in their current state
if (!ActionBlockerSystem.CanInteract(playerEntity) || !ActionBlockerSystem.CanUse(playerEntity))
if (!actionBlocker.CanInteract(playerEntity) || !actionBlocker.CanUse(playerEntity))
return false;
//Check if device is powered
if (needsPower && !Powered)
Expand Down
6 changes: 3 additions & 3 deletions Content.Server/Access/Components/IdCardConsoleComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
using Content.Shared.ActionBlocker;
using Content.Shared.Acts;
using Content.Shared.Interaction;
using Content.Shared.Notification;
using Content.Shared.Interaction.Events;
using Content.Shared.Notification.Managers;
using Content.Shared.Verbs;
using Robust.Server.GameObjects;
Expand Down Expand Up @@ -259,7 +259,7 @@ public sealed class EjectPrivilegedIDVerb : Verb<IdCardConsoleComponent>
{
protected override void GetData(IEntity user, IdCardConsoleComponent component, VerbData data)
{
if (!ActionBlockerSystem.CanInteract(user))
if (!EntitySystem.Get<ActionBlockerSystem>().CanInteract(user))
{
data.Visibility = VerbVisibility.Invisible;
return;
Expand All @@ -284,7 +284,7 @@ public sealed class EjectTargetIDVerb : Verb<IdCardConsoleComponent>
{
protected override void GetData(IEntity user, IdCardConsoleComponent component, VerbData data)
{
if (!ActionBlockerSystem.CanInteract(user))
if (!EntitySystem.Get<ActionBlockerSystem>().CanInteract(user))
{
data.Visibility = VerbVisibility.Invisible;
return;
Expand Down
4 changes: 2 additions & 2 deletions Content.Server/Actions/Actions/DisarmAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
using Content.Shared.Actions.Components;
using Content.Shared.Audio;
using Content.Shared.Cooldown;
using Content.Shared.Interaction.Events;
using Content.Shared.Interaction.Helpers;
using Content.Shared.Notification;
using Content.Shared.Notification.Managers;
using JetBrains.Annotations;
using Robust.Server.GameObjects;
Expand Down Expand Up @@ -57,7 +57,7 @@ public void DoTargetEntityAction(TargetEntityActionEventArgs args)
}

if (!args.Performer.TryGetComponent<SharedActionsComponent>(out var actions)) return;
if (args.Target == args.Performer || !args.Performer.CanAttack()) return;
if (args.Target == args.Performer || !EntitySystem.Get<ActionBlockerSystem>().CanAttack(args.Performer)) return;

var random = IoCManager.Resolve<IRobustRandom>();
var audio = EntitySystem.Get<AudioSystem>();
Expand Down
4 changes: 3 additions & 1 deletion Content.Server/Actions/Actions/ScreamAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@
using Content.Shared.Audio;
using Content.Shared.CharacterAppearance;
using Content.Shared.Cooldown;
using Content.Shared.Speech;
using JetBrains.Annotations;
using Robust.Shared.Audio;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Player;
using Robust.Shared.Random;
Expand Down Expand Up @@ -40,7 +42,7 @@ public ScreamAction()

public void DoInstantAction(InstantActionEventArgs args)
{
if (!ActionBlockerSystem.CanSpeak(args.Performer)) return;
if (!EntitySystem.Get<ActionBlockerSystem>().CanSpeak(args.Performer)) return;
if (!args.Performer.TryGetComponent<HumanoidAppearanceComponent>(out var humanoid)) return;
if (!args.Performer.TryGetComponent<SharedActionsComponent>(out var actions)) return;

Expand Down
3 changes: 2 additions & 1 deletion Content.Server/Actions/ServerActionsComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using Content.Shared.Actions;
using Content.Shared.Actions.Components;
using Content.Shared.Actions.Prototypes;
using Content.Shared.Interaction.Events;
using Robust.Server.GameObjects;
using Robust.Server.GameStates;
using Robust.Shared.GameObjects;
Expand Down Expand Up @@ -186,7 +187,7 @@ private bool CheckRangeAndSetFacing(EntityCoordinates target, IEntity player)
return false;
}

if (!ActionBlockerSystem.CanChangeDirection(player)) return true;
if (!EntitySystem.Get<ActionBlockerSystem>().CanChangeDirection(player)) return true;

// don't set facing unless they clicked far enough away
var diff = targetWorldPos - player.Transform.WorldPosition;
Expand Down
14 changes: 6 additions & 8 deletions Content.Server/Arcade/Components/BlockGameArcadeComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using Content.Shared.ActionBlocker;
using Content.Shared.Arcade;
using Content.Shared.Interaction;
using Content.Shared.Interaction.Events;
using Content.Shared.NetIDs;
using Robust.Server.GameObjects;
using Robust.Server.Player;
Expand Down Expand Up @@ -49,15 +50,11 @@ public override void HandleMessage(ComponentMessage message, IComponent? compone

void IActivate.Activate(ActivateEventArgs eventArgs)
{
if(!eventArgs.User.TryGetComponent(out ActorComponent? actor))
{
if(!Powered || !eventArgs.User.TryGetComponent(out ActorComponent? actor))
return;
}
if (!Powered)
{

if(!EntitySystem.Get<ActionBlockerSystem>().CanInteract(eventArgs.User))
return;
}
if(!ActionBlockerSystem.CanInteract(actor.PlayerSession.AttachedEntity)) return;

UserInterface?.Toggle(actor.PlayerSession);
RegisterPlayerSession(actor.PlayerSession);
Expand Down Expand Up @@ -134,7 +131,8 @@ private void UserInterfaceOnOnReceiveMessage(ServerBoundUserInterfaceMessage obj
case BlockGameMessages.BlockGamePlayerActionMessage playerActionMessage:
if (obj.Session != _player) break;

if (!ActionBlockerSystem.CanInteract(Owner))
// TODO: Should this check if the Owner can interact...?
if (!EntitySystem.Get<ActionBlockerSystem>().CanInteract(Owner))
{
DeactivePlayer(obj.Session);
break;
Expand Down
11 changes: 4 additions & 7 deletions Content.Server/Arcade/Components/SpaceVillainArcadeComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using Content.Shared.ActionBlocker;
using Content.Shared.Arcade;
using Content.Shared.Interaction;
using Content.Shared.Interaction.Events;
using Content.Shared.Wires;
using Robust.Server.GameObjects;
using Robust.Shared.Audio;
Expand Down Expand Up @@ -58,15 +59,11 @@ public class SpaceVillainArcadeComponent : SharedSpaceVillainArcadeComponent, IA

void IActivate.Activate(ActivateEventArgs eventArgs)
{
if(!eventArgs.User.TryGetComponent(out ActorComponent? actor))
{
if(!Powered || !eventArgs.User.TryGetComponent(out ActorComponent? actor))
return;
}
if (!Powered)
{

if(!EntitySystem.Get<ActionBlockerSystem>().CanInteract(eventArgs.User))
return;
}
if(!ActionBlockerSystem.CanInteract(actor.PlayerSession.AttachedEntity)) return;

_game ??= new SpaceVillainGame(this);

Expand Down
3 changes: 2 additions & 1 deletion Content.Server/Body/Surgery/Components/SurgeryToolSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Content.Server.Body.Surgery.Messages;
using Content.Shared.ActionBlocker;
using Content.Shared.GameTicking;
using Content.Shared.Interaction.Events;
using Content.Shared.Interaction.Helpers;
using JetBrains.Annotations;
using Robust.Shared.GameObjects;
Expand Down Expand Up @@ -52,7 +53,7 @@ public override void Update(float frameTime)
continue;
}

if (!ActionBlockerSystem.CanInteract(tool.PerformerCache) ||
if (!Get<ActionBlockerSystem>().CanInteract(tool.PerformerCache) ||
!tool.PerformerCache.InRangeUnobstructed(tool.BodyCache))
{
tool.CloseAllSurgeryUIs();
Expand Down
3 changes: 2 additions & 1 deletion Content.Server/Botany/Components/LogComponent.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Threading.Tasks;
using Content.Shared.ActionBlocker;
using Content.Shared.Interaction;
using Content.Shared.Interaction.Events;
using Content.Shared.Random.Helpers;
using Content.Shared.Tag;
using Robust.Shared.GameObjects;
Expand All @@ -14,7 +15,7 @@ public class LogComponent : Component, IInteractUsing

async Task<bool> IInteractUsing.InteractUsing(InteractUsingEventArgs eventArgs)
{
if (!ActionBlockerSystem.CanInteract(eventArgs.User))
if (!EntitySystem.Get<ActionBlockerSystem>().CanInteract(eventArgs.User))
return false;

if (eventArgs.Using.HasTag("BotanySharp"))
Expand Down
6 changes: 3 additions & 3 deletions Content.Server/Botany/Components/PlantHolderComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
using Content.Shared.Chemistry.Solution.Components;
using Content.Shared.Examine;
using Content.Shared.Interaction;
using Content.Shared.Notification;
using Content.Shared.Interaction.Events;
using Content.Shared.Notification.Managers;
using Content.Shared.Random.Helpers;
using Content.Shared.Tag;
Expand Down Expand Up @@ -420,7 +420,7 @@ private void CheckLevelSanity()

public bool DoHarvest(IEntity user)
{
if (Seed == null || user.Deleted || !ActionBlockerSystem.CanInteract(user))
if (Seed == null || user.Deleted || !EntitySystem.Get<ActionBlockerSystem>().CanInteract(user))
return false;

if (Harvest && !Dead)
Expand Down Expand Up @@ -645,7 +645,7 @@ async Task<bool> IInteractUsing.InteractUsing(InteractUsingEventArgs eventArgs)
var user = eventArgs.User;
var usingItem = eventArgs.Using;

if (usingItem == null || usingItem.Deleted || !ActionBlockerSystem.CanInteract(user))
if (usingItem == null || usingItem.Deleted || !EntitySystem.Get<ActionBlockerSystem>().CanInteract(user))
return false;

if (usingItem.TryGetComponent(out SeedComponent? seeds))
Expand Down
8 changes: 4 additions & 4 deletions Content.Server/Buckle/Components/BuckleComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
using Content.Shared.ActionBlocker;
using Content.Shared.Alert;
using Content.Shared.Buckle.Components;
using Content.Shared.Interaction.Events;
using Content.Shared.Interaction.Helpers;
using Content.Shared.Notification;
using Content.Shared.Notification.Managers;
using Content.Shared.Verbs;
using Robust.Server.GameObjects;
Expand Down Expand Up @@ -161,7 +161,7 @@ private bool CanBuckle(IEntity? user, IEntity to, [NotNullWhen(true)] out StrapC
return false;
}

if (!ActionBlockerSystem.CanInteract(user))
if (!EntitySystem.Get<ActionBlockerSystem>().CanInteract(user))
{
user.PopupMessage(Loc.GetString("You can't do that!"));
return false;
Expand Down Expand Up @@ -314,7 +314,7 @@ public bool TryUnbuckle(IEntity user, bool force = false)
return false;
}

if (!ActionBlockerSystem.CanInteract(user))
if (!EntitySystem.Get<ActionBlockerSystem>().CanInteract(user))
{
user.PopupMessage(Loc.GetString("You can't do that!"));
return false;
Expand Down Expand Up @@ -439,7 +439,7 @@ private sealed class BuckleVerb : Verb<BuckleComponent>
{
protected override void GetData(IEntity user, BuckleComponent component, VerbData data)
{
if (!ActionBlockerSystem.CanInteract(user) || !component.Buckled)
if (!EntitySystem.Get<ActionBlockerSystem>().CanInteract(user) || !component.Buckled)
{
data.Visibility = VerbVisibility.Invisible;
return;
Expand Down
Loading

0 comments on commit 9b8185d

Please sign in to comment.