Fix being able to teleport with the ghost warp menu while alive (#3246)

This commit is contained in:
DrSmugleaf
2021-02-16 01:55:09 +01:00
committed by GitHub
parent 3703ae134b
commit 17a224ad2c
2 changed files with 32 additions and 11 deletions

View File

@@ -1,3 +1,4 @@
#nullable enable
using Content.Client.GameObjects.Components.Observer; using Content.Client.GameObjects.Components.Observer;
using Robust.Client.Console; using Robust.Client.Console;
using Robust.Client.UserInterface; using Robust.Client.UserInterface;
@@ -16,17 +17,19 @@ namespace Content.Client.UserInterface
private readonly Button _ghostRoles = new() {Text = Loc.GetString("Ghost Roles")}; private readonly Button _ghostRoles = new() {Text = Loc.GetString("Ghost Roles")};
private readonly GhostComponent _owner; private readonly GhostComponent _owner;
public GhostTargetWindow? TargetWindow { get; private set; }
public GhostGui(GhostComponent owner) public GhostGui(GhostComponent owner)
{ {
IoCManager.InjectDependencies(this); IoCManager.InjectDependencies(this);
_owner = owner; _owner = owner;
var targetMenu = new GhostTargetWindow(owner); TargetWindow = new GhostTargetWindow(owner);
MouseFilter = MouseFilterMode.Ignore; MouseFilter = MouseFilterMode.Ignore;
_ghostWarp.OnPressed += args => targetMenu.Populate(); _ghostWarp.OnPressed += args => TargetWindow.Populate();
_returnToBody.OnPressed += args => owner.SendReturnToBodyMessage(); _returnToBody.OnPressed += args => owner.SendReturnToBodyMessage();
_ghostRoles.OnPressed += _ => IoCManager.Resolve<IClientConsoleHost>().RemoteExecuteCommand(null, "ghostroles"); _ghostRoles.OnPressed += _ => IoCManager.Resolve<IClientConsoleHost>().RemoteExecuteCommand(null, "ghostroles");
@@ -49,7 +52,7 @@ namespace Content.Client.UserInterface
} }
} }
internal class GhostTargetWindow : SS14Window public class GhostTargetWindow : SS14Window
{ {
protected override Vector2? CustomSize => (300, 450); protected override Vector2? CustomSize => (300, 450);
private readonly GhostComponent _owner; private readonly GhostComponent _owner;

View File

@@ -71,7 +71,8 @@ namespace Content.Server.GameObjects.Components.Observer
switch (message) switch (message)
{ {
case ReturnToBodyComponentMessage _: case ReturnToBodyComponentMessage:
{
if (!Owner.TryGetComponent(out IActorComponent? actor) || if (!Owner.TryGetComponent(out IActorComponent? actor) ||
!CanReturnToBody) !CanReturnToBody)
{ {
@@ -85,6 +86,7 @@ namespace Content.Server.GameObjects.Components.Observer
Owner.Delete(); Owner.Delete();
} }
break; break;
}
case ReturnToCloneComponentMessage _: case ReturnToCloneComponentMessage _:
if (Owner.TryGetComponent(out VisitingMindComponent? mind)) if (Owner.TryGetComponent(out VisitingMindComponent? mind))
@@ -93,16 +95,31 @@ namespace Content.Server.GameObjects.Components.Observer
} }
break; break;
case GhostWarpRequestMessage warp: case GhostWarpRequestMessage warp:
{
if (session?.AttachedEntity != Owner)
{
break;
}
if (warp.PlayerTarget != default) if (warp.PlayerTarget != default)
{ {
foreach (var player in _playerManager.GetAllPlayers()) if (!Owner.EntityManager.TryGetEntity(warp.PlayerTarget, out var entity))
{ {
if (player.AttachedEntity != null && warp.PlayerTarget == player.AttachedEntity.Uid) break;
{
session!.AttachedEntity!.Transform.Coordinates =
player.AttachedEntity.Transform.Coordinates;
}
} }
if (!entity.TryGetComponent(out IActorComponent? actor))
{
break;
}
if (!_playerManager.TryGetSessionByChannel(actor.playerSession.ConnectedClient, out var player) ||
player.AttachedEntity != entity)
{
break;
}
Owner.Transform.Coordinates = entity.Transform.Coordinates;
} }
else else
{ {
@@ -110,11 +127,12 @@ namespace Content.Server.GameObjects.Components.Observer
{ {
if (warp.WarpName == warpPoint.Location) if (warp.WarpName == warpPoint.Location)
{ {
session!.AttachedEntity!.Transform.Coordinates = warpPoint.Owner.Transform.Coordinates ; Owner.Transform.Coordinates = warpPoint.Owner.Transform.Coordinates;
} }
} }
} }
break; break;
}
case GhostRequestPlayerNameData _: case GhostRequestPlayerNameData _:
var playerNames = new Dictionary<EntityUid, string>(); var playerNames = new Dictionary<EntityUid, string>();
foreach (var names in _playerManager.GetAllPlayers()) foreach (var names in _playerManager.GetAllPlayers())