Make ghost warp use AttachToGridOrMap() (#11069)
This commit is contained in:
@@ -1,6 +1,8 @@
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using Content.Server.Ghost.Components;
|
||||||
using Content.Server.Warps;
|
using Content.Server.Warps;
|
||||||
using Content.Shared.Administration;
|
using Content.Shared.Administration;
|
||||||
|
using Content.Shared.Follower;
|
||||||
using Robust.Server.Player;
|
using Robust.Server.Player;
|
||||||
using Robust.Shared.Console;
|
using Robust.Shared.Console;
|
||||||
using Robust.Shared.Enums;
|
using Robust.Shared.Enums;
|
||||||
@@ -56,8 +58,8 @@ namespace Content.Server.Administration.Commands
|
|||||||
|
|
||||||
var found = entMan.EntityQuery<WarpPointComponent>(true)
|
var found = entMan.EntityQuery<WarpPointComponent>(true)
|
||||||
.Where(p => p.Location == location)
|
.Where(p => p.Location == location)
|
||||||
.Select(p => entMan.GetComponent<TransformComponent>(p.Owner).Coordinates)
|
.Select(p => (entMan.GetComponent<TransformComponent>(p.Owner).Coordinates, p.Follow))
|
||||||
.OrderBy(p => p, Comparer<EntityCoordinates>.Create((a, b) =>
|
.OrderBy(p => p.Item1, Comparer<EntityCoordinates>.Create((a, b) =>
|
||||||
{
|
{
|
||||||
// Sort so that warp points on the same grid/map are first.
|
// Sort so that warp points on the same grid/map are first.
|
||||||
// So if you have two maps loaded with the same warp points,
|
// So if you have two maps loaded with the same warp points,
|
||||||
@@ -102,18 +104,26 @@ namespace Content.Server.Administration.Commands
|
|||||||
}))
|
}))
|
||||||
.FirstOrDefault();
|
.FirstOrDefault();
|
||||||
|
|
||||||
var entityUid = found.GetGridUid(entMan);
|
var (coords, follow) = found;
|
||||||
if (entityUid != EntityUid.Invalid)
|
|
||||||
|
if (coords.EntityId == EntityUid.Invalid)
|
||||||
{
|
{
|
||||||
entMan.GetComponent<TransformComponent>(playerEntity).Coordinates = found;
|
shell.WriteError("That location does not exist!");
|
||||||
if (entMan.TryGetComponent(playerEntity, out IPhysBody? physics))
|
return;
|
||||||
{
|
|
||||||
physics.LinearVelocity = Vector2.Zero;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
|
||||||
|
if (follow && entMan.HasComponent<GhostComponent>(playerEntity))
|
||||||
{
|
{
|
||||||
shell.WriteLine("That location does not exist!");
|
entMan.EntitySysManager.GetEntitySystem<FollowerSystem>().StartFollowingEntity(playerEntity, coords.EntityId);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var xform = entMan.GetComponent<TransformComponent>(playerEntity);
|
||||||
|
xform.Coordinates = coords;
|
||||||
|
xform.AttachToGridOrMap();
|
||||||
|
if (entMan.TryGetComponent(playerEntity, out IPhysBody? physics))
|
||||||
|
{
|
||||||
|
physics.LinearVelocity = Vector2.Zero;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -184,13 +184,26 @@ namespace Content.Server.Ghost
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (FindLocation(msg.Name) is { } warp)
|
// TODO: why the fuck is this using the name instead of an entity id or something?
|
||||||
|
// at least it makes sense for the warp command to need to use names, but not this.
|
||||||
|
|
||||||
|
if (FindLocation(msg.Name) is not { } warp)
|
||||||
{
|
{
|
||||||
EntityManager.GetComponent<TransformComponent>(ghost.Owner).Coordinates = EntityManager.GetComponent<TransformComponent>(warp.Owner).Coordinates;
|
Logger.Warning($"User {args.SenderSession.Name} tried to warp to an invalid warp: {msg.Name}");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (warp.Follow)
|
||||||
|
{
|
||||||
|
_followerSystem.StartFollowingEntity(attached, warp.Owner);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Logger.Warning($"User {args.SenderSession.Name} tried to warp to an invalid warp: {msg.Name}");
|
var xform = Transform(attached);
|
||||||
|
xform.Coordinates = Transform(warp.Owner).Coordinates;
|
||||||
|
xform.AttachToGridOrMap();
|
||||||
|
if (TryComp(attached, out PhysicsComponent? physics))
|
||||||
|
physics.LinearVelocity = Vector2.Zero;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnGhostWarpToTargetRequest(GhostWarpToTargetRequestEvent msg, EntitySessionEventArgs args)
|
private void OnGhostWarpToTargetRequest(GhostWarpToTargetRequestEvent msg, EntitySessionEventArgs args)
|
||||||
|
|||||||
@@ -7,5 +7,11 @@ namespace Content.Server.Warps
|
|||||||
public sealed class WarpPointComponent : Component
|
public sealed class WarpPointComponent : Component
|
||||||
{
|
{
|
||||||
[ViewVariables(VVAccess.ReadWrite)] [DataField("location")] public string? Location { get; set; }
|
[ViewVariables(VVAccess.ReadWrite)] [DataField("location")] public string? Location { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// If true, ghosts warping to this entity will begin following it.
|
||||||
|
/// </summary>
|
||||||
|
[DataField("follow")]
|
||||||
|
public readonly bool Follow = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,6 +13,7 @@
|
|||||||
price: 2000
|
price: 2000
|
||||||
- type: CargoSellBlacklist
|
- type: CargoSellBlacklist
|
||||||
- type: WarpPoint
|
- type: WarpPoint
|
||||||
|
follow: true
|
||||||
location: nuke disk
|
location: nuke disk
|
||||||
|
|
||||||
- type: entity
|
- type: entity
|
||||||
|
|||||||
Reference in New Issue
Block a user