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