Add ActionBlockerExtensions

This commit is contained in:
DrSmugleaf
2020-12-20 04:26:21 +01:00
parent 026d96fd2d
commit fcd52fa90c
80 changed files with 369 additions and 196 deletions

View File

@@ -0,0 +1,77 @@
using Robust.Shared.Interfaces.GameObjects;
namespace Content.Shared.GameObjects.EntitySystems.ActionBlocker
{
public static class ActionBlockerExtensions
{
public static bool CanMove(this IEntity entity)
{
return ActionBlockerSystem.CanMove(entity);
}
public static bool CanInteract(this IEntity entity)
{
return ActionBlockerSystem.CanInteract(entity);
}
public static bool CanUse(this IEntity entity)
{
return ActionBlockerSystem.CanUse(entity);
}
public static bool CanThrow(this IEntity entity)
{
return ActionBlockerSystem.CanThrow(entity);
}
public static bool CanSpeak(this IEntity entity)
{
return ActionBlockerSystem.CanSpeak(entity);
}
public static bool CanDrop(this IEntity entity)
{
return ActionBlockerSystem.CanDrop(entity);
}
public static bool CanPickup(this IEntity entity)
{
return ActionBlockerSystem.CanPickup(entity);
}
public static bool CanEmote(this IEntity entity)
{
return ActionBlockerSystem.CanEmote(entity);
}
public static bool CanAttack(this IEntity entity)
{
return ActionBlockerSystem.CanAttack(entity);
}
public static bool CanEquip(this IEntity entity)
{
return ActionBlockerSystem.CanEquip(entity);
}
public static bool CanUnequip(this IEntity entity)
{
return ActionBlockerSystem.CanUnequip(entity);
}
public static bool CanChangeDirection(this IEntity entity)
{
return ActionBlockerSystem.CanChangeDirection(entity);
}
public static bool CanShiver(this IEntity entity)
{
return ActionBlockerSystem.CanShiver(entity);
}
public static bool CanSweat(this IEntity entity)
{
return ActionBlockerSystem.CanSweat(entity);
}
}
}

View File

@@ -0,0 +1,178 @@
using JetBrains.Annotations;
using Robust.Shared.GameObjects.Systems;
using Robust.Shared.Interfaces.GameObjects;
namespace Content.Shared.GameObjects.EntitySystems.ActionBlocker
{
/// <summary>
/// Utility methods to check if a specific entity is allowed to perform an action.
/// For effects see <see cref="EffectBlockerSystem"/>
/// </summary>
[UsedImplicitly]
public class ActionBlockerSystem : EntitySystem
{
public static bool CanMove(IEntity entity)
{
var canMove = true;
foreach (var blockers in entity.GetAllComponents<IActionBlocker>())
{
canMove &= blockers.CanMove(); // Sets var to false if false
}
return canMove;
}
public static bool CanInteract(IEntity entity)
{
var canInteract = true;
foreach (var blockers in entity.GetAllComponents<IActionBlocker>())
{
canInteract &= blockers.CanInteract();
}
return canInteract;
}
public static bool CanUse(IEntity entity)
{
var canUse = true;
foreach (var blockers in entity.GetAllComponents<IActionBlocker>())
{
canUse &= blockers.CanUse();
}
return canUse;
}
public static bool CanThrow(IEntity entity)
{
var canThrow = true;
foreach (var blockers in entity.GetAllComponents<IActionBlocker>())
{
canThrow &= blockers.CanThrow();
}
return canThrow;
}
public static bool CanSpeak(IEntity entity)
{
var canSpeak = true;
foreach (var blockers in entity.GetAllComponents<IActionBlocker>())
{
canSpeak &= blockers.CanSpeak();
}
return canSpeak;
}
public static bool CanDrop(IEntity entity)
{
var canDrop = true;
foreach (var blockers in entity.GetAllComponents<IActionBlocker>())
{
canDrop &= blockers.CanDrop();
}
return canDrop;
}
public static bool CanPickup(IEntity entity)
{
var canPickup = true;
foreach (var blockers in entity.GetAllComponents<IActionBlocker>())
{
canPickup &= blockers.CanPickup();
}
return canPickup;
}
public static bool CanEmote(IEntity entity)
{
var canEmote = true;
foreach (var blockers in entity.GetAllComponents<IActionBlocker>())
{
canEmote &= blockers.CanEmote();
}
return canEmote;
}
public static bool CanAttack(IEntity entity)
{
var canAttack = true;
foreach (var blockers in entity.GetAllComponents<IActionBlocker>())
{
canAttack &= blockers.CanAttack();
}
return canAttack;
}
public static bool CanEquip(IEntity entity)
{
var canEquip = true;
foreach (var blockers in entity.GetAllComponents<IActionBlocker>())
{
canEquip &= blockers.CanEquip();
}
return canEquip;
}
public static bool CanUnequip(IEntity entity)
{
var canUnequip = true;
foreach (var blockers in entity.GetAllComponents<IActionBlocker>())
{
canUnequip &= blockers.CanUnequip();
}
return canUnequip;
}
public static bool CanChangeDirection(IEntity entity)
{
var canChangeDirection = true;
foreach (var blockers in entity.GetAllComponents<IActionBlocker>())
{
canChangeDirection &= blockers.CanChangeDirection();
}
return canChangeDirection;
}
public static bool CanShiver(IEntity entity)
{
var canShiver = true;
foreach (var component in entity.GetAllComponents<IActionBlocker>())
{
canShiver &= component.CanShiver();
}
return canShiver;
}
public static bool CanSweat(IEntity entity)
{
var canSweat = true;
foreach (var component in entity.GetAllComponents<IActionBlocker>())
{
canSweat &= component.CanSweat();
}
return canSweat;
}
}
}

