World target action uses entity coordinates (#12484)
This commit is contained in:
@@ -100,26 +100,24 @@ public sealed class DecalPlacementSystem : EntitySystem
|
||||
if (args.Handled)
|
||||
return;
|
||||
|
||||
if (!_mapMan.TryFindGridAt(args.Target, out var grid))
|
||||
if (args.Target.GetGridUid(EntityManager) == null)
|
||||
return;
|
||||
|
||||
args.Handled = true;
|
||||
|
||||
var coords = EntityCoordinates.FromMap(grid.GridEntityId, args.Target, EntityManager);
|
||||
|
||||
if (args.Snap)
|
||||
{
|
||||
var newPos = new Vector2(
|
||||
(float) (MathF.Round(coords.X - 0.5f, MidpointRounding.AwayFromZero) + 0.5),
|
||||
(float) (MathF.Round(coords.Y - 0.5f, MidpointRounding.AwayFromZero) + 0.5)
|
||||
(float) (MathF.Round(args.Target.X - 0.5f, MidpointRounding.AwayFromZero) + 0.5),
|
||||
(float) (MathF.Round(args.Target.Y - 0.5f, MidpointRounding.AwayFromZero) + 0.5)
|
||||
);
|
||||
coords = coords.WithPosition(newPos);
|
||||
args.Target = args.Target.WithPosition(newPos);
|
||||
}
|
||||
|
||||
coords = coords.Offset(new Vector2(-0.5f, -0.5f));
|
||||
args.Target = args.Target.Offset(new Vector2(-0.5f, -0.5f));
|
||||
|
||||
var decal = new Decal(coords.Position, args.DecalId, args.Color, Angle.FromDegrees(args.Rotation), args.ZIndex, args.Cleanable);
|
||||
RaiseNetworkEvent(new RequestDecalPlacementEvent(decal, coords));
|
||||
var decal = new Decal(args.Target.Position, args.DecalId, args.Color, Angle.FromDegrees(args.Rotation), args.ZIndex, args.Cleanable);
|
||||
RaiseNetworkEvent(new RequestDecalPlacementEvent(decal, args.Target));
|
||||
}
|
||||
|
||||
private void OnFillSlot(FillActionSlotEvent ev)
|
||||
|
||||
@@ -205,7 +205,7 @@ public sealed class ActionUIController : UIController, IOnStateChanged<GameplayS
|
||||
if (_actionsSystem == null)
|
||||
return false;
|
||||
|
||||
var coords = args.Coordinates.ToMap(_entities);
|
||||
var coords = args.Coordinates;
|
||||
|
||||
if (!_actionsSystem.ValidateWorldTarget(user, coords, action))
|
||||
{
|
||||
|
||||
@@ -39,7 +39,7 @@ public sealed class MagicSystem : EntitySystem
|
||||
[Dependency] private readonly SharedActionsSystem _actionsSystem = default!;
|
||||
[Dependency] private readonly DoAfterSystem _doAfter = default!;
|
||||
[Dependency] private readonly GunSystem _gunSystem = default!;
|
||||
|
||||
[Dependency] private readonly SharedTransformSystem _transformSystem = default!;
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
@@ -159,7 +159,7 @@ public sealed class MagicSystem : EntitySystem
|
||||
foreach (var pos in GetSpawnPositions(xform, ev.Pos))
|
||||
{
|
||||
var ent = Spawn(ev.Prototype, pos.SnapToGrid(EntityManager, _mapManager));
|
||||
_gunSystem.ShootProjectile(ent,ev.Target.Position - Transform(ent).MapPosition.Position, ev.Performer);
|
||||
_gunSystem.ShootProjectile(ent, ev.Target.Position - Transform(ent).Coordinates.Position, ev.Performer);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -232,9 +232,9 @@ public sealed class MagicSystem : EntitySystem
|
||||
|
||||
var transform = Transform(args.Performer);
|
||||
|
||||
if (transform.MapID != args.Target.MapId) return;
|
||||
if (transform.MapID != args.Target.GetMapId(EntityManager)) return;
|
||||
|
||||
transform.WorldPosition = args.Target.Position;
|
||||
_transformSystem.SetCoordinates(args.Performer, args.Target);
|
||||
transform.AttachToGridOrMap();
|
||||
SoundSystem.Play(args.BlinkSound.GetSound(), Filter.Pvs(args.Target), args.Performer, AudioParams.Default.WithVolume(args.BlinkVolume));
|
||||
args.Handled = true;
|
||||
@@ -323,14 +323,14 @@ public sealed class MagicSystem : EntitySystem
|
||||
/// offset
|
||||
/// </remarks>
|
||||
/// <param name="entityEntries"> The list of Entities to spawn in</param>
|
||||
/// <param name="mapCoords"> Map Coordinates where the entities will spawn</param>
|
||||
/// <param name="entityCoords"> Map Coordinates where the entities will spawn</param>
|
||||
/// <param name="lifetime"> Check to see if the entities should self delete</param>
|
||||
/// <param name="offsetVector2"> A Vector2 offset that the entities will spawn in</param>
|
||||
private void SpawnSpellHelper(List<EntitySpawnEntry> entityEntries, MapCoordinates mapCoords, float? lifetime, Vector2 offsetVector2)
|
||||
private void SpawnSpellHelper(List<EntitySpawnEntry> entityEntries, EntityCoordinates entityCoords, float? lifetime, Vector2 offsetVector2)
|
||||
{
|
||||
var getProtos = EntitySpawnCollection.GetSpawns(entityEntries, _random);
|
||||
|
||||
var offsetCoords = mapCoords;
|
||||
var offsetCoords = entityCoords;
|
||||
foreach (var proto in getProtos)
|
||||
{
|
||||
// TODO: Share this code with instant because they're both doing similar things for positioning.
|
||||
|
||||
@@ -44,7 +44,7 @@ public sealed class RequestPerformActionEvent : EntityEventArgs
|
||||
{
|
||||
public readonly ActionType Action;
|
||||
public readonly EntityUid? EntityTarget;
|
||||
public readonly MapCoordinates? MapTarget;
|
||||
public readonly EntityCoordinates? EntityCoordinatesTarget;
|
||||
|
||||
public RequestPerformActionEvent(InstantAction action)
|
||||
{
|
||||
@@ -57,10 +57,10 @@ public sealed class RequestPerformActionEvent : EntityEventArgs
|
||||
EntityTarget = entityTarget;
|
||||
}
|
||||
|
||||
public RequestPerformActionEvent(WorldTargetAction action, MapCoordinates mapTarget)
|
||||
public RequestPerformActionEvent(WorldTargetAction action, EntityCoordinates entityCoordinatesTarget)
|
||||
{
|
||||
Action = action;
|
||||
MapTarget = mapTarget;
|
||||
EntityCoordinatesTarget = entityCoordinatesTarget;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -102,7 +102,7 @@ public abstract class WorldTargetActionEvent : BaseActionEvent
|
||||
/// <summary>
|
||||
/// The coordinates of the location that the user targeted.
|
||||
/// </summary>
|
||||
public MapCoordinates Target;
|
||||
public EntityCoordinates Target;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -156,27 +156,27 @@ public abstract class SharedActionsSystem : EntitySystem
|
||||
|
||||
case WorldTargetAction worldAction:
|
||||
|
||||
if (ev.MapTarget is not MapCoordinates mapTarget)
|
||||
if (ev.EntityCoordinatesTarget is not EntityCoordinates entityCoordinatesTarget)
|
||||
{
|
||||
Logger.Error($"Attempted to perform a map-targeted action without a target! Action: {worldAction.DisplayName}");
|
||||
Logger.Error($"Attempted to perform a world-targeted action without a target! Action: {worldAction.DisplayName}");
|
||||
return;
|
||||
}
|
||||
|
||||
_rotateToFaceSystem.TryFaceCoordinates(user, mapTarget.Position);
|
||||
_rotateToFaceSystem.TryFaceCoordinates(user, entityCoordinatesTarget.Position);
|
||||
|
||||
if (!ValidateWorldTarget(user, mapTarget, worldAction))
|
||||
if (!ValidateWorldTarget(user, entityCoordinatesTarget, worldAction))
|
||||
return;
|
||||
|
||||
if (act.Provider == null)
|
||||
_adminLogger.Add(LogType.Action,
|
||||
$"{ToPrettyString(user):user} is performing the {name:action} action targeted at {mapTarget:target}.");
|
||||
$"{ToPrettyString(user):user} is performing the {name:action} action targeted at {entityCoordinatesTarget:target}.");
|
||||
else
|
||||
_adminLogger.Add(LogType.Action,
|
||||
$"{ToPrettyString(user):user} is performing the {name:action} action (provided by {ToPrettyString(act.Provider.Value):provider}) targeted at {mapTarget:target}.");
|
||||
$"{ToPrettyString(user):user} is performing the {name:action} action (provided by {ToPrettyString(act.Provider.Value):provider}) targeted at {entityCoordinatesTarget:target}.");
|
||||
|
||||
if (worldAction.Event != null)
|
||||
{
|
||||
worldAction.Event.Target = mapTarget;
|
||||
worldAction.Event.Target = entityCoordinatesTarget;
|
||||
performEvent = worldAction.Event;
|
||||
}
|
||||
|
||||
@@ -243,11 +243,8 @@ public abstract class SharedActionsSystem : EntitySystem
|
||||
return _interactionSystem.CanAccessViaStorage(user, target);
|
||||
}
|
||||
|
||||
public bool ValidateWorldTarget(EntityUid user, MapCoordinates coords, WorldTargetAction action)
|
||||
public bool ValidateWorldTarget(EntityUid user, EntityCoordinates coords, WorldTargetAction action)
|
||||
{
|
||||
if (coords == MapCoordinates.Nullspace)
|
||||
return false;
|
||||
|
||||
if (action.CheckCanInteract && !_actionBlockerSystem.CanInteract(user, null))
|
||||
return false;
|
||||
|
||||
@@ -256,13 +253,13 @@ public abstract class SharedActionsSystem : EntitySystem
|
||||
// even if we don't check for obstructions, we may still need to check the range.
|
||||
var xform = Transform(user);
|
||||
|
||||
if (xform.MapID != coords.MapId)
|
||||
if (xform.MapID != coords.GetMapId(EntityManager))
|
||||
return false;
|
||||
|
||||
if (action.Range <= 0)
|
||||
return true;
|
||||
|
||||
return (xform.WorldPosition - coords.Position).Length <= action.Range;
|
||||
return coords.InRange(EntityManager, Transform(user).Coordinates, action.Range);
|
||||
}
|
||||
|
||||
return _interactionSystem.InRangeUnobstructed(user, coords, range: action.Range);
|
||||
|
||||
Reference in New Issue
Block a user