Replace every usage of GridCoordinates with EntityCoordinates (#2021)
* Update RobustToolbox * Transition direct type usages * More updates * Fix invalid use of to map * Update RobustToolbox * Fix dropping items * Rename name usages of "GridCoordinates" to "EntityCoordinates" * Revert "Update RobustToolbox" This reverts commit 9f334a17c5908ded0043a63158bb671e4aa3f346. * Revert "Update RobustToolbox" This reverts commit 3a9c8cfa3606fa501aa84407796d2ad920853a09. # Conflicts: # RobustToolbox * Fix cursed IMapGrid method usage. * GridTileLookupTest now uses EntityCoordinates Co-authored-by: Víctor Aguilera Puerto <6766154+Zumorica@users.noreply.github.com> Co-authored-by: Víctor Aguilera Puerto <zddm@outlook.es>
This commit is contained in:
@@ -39,7 +39,7 @@ namespace Content.Shared.GameObjects.Components.Movement
|
||||
/// </summary>
|
||||
(Vector2 walking, Vector2 sprinting) VelocityDir { get; }
|
||||
|
||||
GridCoordinates LastPosition { get; set; }
|
||||
EntityCoordinates LastPosition { get; set; }
|
||||
|
||||
float StepSoundDistance { get; set; }
|
||||
|
||||
|
||||
@@ -132,7 +132,7 @@ namespace Content.Shared.GameObjects.Components.Movement
|
||||
}
|
||||
}
|
||||
|
||||
public abstract GridCoordinates LastPosition { get; set; }
|
||||
public abstract EntityCoordinates LastPosition { get; set; }
|
||||
public abstract float StepSoundDistance { get; set; }
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -38,9 +38,9 @@ namespace Content.Shared.GameObjects.Components.Movement
|
||||
[Serializable, NetSerializable]
|
||||
public class TeleportMessage : ComponentMessage
|
||||
{
|
||||
public readonly GridCoordinates Target;
|
||||
public readonly EntityCoordinates Target;
|
||||
|
||||
public TeleportMessage(GridCoordinates target)
|
||||
public TeleportMessage(EntityCoordinates target)
|
||||
{
|
||||
Target = target;
|
||||
}
|
||||
|
||||
@@ -31,23 +31,23 @@ namespace Content.Shared.GameObjects.Components
|
||||
{
|
||||
// To see what these do look at DoAfter and DoAfterEventArgs
|
||||
public byte ID { get; }
|
||||
|
||||
|
||||
public TimeSpan StartTime { get; }
|
||||
|
||||
public GridCoordinates UserGrid { get; }
|
||||
|
||||
public GridCoordinates TargetGrid { get; }
|
||||
|
||||
|
||||
public EntityCoordinates UserGrid { get; }
|
||||
|
||||
public EntityCoordinates TargetGrid { get; }
|
||||
|
||||
public EntityUid TargetUid { get; }
|
||||
|
||||
public float Delay { get; }
|
||||
|
||||
|
||||
// TODO: The other ones need predicting
|
||||
public bool BreakOnUserMove { get; }
|
||||
|
||||
|
||||
public bool BreakOnTargetMove { get; }
|
||||
|
||||
public DoAfterMessage(byte id, GridCoordinates userGrid, GridCoordinates targetGrid, TimeSpan startTime, float delay, bool breakOnUserMove, bool breakOnTargetMove, EntityUid targetUid = default)
|
||||
|
||||
public DoAfterMessage(byte id, EntityCoordinates userGrid, EntityCoordinates targetGrid, TimeSpan startTime, float delay, bool breakOnUserMove, bool breakOnTargetMove, EntityUid targetUid = default)
|
||||
{
|
||||
ID = id;
|
||||
UserGrid = userGrid;
|
||||
@@ -59,4 +59,4 @@ namespace Content.Shared.GameObjects.Components
|
||||
TargetUid = targetUid;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,11 +11,11 @@ namespace Content.Shared.GameObjects.EntitySystemMessages
|
||||
[Serializable, NetSerializable]
|
||||
public class DragDropMessage : EntitySystemMessage
|
||||
{
|
||||
public GridCoordinates DropLocation { get; }
|
||||
public EntityCoordinates DropLocation { get; }
|
||||
public EntityUid Dropped { get; }
|
||||
public EntityUid Target { get; }
|
||||
|
||||
public DragDropMessage(GridCoordinates dropLocation, EntityUid dropped, EntityUid target)
|
||||
public DragDropMessage(EntityCoordinates dropLocation, EntityUid dropped, EntityUid target)
|
||||
{
|
||||
DropLocation = dropLocation;
|
||||
Dropped = dropped;
|
||||
|
||||
@@ -47,7 +47,7 @@ namespace Content.Shared.GameObjects.EntitySystems
|
||||
|
||||
public class ExplosionEventArgs : EventArgs
|
||||
{
|
||||
public GridCoordinates Source { get; set; }
|
||||
public EntityCoordinates Source { get; set; }
|
||||
public IEntity Target { get; set; }
|
||||
public ExplosionSeverity Severity { get; set; }
|
||||
}
|
||||
@@ -71,7 +71,7 @@ namespace Content.Shared.GameObjects.EntitySystems
|
||||
owner.Delete();
|
||||
}
|
||||
|
||||
public void HandleExplosion(GridCoordinates source, IEntity target, ExplosionSeverity severity)
|
||||
public void HandleExplosion(EntityCoordinates source, IEntity target, ExplosionSeverity severity)
|
||||
{
|
||||
var eventArgs = new ExplosionEventArgs
|
||||
{
|
||||
|
||||
@@ -22,7 +22,7 @@ namespace Content.Shared.GameObjects.EntitySystems
|
||||
/// <summary>
|
||||
/// Position to start building.
|
||||
/// </summary>
|
||||
public readonly GridCoordinates Location;
|
||||
public readonly EntityCoordinates Location;
|
||||
|
||||
/// <summary>
|
||||
/// The construction prototype to start building.
|
||||
@@ -36,7 +36,7 @@ namespace Content.Shared.GameObjects.EntitySystems
|
||||
/// </summary>
|
||||
public readonly int Ack;
|
||||
|
||||
public TryStartStructureConstructionMessage(GridCoordinates loc, string prototypeName, Angle angle, int ack)
|
||||
public TryStartStructureConstructionMessage(EntityCoordinates loc, string prototypeName, Angle angle, int ack)
|
||||
{
|
||||
Location = loc;
|
||||
PrototypeName = prototypeName;
|
||||
|
||||
@@ -5,7 +5,6 @@ using Content.Shared.Physics;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Shared.GameObjects.Systems;
|
||||
using Robust.Shared.Interfaces.GameObjects;
|
||||
using Robust.Shared.Interfaces.Map;
|
||||
using Robust.Shared.Interfaces.Physics;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Localization;
|
||||
@@ -21,7 +20,6 @@ namespace Content.Shared.GameObjects.EntitySystems
|
||||
public class SharedInteractionSystem : EntitySystem
|
||||
{
|
||||
[Dependency] private readonly IPhysicsManager _physicsManager = default!;
|
||||
[Dependency] private readonly IMapManager _mapManager = default!;
|
||||
|
||||
public const float InteractionRange = 2;
|
||||
public const float InteractionRangeSquared = InteractionRange * InteractionRange;
|
||||
@@ -284,7 +282,7 @@ namespace Content.Shared.GameObjects.EntitySystems
|
||||
/// </returns>
|
||||
public bool InRangeUnobstructed(
|
||||
IEntity origin,
|
||||
GridCoordinates other,
|
||||
EntityCoordinates other,
|
||||
float range = InteractionRange,
|
||||
CollisionGroup collisionMask = CollisionGroup.Impassable,
|
||||
Ignored predicate = null,
|
||||
@@ -292,7 +290,7 @@ namespace Content.Shared.GameObjects.EntitySystems
|
||||
bool popup = false)
|
||||
{
|
||||
var originPosition = origin.Transform.MapPosition;
|
||||
var otherPosition = other.ToMap(_mapManager);
|
||||
var otherPosition = other.ToMap(EntityManager);
|
||||
predicate ??= e => e == origin;
|
||||
|
||||
var inRange = InRangeUnobstructed(originPosition, otherPosition, range, collisionMask, predicate, ignoreInsideBlocker);
|
||||
@@ -522,7 +520,7 @@ namespace Content.Shared.GameObjects.EntitySystems
|
||||
|
||||
if (target == null)
|
||||
{
|
||||
otherPosition = args.ClickLocation.ToMap(_mapManager);
|
||||
otherPosition = args.ClickLocation.ToMap(EntityManager);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -5,7 +5,6 @@ using Content.Shared.GameObjects.Components.Movement;
|
||||
using Content.Shared.Physics;
|
||||
using Content.Shared.Physics.Pull;
|
||||
using Robust.Shared.Configuration;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.GameObjects.Components;
|
||||
using Robust.Shared.GameObjects.Systems;
|
||||
using Robust.Shared.Input;
|
||||
@@ -58,7 +57,7 @@ namespace Content.Shared.GameObjects.EntitySystems
|
||||
collidable.EnsureController<MoverController>();
|
||||
|
||||
var weightless = !transform.Owner.HasComponent<MovementIgnoreGravityComponent>() &&
|
||||
_physicsManager.IsWeightless(transform.GridPosition);
|
||||
_physicsManager.IsWeightless(transform.Coordinates);
|
||||
|
||||
if (weightless)
|
||||
{
|
||||
|
||||
@@ -21,7 +21,7 @@ namespace Content.Shared.Interfaces.GameObjects.Components
|
||||
public class AfterInteractEventArgs : EventArgs
|
||||
{
|
||||
public IEntity User { get; set; }
|
||||
public GridCoordinates ClickLocation { get; set; }
|
||||
public EntityCoordinates ClickLocation { get; set; }
|
||||
public IEntity Target { get; set; }
|
||||
public bool CanReach { get; set; }
|
||||
}
|
||||
@@ -55,7 +55,7 @@ namespace Content.Shared.Interfaces.GameObjects.Components
|
||||
/// <summary>
|
||||
/// Location that the user clicked outside of their interaction range.
|
||||
/// </summary>
|
||||
public GridCoordinates ClickLocation { get; }
|
||||
public EntityCoordinates ClickLocation { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Is the click location close enough to reach by the player? This does not check for obstructions, just that the target is within
|
||||
@@ -63,7 +63,7 @@ namespace Content.Shared.Interfaces.GameObjects.Components
|
||||
/// </summary>
|
||||
public bool CanReach { get; }
|
||||
|
||||
public AfterInteractMessage(IEntity user, IEntity itemInHand, IEntity attacked, GridCoordinates clickLocation, bool canReach)
|
||||
public AfterInteractMessage(IEntity user, IEntity itemInHand, IEntity attacked, EntityCoordinates clickLocation, bool canReach)
|
||||
{
|
||||
User = user;
|
||||
Attacked = attacked;
|
||||
|
||||
@@ -20,20 +20,19 @@ namespace Content.Shared.Interfaces.GameObjects.Components
|
||||
|
||||
public class AttackEventArgs : EventArgs
|
||||
{
|
||||
public AttackEventArgs(IEntity user, GridCoordinates clickLocation, bool wideAttack, EntityUid target = default)
|
||||
public AttackEventArgs(IEntity user, EntityCoordinates clickLocation, bool wideAttack, EntityUid target = default)
|
||||
{
|
||||
User = user;
|
||||
ClickLocation = clickLocation;
|
||||
WideAttack = wideAttack;
|
||||
Target = target;
|
||||
|
||||
IEntity? targetEntity = null;
|
||||
IoCManager.Resolve<IEntityManager>()?.TryGetEntity(Target, out targetEntity);
|
||||
IoCManager.Resolve<IEntityManager>().TryGetEntity(Target, out var targetEntity);
|
||||
TargetEntity = targetEntity;
|
||||
}
|
||||
|
||||
public IEntity User { get; }
|
||||
public GridCoordinates ClickLocation { get; }
|
||||
public EntityCoordinates ClickLocation { get; }
|
||||
public bool WideAttack { get; }
|
||||
public EntityUid Target { get; }
|
||||
public IEntity? TargetEntity { get; }
|
||||
|
||||
@@ -42,7 +42,7 @@ namespace Content.Shared.Interfaces.GameObjects.Components
|
||||
/// <param name="dropLocation">The location where <see cref="dropped"/> is being dropped.</param>
|
||||
/// <param name="dropped">The entity that is being dragged and dropped.</param>
|
||||
/// <param name="target">The entity that <see cref="dropped"/> is being dropped onto.</param>
|
||||
public DragDropEventArgs(IEntity user, GridCoordinates dropLocation, IEntity dropped, IEntity target)
|
||||
public DragDropEventArgs(IEntity user, EntityCoordinates dropLocation, IEntity dropped, IEntity target)
|
||||
{
|
||||
User = user;
|
||||
DropLocation = dropLocation;
|
||||
@@ -58,7 +58,7 @@ namespace Content.Shared.Interfaces.GameObjects.Components
|
||||
/// <summary>
|
||||
/// The location where <see cref="Dropped"/> is being dropped.
|
||||
/// </summary>
|
||||
public GridCoordinates DropLocation { get; }
|
||||
public EntityCoordinates DropLocation { get; }
|
||||
|
||||
/// <summary>
|
||||
/// The entity that is being dragged and dropped.
|
||||
|
||||
@@ -29,7 +29,7 @@ namespace Content.Shared.Interfaces.GameObjects.Components
|
||||
public class InteractUsingEventArgs : EventArgs, ITargetedInteractEventArgs
|
||||
{
|
||||
public IEntity User { get; set; }
|
||||
public GridCoordinates ClickLocation { get; set; }
|
||||
public EntityCoordinates ClickLocation { get; set; }
|
||||
public IEntity Using { get; set; }
|
||||
public IEntity Target { get; set; }
|
||||
}
|
||||
@@ -63,9 +63,9 @@ namespace Content.Shared.Interfaces.GameObjects.Components
|
||||
/// <summary>
|
||||
/// The original location that was clicked by the user.
|
||||
/// </summary>
|
||||
public GridCoordinates ClickLocation { get; }
|
||||
public EntityCoordinates ClickLocation { get; }
|
||||
|
||||
public InteractUsingMessage(IEntity user, IEntity itemInHand, IEntity attacked, GridCoordinates clickLocation)
|
||||
public InteractUsingMessage(IEntity user, IEntity itemInHand, IEntity attacked, EntityCoordinates clickLocation)
|
||||
{
|
||||
User = user;
|
||||
ItemInHand = itemInHand;
|
||||
|
||||
@@ -16,14 +16,14 @@ namespace Content.Shared.Interfaces.GameObjects.Components
|
||||
|
||||
public class LandEventArgs : EventArgs
|
||||
{
|
||||
public LandEventArgs(IEntity user, GridCoordinates landingLocation)
|
||||
public LandEventArgs(IEntity user, EntityCoordinates landingLocation)
|
||||
{
|
||||
User = user;
|
||||
LandingLocation = landingLocation;
|
||||
}
|
||||
|
||||
public IEntity User { get; }
|
||||
public GridCoordinates LandingLocation { get; }
|
||||
public EntityCoordinates LandingLocation { get; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -50,9 +50,9 @@ namespace Content.Shared.Interfaces.GameObjects.Components
|
||||
/// <summary>
|
||||
/// Location where the item landed.
|
||||
/// </summary>
|
||||
public GridCoordinates LandLocation { get; }
|
||||
public EntityCoordinates LandLocation { get; }
|
||||
|
||||
public LandMessage(IEntity user, IEntity thrown, GridCoordinates landLocation)
|
||||
public LandMessage(IEntity user, IEntity thrown, EntityCoordinates landLocation)
|
||||
{
|
||||
User = user;
|
||||
Thrown = thrown;
|
||||
|
||||
@@ -24,7 +24,7 @@ namespace Content.Shared.Interfaces.GameObjects.Components
|
||||
{
|
||||
public IEntity User { get; set; }
|
||||
public IEntity Using { get; set; }
|
||||
public GridCoordinates ClickLocation { get; set; }
|
||||
public EntityCoordinates ClickLocation { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -56,9 +56,9 @@ namespace Content.Shared.Interfaces.GameObjects.Components
|
||||
/// <summary>
|
||||
/// Location that the user clicked outside of their interaction range.
|
||||
/// </summary>
|
||||
public GridCoordinates ClickLocation { get; }
|
||||
public EntityCoordinates ClickLocation { get; }
|
||||
|
||||
public RangedInteractMessage(IEntity user, IEntity itemInHand, IEntity attacked, GridCoordinates clickLocation)
|
||||
public RangedInteractMessage(IEntity user, IEntity itemInHand, IEntity attacked, EntityCoordinates clickLocation)
|
||||
{
|
||||
User = user;
|
||||
ItemInHand = itemInHand;
|
||||
|
||||
@@ -23,7 +23,7 @@ namespace Content.Shared.Interfaces
|
||||
/// <param name="coordinates">Location on a grid that the message floats up from.</param>
|
||||
/// <param name="viewer">The client attached entity that the message is being sent to.</param>
|
||||
/// <param name="message">Text contents of the message.</param>
|
||||
void PopupMessage(GridCoordinates coordinates, IEntity viewer, string message);
|
||||
void PopupMessage(EntityCoordinates coordinates, IEntity viewer, string message);
|
||||
|
||||
/// <summary>
|
||||
/// Makes a string of text float up from a client's cursor.
|
||||
@@ -64,7 +64,7 @@ namespace Content.Shared.Interfaces
|
||||
/// <param name="coordinates">Location on a grid that the message floats up from.</param>
|
||||
/// <param name="viewer">The client attached entity that the message is being sent to.</param>
|
||||
/// <param name="message">Text contents of the message.</param>
|
||||
public static void PopupMessage(this GridCoordinates coordinates, IEntity viewer, string message)
|
||||
public static void PopupMessage(this EntityCoordinates coordinates, IEntity viewer, string message)
|
||||
{
|
||||
var notifyManager = IoCManager.Resolve<ISharedNotifyManager>();
|
||||
notifyManager.PopupMessage(coordinates, viewer, message);
|
||||
|
||||
@@ -45,33 +45,36 @@ namespace Content.Shared.Maps
|
||||
/// <summary>
|
||||
/// Attempts to get the turf at a certain coordinates or null if no such turf is found.
|
||||
/// </summary>
|
||||
public static TileRef? GetTileRef(this GridCoordinates coordinates)
|
||||
public static TileRef? GetTileRef(this EntityCoordinates coordinates, IEntityManager? entityManager = null, IMapManager? mapManager = null)
|
||||
{
|
||||
if (!coordinates.GridID.IsValid())
|
||||
entityManager ??= IoCManager.Resolve<IEntityManager>();
|
||||
|
||||
if (!coordinates.IsValid(entityManager))
|
||||
return null;
|
||||
|
||||
var mapManager = IoCManager.Resolve<IMapManager>();
|
||||
mapManager ??= IoCManager.Resolve<IMapManager>();
|
||||
|
||||
if (!mapManager.TryGetGrid(coordinates.GridID, out var grid))
|
||||
if (!mapManager.TryGetGrid(coordinates.GetGridId(entityManager), out var grid))
|
||||
return null;
|
||||
|
||||
if (!grid.TryGetTileRef(coordinates.ToMapIndices(mapManager), out var tile))
|
||||
if (!grid.TryGetTileRef(coordinates.ToMapIndices(entityManager, mapManager), out var tile))
|
||||
return null;
|
||||
|
||||
return tile;
|
||||
}
|
||||
|
||||
public static bool TryGetTileRef(this GridCoordinates coordinates, [NotNullWhen(true)] out TileRef? turf)
|
||||
public static bool TryGetTileRef(this EntityCoordinates coordinates, [NotNullWhen(true)] out TileRef? turf)
|
||||
{
|
||||
return (turf = coordinates.GetTileRef()) != null;
|
||||
}
|
||||
|
||||
public static bool PryTile(this GridCoordinates coordinates,
|
||||
IMapManager? mapManager = null, ITileDefinitionManager? tileDefinitionManager = null, IEntityManager? entityManager = null)
|
||||
public static bool PryTile(this EntityCoordinates coordinates, IEntityManager? entityManager = null,
|
||||
IMapManager? mapManager = null)
|
||||
{
|
||||
entityManager ??= IoCManager.Resolve<IEntityManager>();
|
||||
mapManager ??= IoCManager.Resolve<IMapManager>();
|
||||
|
||||
return coordinates.ToMapIndices(mapManager).PryTile(coordinates.GridID);
|
||||
return coordinates.ToMapIndices(entityManager, mapManager).PryTile(coordinates.GetGridId(entityManager));
|
||||
}
|
||||
|
||||
public static bool PryTile(this MapIndices indices, GridId gridId,
|
||||
@@ -109,7 +112,7 @@ namespace Content.Shared.Maps
|
||||
var half = mapGrid.TileSize / 2f;
|
||||
|
||||
//Actually spawn the relevant tile item at the right position and give it some random offset.
|
||||
var tileItem = entityManager.SpawnEntity(tileDef.ItemDropPrototypeName, indices.ToGridCoordinates(mapManager, tileRef.GridIndex).Offset(new Vector2(half, half)));
|
||||
var tileItem = entityManager.SpawnEntity(tileDef.ItemDropPrototypeName, indices.ToEntityCoordinates(mapManager, tileRef.GridIndex).Offset(new Vector2(half, half)));
|
||||
tileItem.RandomOffset(0.25f);
|
||||
return true;
|
||||
}
|
||||
@@ -147,9 +150,11 @@ namespace Content.Shared.Maps
|
||||
return false;
|
||||
}
|
||||
|
||||
public static GridCoordinates GridPosition(this TileRef turf)
|
||||
public static EntityCoordinates GridPosition(this TileRef turf, IMapManager? mapManager = null)
|
||||
{
|
||||
return new GridCoordinates(turf.X, turf.Y, turf.GridIndex);
|
||||
mapManager ??= IoCManager.Resolve<IMapManager>();
|
||||
|
||||
return turf.GridIndices.ToEntityCoordinates(mapManager, turf.GridIndex);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -15,7 +15,7 @@ namespace Content.Shared.Physics
|
||||
public void Move(Vector2 velocityDirection, float speed)
|
||||
{
|
||||
if (ControlledComponent?.Owner.HasComponent<MovementIgnoreGravityComponent>() == false &&
|
||||
IoCManager.Resolve<IPhysicsManager>().IsWeightless(ControlledComponent.Owner.Transform.GridPosition))
|
||||
IoCManager.Resolve<IPhysicsManager>().IsWeightless(ControlledComponent.Owner.Transform.Coordinates))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ namespace Content.Shared.Physics
|
||||
public void Move(Vector2 velocityDirection, float speed)
|
||||
{
|
||||
if (ControlledComponent?.Owner.HasComponent<MovementIgnoreGravityComponent>() == false
|
||||
&& _physicsManager.IsWeightless(ControlledComponent.Owner.Transform.GridPosition))
|
||||
&& _physicsManager.IsWeightless(ControlledComponent.Owner.Transform.Coordinates))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ using System;
|
||||
using Content.Shared.GameObjects.EntitySystems;
|
||||
using Robust.Shared.Containers;
|
||||
using Robust.Shared.GameObjects.Components;
|
||||
using Robust.Shared.Interfaces.Map;
|
||||
using Robust.Shared.Interfaces.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Maths;
|
||||
@@ -22,7 +22,7 @@ namespace Content.Shared.Physics.Pull
|
||||
|
||||
public bool GettingPulled => _puller != null;
|
||||
|
||||
private GridCoordinates? _movingTo;
|
||||
private EntityCoordinates? _movingTo;
|
||||
|
||||
public ICollidableComponent? Puller => _puller;
|
||||
|
||||
@@ -76,23 +76,23 @@ namespace Content.Shared.Physics.Pull
|
||||
ControlledComponent.TryRemoveController<PullController>();
|
||||
}
|
||||
|
||||
public void TryMoveTo(GridCoordinates from, GridCoordinates to)
|
||||
public void TryMoveTo(EntityCoordinates from, EntityCoordinates to)
|
||||
{
|
||||
if (_puller == null || ControlledComponent == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var mapManager = IoCManager.Resolve<IMapManager>();
|
||||
var entityManager = IoCManager.Resolve<IEntityManager>();
|
||||
|
||||
if (!from.InRange(mapManager, to, SharedInteractionSystem.InteractionRange))
|
||||
if (!from.InRange(entityManager, to, SharedInteractionSystem.InteractionRange))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
ControlledComponent.WakeBody();
|
||||
|
||||
var dist = _puller.Owner.Transform.GridPosition.Position - to.Position;
|
||||
var dist = _puller.Owner.Transform.Coordinates.Position - to.Position;
|
||||
|
||||
if (Math.Sqrt(dist.LengthSquared) > DistBeforeStopPull ||
|
||||
Math.Sqrt(dist.LengthSquared) < 0.25f)
|
||||
@@ -125,7 +125,7 @@ namespace Content.Shared.Physics.Pull
|
||||
}
|
||||
else if (_movingTo.HasValue)
|
||||
{
|
||||
var diff = _movingTo.Value.Position - ControlledComponent.Owner.Transform.GridPosition.Position;
|
||||
var diff = _movingTo.Value.Position - ControlledComponent.Owner.Transform.Coordinates.Position;
|
||||
LinearVelocity = diff.Normalized * 5;
|
||||
}
|
||||
else if (dist.Length > DistBeforePull)
|
||||
@@ -153,7 +153,7 @@ namespace Content.Shared.Physics.Pull
|
||||
return;
|
||||
}
|
||||
|
||||
if (ControlledComponent.Owner.Transform.GridPosition.Position.EqualsApprox(_movingTo.Value.Position, 0.01))
|
||||
if (ControlledComponent.Owner.Transform.Coordinates.Position.EqualsApprox(_movingTo.Value.Position, 0.01))
|
||||
{
|
||||
_movingTo = null;
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ namespace Content.Shared.Physics
|
||||
return;
|
||||
}
|
||||
|
||||
if (_physicsManager.IsWeightless(ControlledComponent.Owner.Transform.GridPosition))
|
||||
if (_physicsManager.IsWeightless(ControlledComponent.Owner.Transform.Coordinates))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ namespace Content.Shared
|
||||
{
|
||||
public abstract void PopupMessage(IEntity source, IEntity viewer, string message);
|
||||
|
||||
public abstract void PopupMessage(GridCoordinates coordinates, IEntity viewer, string message);
|
||||
public abstract void PopupMessage(EntityCoordinates coordinates, IEntity viewer, string message);
|
||||
|
||||
public abstract void PopupMessageCursor(IEntity viewer, string message);
|
||||
|
||||
@@ -50,12 +50,12 @@ namespace Content.Shared
|
||||
#endregion
|
||||
|
||||
public string Message { get; set; }
|
||||
public GridCoordinates Coordinates;
|
||||
public EntityCoordinates Coordinates;
|
||||
|
||||
public override void ReadFromBuffer(NetIncomingMessage buffer)
|
||||
{
|
||||
Message = buffer.ReadString();
|
||||
Coordinates = buffer.ReadGridLocalCoordinates();
|
||||
Coordinates = buffer.ReadEntityCoordinates();
|
||||
}
|
||||
|
||||
public override void WriteToBuffer(NetOutgoingMessage buffer)
|
||||
|
||||
58
Content.Shared/Utility/EntityCoordinatesExtensions.cs
Normal file
58
Content.Shared/Utility/EntityCoordinatesExtensions.cs
Normal file
@@ -0,0 +1,58 @@
|
||||
#nullable enable
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Interfaces.GameObjects;
|
||||
using Robust.Shared.Interfaces.Map;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Map;
|
||||
using Vector2 = Robust.Shared.Maths.Vector2;
|
||||
|
||||
namespace Content.Shared.Utility
|
||||
{
|
||||
public static class EntityCoordinatesExtensions
|
||||
{
|
||||
public static EntityCoordinates ToCoordinates(this EntityUid id, Vector2 offset)
|
||||
{
|
||||
return new EntityCoordinates(id, offset);
|
||||
}
|
||||
|
||||
public static EntityCoordinates ToCoordinates(this EntityUid id, float x, float y)
|
||||
{
|
||||
return new EntityCoordinates(id, x, y);
|
||||
}
|
||||
|
||||
public static EntityCoordinates ToCoordinates(this EntityUid id)
|
||||
{
|
||||
return ToCoordinates(id, Vector2.Zero);
|
||||
}
|
||||
|
||||
public static EntityCoordinates ToCoordinates(this IEntity entity, Vector2 offset)
|
||||
{
|
||||
return ToCoordinates(entity.Uid, offset);
|
||||
}
|
||||
|
||||
public static EntityCoordinates ToCoordinates(this IEntity entity, float x, float y)
|
||||
{
|
||||
return new EntityCoordinates(entity.Uid, x, y);
|
||||
}
|
||||
|
||||
public static EntityCoordinates ToCoordinates(this IEntity entity)
|
||||
{
|
||||
return ToCoordinates(entity.Uid, Vector2.Zero);
|
||||
}
|
||||
|
||||
public static EntityCoordinates ToCoordinates(this IMapGrid grid, Vector2 offset)
|
||||
{
|
||||
return ToCoordinates(grid.GridEntityId, offset);
|
||||
}
|
||||
|
||||
public static EntityCoordinates ToCoordinates(this IMapGrid grid, float x, float y)
|
||||
{
|
||||
return ToCoordinates(grid.GridEntityId, x, y);
|
||||
}
|
||||
|
||||
public static EntityCoordinates ToCoordinates(this IMapGrid grid)
|
||||
{
|
||||
return ToCoordinates(grid.GridEntityId, Vector2.Zero);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,5 @@
|
||||
using System.Collections.Generic;
|
||||
using Content.Shared.Maps;
|
||||
using Robust.Shared.Interfaces.Map;
|
||||
using Robust.Shared.Interfaces.Random;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Map;
|
||||
@@ -59,10 +58,8 @@ namespace Content.Shared.Utility
|
||||
/// Gets tiles in random directions from the given one.
|
||||
/// </summary>
|
||||
/// <returns>An enumerable of the adjacent tiles.</returns>
|
||||
public static IEnumerable<TileRef> AdjacentTilesRandom(this GridCoordinates coordinates, bool ignoreSpace = false)
|
||||
public static IEnumerable<TileRef> AdjacentTilesRandom(this EntityCoordinates coordinates, bool ignoreSpace = false)
|
||||
{
|
||||
var mapManager = IoCManager.Resolve<IMapManager>();
|
||||
|
||||
foreach (var direction in RandomDirections())
|
||||
{
|
||||
var adjacent = coordinates.Offset(direction).GetTileRef();
|
||||
@@ -81,7 +78,7 @@ namespace Content.Shared.Utility
|
||||
}
|
||||
}
|
||||
|
||||
public static GridCoordinates Offset(this GridCoordinates coordinates, Direction direction)
|
||||
public static EntityCoordinates Offset(this EntityCoordinates coordinates, Direction direction)
|
||||
{
|
||||
return coordinates.Offset(direction.ToVec());
|
||||
}
|
||||
|
||||
@@ -4,7 +4,6 @@ using Content.Shared.Physics;
|
||||
using Robust.Shared.GameObjects.Systems;
|
||||
using Robust.Shared.Interfaces.GameObjects;
|
||||
using Robust.Shared.Interfaces.GameObjects.Components;
|
||||
using Robust.Shared.Interfaces.Map;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Map;
|
||||
using static Content.Shared.GameObjects.EntitySystems.SharedInteractionSystem;
|
||||
@@ -59,7 +58,7 @@ namespace Content.Shared.Utility
|
||||
|
||||
public static bool InRangeUnobstructed(
|
||||
this IEntity origin,
|
||||
GridCoordinates other,
|
||||
EntityCoordinates other,
|
||||
float range = InteractionRange,
|
||||
CollisionGroup collisionMask = CollisionGroup.Impassable,
|
||||
Ignored predicate = null,
|
||||
@@ -133,7 +132,7 @@ namespace Content.Shared.Utility
|
||||
|
||||
public static bool InRangeUnobstructed(
|
||||
this IComponent origin,
|
||||
GridCoordinates other,
|
||||
EntityCoordinates other,
|
||||
float range = InteractionRange,
|
||||
CollisionGroup collisionMask = CollisionGroup.Impassable,
|
||||
Ignored predicate = null,
|
||||
@@ -210,7 +209,7 @@ namespace Content.Shared.Utility
|
||||
|
||||
public static bool InRangeUnobstructed(
|
||||
this IContainer origin,
|
||||
GridCoordinates other,
|
||||
EntityCoordinates other,
|
||||
float range = InteractionRange,
|
||||
CollisionGroup collisionMask = CollisionGroup.Impassable,
|
||||
Ignored predicate = null,
|
||||
@@ -239,17 +238,17 @@ namespace Content.Shared.Utility
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region GridCoordinates
|
||||
#region EntityCoordinates
|
||||
public static bool InRangeUnobstructed(
|
||||
this GridCoordinates origin,
|
||||
this EntityCoordinates origin,
|
||||
IEntity other,
|
||||
float range = InteractionRange,
|
||||
CollisionGroup collisionMask = CollisionGroup.Impassable,
|
||||
Ignored predicate = null,
|
||||
bool ignoreInsideBlocker = false)
|
||||
{
|
||||
var mapManager = IoCManager.Resolve<IMapManager>();
|
||||
var originPosition = origin.ToMap(mapManager);
|
||||
var entityManager = IoCManager.Resolve<IEntityManager>();
|
||||
var originPosition = origin.ToMap(entityManager);
|
||||
var otherPosition = other.Transform.MapPosition;
|
||||
|
||||
return SharedInteractionSystem.InRangeUnobstructed(originPosition, otherPosition, range, collisionMask,
|
||||
@@ -257,15 +256,15 @@ namespace Content.Shared.Utility
|
||||
}
|
||||
|
||||
public static bool InRangeUnobstructed(
|
||||
this GridCoordinates origin,
|
||||
this EntityCoordinates origin,
|
||||
IComponent other,
|
||||
float range = InteractionRange,
|
||||
CollisionGroup collisionMask = CollisionGroup.Impassable,
|
||||
Ignored predicate = null,
|
||||
bool ignoreInsideBlocker = false)
|
||||
{
|
||||
var mapManager = IoCManager.Resolve<IMapManager>();
|
||||
var originPosition = origin.ToMap(mapManager);
|
||||
var entityManager = IoCManager.Resolve<IEntityManager>();
|
||||
var originPosition = origin.ToMap(entityManager);
|
||||
var otherPosition = other.Owner.Transform.MapPosition;
|
||||
|
||||
return SharedInteractionSystem.InRangeUnobstructed(originPosition, otherPosition, range, collisionMask,
|
||||
@@ -273,15 +272,15 @@ namespace Content.Shared.Utility
|
||||
}
|
||||
|
||||
public static bool InRangeUnobstructed(
|
||||
this GridCoordinates origin,
|
||||
this EntityCoordinates origin,
|
||||
IContainer other,
|
||||
float range = InteractionRange,
|
||||
CollisionGroup collisionMask = CollisionGroup.Impassable,
|
||||
Ignored predicate = null,
|
||||
bool ignoreInsideBlocker = false)
|
||||
{
|
||||
var mapManager = IoCManager.Resolve<IMapManager>();
|
||||
var originPosition = origin.ToMap(mapManager);
|
||||
var entityManager = IoCManager.Resolve<IEntityManager>();
|
||||
var originPosition = origin.ToMap(entityManager);
|
||||
var otherPosition = other.Owner.Transform.MapPosition;
|
||||
|
||||
return SharedInteractionSystem.InRangeUnobstructed(originPosition, otherPosition, range, collisionMask,
|
||||
@@ -289,31 +288,31 @@ namespace Content.Shared.Utility
|
||||
}
|
||||
|
||||
public static bool InRangeUnobstructed(
|
||||
this GridCoordinates origin,
|
||||
GridCoordinates other,
|
||||
this EntityCoordinates origin,
|
||||
EntityCoordinates other,
|
||||
float range = InteractionRange,
|
||||
CollisionGroup collisionMask = CollisionGroup.Impassable,
|
||||
Ignored predicate = null,
|
||||
bool ignoreInsideBlocker = false)
|
||||
{
|
||||
var mapManager = IoCManager.Resolve<IMapManager>();
|
||||
var originPosition = origin.ToMap(mapManager);
|
||||
var otherPosition = other.ToMap(mapManager);
|
||||
var entityManager = IoCManager.Resolve<IEntityManager>();
|
||||
var originPosition = origin.ToMap(entityManager);
|
||||
var otherPosition = other.ToMap(entityManager);
|
||||
|
||||
return SharedInteractionSystem.InRangeUnobstructed(originPosition, otherPosition, range, collisionMask,
|
||||
predicate, ignoreInsideBlocker);
|
||||
}
|
||||
|
||||
public static bool InRangeUnobstructed(
|
||||
this GridCoordinates origin,
|
||||
this EntityCoordinates origin,
|
||||
MapCoordinates other,
|
||||
float range = InteractionRange,
|
||||
CollisionGroup collisionMask = CollisionGroup.Impassable,
|
||||
Ignored predicate = null,
|
||||
bool ignoreInsideBlocker = false)
|
||||
{
|
||||
var mapManager = IoCManager.Resolve<IMapManager>();
|
||||
var originPosition = origin.ToMap(mapManager);
|
||||
var entityManager = IoCManager.Resolve<IEntityManager>();
|
||||
var originPosition = origin.ToMap(entityManager);
|
||||
|
||||
return SharedInteractionSystem.InRangeUnobstructed(originPosition, other, range, collisionMask, predicate,
|
||||
ignoreInsideBlocker);
|
||||
@@ -365,14 +364,14 @@ namespace Content.Shared.Utility
|
||||
|
||||
public static bool InRangeUnobstructed(
|
||||
this MapCoordinates origin,
|
||||
GridCoordinates other,
|
||||
EntityCoordinates other,
|
||||
float range = InteractionRange,
|
||||
CollisionGroup collisionMask = CollisionGroup.Impassable,
|
||||
Ignored predicate = null,
|
||||
bool ignoreInsideBlocker = false)
|
||||
{
|
||||
var mapManager = IoCManager.Resolve<IMapManager>();
|
||||
var otherPosition = other.ToMap(mapManager);
|
||||
var entityManager = IoCManager.Resolve<IEntityManager>();
|
||||
var otherPosition = other.ToMap(entityManager);
|
||||
|
||||
return SharedInteractionSystem.InRangeUnobstructed(origin, otherPosition, range, collisionMask, predicate,
|
||||
ignoreInsideBlocker);
|
||||
|
||||
Reference in New Issue
Block a user