View File

@@ -0,0 +1,37 @@
namespace Content.Shared.GameObjects.EntitySystems.ActionBlocker
{
/// <summary>
/// This interface gives components the ability to block certain actions from
/// being done by the owning entity. For effects see <see cref="IEffectBlocker"/>
/// </summary>
public interface IActionBlocker
{
bool CanMove() => true;
bool CanInteract() => true;
bool CanUse() => true;
bool CanThrow() => true;
bool CanSpeak() => true;
bool CanDrop() => true;
bool CanPickup() => true;
bool CanEmote() => true;
bool CanAttack() => true;
bool CanEquip() => true;
bool CanUnequip() => true;
bool CanChangeDirection() => true;
bool CanShiver() => true;
bool CanSweat() => true;
}
}

View File

@@ -1,195 +0,0 @@
using Robust.Shared.GameObjects.Systems;
using Robust.Shared.Interfaces.GameObjects;
namespace Content.Shared.GameObjects.EntitySystems
{
/// <summary>
/// This interface gives components the ability to block certain actions from
/// being done by the owning entity. For effects see <see cref="IEffectBlocker"/>
/// </summary>
public interface IActionBlocker
{
bool CanMove() => true;
bool CanInteract() => true;
bool CanUse() => true;
bool CanThrow() => true;
bool CanSpeak() => true;
bool CanDrop() => true;
bool CanPickup() => true;
bool CanEmote() => true;
bool CanAttack() => true;
bool CanEquip() => true;
bool CanUnequip() => true;
bool CanChangeDirection() => true;
bool CanShiver() => true;
bool CanSweat() => true;
}
/// <summary>
/// Utility methods to check if a specific entity is allowed to perform an action.
/// For effects see <see cref="EffectBlockerSystem"/>
/// </summary>
public class ActionBlockerSystem : EntitySystem
{
public static bool CanMove(IEntity entity)
{
bool canmove = true;
foreach (var actionblockercomponents in entity.GetAllComponents<IActionBlocker>())
{
canmove &= actionblockercomponents.CanMove(); // Sets var to false if false
}
return canmove;
}
public static bool CanInteract(IEntity entity)
{
bool caninteract = true;
foreach (var actionblockercomponents in entity.GetAllComponents<IActionBlocker>())
{
caninteract &= actionblockercomponents.CanInteract();
}
return caninteract;
}
public static bool CanUse(IEntity entity)
{
bool canuse = true;
foreach (var actionblockercomponents in entity.GetAllComponents<IActionBlocker>())
{
canuse &= actionblockercomponents.CanUse();
}
return canuse;
}
public static bool CanThrow(IEntity entity)
{
bool canthrow = true;
foreach (var actionblockercomponents in entity.GetAllComponents<IActionBlocker>())
{
canthrow &= actionblockercomponents.CanThrow();
}
return canthrow;
}
public static bool CanSpeak(IEntity entity)
{
bool canspeak = true;
foreach (var actionblockercomponents in entity.GetAllComponents<IActionBlocker>())
{
canspeak &= actionblockercomponents.CanSpeak();
}
return canspeak;
}
public static bool CanDrop(IEntity entity)
{
bool candrop = true;
foreach (var actionblockercomponents in entity.GetAllComponents<IActionBlocker>())
{
candrop &= actionblockercomponents.CanDrop();
}
return candrop;
}
public static bool CanPickup(IEntity entity)
{
bool canpickup = true;
foreach (var actionblockercomponents in entity.GetAllComponents<IActionBlocker>())
{
canpickup &= actionblockercomponents.CanPickup();
}
return canpickup;
}
public static bool CanEmote(IEntity entity)
{
bool canemote = true;
foreach (var actionblockercomponents in entity.GetAllComponents<IActionBlocker>())
{
canemote &= actionblockercomponents.CanEmote();
}
return canemote;
}
public static bool CanAttack(IEntity entity)
{
bool canattack = true;
foreach (var actionblockercomponents in entity.GetAllComponents<IActionBlocker>())
{
canattack &= actionblockercomponents.CanAttack();
}
return canattack;
}
public static bool CanEquip(IEntity entity)
{
bool canequip = true;
foreach (var actionblockercomponents in entity.GetAllComponents<IActionBlocker>())
{
canequip &= actionblockercomponents.CanEquip();
}
return canequip;
}
public static bool CanUnequip(IEntity entity)
{
bool canunequip = true;
foreach (var actionblockercomponents in entity.GetAllComponents<IActionBlocker>())
{
canunequip &= actionblockercomponents.CanUnequip();
}
return canunequip;
}
public static bool CanChangeDirection(IEntity entity)
{
bool canchangedirection = true;
foreach (var actionblockercomponents in entity.GetAllComponents<IActionBlocker>())
{
canchangedirection &= actionblockercomponents.CanChangeDirection();
}
return canchangedirection;
}
public static bool CanShiver(IEntity entity)
{
var canShiver = true;
foreach (var component in entity.GetAllComponents<IActionBlocker>())
{
canShiver &= component.CanShiver();
}
return canShiver;
}
public static bool CanSweat(IEntity entity)
{
var canSweat = true;
foreach (var component in entity.GetAllComponents<IActionBlocker>())
{
canSweat &= component.CanSweat();
}
return canSweat;
}
}
}

View File

@@ -1,4 +1,5 @@
using Robust.Shared.GameObjects.Systems;
using Content.Shared.GameObjects.EntitySystems.ActionBlocker;
using Robust.Shared.GameObjects.Systems;
using Robust.Shared.Interfaces.GameObjects;
namespace Content.Shared.GameObjects.EntitySystems

View File

@@ -2,6 +2,7 @@
using System.Diagnostics.CodeAnalysis;
using Content.Shared.GameObjects.Components.Items;
using Content.Shared.GameObjects.Components.Movement;
using Content.Shared.GameObjects.EntitySystems.ActionBlocker;
using Content.Shared.Physics;
using Content.Shared.Physics.Pull;
using Robust.Shared.Configuration;