Fix 3000 errors
This commit is contained in:
@@ -13,6 +13,8 @@ namespace Content.Server.AI.Commands
|
||||
[AdminCommand(AdminFlags.Fun)]
|
||||
public class AddAiCommand : IConsoleCommand
|
||||
{
|
||||
[Dependency] private readonly IEntityManager _entities = default!;
|
||||
|
||||
public string Command => "addai";
|
||||
public string Description => "Add an ai component with a given processor to an entity.";
|
||||
public string Help => "Usage: addai <entityId> <behaviorSet1> <behaviorSet2>..."
|
||||
@@ -29,25 +31,25 @@ namespace Content.Server.AI.Commands
|
||||
|
||||
var entId = new EntityUid(int.Parse(args[0]));
|
||||
|
||||
if (!IoCManager.Resolve<IEntityManager>().TryGetEntity(entId, out var ent))
|
||||
if (!_entities.EntityExists(entId))
|
||||
{
|
||||
shell.WriteLine($"Unable to find entity with uid {entId}");
|
||||
return;
|
||||
}
|
||||
|
||||
if (IoCManager.Resolve<IEntityManager>().HasComponent<AiControllerComponent>(ent))
|
||||
if (_entities.HasComponent<AiControllerComponent>(entId))
|
||||
{
|
||||
shell.WriteLine("Entity already has an AI component.");
|
||||
return;
|
||||
}
|
||||
|
||||
// TODO: IMover refffaaccctttooorrr
|
||||
if (IoCManager.Resolve<IEntityManager>().HasComponent<IMoverComponent>(ent))
|
||||
if (_entities.HasComponent<IMoverComponent>(entId))
|
||||
{
|
||||
IoCManager.Resolve<IEntityManager>().RemoveComponent<IMoverComponent>(ent);
|
||||
_entities.RemoveComponent<IMoverComponent>(entId);
|
||||
}
|
||||
|
||||
var comp = IoCManager.Resolve<IEntityManager>().AddComponent<UtilityAi>(ent);
|
||||
var comp = _entities.AddComponent<UtilityAi>(entId);
|
||||
var behaviorManager = IoCManager.Resolve<INpcBehaviorManager>();
|
||||
|
||||
for (var i = 1; i < args.Length; i++)
|
||||
|
||||
@@ -54,12 +54,12 @@ namespace Content.Server.AI.EntitySystems
|
||||
|
||||
public Faction GetHostileFactions(Faction faction) => _hostileFactions.TryGetValue(faction, out var hostiles) ? hostiles : Faction.None;
|
||||
|
||||
public Faction GetFactions(IEntity entity) =>
|
||||
public Faction GetFactions(EntityUid entity) =>
|
||||
IoCManager.Resolve<IEntityManager>().TryGetComponent(entity, out AiFactionTagComponent? factionTags)
|
||||
? factionTags.Factions
|
||||
: Faction.None;
|
||||
|
||||
public IEnumerable<IEntity> GetNearbyHostiles(IEntity entity, float range)
|
||||
public IEnumerable<EntityUid> GetNearbyHostiles(EntityUid entity, float range)
|
||||
{
|
||||
var ourFaction = GetFactions(entity);
|
||||
var hostile = GetHostileFactions(ourFaction);
|
||||
|
||||
@@ -12,10 +12,10 @@ namespace Content.Server.AI.Operators.Combat.Melee
|
||||
private readonly float _burstTime;
|
||||
private float _elapsedTime;
|
||||
|
||||
private readonly IEntity _owner;
|
||||
private readonly IEntity _target;
|
||||
private readonly EntityUid _owner;
|
||||
private readonly EntityUid _target;
|
||||
|
||||
public SwingMeleeWeaponOperator(IEntity owner, IEntity target, float burstTime = 1.0f)
|
||||
public SwingMeleeWeaponOperator(EntityUid owner, EntityUid target, float burstTime = 1.0f)
|
||||
{
|
||||
_owner = owner;
|
||||
_target = target;
|
||||
|
||||
@@ -11,11 +11,11 @@ namespace Content.Server.AI.Operators.Combat.Melee
|
||||
private readonly float _burstTime;
|
||||
private float _elapsedTime;
|
||||
|
||||
private readonly IEntity _owner;
|
||||
private readonly IEntity _target;
|
||||
private readonly EntityUid _owner;
|
||||
private readonly EntityUid _target;
|
||||
private UnarmedCombatComponent? _unarmedCombat;
|
||||
|
||||
public UnarmedCombatOperator(IEntity owner, IEntity target, float burstTime = 1.0f)
|
||||
public UnarmedCombatOperator(EntityUid owner, EntityUid target, float burstTime = 1.0f)
|
||||
{
|
||||
_owner = owner;
|
||||
_target = target;
|
||||
|
||||
@@ -14,10 +14,10 @@ namespace Content.Server.AI.Operators.Inventory
|
||||
/// </summary>
|
||||
public sealed class CloseLastStorageOperator : AiOperator
|
||||
{
|
||||
private readonly IEntity _owner;
|
||||
private IEntity? _target;
|
||||
private readonly EntityUid _owner;
|
||||
private EntityUid _target;
|
||||
|
||||
public CloseLastStorageOperator(IEntity owner)
|
||||
public CloseLastStorageOperator(EntityUid owner)
|
||||
{
|
||||
_owner = owner;
|
||||
}
|
||||
@@ -38,7 +38,7 @@ namespace Content.Server.AI.Operators.Inventory
|
||||
|
||||
_target = blackboard.GetState<LastOpenedStorageState>().GetValue();
|
||||
|
||||
return _target != null;
|
||||
return _target != default;
|
||||
}
|
||||
|
||||
public override bool Shutdown(Outcome outcome)
|
||||
@@ -48,13 +48,13 @@ namespace Content.Server.AI.Operators.Inventory
|
||||
|
||||
var blackboard = UtilityAiHelpers.GetBlackboard(_owner);
|
||||
|
||||
blackboard?.GetState<LastOpenedStorageState>().SetValue(null);
|
||||
blackboard?.GetState<LastOpenedStorageState>().SetValue(default);
|
||||
return true;
|
||||
}
|
||||
|
||||
public override Outcome Execute(float frameTime)
|
||||
{
|
||||
if (_target == null || !_owner.InRangeUnobstructed(_target, popup: true))
|
||||
if (_target == default || !_owner.InRangeUnobstructed(_target, popup: true))
|
||||
{
|
||||
return Outcome.Failed;
|
||||
}
|
||||
|
||||
@@ -6,9 +6,9 @@ namespace Content.Server.AI.Operators.Inventory
|
||||
{
|
||||
public class DropEntityOperator : AiOperator
|
||||
{
|
||||
private readonly IEntity _owner;
|
||||
private readonly IEntity _entity;
|
||||
public DropEntityOperator(IEntity owner, IEntity entity)
|
||||
private readonly EntityUid _owner;
|
||||
private readonly EntityUid _entity;
|
||||
public DropEntityOperator(EntityUid owner, EntityUid entity)
|
||||
{
|
||||
_owner = owner;
|
||||
_entity = entity;
|
||||
|
||||
@@ -6,9 +6,9 @@ namespace Content.Server.AI.Operators.Inventory
|
||||
{
|
||||
public class DropHandItemsOperator : AiOperator
|
||||
{
|
||||
private readonly IEntity _owner;
|
||||
private readonly EntityUid _owner;
|
||||
|
||||
public DropHandItemsOperator(IEntity owner)
|
||||
public DropHandItemsOperator(EntityUid owner)
|
||||
{
|
||||
_owner = owner;
|
||||
}
|
||||
|
||||
@@ -6,9 +6,9 @@ namespace Content.Server.AI.Operators.Inventory
|
||||
{
|
||||
public sealed class EquipEntityOperator : AiOperator
|
||||
{
|
||||
private readonly IEntity _owner;
|
||||
private readonly IEntity _entity;
|
||||
public EquipEntityOperator(IEntity owner, IEntity entity)
|
||||
private readonly EntityUid _owner;
|
||||
private readonly EntityUid _entity;
|
||||
public EquipEntityOperator(EntityUid owner, EntityUid entity)
|
||||
{
|
||||
_owner = owner;
|
||||
_entity = entity;
|
||||
|
||||
@@ -11,10 +11,10 @@ namespace Content.Server.AI.Operators.Inventory
|
||||
/// </summary>
|
||||
public class InteractWithEntityOperator : AiOperator
|
||||
{
|
||||
private readonly IEntity _owner;
|
||||
private readonly IEntity _useTarget;
|
||||
private readonly EntityUid _owner;
|
||||
private readonly EntityUid _useTarget;
|
||||
|
||||
public InteractWithEntityOperator(IEntity owner, IEntity useTarget)
|
||||
public InteractWithEntityOperator(EntityUid owner, EntityUid useTarget)
|
||||
{
|
||||
_owner = owner;
|
||||
_useTarget = useTarget;
|
||||
|
||||
@@ -14,10 +14,10 @@ namespace Content.Server.AI.Operators.Inventory
|
||||
/// </summary>
|
||||
public sealed class OpenStorageOperator : AiOperator
|
||||
{
|
||||
private readonly IEntity _owner;
|
||||
private readonly IEntity _target;
|
||||
private readonly EntityUid _owner;
|
||||
private readonly EntityUid _target;
|
||||
|
||||
public OpenStorageOperator(IEntity owner, IEntity target)
|
||||
public OpenStorageOperator(EntityUid owner, EntityUid target)
|
||||
{
|
||||
_owner = owner;
|
||||
_target = target;
|
||||
|
||||
@@ -11,10 +11,10 @@ namespace Content.Server.AI.Operators.Inventory
|
||||
public class PickupEntityOperator : AiOperator
|
||||
{
|
||||
// Input variables
|
||||
private readonly IEntity _owner;
|
||||
private readonly IEntity _target;
|
||||
private readonly EntityUid _owner;
|
||||
private readonly EntityUid _target;
|
||||
|
||||
public PickupEntityOperator(IEntity owner, IEntity target)
|
||||
public PickupEntityOperator(EntityUid owner, EntityUid target)
|
||||
{
|
||||
_owner = owner;
|
||||
_target = target;
|
||||
|
||||
@@ -10,10 +10,10 @@ namespace Content.Server.AI.Operators.Inventory
|
||||
/// </summary>
|
||||
public class UseItemInInventoryOperator : AiOperator
|
||||
{
|
||||
private readonly IEntity _owner;
|
||||
private readonly IEntity _target;
|
||||
private readonly EntityUid _owner;
|
||||
private readonly EntityUid _target;
|
||||
|
||||
public UseItemInInventoryOperator(IEntity owner, IEntity target)
|
||||
public UseItemInInventoryOperator(EntityUid owner, EntityUid target)
|
||||
{
|
||||
_owner = owner;
|
||||
_target = target;
|
||||
|
||||
@@ -8,9 +8,9 @@ namespace Content.Server.AI.Operators.Movement
|
||||
public sealed class MoveToEntityOperator : AiOperator
|
||||
{
|
||||
// TODO: This and steering need to support InRangeUnobstructed now
|
||||
private readonly IEntity _owner;
|
||||
private readonly EntityUid _owner;
|
||||
private EntityTargetSteeringRequest? _request;
|
||||
private readonly IEntity _target;
|
||||
private readonly EntityUid _target;
|
||||
// For now we'll just get as close as we can because we're not doing LOS checks to be able to pick up at the max interaction range
|
||||
public float ArrivalDistance { get; }
|
||||
public float PathfindingProximity { get; }
|
||||
@@ -18,8 +18,8 @@ namespace Content.Server.AI.Operators.Movement
|
||||
private readonly bool _requiresInRangeUnobstructed;
|
||||
|
||||
public MoveToEntityOperator(
|
||||
IEntity owner,
|
||||
IEntity target,
|
||||
EntityUid owner,
|
||||
EntityUid target,
|
||||
float arrivalDistance = 1.0f,
|
||||
float pathfindingProximity = 1.5f,
|
||||
bool requiresInRangeUnobstructed = false)
|
||||
|
||||
@@ -8,12 +8,12 @@ namespace Content.Server.AI.Operators.Movement
|
||||
{
|
||||
public sealed class MoveToGridOperator : AiOperator
|
||||
{
|
||||
private readonly IEntity _owner;
|
||||
private readonly EntityUid _owner;
|
||||
private GridTargetSteeringRequest? _request;
|
||||
private readonly EntityCoordinates _target;
|
||||
public float DesiredRange { get; set; }
|
||||
|
||||
public MoveToGridOperator(IEntity owner, EntityCoordinates target, float desiredRange = 1.5f)
|
||||
public MoveToGridOperator(EntityUid owner, EntityCoordinates target, float desiredRange = 1.5f)
|
||||
{
|
||||
_owner = owner;
|
||||
_target = target;
|
||||
|
||||
@@ -11,11 +11,11 @@ namespace Content.Server.AI.Operators.Nutrition
|
||||
{
|
||||
public class UseDrinkInInventoryOperator : AiOperator
|
||||
{
|
||||
private readonly IEntity _owner;
|
||||
private readonly IEntity _target;
|
||||
private readonly EntityUid _owner;
|
||||
private readonly EntityUid _target;
|
||||
private float _interactionCooldown;
|
||||
|
||||
public UseDrinkInInventoryOperator(IEntity owner, IEntity target)
|
||||
public UseDrinkInInventoryOperator(EntityUid owner, EntityUid target)
|
||||
{
|
||||
_owner = owner;
|
||||
_target = target;
|
||||
@@ -29,10 +29,12 @@ namespace Content.Server.AI.Operators.Nutrition
|
||||
return Outcome.Continuing;
|
||||
}
|
||||
|
||||
var entities = IoCManager.Resolve<IEntityManager>();
|
||||
|
||||
// TODO: Also have this check storage a la backpack etc.
|
||||
if ((!IoCManager.Resolve<IEntityManager>().EntityExists(_target) ? EntityLifeStage.Deleted : IoCManager.Resolve<IEntityManager>().GetComponent<MetaDataComponent>(_target).EntityLifeStage) >= EntityLifeStage.Deleted ||
|
||||
!IoCManager.Resolve<IEntityManager>().TryGetComponent(_owner, out HandsComponent? handsComponent) ||
|
||||
!IoCManager.Resolve<IEntityManager>().TryGetComponent(_target, out ItemComponent? itemComponent))
|
||||
if ((!entities.EntityExists(_target) ? EntityLifeStage.Deleted : entities.GetComponent<MetaDataComponent>(_target).EntityLifeStage) >= EntityLifeStage.Deleted ||
|
||||
!entities.TryGetComponent(_owner, out HandsComponent? handsComponent) ||
|
||||
!entities.TryGetComponent(_target, out ItemComponent? itemComponent))
|
||||
{
|
||||
return Outcome.Failed;
|
||||
}
|
||||
@@ -43,7 +45,7 @@ namespace Content.Server.AI.Operators.Nutrition
|
||||
{
|
||||
if (handsComponent.GetItem(slot) != itemComponent) continue;
|
||||
handsComponent.ActiveHand = slot;
|
||||
if (!IoCManager.Resolve<IEntityManager>().TryGetComponent(_target, out drinkComponent))
|
||||
if (!entities.TryGetComponent(_target, out drinkComponent))
|
||||
{
|
||||
return Outcome.Failed;
|
||||
}
|
||||
@@ -59,7 +61,7 @@ namespace Content.Server.AI.Operators.Nutrition
|
||||
}
|
||||
|
||||
if (drinkComponent.Deleted || EntitySystem.Get<DrinkSystem>().IsEmpty(drinkComponent.Owner, drinkComponent)
|
||||
|| IoCManager.Resolve<IEntityManager>().TryGetComponent(_owner, out ThirstComponent? thirstComponent) &&
|
||||
|| entities.TryGetComponent(_owner, out ThirstComponent? thirstComponent) &&
|
||||
thirstComponent.CurrentThirst >= thirstComponent.ThirstThresholds[ThirstThreshold.Okay])
|
||||
{
|
||||
return Outcome.Success;
|
||||
|
||||
@@ -10,11 +10,11 @@ namespace Content.Server.AI.Operators.Nutrition
|
||||
{
|
||||
public class UseFoodInInventoryOperator : AiOperator
|
||||
{
|
||||
private readonly IEntity _owner;
|
||||
private readonly IEntity _target;
|
||||
private readonly EntityUid _owner;
|
||||
private readonly EntityUid _target;
|
||||
private float _interactionCooldown;
|
||||
|
||||
public UseFoodInInventoryOperator(IEntity owner, IEntity target)
|
||||
public UseFoodInInventoryOperator(EntityUid owner, EntityUid target)
|
||||
{
|
||||
_owner = owner;
|
||||
_target = target;
|
||||
@@ -28,10 +28,12 @@ namespace Content.Server.AI.Operators.Nutrition
|
||||
return Outcome.Continuing;
|
||||
}
|
||||
|
||||
var entities = IoCManager.Resolve<IEntityManager>();
|
||||
|
||||
// TODO: Also have this check storage a la backpack etc.
|
||||
if ((!IoCManager.Resolve<IEntityManager>().EntityExists(_target) ? EntityLifeStage.Deleted : IoCManager.Resolve<IEntityManager>().GetComponent<MetaDataComponent>(_target).EntityLifeStage) >= EntityLifeStage.Deleted ||
|
||||
!IoCManager.Resolve<IEntityManager>().TryGetComponent(_owner, out HandsComponent? handsComponent) ||
|
||||
!IoCManager.Resolve<IEntityManager>().TryGetComponent(_target, out ItemComponent? itemComponent))
|
||||
if ((!entities.EntityExists(_target) ? EntityLifeStage.Deleted : entities.GetComponent<MetaDataComponent>(_target).EntityLifeStage) >= EntityLifeStage.Deleted ||
|
||||
!entities.TryGetComponent(_owner, out HandsComponent? handsComponent) ||
|
||||
!entities.TryGetComponent(_target, out ItemComponent? itemComponent))
|
||||
{
|
||||
return Outcome.Failed;
|
||||
}
|
||||
@@ -42,7 +44,7 @@ namespace Content.Server.AI.Operators.Nutrition
|
||||
{
|
||||
if (handsComponent.GetItem(slot) != itemComponent) continue;
|
||||
handsComponent.ActiveHand = slot;
|
||||
if (!IoCManager.Resolve<IEntityManager>().TryGetComponent(_target, out foodComponent))
|
||||
if (!entities.TryGetComponent(_target, out foodComponent))
|
||||
{
|
||||
return Outcome.Failed;
|
||||
}
|
||||
@@ -57,9 +59,9 @@ namespace Content.Server.AI.Operators.Nutrition
|
||||
return Outcome.Failed;
|
||||
}
|
||||
|
||||
if ((!IoCManager.Resolve<IEntityManager>().EntityExists(_target) ? EntityLifeStage.Deleted : IoCManager.Resolve<IEntityManager>().GetComponent<MetaDataComponent>(_target).EntityLifeStage) >= EntityLifeStage.Deleted ||
|
||||
if ((!entities.EntityExists(_target) ? EntityLifeStage.Deleted : entities.GetComponent<MetaDataComponent>(_target).EntityLifeStage) >= EntityLifeStage.Deleted ||
|
||||
foodComponent.UsesRemaining == 0 ||
|
||||
IoCManager.Resolve<IEntityManager>().TryGetComponent(_owner, out HungerComponent? hungerComponent) &&
|
||||
entities.TryGetComponent(_owner, out HungerComponent? hungerComponent) &&
|
||||
hungerComponent.CurrentHunger >= hungerComponent.HungerThresholds[HungerThreshold.Okay])
|
||||
{
|
||||
return Outcome.Success;
|
||||
|
||||
@@ -7,7 +7,7 @@ namespace Content.Server.AI.Operators.Sequences
|
||||
{
|
||||
public class GoPickupEntitySequence : SequenceOperator
|
||||
{
|
||||
public GoPickupEntitySequence(IEntity owner, IEntity target)
|
||||
public GoPickupEntitySequence(EntityUid owner, EntityUid target)
|
||||
{
|
||||
Sequence = new Queue<AiOperator>(new AiOperator[]
|
||||
{
|
||||
@@ -17,4 +17,4 @@ namespace Content.Server.AI.Operators.Sequences
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Content.Server.Access.Components;
|
||||
using Content.Server.Access.Systems;
|
||||
using Content.Server.AI.Pathfinding.Pathfinders;
|
||||
using Content.Shared.AI;
|
||||
@@ -171,7 +170,7 @@ namespace Content.Server.AI.Pathfinding.Accessible
|
||||
/// <param name="target"></param>
|
||||
/// <param name="range"></param>
|
||||
/// <returns></returns>
|
||||
public bool CanAccess(IEntity entity, IEntity target, float range = 0.0f)
|
||||
public bool CanAccess(EntityUid entity, EntityUid target, float range = 0.0f)
|
||||
{
|
||||
// TODO: Handle this gracefully instead of just failing.
|
||||
if (!IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(target).GridID.IsValid())
|
||||
@@ -208,7 +207,7 @@ namespace Content.Server.AI.Pathfinding.Accessible
|
||||
return CanAccess(entity, targetNode);
|
||||
}
|
||||
|
||||
public bool CanAccess(IEntity entity, PathfindingNode targetNode)
|
||||
public bool CanAccess(EntityUid entity, PathfindingNode targetNode)
|
||||
{
|
||||
if (IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(entity).GridID != targetNode.TileRef.GridIndex)
|
||||
{
|
||||
@@ -423,7 +422,7 @@ namespace Content.Server.AI.Pathfinding.Accessible
|
||||
/// </summary>
|
||||
/// <param name="entity"></param>
|
||||
/// <returns></returns>
|
||||
public PathfindingRegion? GetRegion(IEntity entity)
|
||||
public PathfindingRegion? GetRegion(EntityUid entity)
|
||||
{
|
||||
if (!IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(entity).GridID.IsValid())
|
||||
{
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
using System.Collections.Generic;
|
||||
using Content.Server.Access.Components;
|
||||
using Content.Server.Access.Systems;
|
||||
using Content.Server.AI.Components;
|
||||
using Robust.Shared.GameObjects;
|
||||
@@ -26,7 +25,7 @@ namespace Content.Server.AI.Pathfinding.Accessible
|
||||
/// </summary>
|
||||
/// <param name="entity"></param>
|
||||
/// <returns></returns>
|
||||
public static ReachableArgs GetArgs(IEntity entity)
|
||||
public static ReachableArgs GetArgs(EntityUid entity)
|
||||
{
|
||||
var collisionMask = 0;
|
||||
if (IoCManager.Resolve<IEntityManager>().TryGetComponent(entity, out IPhysBody? physics))
|
||||
|
||||
@@ -23,17 +23,17 @@ namespace Content.Server.AI.Pathfinding
|
||||
/// Whenever there's a change in the collision layers we update the mask as the graph has more reads than writes
|
||||
/// </summary>
|
||||
public int BlockedCollisionMask { get; private set; }
|
||||
private readonly Dictionary<IEntity, int> _blockedCollidables = new(0);
|
||||
private readonly Dictionary<EntityUid, int> _blockedCollidables = new(0);
|
||||
|
||||
public IReadOnlyDictionary<IEntity, int> PhysicsLayers => _physicsLayers;
|
||||
private readonly Dictionary<IEntity, int> _physicsLayers = new(0);
|
||||
public IReadOnlyDictionary<EntityUid, int> PhysicsLayers => _physicsLayers;
|
||||
private readonly Dictionary<EntityUid, int> _physicsLayers = new(0);
|
||||
|
||||
/// <summary>
|
||||
/// The entities on this tile that require access to traverse
|
||||
/// </summary>
|
||||
/// We don't store the ICollection, at least for now, as we'd need to replicate the access code here
|
||||
public IReadOnlyCollection<AccessReader> AccessReaders => _accessReaders.Values;
|
||||
private readonly Dictionary<IEntity, AccessReader> _accessReaders = new(0);
|
||||
private readonly Dictionary<EntityUid, AccessReader> _accessReaders = new(0);
|
||||
|
||||
public PathfindingNode(PathfindingChunk parent, TileRef tileRef)
|
||||
{
|
||||
@@ -42,7 +42,7 @@ namespace Content.Server.AI.Pathfinding
|
||||
GenerateMask();
|
||||
}
|
||||
|
||||
public static bool IsRelevant(IEntity entity, IPhysBody physicsComponent)
|
||||
public static bool IsRelevant(EntityUid entity, IPhysBody physicsComponent)
|
||||
{
|
||||
if (IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(entity).GridID == GridId.Invalid ||
|
||||
(PathfindingSystem.TrackedCollisionLayers & physicsComponent.CollisionLayer) == 0)
|
||||
@@ -258,7 +258,7 @@ namespace Content.Server.AI.Pathfinding
|
||||
/// <param name="entity"></param>
|
||||
/// TODO: These 2 methods currently don't account for a bunch of changes (e.g. airlock unpowered, wrenching, etc.)
|
||||
/// TODO: Could probably optimise this slightly more.
|
||||
public void AddEntity(IEntity entity, IPhysBody physicsComponent)
|
||||
public void AddEntity(EntityUid entity, IPhysBody physicsComponent)
|
||||
{
|
||||
// If we're a door
|
||||
if (IoCManager.Resolve<IEntityManager>().HasComponent<AirlockComponent>(entity) || IoCManager.Resolve<IEntityManager>().HasComponent<ServerDoorComponent>(entity))
|
||||
@@ -294,7 +294,7 @@ namespace Content.Server.AI.Pathfinding
|
||||
/// Will check each category and remove it from the applicable one
|
||||
/// </summary>
|
||||
/// <param name="entity"></param>
|
||||
public void RemoveEntity(IEntity entity)
|
||||
public void RemoveEntity(EntityUid entity)
|
||||
{
|
||||
// There's no guarantee that the entity isn't deleted
|
||||
// 90% of updates are probably entities moving around
|
||||
|
||||
@@ -2,7 +2,6 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using Content.Server.Access;
|
||||
using Content.Server.Access.Components;
|
||||
using Content.Server.Access.Systems;
|
||||
using Content.Server.AI.Pathfinding.Pathfinders;
|
||||
using Content.Server.CPUJob.JobQueues;
|
||||
@@ -46,7 +45,7 @@ namespace Content.Server.AI.Pathfinding
|
||||
private readonly Queue<TileRef> _tileUpdateQueue = new();
|
||||
|
||||
// Need to store previously known entity positions for collidables for when they move
|
||||
private readonly Dictionary<IEntity, PathfindingNode> _lastKnownPositions = new();
|
||||
private readonly Dictionary<EntityUid, PathfindingNode> _lastKnownPositions = new();
|
||||
|
||||
public const int TrackedCollisionLayers = (int)
|
||||
(CollisionGroup.Impassable |
|
||||
@@ -85,15 +84,15 @@ namespace Content.Server.AI.Pathfinding
|
||||
|
||||
foreach (var update in _collidableUpdateQueue)
|
||||
{
|
||||
if (!EntityManager.TryGetEntity(update.Owner, out var entity)) continue;
|
||||
if (!EntityManager.EntityExists(update.Owner)) continue;
|
||||
|
||||
if (update.CanCollide)
|
||||
{
|
||||
HandleEntityAdd(entity);
|
||||
HandleEntityAdd(update.Owner);
|
||||
}
|
||||
else
|
||||
{
|
||||
HandleEntityRemove(entity);
|
||||
HandleEntityRemove(update.Owner);
|
||||
}
|
||||
|
||||
totalUpdates++;
|
||||
@@ -182,7 +181,7 @@ namespace Content.Server.AI.Pathfinding
|
||||
/// </summary>
|
||||
/// <param name="entity"></param>
|
||||
/// <returns></returns>
|
||||
public PathfindingNode GetNode(IEntity entity)
|
||||
public PathfindingNode GetNode(EntityUid entity)
|
||||
{
|
||||
var tile = _mapManager.GetGrid(IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(entity).GridID).GetTileRef(IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(entity).Coordinates);
|
||||
return GetNode(tile);
|
||||
@@ -263,7 +262,7 @@ namespace Content.Server.AI.Pathfinding
|
||||
/// </summary>
|
||||
/// The node will filter it to the correct category (if possible)
|
||||
/// <param name="entity"></param>
|
||||
private void HandleEntityAdd(IEntity entity)
|
||||
private void HandleEntityAdd(EntityUid entity)
|
||||
{
|
||||
if ((!IoCManager.Resolve<IEntityManager>().EntityExists(entity) ? EntityLifeStage.Deleted : IoCManager.Resolve<IEntityManager>().GetComponent<MetaDataComponent>(entity).EntityLifeStage) >= EntityLifeStage.Deleted ||
|
||||
_lastKnownPositions.ContainsKey(entity) ||
|
||||
@@ -282,7 +281,7 @@ namespace Content.Server.AI.Pathfinding
|
||||
_lastKnownPositions.Add(entity, node);
|
||||
}
|
||||
|
||||
private void HandleEntityRemove(IEntity entity)
|
||||
private void HandleEntityRemove(EntityUid entity)
|
||||
{
|
||||
if (!_lastKnownPositions.TryGetValue(entity, out var node))
|
||||
{
|
||||
@@ -361,7 +360,7 @@ namespace Content.Server.AI.Pathfinding
|
||||
// TODO: Need to rethink the pathfinder utils (traversable etc.). Maybe just chuck them all in PathfindingSystem
|
||||
// Otherwise you get the steerer using this and the pathfinders using a different traversable.
|
||||
// Also look at increasing tile cost the more physics entities are on it
|
||||
public bool CanTraverse(IEntity entity, EntityCoordinates coordinates)
|
||||
public bool CanTraverse(EntityUid entity, EntityCoordinates coordinates)
|
||||
{
|
||||
var gridId = coordinates.GetGridId(EntityManager);
|
||||
var tile = _mapManager.GetGrid(gridId).GetTileRef(coordinates);
|
||||
@@ -369,7 +368,7 @@ namespace Content.Server.AI.Pathfinding
|
||||
return CanTraverse(entity, node);
|
||||
}
|
||||
|
||||
public bool CanTraverse(IEntity entity, PathfindingNode node)
|
||||
public bool CanTraverse(EntityUid entity, PathfindingNode node)
|
||||
{
|
||||
if (IoCManager.Resolve<IEntityManager>().TryGetComponent(entity, out IPhysBody? physics) &&
|
||||
(physics.CollisionMask & node.BlockedCollisionMask) != 0)
|
||||
|
||||
@@ -3,7 +3,6 @@ using System.Collections.Generic;
|
||||
using System.Runtime.ExceptionServices;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Content.Server.Access.Components;
|
||||
using Content.Server.Access.Systems;
|
||||
using Content.Server.AI.Components;
|
||||
using Content.Server.AI.Pathfinding;
|
||||
@@ -11,7 +10,6 @@ using Content.Server.AI.Pathfinding.Pathfinders;
|
||||
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;
|
||||
@@ -47,43 +45,43 @@ namespace Content.Server.AI.Steering
|
||||
/// </summary>
|
||||
private const float InRangeUnobstructedCooldown = 0.25f;
|
||||
|
||||
private Dictionary<IEntity, IAiSteeringRequest> RunningAgents => _agentLists[_listIndex];
|
||||
private Dictionary<EntityUid, IAiSteeringRequest> RunningAgents => _agentLists[_listIndex];
|
||||
|
||||
// We'll cycle the running list every tick as all we're doing is getting a vector2 for the
|
||||
// agent's steering. Should help a lot given this is the most expensive operator by far.
|
||||
// The AI will keep moving, it's just it'll keep moving in its existing direction.
|
||||
// If we change to 20/30 TPS you might want to change this but for now it's fine
|
||||
private readonly List<Dictionary<IEntity, IAiSteeringRequest>> _agentLists = new(AgentListCount);
|
||||
private readonly List<Dictionary<EntityUid, IAiSteeringRequest>> _agentLists = new(AgentListCount);
|
||||
private const int AgentListCount = 2;
|
||||
private int _listIndex;
|
||||
|
||||
// Cache nextGrid
|
||||
private readonly Dictionary<IEntity, EntityCoordinates> _nextGrid = new();
|
||||
private readonly Dictionary<EntityUid, EntityCoordinates> _nextGrid = new();
|
||||
|
||||
/// <summary>
|
||||
/// Current live paths for AI
|
||||
/// </summary>
|
||||
private readonly Dictionary<IEntity, Queue<TileRef>> _paths = new();
|
||||
private readonly Dictionary<EntityUid, Queue<TileRef>> _paths = new();
|
||||
|
||||
/// <summary>
|
||||
/// Pathfinding request jobs we're waiting on
|
||||
/// </summary>
|
||||
private readonly Dictionary<IEntity, (CancellationTokenSource CancelToken, CPUJob.JobQueues.Job<Queue<TileRef>> Job)> _pathfindingRequests =
|
||||
private readonly Dictionary<EntityUid, (CancellationTokenSource CancelToken, CPUJob.JobQueues.Job<Queue<TileRef>> Job)> _pathfindingRequests =
|
||||
new();
|
||||
|
||||
/// <summary>
|
||||
/// Keep track of how long we've been in 1 position and re-path if it's been too long
|
||||
/// </summary>
|
||||
private readonly Dictionary<IEntity, int> _stuckCounter = new();
|
||||
private readonly Dictionary<EntityUid, int> _stuckCounter = new();
|
||||
|
||||
/// <summary>
|
||||
/// Get a fixed position for the target entity; if they move then re-path
|
||||
/// </summary>
|
||||
private readonly Dictionary<IEntity, EntityCoordinates> _entityTargetPosition = new();
|
||||
private readonly Dictionary<EntityUid, EntityCoordinates> _entityTargetPosition = new();
|
||||
|
||||
// Anti-Stuck
|
||||
// Given the collision avoidance can lead to twitching need to store a reference position and check if we've been near this too long
|
||||
private readonly Dictionary<IEntity, EntityCoordinates> _stuckPositions = new();
|
||||
private readonly Dictionary<EntityUid, EntityCoordinates> _stuckPositions = new();
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
@@ -91,7 +89,7 @@ namespace Content.Server.AI.Steering
|
||||
|
||||
for (var i = 0; i < AgentListCount; i++)
|
||||
{
|
||||
_agentLists.Add(new Dictionary<IEntity, IAiSteeringRequest>());
|
||||
_agentLists.Add(new Dictionary<EntityUid, IAiSteeringRequest>());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -101,7 +99,7 @@ namespace Content.Server.AI.Steering
|
||||
/// We'll add it to the movement list that has the least number of agents
|
||||
/// <param name="entity"></param>
|
||||
/// <param name="steeringRequest"></param>
|
||||
public void Register(IEntity entity, IAiSteeringRequest steeringRequest)
|
||||
public void Register(EntityUid entity, IAiSteeringRequest steeringRequest)
|
||||
{
|
||||
var lowestListCount = 1000;
|
||||
var lowestListIndex = 0;
|
||||
@@ -127,9 +125,9 @@ namespace Content.Server.AI.Steering
|
||||
/// </summary>
|
||||
/// <param name="entity"></param>
|
||||
/// <exception cref="InvalidOperationException"></exception>
|
||||
public void Unregister(IEntity entity)
|
||||
public void Unregister(EntityUid entity)
|
||||
{
|
||||
if (IoCManager.Resolve<IEntityManager>().TryGetComponent(entity, out AiControllerComponent? controller))
|
||||
if (EntityManager.TryGetComponent(entity, out AiControllerComponent? controller))
|
||||
{
|
||||
controller.VelocityDir = Vector2.Zero;
|
||||
}
|
||||
@@ -194,7 +192,7 @@ namespace Content.Server.AI.Steering
|
||||
/// </summary>
|
||||
/// <param name="entity"></param>
|
||||
/// <returns></returns>
|
||||
public bool IsRegistered(IEntity entity)
|
||||
public bool IsRegistered(EntityUid entity)
|
||||
{
|
||||
foreach (var agentList in _agentLists)
|
||||
{
|
||||
@@ -245,26 +243,26 @@ namespace Content.Server.AI.Steering
|
||||
/// <param name="frameTime"></param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="NotImplementedException"></exception>
|
||||
private SteeringStatus Steer(IEntity entity, IAiSteeringRequest steeringRequest, float frameTime)
|
||||
private SteeringStatus Steer(EntityUid entity, IAiSteeringRequest steeringRequest, float frameTime)
|
||||
{
|
||||
// Main optimisation to be done below is the redundant calls and adding more variables
|
||||
if ((!IoCManager.Resolve<IEntityManager>().EntityExists(entity) ? EntityLifeStage.Deleted : IoCManager.Resolve<IEntityManager>().GetComponent<MetaDataComponent>(entity).EntityLifeStage) >= EntityLifeStage.Deleted ||
|
||||
!IoCManager.Resolve<IEntityManager>().TryGetComponent(entity, out AiControllerComponent? controller) ||
|
||||
if ((!EntityManager.EntityExists(entity) ? EntityLifeStage.Deleted : EntityManager.GetComponent<MetaDataComponent>(entity).EntityLifeStage) >= EntityLifeStage.Deleted ||
|
||||
!EntityManager.TryGetComponent(entity, out AiControllerComponent? controller) ||
|
||||
!EntitySystem.Get<ActionBlockerSystem>().CanMove(entity) ||
|
||||
!IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(entity).GridID.IsValid())
|
||||
!EntityManager.GetComponent<TransformComponent>(entity).GridID.IsValid())
|
||||
{
|
||||
return SteeringStatus.NoPath;
|
||||
}
|
||||
|
||||
var entitySteering = steeringRequest as EntityTargetSteeringRequest;
|
||||
|
||||
if (entitySteering != null && (!IoCManager.Resolve<IEntityManager>().EntityExists(entitySteering.Target) ? EntityLifeStage.Deleted : IoCManager.Resolve<IEntityManager>().GetComponent<MetaDataComponent>(entitySteering.Target).EntityLifeStage) >= EntityLifeStage.Deleted)
|
||||
if (entitySteering != null && (!EntityManager.EntityExists(entitySteering.Target) ? EntityLifeStage.Deleted : EntityManager.GetComponent<MetaDataComponent>(entitySteering.Target).EntityLifeStage) >= EntityLifeStage.Deleted)
|
||||
{
|
||||
controller.VelocityDir = Vector2.Zero;
|
||||
return SteeringStatus.NoPath;
|
||||
}
|
||||
|
||||
if (_pauseManager.IsGridPaused(IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(entity).GridID))
|
||||
if (_pauseManager.IsGridPaused(EntityManager.GetComponent<TransformComponent>(entity).GridID))
|
||||
{
|
||||
controller.VelocityDir = Vector2.Zero;
|
||||
return SteeringStatus.Pending;
|
||||
@@ -272,14 +270,14 @@ namespace Content.Server.AI.Steering
|
||||
|
||||
// Validation
|
||||
// Check if we can even arrive -> Currently only samegrid movement supported
|
||||
if (IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(entity).GridID != steeringRequest.TargetGrid.GetGridId(EntityManager))
|
||||
if (EntityManager.GetComponent<TransformComponent>(entity).GridID != steeringRequest.TargetGrid.GetGridId(EntityManager))
|
||||
{
|
||||
controller.VelocityDir = Vector2.Zero;
|
||||
return SteeringStatus.NoPath;
|
||||
}
|
||||
|
||||
// Check if we have arrived
|
||||
var targetDistance = (IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(entity).MapPosition.Position - steeringRequest.TargetMap.Position).Length;
|
||||
var targetDistance = (EntityManager.GetComponent<TransformComponent>(entity).MapPosition.Position - steeringRequest.TargetMap.Position).Length;
|
||||
steeringRequest.TimeUntilInteractionCheck -= frameTime;
|
||||
|
||||
if (targetDistance <= steeringRequest.ArrivalDistance && steeringRequest.TimeUntilInteractionCheck <= 0.0f)
|
||||
@@ -348,7 +346,7 @@ namespace Content.Server.AI.Steering
|
||||
return SteeringStatus.Pending;
|
||||
}
|
||||
|
||||
var ignoredCollision = new List<IEntity>();
|
||||
var ignoredCollision = new List<EntityUid>();
|
||||
// Check if the target entity has moved - If so then re-path
|
||||
// TODO: Patch the path from the target's position back towards us, stopping if it ever intersects the current path
|
||||
// Probably need a separate "PatchPath" job
|
||||
@@ -408,7 +406,7 @@ namespace Content.Server.AI.Steering
|
||||
/// </summary>
|
||||
/// <param name="entity"></param>
|
||||
/// <param name="steeringRequest"></param>
|
||||
private void RequestPath(IEntity entity, IAiSteeringRequest steeringRequest)
|
||||
private void RequestPath(EntityUid entity, IAiSteeringRequest steeringRequest)
|
||||
{
|
||||
if (_pathfindingRequests.ContainsKey(entity))
|
||||
{
|
||||
@@ -416,11 +414,11 @@ namespace Content.Server.AI.Steering
|
||||
}
|
||||
|
||||
var cancelToken = new CancellationTokenSource();
|
||||
var gridManager = _mapManager.GetGrid(IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(entity).GridID);
|
||||
var startTile = gridManager.GetTileRef(IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(entity).Coordinates);
|
||||
var gridManager = _mapManager.GetGrid(EntityManager.GetComponent<TransformComponent>(entity).GridID);
|
||||
var startTile = gridManager.GetTileRef(EntityManager.GetComponent<TransformComponent>(entity).Coordinates);
|
||||
var endTile = gridManager.GetTileRef(steeringRequest.TargetGrid);
|
||||
var collisionMask = 0;
|
||||
if (IoCManager.Resolve<IEntityManager>().TryGetComponent(entity, out IPhysBody? physics))
|
||||
if (EntityManager.TryGetComponent(entity, out IPhysBody? physics))
|
||||
{
|
||||
collisionMask = physics.CollisionMask;
|
||||
}
|
||||
@@ -443,11 +441,11 @@ namespace Content.Server.AI.Steering
|
||||
/// </summary>
|
||||
/// <param name="entity"></param>
|
||||
/// <param name="path"></param>
|
||||
private void UpdatePath(IEntity entity, Queue<TileRef> path)
|
||||
private void UpdatePath(EntityUid entity, Queue<TileRef> path)
|
||||
{
|
||||
_pathfindingRequests.Remove(entity);
|
||||
|
||||
var entityTile = _mapManager.GetGrid(IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(entity).GridID).GetTileRef(IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(entity).Coordinates);
|
||||
var entityTile = _mapManager.GetGrid(EntityManager.GetComponent<TransformComponent>(entity).GridID).GetTileRef(EntityManager.GetComponent<TransformComponent>(entity).Coordinates);
|
||||
var tile = path.Dequeue();
|
||||
var closestDistance = PathfindingHelpers.OctileDistance(entityTile, tile);
|
||||
|
||||
@@ -474,7 +472,7 @@ namespace Content.Server.AI.Steering
|
||||
/// <param name="entity"></param>
|
||||
/// <param name="steeringRequest"></param>
|
||||
/// <returns></returns>
|
||||
private EntityCoordinates? NextGrid(IEntity entity, IAiSteeringRequest steeringRequest)
|
||||
private EntityCoordinates? NextGrid(EntityUid entity, IAiSteeringRequest steeringRequest)
|
||||
{
|
||||
// Remove the cached grid
|
||||
if (!_paths.ContainsKey(entity) && _nextGrid.ContainsKey(entity))
|
||||
@@ -485,7 +483,7 @@ namespace Content.Server.AI.Steering
|
||||
// If no tiles left just move towards the target (if we're close)
|
||||
if (!_paths.ContainsKey(entity) || _paths[entity].Count == 0)
|
||||
{
|
||||
if ((steeringRequest.TargetGrid.Position - IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(entity).Coordinates.Position).Length <= 2.0f)
|
||||
if ((steeringRequest.TargetGrid.Position - EntityManager.GetComponent<TransformComponent>(entity).Coordinates.Position).Length <= 2.0f)
|
||||
{
|
||||
return steeringRequest.TargetGrid;
|
||||
}
|
||||
@@ -495,7 +493,7 @@ namespace Content.Server.AI.Steering
|
||||
}
|
||||
|
||||
if (!_nextGrid.TryGetValue(entity, out var nextGrid) ||
|
||||
(nextGrid.Position - IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(entity).Coordinates.Position).Length <= TileTolerance)
|
||||
(nextGrid.Position - EntityManager.GetComponent<TransformComponent>(entity).Coordinates.Position).Length <= TileTolerance)
|
||||
{
|
||||
UpdateGridCache(entity);
|
||||
nextGrid = _nextGrid[entity];
|
||||
@@ -510,11 +508,11 @@ namespace Content.Server.AI.Steering
|
||||
/// </summary>
|
||||
/// <param name="entity"></param>
|
||||
/// <param name="dequeue"></param>
|
||||
private void UpdateGridCache(IEntity entity, bool dequeue = true)
|
||||
private void UpdateGridCache(EntityUid entity, bool dequeue = true)
|
||||
{
|
||||
if (_paths[entity].Count == 0) return;
|
||||
var nextTile = dequeue ? _paths[entity].Dequeue() : _paths[entity].Peek();
|
||||
var nextGrid = _mapManager.GetGrid(IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(entity).GridID).GridTileToLocal(nextTile.GridIndices);
|
||||
var nextGrid = _mapManager.GetGrid(EntityManager.GetComponent<TransformComponent>(entity).GridID).GridTileToLocal(nextTile.GridIndices);
|
||||
_nextGrid[entity] = nextGrid;
|
||||
}
|
||||
|
||||
@@ -522,16 +520,16 @@ namespace Content.Server.AI.Steering
|
||||
/// Check if we've been near our last EntityCoordinates too long and try to fix it
|
||||
/// </summary>
|
||||
/// <param name="entity"></param>
|
||||
private void HandleStuck(IEntity entity)
|
||||
private void HandleStuck(EntityUid entity)
|
||||
{
|
||||
if (!_stuckPositions.TryGetValue(entity, out var stuckPosition))
|
||||
{
|
||||
_stuckPositions[entity] = IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(entity).Coordinates;
|
||||
_stuckPositions[entity] = EntityManager.GetComponent<TransformComponent>(entity).Coordinates;
|
||||
_stuckCounter[entity] = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
if ((IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(entity).Coordinates.Position - stuckPosition.Position).Length <= 1.0f)
|
||||
if ((EntityManager.GetComponent<TransformComponent>(entity).Coordinates.Position - stuckPosition.Position).Length <= 1.0f)
|
||||
{
|
||||
_stuckCounter.TryGetValue(entity, out var stuckCount);
|
||||
_stuckCounter[entity] = stuckCount + 1;
|
||||
@@ -539,7 +537,7 @@ namespace Content.Server.AI.Steering
|
||||
else
|
||||
{
|
||||
// No longer stuck
|
||||
_stuckPositions[entity] = IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(entity).Coordinates;
|
||||
_stuckPositions[entity] = EntityManager.GetComponent<TransformComponent>(entity).Coordinates;
|
||||
_stuckCounter[entity] = 0;
|
||||
return;
|
||||
}
|
||||
@@ -562,10 +560,10 @@ namespace Content.Server.AI.Steering
|
||||
/// <param name="entity"></param>
|
||||
/// <param name="grid"></param>
|
||||
/// <returns></returns>
|
||||
private Vector2 Seek(IEntity entity, EntityCoordinates grid)
|
||||
private Vector2 Seek(EntityUid entity, EntityCoordinates grid)
|
||||
{
|
||||
// is-even much
|
||||
var entityPos = IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(entity).Coordinates;
|
||||
var entityPos = EntityManager.GetComponent<TransformComponent>(entity).Coordinates;
|
||||
return entityPos == grid
|
||||
? Vector2.Zero
|
||||
: (grid.Position - entityPos.Position).Normalized;
|
||||
@@ -578,9 +576,9 @@ namespace Content.Server.AI.Steering
|
||||
/// <param name="grid"></param>
|
||||
/// <param name="slowingDistance"></param>
|
||||
/// <returns></returns>
|
||||
private Vector2 Arrival(IEntity entity, EntityCoordinates grid, float slowingDistance = 1.0f)
|
||||
private Vector2 Arrival(EntityUid entity, EntityCoordinates grid, float slowingDistance = 1.0f)
|
||||
{
|
||||
var entityPos = IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(entity).Coordinates;
|
||||
var entityPos = EntityManager.GetComponent<TransformComponent>(entity).Coordinates;
|
||||
DebugTools.Assert(slowingDistance > 0.0f);
|
||||
if (entityPos == grid)
|
||||
{
|
||||
@@ -597,16 +595,16 @@ namespace Content.Server.AI.Steering
|
||||
/// <param name="entity"></param>
|
||||
/// <param name="target"></param>
|
||||
/// <returns></returns>
|
||||
private Vector2 Pursuit(IEntity entity, IEntity target)
|
||||
private Vector2 Pursuit(EntityUid entity, EntityUid target)
|
||||
{
|
||||
var entityPos = IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(entity).Coordinates;
|
||||
var targetPos = IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(target).Coordinates;
|
||||
var entityPos = EntityManager.GetComponent<TransformComponent>(entity).Coordinates;
|
||||
var targetPos = EntityManager.GetComponent<TransformComponent>(target).Coordinates;
|
||||
if (entityPos == targetPos)
|
||||
{
|
||||
return Vector2.Zero;
|
||||
}
|
||||
|
||||
if (IoCManager.Resolve<IEntityManager>().TryGetComponent(target, out IPhysBody? physics))
|
||||
if (EntityManager.TryGetComponent(target, out IPhysBody? physics))
|
||||
{
|
||||
var targetDistance = (targetPos.Position - entityPos.Position);
|
||||
targetPos = targetPos.Offset(physics.LinearVelocity * targetDistance);
|
||||
@@ -622,9 +620,9 @@ namespace Content.Server.AI.Steering
|
||||
/// <param name="direction">entity's travel direction</param>
|
||||
/// <param name="ignoredTargets"></param>
|
||||
/// <returns></returns>
|
||||
private Vector2 CollisionAvoidance(IEntity entity, Vector2 direction, ICollection<IEntity> ignoredTargets)
|
||||
private Vector2 CollisionAvoidance(EntityUid entity, Vector2 direction, ICollection<EntityUid> ignoredTargets)
|
||||
{
|
||||
if (direction == Vector2.Zero || !IoCManager.Resolve<IEntityManager>().TryGetComponent(entity, out IPhysBody? physics))
|
||||
if (direction == Vector2.Zero || !EntityManager.TryGetComponent(entity, out IPhysBody? physics))
|
||||
{
|
||||
return Vector2.Zero;
|
||||
}
|
||||
@@ -636,8 +634,8 @@ namespace Content.Server.AI.Steering
|
||||
var avoidanceVector = Vector2.Zero;
|
||||
var checkTiles = new HashSet<TileRef>();
|
||||
var avoidTiles = new HashSet<TileRef>();
|
||||
var entityGridCoords = IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(entity).Coordinates;
|
||||
var grid = _mapManager.GetGrid(IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(entity).GridID);
|
||||
var entityGridCoords = EntityManager.GetComponent<TransformComponent>(entity).Coordinates;
|
||||
var grid = _mapManager.GetGrid(EntityManager.GetComponent<TransformComponent>(entity).GridID);
|
||||
var currentTile = grid.GetTileRef(entityGridCoords);
|
||||
var halfwayTile = grid.GetTileRef(entityGridCoords.Offset(direction / 2));
|
||||
var nextTile = grid.GetTileRef(entityGridCoords.Offset(direction));
|
||||
@@ -660,18 +658,18 @@ namespace Content.Server.AI.Steering
|
||||
// err for now we'll just assume the first entity is the center and just add a vector for it
|
||||
|
||||
//Pathfinding updates are deferred so this may not be done yet.
|
||||
if ((!IoCManager.Resolve<IEntityManager>().EntityExists(physicsEntity) ? EntityLifeStage.Deleted : IoCManager.Resolve<IEntityManager>().GetComponent<MetaDataComponent>(physicsEntity).EntityLifeStage) >= EntityLifeStage.Deleted) continue;
|
||||
if ((!EntityManager.EntityExists(physicsEntity) ? EntityLifeStage.Deleted : EntityManager.GetComponent<MetaDataComponent>(physicsEntity).EntityLifeStage) >= EntityLifeStage.Deleted) continue;
|
||||
|
||||
// if we're moving in the same direction then ignore
|
||||
// So if 2 entities are moving towards each other and both detect a collision they'll both move in the same direction
|
||||
// i.e. towards the right
|
||||
if (IoCManager.Resolve<IEntityManager>().TryGetComponent(physicsEntity, out IPhysBody? otherPhysics) &&
|
||||
if (EntityManager.TryGetComponent(physicsEntity, out IPhysBody? otherPhysics) &&
|
||||
Vector2.Dot(otherPhysics.LinearVelocity, direction) > 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var centerGrid = IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(physicsEntity).Coordinates;
|
||||
var centerGrid = EntityManager.GetComponent<TransformComponent>(physicsEntity).Coordinates;
|
||||
// Check how close we are to center of tile and get the inverse; if we're closer this is stronger
|
||||
var additionalVector = (centerGrid.Position - entityGridCoords.Position);
|
||||
var distance = additionalVector.Length;
|
||||
|
||||
@@ -9,8 +9,8 @@ namespace Content.Server.AI.Steering
|
||||
public SteeringStatus Status { get; set; } = SteeringStatus.Pending;
|
||||
public MapCoordinates TargetMap => IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(_target).MapPosition;
|
||||
public EntityCoordinates TargetGrid => IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(_target).Coordinates;
|
||||
public IEntity Target => _target;
|
||||
private readonly IEntity _target;
|
||||
public EntityUid Target => _target;
|
||||
private readonly EntityUid _target;
|
||||
|
||||
/// <inheritdoc />
|
||||
public float ArrivalDistance { get; }
|
||||
@@ -31,7 +31,7 @@ namespace Content.Server.AI.Steering
|
||||
/// </summary>
|
||||
public float TimeUntilInteractionCheck { get; set; }
|
||||
|
||||
public EntityTargetSteeringRequest(IEntity target, float arrivalDistance, float pathfindingProximity = 0.5f, bool requiresInRangeUnobstructed = false)
|
||||
public EntityTargetSteeringRequest(EntityUid target, float arrivalDistance, float pathfindingProximity = 0.5f, bool requiresInRangeUnobstructed = false)
|
||||
{
|
||||
_target = target;
|
||||
ArrivalDistance = arrivalDistance;
|
||||
|
||||
@@ -13,7 +13,7 @@ namespace Content.Server.AI.Utility.Actions.Clothing.Gloves
|
||||
{
|
||||
public sealed class EquipGloves : UtilityAction
|
||||
{
|
||||
public IEntity Target { get; set; } = default!;
|
||||
public EntityUid Target { get; set; } = default!;
|
||||
|
||||
public override void SetupOperators(Blackboard context)
|
||||
{
|
||||
|
||||
@@ -14,7 +14,7 @@ namespace Content.Server.AI.Utility.Actions.Clothing.Gloves
|
||||
{
|
||||
public sealed class PickUpGloves : UtilityAction
|
||||
{
|
||||
public IEntity Target { get; set; } = default!;
|
||||
public EntityUid Target { get; set; } = default!;
|
||||
|
||||
public override void SetupOperators(Blackboard context)
|
||||
{
|
||||
|
||||
@@ -13,7 +13,7 @@ namespace Content.Server.AI.Utility.Actions.Clothing.Head
|
||||
{
|
||||
public sealed class EquipHead : UtilityAction
|
||||
{
|
||||
public IEntity Target { get; set; } = default!;
|
||||
public EntityUid Target { get; set; } = default!;
|
||||
|
||||
public override void SetupOperators(Blackboard context)
|
||||
{
|
||||
|
||||
@@ -14,7 +14,7 @@ namespace Content.Server.AI.Utility.Actions.Clothing.Head
|
||||
{
|
||||
public sealed class PickUpHead : UtilityAction
|
||||
{
|
||||
public IEntity Target { get; set; } = default!;
|
||||
public EntityUid Target { get; set; } = default!;
|
||||
|
||||
public override void SetupOperators(Blackboard context)
|
||||
{
|
||||
|
||||
@@ -13,7 +13,7 @@ namespace Content.Server.AI.Utility.Actions.Clothing.OuterClothing
|
||||
{
|
||||
public sealed class EquipOuterClothing : UtilityAction
|
||||
{
|
||||
public IEntity Target { get; set; } = default!;
|
||||
public EntityUid Target { get; set; } = default!;
|
||||
|
||||
public override void SetupOperators(Blackboard context)
|
||||
{
|
||||
|
||||
@@ -14,7 +14,7 @@ namespace Content.Server.AI.Utility.Actions.Clothing.OuterClothing
|
||||
{
|
||||
public sealed class PickUpOuterClothing : UtilityAction
|
||||
{
|
||||
public IEntity Target { get; set; } = default!;
|
||||
public EntityUid Target { get; set; } = default!;
|
||||
|
||||
public override void SetupOperators(Blackboard context)
|
||||
{
|
||||
|
||||
@@ -13,7 +13,7 @@ namespace Content.Server.AI.Utility.Actions.Clothing.Shoes
|
||||
{
|
||||
public sealed class EquipShoes : UtilityAction
|
||||
{
|
||||
public IEntity Target { get; set; } = default!;
|
||||
public EntityUid Target { get; set; } = default!;
|
||||
|
||||
public override void SetupOperators(Blackboard context)
|
||||
{
|
||||
|
||||
@@ -14,7 +14,7 @@ namespace Content.Server.AI.Utility.Actions.Clothing.Shoes
|
||||
{
|
||||
public sealed class PickUpShoes : UtilityAction
|
||||
{
|
||||
public IEntity Target { get; set; } = default!;
|
||||
public EntityUid Target { get; set; } = default!;
|
||||
|
||||
public override void SetupOperators(Blackboard context)
|
||||
{
|
||||
|
||||
@@ -15,7 +15,7 @@ namespace Content.Server.AI.Utility.Actions.Combat.Melee
|
||||
{
|
||||
public sealed class EquipMelee : UtilityAction
|
||||
{
|
||||
public IEntity Target { get; set; } = default!;
|
||||
public EntityUid Target { get; set; } = default!;
|
||||
|
||||
public override void SetupOperators(Blackboard context)
|
||||
{
|
||||
|
||||
@@ -21,13 +21,13 @@ namespace Content.Server.AI.Utility.Actions.Combat.Melee
|
||||
{
|
||||
public sealed class MeleeWeaponAttackEntity : UtilityAction
|
||||
{
|
||||
public IEntity Target { get; set; } = default!;
|
||||
public EntityUid Target { get; set; } = default!;
|
||||
|
||||
public override void SetupOperators(Blackboard context)
|
||||
{
|
||||
MoveToEntityOperator moveOperator;
|
||||
var equipped = context.GetState<EquippedEntityState>().GetValue();
|
||||
if (equipped != null && IoCManager.Resolve<IEntityManager>().TryGetComponent(equipped, out MeleeWeaponComponent? meleeWeaponComponent))
|
||||
if (equipped != default && IoCManager.Resolve<IEntityManager>().TryGetComponent(equipped, out MeleeWeaponComponent? meleeWeaponComponent))
|
||||
{
|
||||
moveOperator = new MoveToEntityOperator(Owner, Target, meleeWeaponComponent.Range - 0.01f);
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ namespace Content.Server.AI.Utility.Actions.Combat.Melee
|
||||
{
|
||||
public sealed class PickUpMeleeWeapon : UtilityAction
|
||||
{
|
||||
public IEntity Target { get; set; } = default!;
|
||||
public EntityUid Target { get; set; } = default!;
|
||||
|
||||
public override void SetupOperators(Blackboard context)
|
||||
{
|
||||
|
||||
@@ -19,7 +19,7 @@ namespace Content.Server.AI.Utility.Actions.Combat.Melee
|
||||
{
|
||||
public sealed class UnarmedAttackEntity : UtilityAction
|
||||
{
|
||||
public IEntity Target { get; set; } = default!;
|
||||
public EntityUid Target { get; set; } = default!;
|
||||
|
||||
public override void SetupOperators(Blackboard context)
|
||||
{
|
||||
|
||||
@@ -7,7 +7,7 @@ namespace Content.Server.AI.Utility.Actions
|
||||
/// <summary>
|
||||
/// NPC this action is attached to.
|
||||
/// </summary>
|
||||
IEntity Owner { get; set; }
|
||||
EntityUid Owner { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Highest possible score for this action.
|
||||
|
||||
@@ -14,7 +14,7 @@ namespace Content.Server.AI.Utility.Actions.Nutrition.Drink
|
||||
{
|
||||
public sealed class PickUpDrink : UtilityAction
|
||||
{
|
||||
public IEntity Target { get; set; } = default!;
|
||||
public EntityUid Target { get; set; } = default!;
|
||||
|
||||
public override void SetupOperators(Blackboard context)
|
||||
{
|
||||
|
||||
@@ -15,7 +15,7 @@ namespace Content.Server.AI.Utility.Actions.Nutrition.Drink
|
||||
{
|
||||
public sealed class UseDrinkInInventory : UtilityAction
|
||||
{
|
||||
public IEntity Target { get; set; } = default!;
|
||||
public EntityUid Target { get; set; } = default!;
|
||||
|
||||
public override void SetupOperators(Blackboard context)
|
||||
{
|
||||
|
||||
@@ -14,7 +14,7 @@ namespace Content.Server.AI.Utility.Actions.Nutrition.Food
|
||||
{
|
||||
public sealed class PickUpFood : UtilityAction
|
||||
{
|
||||
public IEntity Target { get; set; } = default!;
|
||||
public EntityUid Target { get; set; } = default!;
|
||||
|
||||
public override void SetupOperators(Blackboard context)
|
||||
{
|
||||
|
||||
@@ -15,7 +15,7 @@ namespace Content.Server.AI.Utility.Actions.Nutrition.Food
|
||||
{
|
||||
public sealed class UseFoodInInventory : UtilityAction
|
||||
{
|
||||
public IEntity Target { get; set; } = default!;
|
||||
public EntityUid Target { get; set; } = default!;
|
||||
|
||||
public override void SetupOperators(Blackboard context)
|
||||
{
|
||||
|
||||
@@ -36,7 +36,7 @@ namespace Content.Server.AI.Utility.Actions
|
||||
public const float CombatBonus = 30.0f;
|
||||
public const float DangerBonus = 50.0f;
|
||||
|
||||
public IEntity Owner { get; set; }
|
||||
public EntityUid Owner { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// All the considerations are multiplied together to get the final score; a consideration of 0.0 means the action is not possible.
|
||||
|
||||
@@ -10,13 +10,9 @@ namespace Content.Server.AI.Utility.Considerations.Combat.Melee
|
||||
{
|
||||
protected override float GetScore(Blackboard context)
|
||||
{
|
||||
IEntity tempQualifier = context.GetState<SelfState>().GetValue();
|
||||
if (tempQualifier != null)
|
||||
{
|
||||
IoCManager.Resolve<IEntityManager>().HasComponent<UnarmedCombatComponent>(tempQualifier);
|
||||
}
|
||||
|
||||
return RETURNED_VALUE ?? false ? 1.0f : 0.0f;
|
||||
var entityManager = IoCManager.Resolve<IEntityManager>();
|
||||
var entity = context.GetState<SelfState>().GetValue();
|
||||
return entityManager.HasComponent<UnarmedCombatComponent>(entity) ? 1.0f : 0.0f;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,14 +10,17 @@ namespace Content.Server.AI.Utility.Considerations.Movement
|
||||
protected override float GetScore(Blackboard context)
|
||||
{
|
||||
var self = context.GetState<SelfState>().GetValue();
|
||||
var target = context.GetState<TargetEntityState>().GetValue();
|
||||
if (target == null || (!IoCManager.Resolve<IEntityManager>().EntityExists(target) ? EntityLifeStage.Deleted : IoCManager.Resolve<IEntityManager>().GetComponent<MetaDataComponent>(target).EntityLifeStage) >= EntityLifeStage.Deleted || IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(target).GridID != (self != null ? IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(self) : null).GridID)
|
||||
var entities = IoCManager.Resolve<IEntityManager>();
|
||||
|
||||
if (context.GetState<TargetEntityState>().GetValue() is not {Valid: true} target ||
|
||||
(!entities.EntityExists(target) ? EntityLifeStage.Deleted : entities.GetComponent<MetaDataComponent>(target).EntityLifeStage) >= EntityLifeStage.Deleted ||
|
||||
entities.GetComponent<TransformComponent>(target).GridID != entities.GetComponent<TransformComponent>(self).GridID)
|
||||
{
|
||||
return 0.0f;
|
||||
}
|
||||
|
||||
// Anything further than 100 tiles gets clamped
|
||||
return (IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(target).Coordinates.Position - IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(self).Coordinates.Position).Length / 100;
|
||||
return (entities.GetComponent<TransformComponent>(target).Coordinates.Position - entities.GetComponent<TransformComponent>(self).Coordinates.Position).Length / 100;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ namespace Content.Server.AI.Utility.Considerations.State
|
||||
return 0;
|
||||
}
|
||||
|
||||
context.GetStoredState(stateData, out StoredStateData<IEntity> state);
|
||||
context.GetStoredState(stateData, out StoredStateData<EntityUid> state);
|
||||
return state.GetValue() == null ? 1.0f : 0.0f;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ namespace Content.Server.AI.Utility.ExpandableActions
|
||||
/// </summary>
|
||||
public abstract class ExpandableUtilityAction : IAiUtility
|
||||
{
|
||||
public IEntity Owner { get; set; } = default!;
|
||||
public EntityUid Owner { get; set; } = default!;
|
||||
|
||||
public abstract float Bonus { get; }
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ namespace Content.Server.AI.Utility
|
||||
{
|
||||
public static class UtilityAiHelpers
|
||||
{
|
||||
public static Blackboard? GetBlackboard(IEntity entity)
|
||||
public static Blackboard? GetBlackboard(EntityUid entity)
|
||||
{
|
||||
if (!IoCManager.Resolve<IEntityManager>().TryGetComponent(entity, out AiControllerComponent? aiControllerComponent))
|
||||
{
|
||||
|
||||
@@ -1,21 +1,16 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Content.Server.AI.Components;
|
||||
using Content.Shared.Physics;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Maths;
|
||||
using Robust.Shared.Physics;
|
||||
using Robust.Shared.Physics.Broadphase;
|
||||
|
||||
namespace Content.Server.AI.Utils
|
||||
{
|
||||
public static class Visibility
|
||||
{
|
||||
// Should this be in robust or something? Fark it
|
||||
public static IEnumerable<IEntity> GetNearestEntities(EntityCoordinates grid, Type component, float range)
|
||||
public static IEnumerable<EntityUid> GetNearestEntities(EntityCoordinates grid, Type component, float range)
|
||||
{
|
||||
var inRange = GetEntitiesInRange(grid, component, range).ToList();
|
||||
var sortedInRange = inRange.OrderBy(o => (IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(o).Coordinates.Position - grid.Position).Length);
|
||||
@@ -23,7 +18,7 @@ namespace Content.Server.AI.Utils
|
||||
return sortedInRange;
|
||||
}
|
||||
|
||||
public static IEnumerable<IEntity> GetEntitiesInRange(EntityCoordinates grid, Type component, float range)
|
||||
public static IEnumerable<EntityUid> GetEntitiesInRange(EntityCoordinates grid, Type component, float range)
|
||||
{
|
||||
var entityManager = IoCManager.Resolve<IEntityManager>();
|
||||
foreach (var entity in entityManager.GetAllComponents(component).Select(c => c.Owner))
|
||||
|
||||
@@ -12,18 +12,18 @@ namespace Content.Server.AI.WorldState
|
||||
{
|
||||
// Some stuff like "My Health" is easy to represent as components but abstract stuff like "How much food is nearby"
|
||||
// is harder. This also allows data to be cached if it's being hit frequently.
|
||||
|
||||
|
||||
// This also stops you from re-writing the same boilerplate everywhere of stuff like "Do I have OuterClothing on?"
|
||||
|
||||
private readonly Dictionary<Type, IAiState> _states = new();
|
||||
private readonly List<IPlanningState> _planningStates = new();
|
||||
|
||||
public Blackboard(IEntity owner)
|
||||
public Blackboard(EntityUid owner)
|
||||
{
|
||||
Setup(owner);
|
||||
}
|
||||
|
||||
private void Setup(IEntity owner)
|
||||
private void Setup(EntityUid owner)
|
||||
{
|
||||
var typeFactory = IoCManager.Resolve<IDynamicTypeFactory>();
|
||||
var blackboardManager = IoCManager.Resolve<BlackboardManager>();
|
||||
|
||||
@@ -10,7 +10,7 @@ namespace Content.Server.AI.WorldState
|
||||
/// </summary>
|
||||
public interface IAiState
|
||||
{
|
||||
void Setup(IEntity owner);
|
||||
void Setup(EntityUid owner);
|
||||
}
|
||||
|
||||
public interface IPlanningState
|
||||
@@ -32,9 +32,9 @@ namespace Content.Server.AI.WorldState
|
||||
public abstract class StateData<T> : IAiState
|
||||
{
|
||||
public abstract string Name { get; }
|
||||
protected IEntity Owner { get; private set; } = default!;
|
||||
protected EntityUid Owner { get; private set; } = default!;
|
||||
|
||||
public void Setup(IEntity owner)
|
||||
public void Setup(EntityUid owner)
|
||||
{
|
||||
Owner = owner;
|
||||
}
|
||||
@@ -51,11 +51,11 @@ namespace Content.Server.AI.WorldState
|
||||
{
|
||||
// Probably not the best class name but couldn't think of anything better
|
||||
public abstract string Name { get; }
|
||||
private IEntity? Owner { get; set; }
|
||||
private EntityUid Owner { get; set; }
|
||||
|
||||
private T? _value;
|
||||
|
||||
public void Setup(IEntity owner)
|
||||
public void Setup(EntityUid owner)
|
||||
{
|
||||
Owner = owner;
|
||||
}
|
||||
@@ -79,10 +79,10 @@ namespace Content.Server.AI.WorldState
|
||||
public abstract class PlanningStateData<T> : IAiState, IPlanningState
|
||||
{
|
||||
public abstract string Name { get; }
|
||||
protected IEntity? Owner { get; private set; }
|
||||
protected EntityUid Owner { get; private set; }
|
||||
protected T? Value;
|
||||
|
||||
public void Setup(IEntity owner)
|
||||
public void Setup(EntityUid owner)
|
||||
{
|
||||
Owner = owner;
|
||||
}
|
||||
@@ -108,7 +108,7 @@ namespace Content.Server.AI.WorldState
|
||||
public abstract class CachedStateData<T> : IAiState, ICachedState
|
||||
{
|
||||
public abstract string Name { get; }
|
||||
protected IEntity Owner { get; private set; } = default!;
|
||||
protected EntityUid Owner { get; private set; } = default!;
|
||||
private bool _cached;
|
||||
protected T Value = default!;
|
||||
private TimeSpan _lastCache = TimeSpan.Zero;
|
||||
@@ -117,7 +117,7 @@ namespace Content.Server.AI.WorldState
|
||||
/// </summary>
|
||||
protected double CacheTime { get; set; } = 2.0f;
|
||||
|
||||
public void Setup(IEntity owner)
|
||||
public void Setup(EntityUid owner)
|
||||
{
|
||||
Owner = owner;
|
||||
}
|
||||
|
||||
@@ -8,13 +8,13 @@ using Robust.Shared.IoC;
|
||||
namespace Content.Server.AI.WorldState.States.Clothing
|
||||
{
|
||||
[UsedImplicitly]
|
||||
public sealed class EquippedClothingState : StateData<Dictionary<EquipmentSlotDefines.Slots, IEntity>>
|
||||
public sealed class EquippedClothingState : StateData<Dictionary<EquipmentSlotDefines.Slots, EntityUid>>
|
||||
{
|
||||
public override string Name => "EquippedClothing";
|
||||
|
||||
public override Dictionary<EquipmentSlotDefines.Slots, IEntity> GetValue()
|
||||
public override Dictionary<EquipmentSlotDefines.Slots, EntityUid> GetValue()
|
||||
{
|
||||
var result = new Dictionary<EquipmentSlotDefines.Slots, IEntity>();
|
||||
var result = new Dictionary<EquipmentSlotDefines.Slots, EntityUid>();
|
||||
|
||||
if (!IoCManager.Resolve<IEntityManager>().TryGetComponent(Owner, out InventoryComponent? inventoryComponent))
|
||||
{
|
||||
|
||||
@@ -11,13 +11,13 @@ using Robust.Shared.IoC;
|
||||
namespace Content.Server.AI.WorldState.States.Clothing
|
||||
{
|
||||
[UsedImplicitly]
|
||||
public sealed class NearbyClothingState : CachedStateData<List<IEntity>>
|
||||
public sealed class NearbyClothingState : CachedStateData<List<EntityUid>>
|
||||
{
|
||||
public override string Name => "NearbyClothing";
|
||||
|
||||
protected override List<IEntity> GetTrueValue()
|
||||
protected override List<EntityUid> GetTrueValue()
|
||||
{
|
||||
var result = new List<IEntity>();
|
||||
var result = new List<EntityUid>();
|
||||
|
||||
if (!IoCManager.Resolve<IEntityManager>().TryGetComponent(Owner, out AiControllerComponent? controller))
|
||||
{
|
||||
|
||||
@@ -9,13 +9,13 @@ using Robust.Shared.IoC;
|
||||
namespace Content.Server.AI.WorldState.States.Combat.Nearby
|
||||
{
|
||||
[UsedImplicitly]
|
||||
public sealed class NearbyMeleeWeapons : CachedStateData<List<IEntity>>
|
||||
public sealed class NearbyMeleeWeapons : CachedStateData<List<EntityUid>>
|
||||
{
|
||||
public override string Name => "NearbyMeleeWeapons";
|
||||
|
||||
protected override List<IEntity> GetTrueValue()
|
||||
protected override List<EntityUid> GetTrueValue()
|
||||
{
|
||||
var result = new List<IEntity>();
|
||||
var result = new List<EntityUid>();
|
||||
|
||||
if (!IoCManager.Resolve<IEntityManager>().TryGetComponent(Owner, out AiControllerComponent? controller))
|
||||
{
|
||||
|
||||
@@ -4,13 +4,13 @@ using Robust.Shared.GameObjects;
|
||||
namespace Content.Server.AI.WorldState.States.Combat
|
||||
{
|
||||
[UsedImplicitly]
|
||||
public sealed class WeaponEntityState : PlanningStateData<IEntity>
|
||||
public sealed class WeaponEntityState : PlanningStateData<EntityUid>
|
||||
{
|
||||
// Similar to TargetEntity
|
||||
public override string Name => "WeaponEntity";
|
||||
public override void Reset()
|
||||
{
|
||||
Value = null;
|
||||
Value = default;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,12 +7,12 @@ using Robust.Shared.IoC;
|
||||
namespace Content.Server.AI.WorldState.States.Hands
|
||||
{
|
||||
[UsedImplicitly]
|
||||
public class HandItemsState : StateData<List<IEntity>>
|
||||
public class HandItemsState : StateData<List<EntityUid>>
|
||||
{
|
||||
public override string Name => "HandItems";
|
||||
public override List<IEntity> GetValue()
|
||||
public override List<EntityUid> GetValue()
|
||||
{
|
||||
var result = new List<IEntity>();
|
||||
var result = new List<EntityUid>();
|
||||
if (!IoCManager.Resolve<IEntityManager>().TryGetComponent(Owner, out HandsComponent? handsComponent))
|
||||
{
|
||||
return result;
|
||||
|
||||
@@ -9,18 +9,18 @@ namespace Content.Server.AI.WorldState.States.Inventory
|
||||
/// AKA what's in active hand
|
||||
/// </summary>
|
||||
[UsedImplicitly]
|
||||
public sealed class EquippedEntityState : StateData<IEntity>
|
||||
public sealed class EquippedEntityState : StateData<EntityUid>
|
||||
{
|
||||
public override string Name => "EquippedEntity";
|
||||
|
||||
public override IEntity? GetValue()
|
||||
public override EntityUid GetValue()
|
||||
{
|
||||
if (!IoCManager.Resolve<IEntityManager>().TryGetComponent(Owner, out HandsComponent? handsComponent))
|
||||
{
|
||||
return null;
|
||||
return default;
|
||||
}
|
||||
|
||||
return handsComponent.GetActiveHand?.Owner;
|
||||
return handsComponent.GetActiveHand?.Owner ?? default;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,11 +7,11 @@ using Robust.Shared.IoC;
|
||||
namespace Content.Server.AI.WorldState.States.Inventory
|
||||
{
|
||||
[UsedImplicitly]
|
||||
public sealed class EnumerableInventoryState : StateData<IEnumerable<IEntity>>
|
||||
public sealed class EnumerableInventoryState : StateData<IEnumerable<EntityUid>>
|
||||
{
|
||||
public override string Name => "EnumerableInventory";
|
||||
|
||||
public override IEnumerable<IEntity> GetValue()
|
||||
public override IEnumerable<EntityUid> GetValue()
|
||||
{
|
||||
if (IoCManager.Resolve<IEntityManager>().TryGetComponent(Owner, out HandsComponent? handsComponent))
|
||||
{
|
||||
|
||||
@@ -9,16 +9,16 @@ namespace Content.Server.AI.WorldState.States.Inventory
|
||||
/// If we open a storage locker than it will be stored here
|
||||
/// Useful if we want to close it after
|
||||
/// </summary>
|
||||
public sealed class LastOpenedStorageState : StoredStateData<IEntity>
|
||||
public sealed class LastOpenedStorageState : StoredStateData<EntityUid>
|
||||
{
|
||||
// TODO: IF we chain lockers need to handle it.
|
||||
// Fine for now I guess
|
||||
public override string Name => "LastOpenedStorage";
|
||||
|
||||
public override void SetValue(IEntity? value)
|
||||
public override void SetValue(EntityUid value)
|
||||
{
|
||||
base.SetValue(value);
|
||||
if (value != null && !IoCManager.Resolve<IEntityManager>().HasComponent<EntityStorageComponent>(value))
|
||||
if (value.Valid && !IoCManager.Resolve<IEntityManager>().HasComponent<EntityStorageComponent>(value))
|
||||
{
|
||||
Logger.Warning("Set LastOpenedStorageState for an entity that doesn't have a storage component");
|
||||
}
|
||||
|
||||
@@ -9,13 +9,13 @@ using Robust.Shared.IoC;
|
||||
namespace Content.Server.AI.WorldState.States.Mobs
|
||||
{
|
||||
[UsedImplicitly]
|
||||
public sealed class NearbyBodiesState : CachedStateData<List<IEntity>>
|
||||
public sealed class NearbyBodiesState : CachedStateData<List<EntityUid>>
|
||||
{
|
||||
public override string Name => "NearbyBodies";
|
||||
|
||||
protected override List<IEntity> GetTrueValue()
|
||||
protected override List<EntityUid> GetTrueValue()
|
||||
{
|
||||
var result = new List<IEntity>();
|
||||
var result = new List<EntityUid>();
|
||||
|
||||
if (!IoCManager.Resolve<IEntityManager>().TryGetComponent(Owner, out AiControllerComponent? controller))
|
||||
{
|
||||
|
||||
@@ -1,24 +1,21 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Content.Server.AI.Components;
|
||||
using Content.Shared.Damage;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Server.Player;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Player;
|
||||
|
||||
namespace Content.Server.AI.WorldState.States.Mobs
|
||||
{
|
||||
[UsedImplicitly]
|
||||
public sealed class NearbyPlayersState : CachedStateData<List<IEntity>>
|
||||
public sealed class NearbyPlayersState : CachedStateData<List<EntityUid>>
|
||||
{
|
||||
public override string Name => "NearbyPlayers";
|
||||
|
||||
protected override List<IEntity> GetTrueValue()
|
||||
protected override List<EntityUid> GetTrueValue()
|
||||
{
|
||||
var result = new List<IEntity>();
|
||||
var result = new List<EntityUid>();
|
||||
|
||||
if (!IoCManager.Resolve<IEntityManager>().TryGetComponent(Owner, out AiControllerComponent? controller))
|
||||
{
|
||||
@@ -31,14 +28,14 @@ namespace Content.Server.AI.WorldState.States.Mobs
|
||||
|
||||
foreach (var player in nearbyPlayers)
|
||||
{
|
||||
if (player.AttachedEntity == null)
|
||||
if (player.AttachedEntity is not {Valid: true} playerEntity)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (player.AttachedEntity != Owner && IoCManager.Resolve<IEntityManager>().HasComponent<DamageableComponent>(player.AttachedEntity))
|
||||
if (player.AttachedEntity != Owner && IoCManager.Resolve<IEntityManager>().HasComponent<DamageableComponent>(playerEntity))
|
||||
{
|
||||
result.Add(player.AttachedEntity);
|
||||
result.Add(playerEntity);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -4,12 +4,12 @@ using Robust.Shared.GameObjects;
|
||||
namespace Content.Server.AI.WorldState.States.Movement
|
||||
{
|
||||
[UsedImplicitly]
|
||||
public sealed class MoveTargetState : PlanningStateData<IEntity>
|
||||
public sealed class MoveTargetState : PlanningStateData<EntityUid>
|
||||
{
|
||||
public override string Name => "MoveTarget";
|
||||
public override void Reset()
|
||||
{
|
||||
Value = null;
|
||||
Value = default;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,13 +11,13 @@ using Robust.Shared.IoC;
|
||||
namespace Content.Server.AI.WorldState.States.Nutrition
|
||||
{
|
||||
[UsedImplicitly]
|
||||
public sealed class NearbyDrinkState: CachedStateData<List<IEntity>>
|
||||
public sealed class NearbyDrinkState: CachedStateData<List<EntityUid>>
|
||||
{
|
||||
public override string Name => "NearbyDrink";
|
||||
|
||||
protected override List<IEntity> GetTrueValue()
|
||||
protected override List<EntityUid> GetTrueValue()
|
||||
{
|
||||
var result = new List<IEntity>();
|
||||
var result = new List<EntityUid>();
|
||||
|
||||
if (!IoCManager.Resolve<IEntityManager>().TryGetComponent(Owner, out AiControllerComponent? controller))
|
||||
{
|
||||
|
||||
@@ -11,13 +11,13 @@ using Robust.Shared.IoC;
|
||||
namespace Content.Server.AI.WorldState.States.Nutrition
|
||||
{
|
||||
[UsedImplicitly]
|
||||
public sealed class NearbyFoodState : CachedStateData<List<IEntity>>
|
||||
public sealed class NearbyFoodState : CachedStateData<List<EntityUid>>
|
||||
{
|
||||
public override string Name => "NearbyFood";
|
||||
|
||||
protected override List<IEntity> GetTrueValue()
|
||||
protected override List<EntityUid> GetTrueValue()
|
||||
{
|
||||
var result = new List<IEntity>();
|
||||
var result = new List<EntityUid>();
|
||||
|
||||
if (!IoCManager.Resolve<IEntityManager>().TryGetComponent(Owner, out AiControllerComponent? controller))
|
||||
{
|
||||
|
||||
@@ -4,11 +4,11 @@ using Robust.Shared.GameObjects;
|
||||
namespace Content.Server.AI.WorldState.States
|
||||
{
|
||||
[UsedImplicitly]
|
||||
public sealed class SelfState : StateData<IEntity>
|
||||
public sealed class SelfState : StateData<EntityUid>
|
||||
{
|
||||
public override string Name => "Self";
|
||||
|
||||
public override IEntity GetValue()
|
||||
public override EntityUid GetValue()
|
||||
{
|
||||
return Owner;
|
||||
}
|
||||
|
||||
@@ -7,13 +7,13 @@ namespace Content.Server.AI.WorldState.States
|
||||
/// Could be target item to equip, target to attack, etc.
|
||||
/// </summary>
|
||||
[UsedImplicitly]
|
||||
public sealed class TargetEntityState : PlanningStateData<IEntity>
|
||||
public sealed class TargetEntityState : PlanningStateData<EntityUid>
|
||||
{
|
||||
public override string Name => "TargetEntity";
|
||||
|
||||
public override void Reset()
|
||||
{
|
||||
Value = null;
|
||||
Value = default;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,7 +49,6 @@ namespace Content.Server.AME
|
||||
if (IoCManager.Resolve<IEntityManager>().TryGetComponent(nodeOwner, out AMEShieldComponent? shield))
|
||||
{
|
||||
var nodeNeighbors = grid.GetCellsInSquareArea(IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(nodeOwner).Coordinates, 1)
|
||||
.Select(sgc => IoCManager.Resolve<IEntityManager>().GetEntity(sgc))
|
||||
.Where(entity => entity != nodeOwner && IoCManager.Resolve<IEntityManager>().HasComponent<AMEShieldComponent>(entity));
|
||||
|
||||
if (nodeNeighbors.Count() >= 8)
|
||||
|
||||
@@ -28,6 +28,8 @@ namespace Content.Server.AME.Components
|
||||
[ComponentReference(typeof(IInteractUsing))]
|
||||
public class AMEControllerComponent : SharedAMEControllerComponent, IActivate, IInteractUsing
|
||||
{
|
||||
[Dependency] private readonly IEntityManager _entities = default!;
|
||||
|
||||
[ViewVariables] private BoundUserInterface? UserInterface => Owner.GetUIOrNull(AMEControllerUiKey.Key);
|
||||
private bool _injecting;
|
||||
[ViewVariables] public bool Injecting => _injecting;
|
||||
@@ -38,7 +40,7 @@ namespace Content.Server.AME.Components
|
||||
[DataField("clickSound")] private SoundSpecifier _clickSound = new SoundPathSpecifier("/Audio/Machines/machine_switch.ogg");
|
||||
[DataField("injectSound")] private SoundSpecifier _injectSound = new SoundPathSpecifier("/Audio/Effects/bang.ogg");
|
||||
|
||||
private bool Powered => !IoCManager.Resolve<IEntityManager>().TryGetComponent(Owner, out ApcPowerReceiverComponent? receiver) || receiver.Powered;
|
||||
private bool Powered => !_entities.TryGetComponent(Owner, out ApcPowerReceiverComponent? receiver) || receiver.Powered;
|
||||
|
||||
[ViewVariables]
|
||||
private int _stability = 100;
|
||||
@@ -55,9 +57,9 @@ namespace Content.Server.AME.Components
|
||||
UserInterface.OnReceiveMessage += OnUiReceiveMessage;
|
||||
}
|
||||
|
||||
IoCManager.Resolve<IEntityManager>().TryGetComponent(Owner, out _appearance);
|
||||
_entities.TryGetComponent(Owner, out _appearance);
|
||||
|
||||
IoCManager.Resolve<IEntityManager>().TryGetComponent(Owner, out _powerSupplier);
|
||||
_entities.TryGetComponent(Owner, out _powerSupplier);
|
||||
|
||||
_injecting = false;
|
||||
InjectionAmount = 2;
|
||||
@@ -92,11 +94,10 @@ namespace Content.Server.AME.Components
|
||||
return;
|
||||
}
|
||||
|
||||
var jar = _jarSlot.ContainedEntity;
|
||||
if (jar is null)
|
||||
if (_jarSlot.ContainedEntity is not {Valid: true} jar)
|
||||
return;
|
||||
|
||||
IoCManager.Resolve<IEntityManager>().TryGetComponent<AMEFuelContainerComponent?>(jar, out var fuelJar);
|
||||
_entities.TryGetComponent<AMEFuelContainerComponent?>(jar, out var fuelJar);
|
||||
if (fuelJar != null && _powerSupplier != null)
|
||||
{
|
||||
var availableInject = fuelJar.FuelAmount >= InjectionAmount ? InjectionAmount : fuelJar.FuelAmount;
|
||||
@@ -120,12 +121,12 @@ namespace Content.Server.AME.Components
|
||||
/// <param name="args">Data relevant to the event such as the actor which triggered it.</param>
|
||||
void IActivate.Activate(ActivateEventArgs args)
|
||||
{
|
||||
if (!IoCManager.Resolve<IEntityManager>().TryGetComponent(args.User, out ActorComponent? actor))
|
||||
if (!_entities.TryGetComponent(args.User, out ActorComponent? actor))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (!IoCManager.Resolve<IEntityManager>().TryGetComponent(args.User, out HandsComponent? hands))
|
||||
if (!_entities.TryGetComponent(args.User, out HandsComponent? hands))
|
||||
{
|
||||
Owner.PopupMessage(args.User, Loc.GetString("ame-controller-component-interact-no-hands-text"));
|
||||
return;
|
||||
@@ -151,14 +152,13 @@ namespace Content.Server.AME.Components
|
||||
|
||||
private AMEControllerBoundUserInterfaceState GetUserInterfaceState()
|
||||
{
|
||||
var jar = _jarSlot.ContainedEntity;
|
||||
if (jar == null)
|
||||
if (_jarSlot.ContainedEntity is not {Valid: true} jar)
|
||||
{
|
||||
return new AMEControllerBoundUserInterfaceState(Powered, IsMasterController(), false, HasJar, 0, InjectionAmount, GetCoreCount());
|
||||
}
|
||||
|
||||
var jarcomponent = IoCManager.Resolve<IEntityManager>().GetComponent<AMEFuelContainerComponent>(jar);
|
||||
return new AMEControllerBoundUserInterfaceState(Powered, IsMasterController(), _injecting, HasJar, jarcomponent.FuelAmount, InjectionAmount, GetCoreCount());
|
||||
var jarComponent = _entities.GetComponent<AMEFuelContainerComponent>(jar);
|
||||
return new AMEControllerBoundUserInterfaceState(Powered, IsMasterController(), _injecting, HasJar, jarComponent.FuelAmount, InjectionAmount, GetCoreCount());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -166,10 +166,10 @@ namespace Content.Server.AME.Components
|
||||
/// </summary>
|
||||
/// <param name="playerEntity">The player entity.</param>
|
||||
/// <returns>Returns true if the entity can use the controller, and false if it cannot.</returns>
|
||||
private bool PlayerCanUseController(IEntity playerEntity, bool needsPower = true)
|
||||
private bool PlayerCanUseController(EntityUid playerEntity, bool needsPower = true)
|
||||
{
|
||||
//Need player entity to check if they are still able to use the dispenser
|
||||
if (playerEntity == null)
|
||||
if (playerEntity == default)
|
||||
return false;
|
||||
|
||||
var actionBlocker = EntitySystem.Get<ActionBlockerSystem>();
|
||||
@@ -197,7 +197,7 @@ namespace Content.Server.AME.Components
|
||||
/// <param name="obj">A user interface message from the client.</param>
|
||||
private void OnUiReceiveMessage(ServerBoundUserInterfaceMessage obj)
|
||||
{
|
||||
if (obj.Session.AttachedEntity == null)
|
||||
if (obj.Session.AttachedEntity is not {Valid: true} player)
|
||||
{
|
||||
return;
|
||||
}
|
||||
@@ -209,13 +209,13 @@ namespace Content.Server.AME.Components
|
||||
_ => true,
|
||||
};
|
||||
|
||||
if (!PlayerCanUseController(obj.Session.AttachedEntity, needsPower))
|
||||
if (!PlayerCanUseController(player, needsPower))
|
||||
return;
|
||||
|
||||
switch (msg.Button)
|
||||
{
|
||||
case UiButton.Eject:
|
||||
TryEject(obj.Session.AttachedEntity);
|
||||
TryEject(player);
|
||||
break;
|
||||
case UiButton.ToggleInjection:
|
||||
ToggleInjection();
|
||||
@@ -234,19 +234,18 @@ namespace Content.Server.AME.Components
|
||||
ClickSound();
|
||||
}
|
||||
|
||||
private void TryEject(IEntity user)
|
||||
private void TryEject(EntityUid user)
|
||||
{
|
||||
if (!HasJar || _injecting)
|
||||
return;
|
||||
|
||||
var jar = _jarSlot.ContainedEntity;
|
||||
if (jar is null)
|
||||
if (_jarSlot.ContainedEntity is not {Valid: true} jar)
|
||||
return;
|
||||
|
||||
_jarSlot.Remove(jar);
|
||||
UpdateUserInterface();
|
||||
|
||||
if (!IoCManager.Resolve<IEntityManager>().TryGetComponent<HandsComponent?>(user, out var hands) || !IoCManager.Resolve<IEntityManager>().TryGetComponent<ItemComponent?>(jar, out var item))
|
||||
if (!_entities.TryGetComponent<HandsComponent?>(user, out var hands) || !_entities.TryGetComponent<ItemComponent?>(jar, out var item))
|
||||
return;
|
||||
if (hands.CanPutInHand(item))
|
||||
hands.PutInHand(item);
|
||||
@@ -290,7 +289,7 @@ namespace Content.Server.AME.Components
|
||||
|
||||
private AMENodeGroup? GetAMENodeGroup()
|
||||
{
|
||||
IoCManager.Resolve<IEntityManager>().TryGetComponent(Owner, out NodeContainerComponent? nodeContainer);
|
||||
_entities.TryGetComponent(Owner, out NodeContainerComponent? nodeContainer);
|
||||
|
||||
var engineNodeGroup = nodeContainer?.Nodes.Values
|
||||
.Select(node => node.NodeGroup)
|
||||
@@ -336,7 +335,7 @@ namespace Content.Server.AME.Components
|
||||
|
||||
async Task<bool> IInteractUsing.InteractUsing(InteractUsingEventArgs args)
|
||||
{
|
||||
if (!IoCManager.Resolve<IEntityManager>().TryGetComponent(args.User, out HandsComponent? hands))
|
||||
if (!_entities.TryGetComponent(args.User, out HandsComponent? hands))
|
||||
{
|
||||
Owner.PopupMessage(args.User, Loc.GetString("ame-controller-component-interact-using-no-hands-text"));
|
||||
return true;
|
||||
@@ -349,7 +348,7 @@ namespace Content.Server.AME.Components
|
||||
}
|
||||
|
||||
var activeHandEntity = hands.GetActiveHand.Owner;
|
||||
if (IoCManager.Resolve<IEntityManager>().TryGetComponent<AMEFuelContainerComponent?>(activeHandEntity, out var fuelContainer))
|
||||
if (_entities.HasComponent<AMEFuelContainerComponent?>(activeHandEntity))
|
||||
{
|
||||
if (HasJar)
|
||||
{
|
||||
|
||||
@@ -58,7 +58,7 @@ namespace Content.Server.AME.Components
|
||||
|
||||
SoundSystem.Play(Filter.Pvs(Owner), _unwrapSound.GetSound(), Owner);
|
||||
|
||||
IoCManager.Resolve<IEntityManager>().QueueDeleteEntity((EntityUid) Owner);
|
||||
IoCManager.Resolve<IEntityManager>().QueueDeleteEntity(Owner);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -4,11 +4,11 @@ namespace Content.Server.Access
|
||||
{
|
||||
public sealed class AccessReaderChangeMessage : EntityEventArgs
|
||||
{
|
||||
public IEntity Sender { get; }
|
||||
public EntityUid Sender { get; }
|
||||
|
||||
public bool Enabled { get; }
|
||||
|
||||
public AccessReaderChangeMessage(IEntity entity, bool enabled)
|
||||
public AccessReaderChangeMessage(EntityUid entity, bool enabled)
|
||||
{
|
||||
Sender = entity;
|
||||
Enabled = enabled;
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Content.Server.Access.Systems;
|
||||
@@ -6,7 +5,6 @@ using Content.Server.Power.Components;
|
||||
using Content.Server.UserInterface;
|
||||
using Content.Shared.Access;
|
||||
using Content.Shared.Containers.ItemSlots;
|
||||
using Content.Shared.Interaction;
|
||||
using Robust.Server.GameObjects;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
@@ -21,9 +19,10 @@ namespace Content.Server.Access.Components
|
||||
public sealed class IdCardConsoleComponent : SharedIdCardConsoleComponent
|
||||
{
|
||||
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
|
||||
[Dependency] private readonly IEntityManager _entities = default!;
|
||||
|
||||
[ViewVariables] private BoundUserInterface? UserInterface => Owner.GetUIOrNull(IdCardConsoleUiKey.Key);
|
||||
[ViewVariables] private bool Powered => !IoCManager.Resolve<IEntityManager>().TryGetComponent(Owner, out ApcPowerReceiverComponent? receiver) || receiver.Powered;
|
||||
[ViewVariables] private bool Powered => !_entities.TryGetComponent(Owner, out ApcPowerReceiverComponent? receiver) || receiver.Powered;
|
||||
|
||||
protected override void Initialize()
|
||||
{
|
||||
@@ -40,7 +39,7 @@ namespace Content.Server.Access.Components
|
||||
|
||||
private void OnUiReceiveMessage(ServerBoundUserInterfaceMessage obj)
|
||||
{
|
||||
if (obj.Session.AttachedEntity == null)
|
||||
if (obj.Session.AttachedEntity is not {Valid: true} player)
|
||||
{
|
||||
return;
|
||||
}
|
||||
@@ -51,10 +50,10 @@ namespace Content.Server.Access.Components
|
||||
switch (msg.Button)
|
||||
{
|
||||
case UiButton.PrivilegedId:
|
||||
HandleIdButton(obj.Session.AttachedEntity, PrivilegedIdSlot);
|
||||
HandleIdButton(player, PrivilegedIdSlot);
|
||||
break;
|
||||
case UiButton.TargetId:
|
||||
HandleIdButton(obj.Session.AttachedEntity, TargetIdSlot);
|
||||
HandleIdButton(player, TargetIdSlot);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
@@ -70,14 +69,14 @@ namespace Content.Server.Access.Components
|
||||
/// </summary>
|
||||
private bool PrivilegedIdIsAuthorized()
|
||||
{
|
||||
if (!IoCManager.Resolve<IEntityManager>().TryGetComponent(Owner, out AccessReader? reader))
|
||||
if (!_entities.TryGetComponent(Owner, out AccessReader? reader))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
var privilegedIdEntity = PrivilegedIdSlot.Item;
|
||||
var accessSystem = EntitySystem.Get<AccessReaderSystem>();
|
||||
return privilegedIdEntity != null && accessSystem.IsAllowed(reader, privilegedIdEntity);
|
||||
return privilegedIdEntity != null && accessSystem.IsAllowed(reader, privilegedIdEntity.Value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -86,8 +85,7 @@ namespace Content.Server.Access.Components
|
||||
/// </summary>
|
||||
private void TryWriteToTargetId(string newFullName, string newJobTitle, List<string> newAccessList)
|
||||
{
|
||||
var targetIdEntity = TargetIdSlot.Item;
|
||||
if (targetIdEntity == null || !PrivilegedIdIsAuthorized())
|
||||
if (TargetIdSlot.Item is not {Valid: true} targetIdEntity || !PrivilegedIdIsAuthorized())
|
||||
return;
|
||||
|
||||
var cardSystem = EntitySystem.Get<IdCardSystem>();
|
||||
@@ -107,7 +105,7 @@ namespace Content.Server.Access.Components
|
||||
/// <summary>
|
||||
/// Called when one of the insert/remove ID buttons gets pressed.
|
||||
/// </summary>
|
||||
private void HandleIdButton(IEntity user, ItemSlot slot)
|
||||
private void HandleIdButton(EntityUid user, ItemSlot slot)
|
||||
{
|
||||
if (slot.HasItem)
|
||||
EntitySystem.Get<ItemSlotsSystem>().TryEjectToHands(((IComponent) this).Owner, slot, user);
|
||||
@@ -117,12 +115,16 @@ namespace Content.Server.Access.Components
|
||||
|
||||
public void UpdateUserInterface()
|
||||
{
|
||||
var targetIdEntity = TargetIdSlot.Item;
|
||||
IdCardConsoleBoundUserInterfaceState newState;
|
||||
// this could be prettier
|
||||
if (targetIdEntity == null)
|
||||
if (TargetIdSlot.Item is not {Valid: true} targetIdEntity)
|
||||
{
|
||||
IEntity? tempQualifier = PrivilegedIdSlot.Item;
|
||||
var privilegedIdName = string.Empty;
|
||||
if (PrivilegedIdSlot.Item is {Valid: true} item)
|
||||
{
|
||||
privilegedIdName = _entities.GetComponent<MetaDataComponent>(item).EntityName;
|
||||
}
|
||||
|
||||
newState = new IdCardConsoleBoundUserInterfaceState(
|
||||
PrivilegedIdSlot.HasItem,
|
||||
PrivilegedIdIsAuthorized(),
|
||||
@@ -130,16 +132,16 @@ namespace Content.Server.Access.Components
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
(tempQualifier != null ? IoCManager.Resolve<IEntityManager>().GetComponent<MetaDataComponent>(tempQualifier).EntityName : null) ?? string.Empty,
|
||||
privilegedIdName,
|
||||
string.Empty);
|
||||
}
|
||||
else
|
||||
{
|
||||
var targetIdComponent = IoCManager.Resolve<IEntityManager>().GetComponent<IdCardComponent>(targetIdEntity);
|
||||
var targetAccessComponent = IoCManager.Resolve<IEntityManager>().GetComponent<AccessComponent>(targetIdEntity);
|
||||
var targetIdComponent = _entities.GetComponent<IdCardComponent>(targetIdEntity);
|
||||
var targetAccessComponent = _entities.GetComponent<AccessComponent>(targetIdEntity);
|
||||
var name = string.Empty;
|
||||
if(PrivilegedIdSlot.Item != null)
|
||||
name = IoCManager.Resolve<IEntityManager>().GetComponent<MetaDataComponent>(PrivilegedIdSlot.Item).EntityName;
|
||||
if (PrivilegedIdSlot.Item is {Valid: true} item)
|
||||
name = _entities.GetComponent<MetaDataComponent>(item).EntityName;
|
||||
newState = new IdCardConsoleBoundUserInterfaceState(
|
||||
PrivilegedIdSlot.HasItem,
|
||||
PrivilegedIdIsAuthorized(),
|
||||
@@ -148,7 +150,7 @@ namespace Content.Server.Access.Components
|
||||
targetIdComponent.JobTitle,
|
||||
targetAccessComponent.Tags.ToArray(),
|
||||
name,
|
||||
IoCManager.Resolve<IEntityManager>().GetComponent<MetaDataComponent>(targetIdEntity).EntityName);
|
||||
_entities.GetComponent<MetaDataComponent>(targetIdEntity).EntityName);
|
||||
}
|
||||
UserInterface?.SetState(newState);
|
||||
}
|
||||
|
||||
@@ -1,3 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
using Content.Server.Access.Components;
|
||||
using Content.Server.Inventory.Components;
|
||||
using Content.Server.Items;
|
||||
@@ -9,10 +13,6 @@ using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Log;
|
||||
using Robust.Shared.Prototypes;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
|
||||
namespace Content.Server.Access.Systems
|
||||
{
|
||||
@@ -106,16 +106,11 @@ namespace Content.Server.Access.Systems
|
||||
return true;
|
||||
}
|
||||
|
||||
if (EntityManager.TryGetComponent(uid, out PDAComponent? pda))
|
||||
if (EntityManager.TryGetComponent(uid, out PDAComponent? pda) &&
|
||||
pda.ContainedID?.Owner is {Valid: true} id)
|
||||
{
|
||||
IEntity tempQualifier = pda?.ContainedID?.Owner;
|
||||
if (tempQualifier != null)
|
||||
{
|
||||
IoCManager.Resolve<IEntityManager>().GetComponent<AccessComponent>(tempQualifier);
|
||||
}
|
||||
|
||||
tags = RETURNED_VALUE?.Tags;
|
||||
return tags != null;
|
||||
tags = EntityManager.GetComponent<AccessComponent>(id).Tags;
|
||||
return true;
|
||||
}
|
||||
|
||||
tags = null;
|
||||
|
||||
@@ -29,12 +29,12 @@ namespace Content.Server.Act
|
||||
/// <summary>
|
||||
/// The entity being disarmed.
|
||||
/// </summary>
|
||||
public IEntity? Target { get; init; }
|
||||
public EntityUid Target { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// The entity performing the disarm.
|
||||
/// </summary>
|
||||
public IEntity? Source { get; init; }
|
||||
public EntityUid Source { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// Probability for push/knockdown.
|
||||
|
||||
@@ -7,7 +7,7 @@ namespace Content.Server.Act
|
||||
[RequiresExplicitImplementation]
|
||||
public interface ISuicideAct
|
||||
{
|
||||
public SuicideKind Suicide(IEntity victim, IChatManager chat);
|
||||
public SuicideKind Suicide(EntityUid victim, IChatManager chat);
|
||||
}
|
||||
|
||||
public enum SuicideKind
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using Content.Server.Act;
|
||||
using Content.Server.Administration.Logs;
|
||||
using Content.Server.Interaction;
|
||||
using Content.Server.Popups;
|
||||
using Content.Server.Weapon.Melee;
|
||||
using Content.Shared.ActionBlocker;
|
||||
using Content.Shared.Actions;
|
||||
@@ -7,7 +11,9 @@ using Content.Shared.Actions.Behaviors;
|
||||
using Content.Shared.Actions.Components;
|
||||
using Content.Shared.Audio;
|
||||
using Content.Shared.Cooldown;
|
||||
using Content.Shared.Database;
|
||||
using Content.Shared.Interaction.Helpers;
|
||||
using Content.Shared.Popups;
|
||||
using Content.Shared.Sound;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Server.GameObjects;
|
||||
@@ -20,14 +26,6 @@ using Robust.Shared.Player;
|
||||
using Robust.Shared.Random;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
using Robust.Shared.ViewVariables;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Content.Server.Administration.Logs;
|
||||
using Content.Server.Popups;
|
||||
using Content.Shared.Administration.Logs;
|
||||
using Content.Shared.Database;
|
||||
using Content.Shared.Popups;
|
||||
|
||||
namespace Content.Server.Actions.Actions
|
||||
{
|
||||
@@ -60,7 +58,7 @@ namespace Content.Server.Actions.Actions
|
||||
// Fall back to a normal interaction with the entity
|
||||
var player = actor.PlayerSession;
|
||||
var coordinates = IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(args.Target).Coordinates;
|
||||
var target = (EntityUid) args.Target;
|
||||
var target = args.Target;
|
||||
EntitySystem.Get<InteractionSystem>().HandleUseInteraction(player, coordinates, target);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ namespace Content.Server.Actions.Commands
|
||||
}
|
||||
|
||||
if (attachedEntity == null) return;
|
||||
if (!IoCManager.Resolve<IEntityManager>().TryGetComponent(attachedEntity, out ServerActionsComponent? actionsComponent))
|
||||
if (!IoCManager.Resolve<IEntityManager>().TryGetComponent(attachedEntity.Value, out ServerActionsComponent? actionsComponent))
|
||||
{
|
||||
shell.WriteLine("user has no actions component");
|
||||
return;
|
||||
|
||||
@@ -28,7 +28,7 @@ namespace Content.Server.Actions.Commands
|
||||
}
|
||||
|
||||
if (attachedEntity == null) return;
|
||||
if (!IoCManager.Resolve<IEntityManager>().TryGetComponent(attachedEntity, out ServerActionsComponent? actionsComponent))
|
||||
if (!IoCManager.Resolve<IEntityManager>().TryGetComponent(attachedEntity.Value, out ServerActionsComponent? actionsComponent))
|
||||
{
|
||||
shell.WriteLine("user has no actions component");
|
||||
return;
|
||||
|
||||
@@ -28,7 +28,7 @@ namespace Content.Server.Actions.Commands
|
||||
if (!CommandUtils.TryGetAttachedEntityByUsernameOrId(shell, target, player, out attachedEntity)) return;
|
||||
}
|
||||
if (attachedEntity == null) return;
|
||||
if (!IoCManager.Resolve<IEntityManager>().TryGetComponent(attachedEntity, out ServerActionsComponent? actionsComponent))
|
||||
if (!IoCManager.Resolve<IEntityManager>().TryGetComponent(attachedEntity.Value, out ServerActionsComponent? actionsComponent))
|
||||
{
|
||||
shell.WriteLine("user has no actions component");
|
||||
return;
|
||||
|
||||
@@ -1,12 +1,8 @@
|
||||
using System;
|
||||
using Content.Shared.ActionBlocker;
|
||||
using Content.Shared.Actions;
|
||||
using Content.Shared.Actions.Components;
|
||||
using Content.Shared.Actions.Prototypes;
|
||||
using Content.Shared.Interaction.Events;
|
||||
using Content.Shared.Interaction;
|
||||
using Robust.Server.GameObjects;
|
||||
using Robust.Server.GameStates;
|
||||
using Robust.Shared;
|
||||
using Robust.Shared.Configuration;
|
||||
using Robust.Shared.GameObjects;
|
||||
@@ -24,6 +20,7 @@ namespace Content.Server.Actions
|
||||
public sealed class ServerActionsComponent : SharedActionsComponent
|
||||
{
|
||||
[Dependency] private readonly IConfigurationManager _configManager = default!;
|
||||
[Dependency] private readonly IEntityManager _entities = default!;
|
||||
|
||||
private float MaxUpdateRange;
|
||||
|
||||
@@ -55,15 +52,14 @@ namespace Content.Server.Actions
|
||||
throw new ArgumentNullException(nameof(session));
|
||||
}
|
||||
|
||||
var player = session.AttachedEntity;
|
||||
if (player != Owner) return;
|
||||
if (session.AttachedEntity is not {Valid: true} player || player != Owner) return;
|
||||
var attempt = ActionAttempt(performActionMessage, session);
|
||||
if (attempt == null) return;
|
||||
|
||||
if (!attempt.TryGetActionState(this, out var actionState) || !actionState.Enabled)
|
||||
{
|
||||
Logger.DebugS("action", "user {0} attempted to use" +
|
||||
" action {1} which is not granted to them", IoCManager.Resolve<IEntityManager>().GetComponent<MetaDataComponent>(player).EntityName,
|
||||
" action {1} which is not granted to them", _entities.GetComponent<MetaDataComponent>(player).EntityName,
|
||||
attempt);
|
||||
return;
|
||||
}
|
||||
@@ -71,7 +67,7 @@ namespace Content.Server.Actions
|
||||
if (actionState.IsOnCooldown(GameTiming))
|
||||
{
|
||||
Logger.DebugS("action", "user {0} attempted to use" +
|
||||
" action {1} which is on cooldown", IoCManager.Resolve<IEntityManager>().GetComponent<MetaDataComponent>(player).EntityName,
|
||||
" action {1} which is on cooldown", _entities.GetComponent<MetaDataComponent>(player).EntityName,
|
||||
attempt);
|
||||
return;
|
||||
}
|
||||
@@ -86,7 +82,7 @@ namespace Content.Server.Actions
|
||||
if (toggleMsg.ToggleOn == actionState.ToggledOn)
|
||||
{
|
||||
Logger.DebugS("action", "user {0} attempted to" +
|
||||
" toggle action {1} to {2}, but it is already toggled {2}", IoCManager.Resolve<IEntityManager>().GetComponent<MetaDataComponent>(player).EntityName,
|
||||
" toggle action {1} to {2}, but it is already toggled {2}", _entities.GetComponent<MetaDataComponent>(player).EntityName,
|
||||
attempt.Action.Name, toggleMsg.ToggleOn);
|
||||
return;
|
||||
}
|
||||
@@ -109,17 +105,17 @@ namespace Content.Server.Actions
|
||||
break;
|
||||
case BehaviorType.TargetEntity:
|
||||
if (performActionMessage is not ITargetEntityActionMessage targetEntityMsg) return;
|
||||
if (!EntityManager.TryGetEntity(targetEntityMsg.Target, out var entity))
|
||||
if (!EntityManager.EntityExists(targetEntityMsg.Target))
|
||||
{
|
||||
Logger.DebugS("action", "user {0} attempted to" +
|
||||
" perform target entity action {1} but could not find entity with " +
|
||||
"provided uid {2}", IoCManager.Resolve<IEntityManager>().GetComponent<MetaDataComponent>(player).EntityName, attempt.Action.Name,
|
||||
"provided uid {2}", _entities.GetComponent<MetaDataComponent>(player).EntityName, attempt.Action.Name,
|
||||
targetEntityMsg.Target);
|
||||
return;
|
||||
}
|
||||
if (!CheckRangeAndSetFacing(IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(entity).Coordinates, player)) return;
|
||||
if (!CheckRangeAndSetFacing(_entities.GetComponent<TransformComponent>(targetEntityMsg.Target).Coordinates, player)) return;
|
||||
|
||||
attempt.DoTargetEntityAction(player, entity);
|
||||
attempt.DoTargetEntityAction(player, targetEntityMsg.Target);
|
||||
break;
|
||||
case BehaviorType.None:
|
||||
break;
|
||||
@@ -131,48 +127,52 @@ namespace Content.Server.Actions
|
||||
private IActionAttempt? ActionAttempt(BasePerformActionMessage message, ICommonSession session)
|
||||
{
|
||||
IActionAttempt? attempt;
|
||||
var player = session.AttachedEntity;
|
||||
|
||||
switch (message)
|
||||
{
|
||||
case PerformActionMessage performActionMessage:
|
||||
if (!ActionManager.TryGet(performActionMessage.ActionType, out var action))
|
||||
{
|
||||
Logger.DebugS("action", "user {0} attempted to perform" +
|
||||
" unrecognized action {1}", session.AttachedEntity,
|
||||
" unrecognized action {1}", player,
|
||||
performActionMessage.ActionType);
|
||||
return null;
|
||||
}
|
||||
attempt = new ActionAttempt(action);
|
||||
break;
|
||||
case PerformItemActionMessage performItemActionMessage:
|
||||
if (!ActionManager.TryGet(performItemActionMessage.ActionType, out var itemAction))
|
||||
var type = performItemActionMessage.ActionType;
|
||||
if (!ActionManager.TryGet(type, out var itemAction))
|
||||
{
|
||||
Logger.DebugS("action", "user {0} attempted to perform" +
|
||||
" unrecognized item action {1}",
|
||||
session.AttachedEntity, performItemActionMessage.ActionType);
|
||||
player, type);
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!EntityManager.TryGetEntity(performItemActionMessage.Item, out var item))
|
||||
var item = performItemActionMessage.Item;
|
||||
if (!EntityManager.EntityExists(item))
|
||||
{
|
||||
Logger.DebugS("action", "user {0} attempted to perform" +
|
||||
" item action {1} for unknown item {2}",
|
||||
session.AttachedEntity, performItemActionMessage.ActionType, performItemActionMessage.Item);
|
||||
player, type, item);
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!IoCManager.Resolve<IEntityManager>().TryGetComponent<ItemActionsComponent?>(item, out var actionsComponent))
|
||||
if (!_entities.TryGetComponent<ItemActionsComponent?>(item, out var actionsComponent))
|
||||
{
|
||||
Logger.DebugS("action", "user {0} attempted to perform" +
|
||||
" item action {1} for item {2} which has no ItemActionsComponent",
|
||||
session.AttachedEntity, performItemActionMessage.ActionType, item);
|
||||
player, type, item);
|
||||
return null;
|
||||
}
|
||||
|
||||
if (actionsComponent.Holder != session.AttachedEntity)
|
||||
if (actionsComponent.Holder != player)
|
||||
{
|
||||
Logger.DebugS("action", "user {0} attempted to perform" +
|
||||
" item action {1} for item {2} which they are not holding",
|
||||
session.AttachedEntity, performItemActionMessage.ActionType, item);
|
||||
player, type, item);
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -186,7 +186,7 @@ namespace Content.Server.Actions
|
||||
{
|
||||
Logger.DebugS("action", "user {0} attempted to" +
|
||||
" perform action {1} as a {2} behavior, but this action is actually a" +
|
||||
" {3} behavior", session.AttachedEntity, attempt, message.BehaviorType,
|
||||
" {3} behavior", player, attempt, message.BehaviorType,
|
||||
attempt.Action.BehaviorType);
|
||||
return null;
|
||||
}
|
||||
@@ -194,17 +194,17 @@ namespace Content.Server.Actions
|
||||
return attempt;
|
||||
}
|
||||
|
||||
private bool CheckRangeAndSetFacing(EntityCoordinates target, IEntity player)
|
||||
private bool CheckRangeAndSetFacing(EntityCoordinates target, EntityUid player)
|
||||
{
|
||||
// ensure it's within their clickable range
|
||||
var targetWorldPos = target.ToMapPos(EntityManager);
|
||||
var rangeBox = new Box2(IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(player).WorldPosition, IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(player).WorldPosition)
|
||||
var rangeBox = new Box2(_entities.GetComponent<TransformComponent>(player).WorldPosition, _entities.GetComponent<TransformComponent>(player).WorldPosition)
|
||||
.Enlarged(MaxUpdateRange);
|
||||
if (!rangeBox.Contains(targetWorldPos))
|
||||
{
|
||||
Logger.DebugS("action", "user {0} attempted to" +
|
||||
" perform target action further than allowed range",
|
||||
IoCManager.Resolve<IEntityManager>().GetComponent<MetaDataComponent>(player).EntityName);
|
||||
_entities.GetComponent<MetaDataComponent>(player).EntityName);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -57,7 +57,7 @@ namespace Content.Server.Actions.Spells
|
||||
if (!IoCManager.Resolve<IEntityManager>().TryGetComponent(spawnedProto, out ItemComponent? itemComponent))
|
||||
{
|
||||
Logger.Error($"Tried to use {nameof(GiveItemSpell)} but prototype has no {nameof(ItemComponent)}?");
|
||||
IoCManager.Resolve<IEntityManager>().DeleteEntity((EntityUid) spawnedProto);
|
||||
IoCManager.Resolve<IEntityManager>().DeleteEntity(spawnedProto);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -125,13 +125,12 @@ namespace Content.Server.Administration
|
||||
var name = session.Name;
|
||||
var username = string.Empty;
|
||||
|
||||
if(session.AttachedEntity != null)
|
||||
username = IoCManager.Resolve<IEntityManager>().GetComponent<MetaDataComponent>(session.AttachedEntity).EntityName;
|
||||
if (session.AttachedEntity != default)
|
||||
username = EntityManager.GetComponent<MetaDataComponent>(session.AttachedEntity.Value).EntityName;
|
||||
|
||||
var antag = session.ContentData()?.Mind?.AllRoles.Any(r => r.Antagonist) ?? false;
|
||||
var uid = session.AttachedEntity ?? EntityUid.Invalid;
|
||||
|
||||
return new PlayerInfo(name, username, antag, uid, session.UserId);
|
||||
return new PlayerInfo(name, username, antag, session.AttachedEntity ?? default, session.UserId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,7 +15,6 @@ using Content.Server.Mind.Commands;
|
||||
using Content.Server.Mind.Components;
|
||||
using Content.Server.Players;
|
||||
using Content.Shared.Administration;
|
||||
using Content.Shared.Administration.Logs;
|
||||
using Content.Shared.Body.Components;
|
||||
using Content.Shared.Database;
|
||||
using Content.Shared.GameTicking;
|
||||
@@ -56,7 +55,7 @@ namespace Content.Server.Administration
|
||||
|
||||
private void AddDebugVerbs(GetOtherVerbsEvent args)
|
||||
{
|
||||
if (!IoCManager.Resolve<IEntityManager>().TryGetComponent<ActorComponent?>(args.User, out var actor))
|
||||
if (!EntityManager.TryGetComponent<ActorComponent?>(args.User, out var actor))
|
||||
return;
|
||||
|
||||
var player = actor.PlayerSession;
|
||||
@@ -68,7 +67,7 @@ namespace Content.Server.Administration
|
||||
verb.Text = Loc.GetString("delete-verb-get-data-text");
|
||||
verb.Category = VerbCategory.Debug;
|
||||
verb.IconTexture = "/Textures/Interface/VerbIcons/delete_transparent.svg.192dpi.png";
|
||||
verb.Act = () => IoCManager.Resolve<IEntityManager>().DeleteEntity((EntityUid) args.Target);
|
||||
verb.Act = () => EntityManager.DeleteEntity(args.Target);
|
||||
verb.Impact = LogImpact.Medium;
|
||||
args.Verbs.Add(verb);
|
||||
}
|
||||
@@ -88,8 +87,8 @@ namespace Content.Server.Administration
|
||||
// Control mob verb
|
||||
if (_groupController.CanCommand(player, "controlmob") &&
|
||||
args.User != args.Target &&
|
||||
IoCManager.Resolve<IEntityManager>().HasComponent<MindComponent>(args.User) &&
|
||||
IoCManager.Resolve<IEntityManager>().TryGetComponent<MindComponent?>(args.Target, out var targetMind))
|
||||
EntityManager.HasComponent<MindComponent>(args.User) &&
|
||||
EntityManager.TryGetComponent<MindComponent?>(args.Target, out var targetMind))
|
||||
{
|
||||
Verb verb = new();
|
||||
verb.Text = Loc.GetString("control-mob-verb-get-data-text");
|
||||
@@ -106,7 +105,7 @@ namespace Content.Server.Administration
|
||||
// Make Sentient verb
|
||||
if (_groupController.CanCommand(player, "makesentient") &&
|
||||
args.User != args.Target &&
|
||||
!IoCManager.Resolve<IEntityManager>().HasComponent<MindComponent>(args.Target))
|
||||
!EntityManager.HasComponent<MindComponent>(args.Target))
|
||||
{
|
||||
Verb verb = new();
|
||||
verb.Text = Loc.GetString("make-sentient-verb-get-data-text");
|
||||
@@ -125,9 +124,9 @@ namespace Content.Server.Administration
|
||||
verb.Category = VerbCategory.Debug;
|
||||
verb.Act = () =>
|
||||
{
|
||||
var coords = IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(args.Target).Coordinates;
|
||||
var coords = EntityManager.GetComponent<TransformComponent>(args.Target).Coordinates;
|
||||
Timer.Spawn(_gameTiming.TickPeriod, () => _explosions.SpawnExplosion(coords, 0, 1, 2, 1), CancellationToken.None);
|
||||
if (IoCManager.Resolve<IEntityManager>().TryGetComponent(args.Target, out SharedBodyComponent? body))
|
||||
if (EntityManager.TryGetComponent(args.Target, out SharedBodyComponent? body))
|
||||
{
|
||||
body.Gib();
|
||||
}
|
||||
@@ -138,7 +137,7 @@ namespace Content.Server.Administration
|
||||
|
||||
// Set clothing verb
|
||||
if (_groupController.CanCommand(player, "setoutfit") &&
|
||||
IoCManager.Resolve<IEntityManager>().HasComponent<InventoryComponent>(args.Target))
|
||||
EntityManager.HasComponent<InventoryComponent>(args.Target))
|
||||
{
|
||||
Verb verb = new();
|
||||
verb.Text = Loc.GetString("set-outfit-verb-get-data-text");
|
||||
@@ -168,7 +167,7 @@ namespace Content.Server.Administration
|
||||
|
||||
// Get Disposal tube direction verb
|
||||
if (_groupController.CanCommand(player, "tubeconnections") &&
|
||||
IoCManager.Resolve<IEntityManager>().TryGetComponent<IDisposalTubeComponent?>(args.Target, out var tube))
|
||||
EntityManager.TryGetComponent<IDisposalTubeComponent?>(args.Target, out var tube))
|
||||
{
|
||||
Verb verb = new();
|
||||
verb.Text = Loc.GetString("tube-direction-verb-get-data-text");
|
||||
@@ -180,7 +179,7 @@ namespace Content.Server.Administration
|
||||
|
||||
// Make ghost role verb
|
||||
if (_groupController.CanCommand(player, "makeghostrole") &&
|
||||
!(IoCManager.Resolve<IEntityManager>().GetComponentOrNull<MindComponent>(args.TargetUid)?.HasMind ?? false))
|
||||
!(EntityManager.GetComponentOrNull<MindComponent>(args.Target)?.HasMind ?? false))
|
||||
{
|
||||
Verb verb = new();
|
||||
verb.Text = Loc.GetString("make-ghost-role-verb-get-data-text");
|
||||
@@ -194,7 +193,7 @@ namespace Content.Server.Administration
|
||||
|
||||
// Configuration verb. Is this even used for anything!?
|
||||
if (_groupController.CanAdminMenu(player) &&
|
||||
IoCManager.Resolve<IEntityManager>().TryGetComponent<ConfigurationComponent?>(args.TargetUid, out var config))
|
||||
EntityManager.TryGetComponent<ConfigurationComponent?>(args.Target, out var config))
|
||||
{
|
||||
Verb verb = new();
|
||||
verb.Text = Loc.GetString("configure-verb-get-data-text");
|
||||
@@ -206,7 +205,7 @@ namespace Content.Server.Administration
|
||||
|
||||
// Add verb to open Solution Editor
|
||||
if (_groupController.CanCommand(player, "addreagent") &&
|
||||
IoCManager.Resolve<IEntityManager>().HasComponent<SolutionContainerManagerComponent>(args.Target))
|
||||
EntityManager.HasComponent<SolutionContainerManagerComponent>(args.Target))
|
||||
{
|
||||
Verb verb = new();
|
||||
verb.Text = Loc.GetString("edit-solutions-verb-get-data-text");
|
||||
|
||||
@@ -7,13 +7,14 @@ using Robust.Server.Player;
|
||||
using Robust.Shared.Console;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Map;
|
||||
|
||||
namespace Content.Server.Administration.Commands
|
||||
{
|
||||
[AdminCommand(AdminFlags.Admin)]
|
||||
public class AGhost : IConsoleCommand
|
||||
{
|
||||
[Dependency] private readonly IEntityManager _entities = default!;
|
||||
|
||||
public string Command => "aghost";
|
||||
public string Description => "Makes you an admin ghost.";
|
||||
public string Help => "aghost";
|
||||
@@ -35,34 +36,35 @@ namespace Content.Server.Administration.Commands
|
||||
return;
|
||||
}
|
||||
|
||||
if (mind.VisitingEntity != null && IoCManager.Resolve<IEntityManager>().HasComponent<GhostComponent>(mind.VisitingEntity))
|
||||
if (mind.VisitingEntity != default && _entities.HasComponent<GhostComponent>(mind.VisitingEntity))
|
||||
{
|
||||
player.ContentData()!.Mind?.UnVisit();
|
||||
return;
|
||||
}
|
||||
|
||||
var canReturn = mind.CurrentEntity != null;
|
||||
IEntity? tempQualifier = player.AttachedEntity;
|
||||
var ghost = IoCManager.Resolve<IEntityManager>().SpawnEntity((string?) "AdminObserver", (EntityCoordinates) ((tempQualifier != null ? IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(tempQualifier) : null).Coordinates
|
||||
?? EntitySystem.Get<GameTicker>().GetObserverSpawnPoint()));
|
||||
var canReturn = mind.CurrentEntity != default;
|
||||
var coordinates = player.AttachedEntity.HasValue
|
||||
? _entities.GetComponent<TransformComponent>(player.AttachedEntity.Value).Coordinates
|
||||
: EntitySystem.Get<GameTicker>().GetObserverSpawnPoint();
|
||||
var ghost = _entities.SpawnEntity("AdminObserver", coordinates);
|
||||
|
||||
if (canReturn)
|
||||
{
|
||||
// TODO: Remove duplication between all this and "GamePreset.OnGhostAttempt()"...
|
||||
if(!string.IsNullOrWhiteSpace(mind.CharacterName))
|
||||
IoCManager.Resolve<IEntityManager>().GetComponent<MetaDataComponent>(ghost).EntityName = mind.CharacterName;
|
||||
_entities.GetComponent<MetaDataComponent>(ghost).EntityName = mind.CharacterName;
|
||||
else if (!string.IsNullOrWhiteSpace(mind.Session?.Name))
|
||||
IoCManager.Resolve<IEntityManager>().GetComponent<MetaDataComponent>(ghost).EntityName = mind.Session.Name;
|
||||
_entities.GetComponent<MetaDataComponent>(ghost).EntityName = mind.Session.Name;
|
||||
|
||||
mind.Visit(ghost);
|
||||
}
|
||||
else
|
||||
{
|
||||
IoCManager.Resolve<IEntityManager>().GetComponent<MetaDataComponent>(ghost).EntityName = player.Name;
|
||||
_entities.GetComponent<MetaDataComponent>(ghost).EntityName = player.Name;
|
||||
mind.TransferTo(ghost);
|
||||
}
|
||||
|
||||
var comp = IoCManager.Resolve<IEntityManager>().GetComponent<GhostComponent>(ghost);
|
||||
var comp = _entities.GetComponent<GhostComponent>(ghost);
|
||||
EntitySystem.Get<SharedGhostSystem>().SetCanReturnToBody(comp, canReturn);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ namespace Content.Server.Administration.Commands
|
||||
|
||||
if (entityManager.TryGetComponent<EntityStorageComponent>(storageUid, out var storage))
|
||||
{
|
||||
storage.Insert(entityManager.GetEntity(entityUid));
|
||||
storage.Insert(entityUid);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -13,14 +13,15 @@ namespace Content.Server.Administration.Commands
|
||||
[AdminCommand(AdminFlags.Admin)]
|
||||
class ControlMob : IConsoleCommand
|
||||
{
|
||||
[Dependency] private readonly IEntityManager _entities = default!;
|
||||
|
||||
public string Command => "controlmob";
|
||||
public string Description => Loc.GetString("control-mob-command-description");
|
||||
public string Help => Loc.GetString("control-mob-command-help-text");
|
||||
|
||||
public void Execute(IConsoleShell shell, string argStr, string[] args)
|
||||
{
|
||||
var player = shell.Player as IPlayerSession;
|
||||
if (player == null)
|
||||
if (shell.Player is not IPlayerSession player)
|
||||
{
|
||||
shell.WriteLine("shell-server-cannot");
|
||||
return;
|
||||
@@ -32,25 +33,21 @@ namespace Content.Server.Administration.Commands
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
var entityManager = IoCManager.Resolve<IEntityManager>();
|
||||
|
||||
if (!int.TryParse(args[0], out var targetId))
|
||||
{
|
||||
shell.WriteLine(Loc.GetString("shell-argument-must-be-number"));
|
||||
return;
|
||||
}
|
||||
|
||||
var eUid = new EntityUid(targetId);
|
||||
var target = new EntityUid(targetId);
|
||||
|
||||
if (!eUid.IsValid() || !entityManager.EntityExists(eUid))
|
||||
if (!target.IsValid() || !_entities.EntityExists(target))
|
||||
{
|
||||
shell.WriteLine(Loc.GetString("shell-invalid-entity-id"));
|
||||
return;
|
||||
}
|
||||
|
||||
var target = entityManager.GetEntity(eUid);
|
||||
if (!IoCManager.Resolve<IEntityManager>().TryGetComponent(target, out MindComponent? mindComponent))
|
||||
if (!_entities.HasComponent<MindComponent>(target))
|
||||
{
|
||||
shell.WriteLine(Loc.GetString("shell-entity-is-not-mob"));
|
||||
return;
|
||||
|
||||
@@ -37,7 +37,7 @@ namespace Content.Server.Administration.Commands
|
||||
|
||||
foreach (var component in components)
|
||||
{
|
||||
var uid = (EntityUid) component.Owner;
|
||||
var uid = component.Owner;
|
||||
entityManager.RemoveComponent(uid, component);
|
||||
i++;
|
||||
}
|
||||
|
||||
@@ -37,12 +37,12 @@ namespace Content.Server.Administration.Commands
|
||||
var entityManager = IoCManager.Resolve<IEntityManager>();
|
||||
|
||||
var entitiesWithComponents = components.Select(c => entityManager.GetAllComponents(c).Select(x => x.Owner));
|
||||
var entitiesWithAllComponents = entitiesWithComponents.Skip(1).Aggregate(new HashSet<IEntity>(entitiesWithComponents.First()), (h, e) => { h.IntersectWith(e); return h; });
|
||||
var entitiesWithAllComponents = entitiesWithComponents.Skip(1).Aggregate(new HashSet<EntityUid>(entitiesWithComponents.First()), (h, e) => { h.IntersectWith(e); return h; });
|
||||
|
||||
var count = 0;
|
||||
foreach (var entity in entitiesWithAllComponents)
|
||||
{
|
||||
IoCManager.Resolve<IEntityManager>().DeleteEntity((EntityUid) entity);
|
||||
IoCManager.Resolve<IEntityManager>().DeleteEntity(entity);
|
||||
count += 1;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
using System.Linq;
|
||||
using Content.Shared.Administration;
|
||||
using Robust.Shared.Console;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
using System.Linq;
|
||||
using Robust.Shared.Prototypes;
|
||||
|
||||
namespace Content.Server.Administration.Commands
|
||||
{
|
||||
@@ -29,7 +28,7 @@ namespace Content.Server.Administration.Commands
|
||||
|
||||
foreach (var entity in entities)
|
||||
{
|
||||
IoCManager.Resolve<IEntityManager>().DeleteEntity((EntityUid) entity);
|
||||
IoCManager.Resolve<IEntityManager>().DeleteEntity(entity);
|
||||
i++;
|
||||
}
|
||||
|
||||
|
||||
@@ -28,13 +28,13 @@ namespace Content.Server.Administration.Commands
|
||||
|
||||
var entityManager = IoCManager.Resolve<IEntityManager>();
|
||||
|
||||
if (!entityManager.TryGetEntity(id, out var entity))
|
||||
if (!entityManager.EntityExists(id))
|
||||
{
|
||||
shell.WriteLine($"No entity found with id {id}.");
|
||||
return;
|
||||
}
|
||||
|
||||
IoCManager.Resolve<IEntityManager>().DeleteEntity((EntityUid) entity);
|
||||
IoCManager.Resolve<IEntityManager>().DeleteEntity(id);
|
||||
shell.WriteLine($"Deleted entity with id {id}.");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ namespace Content.Server.Administration.Commands
|
||||
public void Execute(IConsoleShell shell, string argStr, string[] args)
|
||||
{
|
||||
var player = shell.Player as IPlayerSession;
|
||||
if (player?.AttachedEntity == null)
|
||||
if (player?.AttachedEntity is not {Valid: true} playerEntity)
|
||||
{
|
||||
shell.WriteLine("You must have an attached entity.");
|
||||
return;
|
||||
@@ -33,7 +33,7 @@ namespace Content.Server.Administration.Commands
|
||||
var lgh = int.Parse(args[4]);
|
||||
var fla = int.Parse(args[5]);
|
||||
|
||||
var mapTransform = IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(player.AttachedEntity).GetMapTransform();
|
||||
var mapTransform = IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(playerEntity).GetMapTransform();
|
||||
var coords = new EntityCoordinates(mapTransform.Owner, x, y);
|
||||
|
||||
EntitySystem.Get<ExplosionSystem>().SpawnExplosion(coords, dev, hvy, lgh, fla);
|
||||
|
||||
@@ -5,7 +5,6 @@ using Content.Shared.Administration;
|
||||
using Robust.Shared.Console;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Prototypes;
|
||||
|
||||
namespace Content.Server.Administration.Commands
|
||||
{
|
||||
@@ -48,17 +47,17 @@ namespace Content.Server.Administration.Commands
|
||||
var entityManager = IoCManager.Resolve<IEntityManager>();
|
||||
var entityIds = new HashSet<string>();
|
||||
|
||||
var entitiesWithComponents = components.Select(c => entityManager.GetAllComponents(c).Select(x => x.Owner));
|
||||
var entitiesWithAllComponents = entitiesWithComponents.Skip(1).Aggregate(new HashSet<IEntity>(entitiesWithComponents.First()), (h, e) => { h.IntersectWith(e); return h; });
|
||||
var entitiesWithComponents = components.Select(c => entityManager.GetAllComponents(c).Select(x => x.Owner)).ToArray();
|
||||
var entitiesWithAllComponents = entitiesWithComponents.Skip(1).Aggregate(new HashSet<EntityUid>(entitiesWithComponents.First()), (h, e) => { h.IntersectWith(e); return h; });
|
||||
|
||||
foreach (var entity in entitiesWithAllComponents)
|
||||
{
|
||||
if (IoCManager.Resolve<IEntityManager>().GetComponent<MetaDataComponent>(entity).EntityPrototype == null)
|
||||
if (entityManager.GetComponent<MetaDataComponent>(entity).EntityPrototype is not { } prototypeId)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
entityIds.Add(IoCManager.Resolve<IEntityManager>().GetComponent<MetaDataComponent>(entity).EntityPrototype.ID);
|
||||
entityIds.Add(prototypeId.ID);
|
||||
}
|
||||
|
||||
if (entityIds.Count == 0)
|
||||
|
||||
@@ -27,22 +27,21 @@ namespace Content.Server.Administration.Commands
|
||||
|
||||
public void Execute(IConsoleShell shell, string argStr, string[] args)
|
||||
{
|
||||
var player = shell.Player as IPlayerSession;
|
||||
if (args.Length < 1 && player != null) //Try to heal the users mob if applicable
|
||||
if (args.Length < 1 && shell.Player is IPlayerSession player) //Try to heal the users mob if applicable
|
||||
{
|
||||
shell.WriteLine(Loc.GetString("rejuvenate-command-self-heal-message"));
|
||||
if (player.AttachedEntity == null)
|
||||
if (player.AttachedEntity == default)
|
||||
{
|
||||
shell.WriteLine(Loc.GetString("rejuvenate-command-no-entity-attached-message"));
|
||||
return;
|
||||
}
|
||||
PerformRejuvenate(player.AttachedEntity);
|
||||
PerformRejuvenate(player.AttachedEntity.Value);
|
||||
}
|
||||
|
||||
var entityManager = IoCManager.Resolve<IEntityManager>();
|
||||
foreach (var arg in args)
|
||||
{
|
||||
if(!EntityUid.TryParse(arg, out var uid) || !entityManager.TryGetEntity(uid, out var entity))
|
||||
if (!EntityUid.TryParse(arg, out var entity) || !entityManager.EntityExists(entity))
|
||||
{
|
||||
shell.WriteLine(Loc.GetString("shell-could-not-find-entity",("entity", arg)));
|
||||
continue;
|
||||
@@ -51,9 +50,9 @@ namespace Content.Server.Administration.Commands
|
||||
}
|
||||
}
|
||||
|
||||
public static void PerformRejuvenate(IEntity target)
|
||||
public static void PerformRejuvenate(EntityUid target)
|
||||
{
|
||||
var targetUid = (EntityUid) target;
|
||||
var targetUid = target;
|
||||
var entMan = IoCManager.Resolve<IEntityManager>();
|
||||
entMan.GetComponentOrNull<MobStateComponent>(targetUid)?.UpdateState(0);
|
||||
entMan.GetComponentOrNull<HungerComponent>(targetUid)?.ResetFood();
|
||||
@@ -61,24 +60,24 @@ namespace Content.Server.Administration.Commands
|
||||
|
||||
EntitySystem.Get<StatusEffectsSystem>().TryRemoveAllStatusEffects(target);
|
||||
|
||||
if (IoCManager.Resolve<IEntityManager>().TryGetComponent(target, out FlammableComponent? flammable))
|
||||
if (entMan.TryGetComponent(target, out FlammableComponent? flammable))
|
||||
{
|
||||
EntitySystem.Get<FlammableSystem>().Extinguish(target, flammable);
|
||||
}
|
||||
|
||||
if (IoCManager.Resolve<IEntityManager>().TryGetComponent(target, out DamageableComponent? damageable))
|
||||
if (entMan.TryGetComponent(target, out DamageableComponent? damageable))
|
||||
{
|
||||
EntitySystem.Get<DamageableSystem>().SetAllDamage(damageable, 0);
|
||||
}
|
||||
|
||||
if (IoCManager.Resolve<IEntityManager>().TryGetComponent(target, out CreamPiedComponent? creamPied))
|
||||
if (entMan.TryGetComponent(target, out CreamPiedComponent? creamPied))
|
||||
{
|
||||
EntitySystem.Get<CreamPieSystem>().SetCreamPied(target, creamPied, false);
|
||||
}
|
||||
|
||||
if (IoCManager.Resolve<IEntityManager>().HasComponent<JitteringComponent>(target))
|
||||
if (entMan.HasComponent<JitteringComponent>(target))
|
||||
{
|
||||
IoCManager.Resolve<IEntityManager>().RemoveComponent<JitteringComponent>(target);
|
||||
entMan.RemoveComponent<JitteringComponent>(target);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ namespace Content.Server.Administration.Commands
|
||||
|
||||
if (entityManager.TryGetComponent<EntityStorageComponent>(parent, out var storage))
|
||||
{
|
||||
storage.Remove(entityManager.GetEntity(entityUid));
|
||||
storage.Remove(entityUid);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
using System.Collections.Generic;
|
||||
using Content.Shared.Administration;
|
||||
using Content.Shared.Administration;
|
||||
using Robust.Shared.Console;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
@@ -33,16 +32,17 @@ namespace Content.Server.Administration.Commands
|
||||
|
||||
foreach (var entity in entityManager.GetEntities())
|
||||
{
|
||||
if (checkPrototype && IoCManager.Resolve<IEntityManager>().GetComponent<MetaDataComponent>(entity).EntityPrototype != prototype || IoCManager.Resolve<IEntityManager>().GetComponent<MetaDataComponent>(entity).EntityPrototype == null)
|
||||
var metaData = entityManager.GetComponent<MetaDataComponent>(entity);
|
||||
if (checkPrototype && metaData.EntityPrototype != prototype || metaData.EntityPrototype == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var modified = false;
|
||||
|
||||
foreach (var component in IoCManager.Resolve<IEntityManager>().GetComponents(entity))
|
||||
foreach (var component in entityManager.GetComponents(entity))
|
||||
{
|
||||
if (IoCManager.Resolve<IEntityManager>().GetComponent<MetaDataComponent>(entity).EntityPrototype.Components.ContainsKey(component.Name))
|
||||
if (metaData.EntityPrototype.Components.ContainsKey(component.Name))
|
||||
continue;
|
||||
|
||||
entityManager.RemoveComponent(entity, component);
|
||||
|
||||
@@ -42,9 +42,7 @@ namespace Content.Server.Administration.Commands
|
||||
return;
|
||||
}
|
||||
|
||||
var target = entityManager.GetEntity(eUid);
|
||||
|
||||
if (!IoCManager.Resolve<IEntityManager>().HasComponent<MindComponent>(target))
|
||||
if (!entityManager.HasComponent<MindComponent>(eUid))
|
||||
{
|
||||
shell.WriteLine(Loc.GetString("set-mind-command-target-has-no-mind-message"));
|
||||
return;
|
||||
@@ -69,11 +67,11 @@ namespace Content.Server.Administration.Commands
|
||||
{
|
||||
mind = new Mind.Mind(session.UserId)
|
||||
{
|
||||
CharacterName = IoCManager.Resolve<IEntityManager>().GetComponent<MetaDataComponent>(target).EntityName
|
||||
CharacterName = entityManager.GetComponent<MetaDataComponent>(eUid).EntityName
|
||||
};
|
||||
mind.ChangeOwningPlayer(session.UserId);
|
||||
}
|
||||
mind.TransferTo(target);
|
||||
mind.TransferTo(eUid);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,17 +43,15 @@ namespace Content.Server.Administration.Commands
|
||||
|
||||
var entityManager = IoCManager.Resolve<IEntityManager>();
|
||||
|
||||
var eUid = new EntityUid(entityUid);
|
||||
var target = new EntityUid(entityUid);
|
||||
|
||||
if (!eUid.IsValid() || !entityManager.EntityExists(eUid))
|
||||
if (!target.IsValid() || !entityManager.EntityExists(target))
|
||||
{
|
||||
shell.WriteLine(Loc.GetString("shell-invalid-entity-id"));
|
||||
return;
|
||||
}
|
||||
|
||||
var target = entityManager.GetEntity(eUid);
|
||||
|
||||
if (!IoCManager.Resolve<IEntityManager>().TryGetComponent<InventoryComponent?>(target, out var inventoryComponent))
|
||||
if (!entityManager.TryGetComponent<InventoryComponent?>(target, out var inventoryComponent))
|
||||
{
|
||||
shell.WriteLine(Loc.GetString("shell-target-entity-does-not-have-message",("missing", "inventory")));
|
||||
return;
|
||||
@@ -82,7 +80,7 @@ namespace Content.Server.Administration.Commands
|
||||
|
||||
HumanoidCharacterProfile? profile = null;
|
||||
// Check if we are setting the outfit of a player to respect the preferences
|
||||
if (IoCManager.Resolve<IEntityManager>().TryGetComponent<ActorComponent?>(target, out var actorComponent))
|
||||
if (entityManager.TryGetComponent<ActorComponent?>(target, out var actorComponent))
|
||||
{
|
||||
var userId = actorComponent.PlayerSession.UserId;
|
||||
var preferencesManager = IoCManager.Resolve<IServerPreferencesManager>();
|
||||
@@ -98,15 +96,15 @@ namespace Content.Server.Administration.Commands
|
||||
{
|
||||
continue;
|
||||
}
|
||||
var equipmentEntity = entityManager.SpawnEntity(gearStr, IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(target).Coordinates);
|
||||
var equipmentEntity = entityManager.SpawnEntity(gearStr, entityManager.GetComponent<TransformComponent>(target).Coordinates);
|
||||
if (slot == EquipmentSlotDefines.Slots.IDCARD &&
|
||||
IoCManager.Resolve<IEntityManager>().TryGetComponent<PDAComponent?>(equipmentEntity, out var pdaComponent) &&
|
||||
entityManager.TryGetComponent<PDAComponent?>(equipmentEntity, out var pdaComponent) &&
|
||||
pdaComponent.ContainedID != null)
|
||||
{
|
||||
pdaComponent.ContainedID.FullName = IoCManager.Resolve<IEntityManager>().GetComponent<MetaDataComponent>(target).EntityName;
|
||||
pdaComponent.ContainedID.FullName = entityManager.GetComponent<MetaDataComponent>(target).EntityName;
|
||||
}
|
||||
|
||||
inventoryComponent.Equip(slot, IoCManager.Resolve<IEntityManager>().GetComponent<ItemComponent>(equipmentEntity), false);
|
||||
inventoryComponent.Equip(slot, entityManager.GetComponent<ItemComponent>(equipmentEntity), false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,19 +53,19 @@ namespace Content.Server.Administration.Commands
|
||||
}
|
||||
else
|
||||
{
|
||||
if (player.Status != SessionStatus.InGame || player.AttachedEntity == null)
|
||||
if (player.Status != SessionStatus.InGame || player.AttachedEntity is not {Valid: true} playerEntity)
|
||||
{
|
||||
shell.WriteLine("You are not in-game!");
|
||||
return;
|
||||
}
|
||||
|
||||
var mapManager = IoCManager.Resolve<IMapManager>();
|
||||
var currentMap = IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(player.AttachedEntity).MapID;
|
||||
var currentGrid = IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(player.AttachedEntity).GridID;
|
||||
var currentMap = entMan.GetComponent<TransformComponent>(playerEntity).MapID;
|
||||
var currentGrid = entMan.GetComponent<TransformComponent>(playerEntity).GridID;
|
||||
|
||||
var found = entMan.EntityQuery<WarpPointComponent>(true)
|
||||
.Where(p => p.Location == location)
|
||||
.Select(p => IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(p.Owner).Coordinates)
|
||||
.Select(p => entMan.GetComponent<TransformComponent>(p.Owner).Coordinates)
|
||||
.OrderBy(p => p, Comparer<EntityCoordinates>.Create((a, b) =>
|
||||
{
|
||||
// Sort so that warp points on the same grid/map are first.
|
||||
@@ -113,8 +113,8 @@ namespace Content.Server.Administration.Commands
|
||||
|
||||
if (found.GetGridId(entMan) != GridId.Invalid)
|
||||
{
|
||||
IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(player.AttachedEntity).Coordinates = found;
|
||||
if (IoCManager.Resolve<IEntityManager>().TryGetComponent(player.AttachedEntity, out IPhysBody? physics))
|
||||
entMan.GetComponent<TransformComponent>(playerEntity).Coordinates = found;
|
||||
if (entMan.TryGetComponent(playerEntity, out IPhysBody? physics))
|
||||
{
|
||||
physics.LinearVelocity = Vector2.Zero;
|
||||
}
|
||||
|
||||
@@ -57,8 +57,7 @@ public partial class AdminLogSystem
|
||||
EntityUid? entityId = properties[key] switch
|
||||
{
|
||||
EntityUid id => id,
|
||||
IEntity entity => entity,
|
||||
IPlayerSession {AttachedEntityUid: { }} session => session.AttachedEntityUid.Value,
|
||||
IPlayerSession {AttachedEntity: {Valid: true}} session => session.AttachedEntity,
|
||||
IComponent component => component.Owner,
|
||||
_ => null
|
||||
};
|
||||
|
||||
@@ -12,10 +12,12 @@ public class PlayerSessionConverter : AdminLogConverter<SerializablePlayer>
|
||||
{
|
||||
writer.WriteStartObject();
|
||||
|
||||
if (value.Player.AttachedEntity != null)
|
||||
if (value.Player.AttachedEntity is {Valid: true} playerEntity)
|
||||
{
|
||||
writer.WriteNumber("id", (int) (EntityUid) value.Player.AttachedEntity);
|
||||
writer.WriteString("name", IoCManager.Resolve<IEntityManager>().GetComponent<MetaDataComponent>(value.Player.AttachedEntity).EntityName);
|
||||
var entityManager = IoCManager.Resolve<IEntityManager>();
|
||||
|
||||
writer.WriteNumber("id", (int) value.Player.AttachedEntity);
|
||||
writer.WriteString("name", entityManager.GetComponent<MetaDataComponent>(playerEntity).EntityName);
|
||||
}
|
||||
|
||||
writer.WriteString("player", value.Player.UserId.UserId);
|
||||
|
||||
@@ -12,8 +12,9 @@ namespace Content.Server.Administration.UI
|
||||
public sealed class SetOutfitEui : BaseEui
|
||||
{
|
||||
[Dependency] private readonly IAdminManager _adminManager = default!;
|
||||
private readonly IEntity _target;
|
||||
public SetOutfitEui(IEntity entity)
|
||||
private readonly EntityUid _target;
|
||||
|
||||
public SetOutfitEui(EntityUid entity)
|
||||
{
|
||||
_target = entity;
|
||||
IoCManager.InjectDependencies(this);
|
||||
|
||||
@@ -19,7 +19,7 @@ namespace Content.Server.Alert.Click
|
||||
{
|
||||
var ps = EntitySystem.Get<SharedPullingSystem>();
|
||||
var playerTarget = ps.GetPulled(args.Player);
|
||||
if (playerTarget != null && IoCManager.Resolve<IEntityManager>().TryGetComponent(playerTarget, out SharedPullableComponent playerPullable))
|
||||
if (playerTarget != default && IoCManager.Resolve<IEntityManager>().TryGetComponent(playerTarget, out SharedPullableComponent playerPullable))
|
||||
{
|
||||
ps.TryStopPull(playerPullable);
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ namespace Content.Server.Alert.Commands
|
||||
if (!CommandUtils.TryGetAttachedEntityByUsernameOrId(shell, target, player, out attachedEntity)) return;
|
||||
}
|
||||
|
||||
if (!IoCManager.Resolve<IEntityManager>().TryGetComponent(attachedEntity, out ServerAlertsComponent? alertsComponent))
|
||||
if (!IoCManager.Resolve<IEntityManager>().TryGetComponent(attachedEntity.Value, out ServerAlertsComponent? alertsComponent))
|
||||
{
|
||||
shell.WriteLine("user has no alerts component");
|
||||
return;
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user