From a3fdcd3a681a6f6077aab21d79828f0b7136350c Mon Sep 17 00:00:00 2001 From: DrSmugleaf Date: Sun, 20 Dec 2020 04:31:04 +0100 Subject: [PATCH] Add EffectBlockerExtensions --- .../Tests/Buckle/BuckleTest.cs | 1 + .../Components/GUI/InventoryComponent.cs | 1 + .../Components/Movement/NoSlipComponent.cs | 1 + .../Buckle/SharedBuckleComponent.cs | 1 + .../Movement/SharedSlipperyComponent.cs | 1 + .../ActionBlocker/ActionBlockerSystem.cs | 51 ++++++++++--------- .../ActionBlocker/IActionBlocker.cs | 6 ++- .../EffectBlocker/EffectBlockerExtensions.cs | 17 +++++++ .../EffectBlockerSystem.cs | 16 ++---- .../EffectBlocker/IEffectBlocker.cs | 14 +++++ .../SharedStandingStateSystem.cs | 1 + 11 files changed, 72 insertions(+), 38 deletions(-) create mode 100644 Content.Shared/GameObjects/EntitySystems/EffectBlocker/EffectBlockerExtensions.cs rename Content.Shared/GameObjects/EntitySystems/{ => EffectBlocker}/EffectBlockerSystem.cs (73%) create mode 100644 Content.Shared/GameObjects/EntitySystems/EffectBlocker/IEffectBlocker.cs diff --git a/Content.IntegrationTests/Tests/Buckle/BuckleTest.cs b/Content.IntegrationTests/Tests/Buckle/BuckleTest.cs index b6918abae8..2bf519db3f 100644 --- a/Content.IntegrationTests/Tests/Buckle/BuckleTest.cs +++ b/Content.IntegrationTests/Tests/Buckle/BuckleTest.cs @@ -8,6 +8,7 @@ using Content.Shared.GameObjects.Components.Body.Part; using Content.Shared.GameObjects.Components.Buckle; using Content.Shared.GameObjects.EntitySystems; using Content.Shared.GameObjects.EntitySystems.ActionBlocker; +using Content.Shared.GameObjects.EntitySystems.EffectBlocker; using Content.Shared.Utility; using NUnit.Framework; using Robust.Shared.Interfaces.GameObjects; diff --git a/Content.Server/GameObjects/Components/GUI/InventoryComponent.cs b/Content.Server/GameObjects/Components/GUI/InventoryComponent.cs index 593fdf7e80..2ef74a187e 100644 --- a/Content.Server/GameObjects/Components/GUI/InventoryComponent.cs +++ b/Content.Server/GameObjects/Components/GUI/InventoryComponent.cs @@ -8,6 +8,7 @@ using Content.Server.Interfaces.GameObjects; using Content.Shared.GameObjects.Components.Inventory; using Content.Shared.GameObjects.EntitySystems; using Content.Shared.GameObjects.EntitySystems.ActionBlocker; +using Content.Shared.GameObjects.EntitySystems.EffectBlocker; using Content.Shared.Interfaces; using Robust.Server.GameObjects.Components.Container; using Robust.Shared.Containers; diff --git a/Content.Server/GameObjects/Components/Movement/NoSlipComponent.cs b/Content.Server/GameObjects/Components/Movement/NoSlipComponent.cs index c541377f4b..0e40b39bed 100644 --- a/Content.Server/GameObjects/Components/Movement/NoSlipComponent.cs +++ b/Content.Server/GameObjects/Components/Movement/NoSlipComponent.cs @@ -1,4 +1,5 @@ using Content.Shared.GameObjects.EntitySystems; +using Content.Shared.GameObjects.EntitySystems.EffectBlocker; using Robust.Shared.GameObjects; namespace Content.Server.GameObjects.Components.Movement diff --git a/Content.Shared/GameObjects/Components/Buckle/SharedBuckleComponent.cs b/Content.Shared/GameObjects/Components/Buckle/SharedBuckleComponent.cs index 807c9035a0..a78bd4a35c 100644 --- a/Content.Shared/GameObjects/Components/Buckle/SharedBuckleComponent.cs +++ b/Content.Shared/GameObjects/Components/Buckle/SharedBuckleComponent.cs @@ -3,6 +3,7 @@ using System; using Content.Shared.GameObjects.Components.Strap; using Content.Shared.GameObjects.EntitySystems; using Content.Shared.GameObjects.EntitySystems.ActionBlocker; +using Content.Shared.GameObjects.EntitySystems.EffectBlocker; using Content.Shared.Interfaces.GameObjects.Components; using Robust.Shared.GameObjects; using Robust.Shared.GameObjects.ComponentDependencies; diff --git a/Content.Shared/GameObjects/Components/Movement/SharedSlipperyComponent.cs b/Content.Shared/GameObjects/Components/Movement/SharedSlipperyComponent.cs index 6e79a32faa..de3b2bdd8f 100644 --- a/Content.Shared/GameObjects/Components/Movement/SharedSlipperyComponent.cs +++ b/Content.Shared/GameObjects/Components/Movement/SharedSlipperyComponent.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Linq; using Content.Shared.GameObjects.Components.Mobs; using Content.Shared.GameObjects.EntitySystems; +using Content.Shared.GameObjects.EntitySystems.EffectBlocker; using Content.Shared.Physics; using Robust.Shared.Containers; using Robust.Shared.GameObjects; diff --git a/Content.Shared/GameObjects/EntitySystems/ActionBlocker/ActionBlockerSystem.cs b/Content.Shared/GameObjects/EntitySystems/ActionBlocker/ActionBlockerSystem.cs index 094ef7b8fa..63367caa19 100644 --- a/Content.Shared/GameObjects/EntitySystems/ActionBlocker/ActionBlockerSystem.cs +++ b/Content.Shared/GameObjects/EntitySystems/ActionBlocker/ActionBlockerSystem.cs @@ -1,4 +1,5 @@ -using JetBrains.Annotations; +using Content.Shared.GameObjects.EntitySystems.EffectBlocker; +using JetBrains.Annotations; using Robust.Shared.GameObjects.Systems; using Robust.Shared.Interfaces.GameObjects; @@ -15,9 +16,9 @@ namespace Content.Shared.GameObjects.EntitySystems.ActionBlocker { var canMove = true; - foreach (var blockers in entity.GetAllComponents()) + foreach (var blocker in entity.GetAllComponents()) { - canMove &= blockers.CanMove(); // Sets var to false if false + canMove &= blocker.CanMove(); // Sets var to false if false } return canMove; @@ -27,9 +28,9 @@ namespace Content.Shared.GameObjects.EntitySystems.ActionBlocker { var canInteract = true; - foreach (var blockers in entity.GetAllComponents()) + foreach (var blocker in entity.GetAllComponents()) { - canInteract &= blockers.CanInteract(); + canInteract &= blocker.CanInteract(); } return canInteract; @@ -39,9 +40,9 @@ namespace Content.Shared.GameObjects.EntitySystems.ActionBlocker { var canUse = true; - foreach (var blockers in entity.GetAllComponents()) + foreach (var blocker in entity.GetAllComponents()) { - canUse &= blockers.CanUse(); + canUse &= blocker.CanUse(); } return canUse; @@ -51,9 +52,9 @@ namespace Content.Shared.GameObjects.EntitySystems.ActionBlocker { var canThrow = true; - foreach (var blockers in entity.GetAllComponents()) + foreach (var blocker in entity.GetAllComponents()) { - canThrow &= blockers.CanThrow(); + canThrow &= blocker.CanThrow(); } return canThrow; @@ -63,9 +64,9 @@ namespace Content.Shared.GameObjects.EntitySystems.ActionBlocker { var canSpeak = true; - foreach (var blockers in entity.GetAllComponents()) + foreach (var blocker in entity.GetAllComponents()) { - canSpeak &= blockers.CanSpeak(); + canSpeak &= blocker.CanSpeak(); } return canSpeak; @@ -75,9 +76,9 @@ namespace Content.Shared.GameObjects.EntitySystems.ActionBlocker { var canDrop = true; - foreach (var blockers in entity.GetAllComponents()) + foreach (var blocker in entity.GetAllComponents()) { - canDrop &= blockers.CanDrop(); + canDrop &= blocker.CanDrop(); } return canDrop; @@ -87,9 +88,9 @@ namespace Content.Shared.GameObjects.EntitySystems.ActionBlocker { var canPickup = true; - foreach (var blockers in entity.GetAllComponents()) + foreach (var blocker in entity.GetAllComponents()) { - canPickup &= blockers.CanPickup(); + canPickup &= blocker.CanPickup(); } return canPickup; @@ -99,9 +100,9 @@ namespace Content.Shared.GameObjects.EntitySystems.ActionBlocker { var canEmote = true; - foreach (var blockers in entity.GetAllComponents()) + foreach (var blocker in entity.GetAllComponents()) { - canEmote &= blockers.CanEmote(); + canEmote &= blocker.CanEmote(); } return canEmote; @@ -111,9 +112,9 @@ namespace Content.Shared.GameObjects.EntitySystems.ActionBlocker { var canAttack = true; - foreach (var blockers in entity.GetAllComponents()) + foreach (var blocker in entity.GetAllComponents()) { - canAttack &= blockers.CanAttack(); + canAttack &= blocker.CanAttack(); } return canAttack; @@ -123,9 +124,9 @@ namespace Content.Shared.GameObjects.EntitySystems.ActionBlocker { var canEquip = true; - foreach (var blockers in entity.GetAllComponents()) + foreach (var blocker in entity.GetAllComponents()) { - canEquip &= blockers.CanEquip(); + canEquip &= blocker.CanEquip(); } return canEquip; @@ -135,9 +136,9 @@ namespace Content.Shared.GameObjects.EntitySystems.ActionBlocker { var canUnequip = true; - foreach (var blockers in entity.GetAllComponents()) + foreach (var blocker in entity.GetAllComponents()) { - canUnequip &= blockers.CanUnequip(); + canUnequip &= blocker.CanUnequip(); } return canUnequip; @@ -147,9 +148,9 @@ namespace Content.Shared.GameObjects.EntitySystems.ActionBlocker { var canChangeDirection = true; - foreach (var blockers in entity.GetAllComponents()) + foreach (var blocker in entity.GetAllComponents()) { - canChangeDirection &= blockers.CanChangeDirection(); + canChangeDirection &= blocker.CanChangeDirection(); } return canChangeDirection; diff --git a/Content.Shared/GameObjects/EntitySystems/ActionBlocker/IActionBlocker.cs b/Content.Shared/GameObjects/EntitySystems/ActionBlocker/IActionBlocker.cs index 0c47f44dca..8d23ceea0d 100644 --- a/Content.Shared/GameObjects/EntitySystems/ActionBlocker/IActionBlocker.cs +++ b/Content.Shared/GameObjects/EntitySystems/ActionBlocker/IActionBlocker.cs @@ -1,4 +1,6 @@ -namespace Content.Shared.GameObjects.EntitySystems.ActionBlocker +using Content.Shared.GameObjects.EntitySystems.EffectBlocker; + +namespace Content.Shared.GameObjects.EntitySystems.ActionBlocker { /// /// This interface gives components the ability to block certain actions from @@ -34,4 +36,4 @@ bool CanSweat() => true; } -} \ No newline at end of file +} diff --git a/Content.Shared/GameObjects/EntitySystems/EffectBlocker/EffectBlockerExtensions.cs b/Content.Shared/GameObjects/EntitySystems/EffectBlocker/EffectBlockerExtensions.cs new file mode 100644 index 0000000000..842695f3ec --- /dev/null +++ b/Content.Shared/GameObjects/EntitySystems/EffectBlocker/EffectBlockerExtensions.cs @@ -0,0 +1,17 @@ +using Robust.Shared.Interfaces.GameObjects; + +namespace Content.Shared.GameObjects.EntitySystems.EffectBlocker +{ + public static class EffectBlockerExtensions + { + public static bool CanFall(this IEntity entity) + { + return EffectBlockerSystem.CanFall(entity); + } + + public static bool CanSlip(this IEntity entity) + { + return EffectBlockerSystem.CanSlip(entity); + } + } +} diff --git a/Content.Shared/GameObjects/EntitySystems/EffectBlockerSystem.cs b/Content.Shared/GameObjects/EntitySystems/EffectBlocker/EffectBlockerSystem.cs similarity index 73% rename from Content.Shared/GameObjects/EntitySystems/EffectBlockerSystem.cs rename to Content.Shared/GameObjects/EntitySystems/EffectBlocker/EffectBlockerSystem.cs index 2458dfd847..215630014c 100644 --- a/Content.Shared/GameObjects/EntitySystems/EffectBlockerSystem.cs +++ b/Content.Shared/GameObjects/EntitySystems/EffectBlocker/EffectBlockerSystem.cs @@ -1,28 +1,21 @@ using Content.Shared.GameObjects.EntitySystems.ActionBlocker; +using JetBrains.Annotations; using Robust.Shared.GameObjects.Systems; using Robust.Shared.Interfaces.GameObjects; -namespace Content.Shared.GameObjects.EntitySystems +namespace Content.Shared.GameObjects.EntitySystems.EffectBlocker { - /// - /// This interface gives components the ability to block certain effects - /// from affecting the owning entity. For actions see - /// - public interface IEffectBlocker - { - bool CanFall() => true; - bool CanSlip() => true; - } - /// /// Utility methods to check if an effect is allowed to affect a specific entity. /// For actions see /// + [UsedImplicitly] public class EffectBlockerSystem : EntitySystem { public static bool CanFall(IEntity entity) { var canFall = true; + foreach (var blocker in entity.GetAllComponents()) { canFall &= blocker.CanFall(); // Sets var to false if false @@ -34,6 +27,7 @@ namespace Content.Shared.GameObjects.EntitySystems public static bool CanSlip(IEntity entity) { var canSlip = true; + foreach (var blocker in entity.GetAllComponents()) { canSlip &= blocker.CanSlip(); // Sets var to false if false diff --git a/Content.Shared/GameObjects/EntitySystems/EffectBlocker/IEffectBlocker.cs b/Content.Shared/GameObjects/EntitySystems/EffectBlocker/IEffectBlocker.cs new file mode 100644 index 0000000000..5cce28829d --- /dev/null +++ b/Content.Shared/GameObjects/EntitySystems/EffectBlocker/IEffectBlocker.cs @@ -0,0 +1,14 @@ +using Content.Shared.GameObjects.EntitySystems.ActionBlocker; + +namespace Content.Shared.GameObjects.EntitySystems.EffectBlocker +{ + /// + /// This interface gives components the ability to block certain effects + /// from affecting the owning entity. For actions see + /// + public interface IEffectBlocker + { + bool CanFall() => true; + bool CanSlip() => true; + } +} diff --git a/Content.Shared/GameObjects/EntitySystems/SharedStandingStateSystem.cs b/Content.Shared/GameObjects/EntitySystems/SharedStandingStateSystem.cs index 9526b5414a..46fb1dec2e 100644 --- a/Content.Shared/GameObjects/EntitySystems/SharedStandingStateSystem.cs +++ b/Content.Shared/GameObjects/EntitySystems/SharedStandingStateSystem.cs @@ -1,3 +1,4 @@ +using Content.Shared.GameObjects.EntitySystems.EffectBlocker; using Robust.Shared.GameObjects.Systems; using Robust.Shared.Interfaces.GameObjects;