Ghost Teleporting (#2071)
* Fix? Nuked everything and put my code back in, hope everything works * Nullable fix? * nullable fix electric boogaloo * Haha nullable error go brrr send help * Cleanup and fix not clearing the button list * Remove unnecessary brackets and parentheses Co-authored-by: DrSmugleaf <DrSmugleaf@users.noreply.github.com>
This commit is contained in:
@@ -1,23 +1,29 @@
|
||||
using Content.Server.GameObjects.Components.Mobs;
|
||||
using Content.Server.Mobs;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Content.Server.GameObjects.Components.Markers;
|
||||
using Content.Server.Players;
|
||||
using Content.Server.GameObjects.Components.Mobs;
|
||||
using Content.Server.Mobs;
|
||||
using Content.Shared.GameObjects.Components.Observer;
|
||||
using Robust.Server.GameObjects;
|
||||
using Robust.Server.GameObjects.Components;
|
||||
using Robust.Server.Interfaces.GameObjects;
|
||||
using Robust.Server.Interfaces.Player;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Interfaces.GameObjects;
|
||||
using Robust.Shared.Interfaces.Network;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Players;
|
||||
using Robust.Shared.ViewVariables;
|
||||
|
||||
#nullable enable
|
||||
namespace Content.Server.GameObjects.Components.Observer
|
||||
{
|
||||
[RegisterComponent]
|
||||
public class GhostComponent : SharedGhostComponent
|
||||
{
|
||||
private bool _canReturnToBody = true;
|
||||
|
||||
[Dependency] private readonly IPlayerManager _playerManager = default!;
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
public bool CanReturnToBody
|
||||
{
|
||||
@@ -38,7 +44,7 @@ namespace Content.Server.GameObjects.Components.Observer
|
||||
|
||||
public override ComponentState GetComponentState() => new GhostComponentState(CanReturnToBody);
|
||||
|
||||
public override void HandleMessage(ComponentMessage message, IComponent component)
|
||||
public override void HandleMessage(ComponentMessage message, IComponent? component)
|
||||
{
|
||||
base.HandleMessage(message, component);
|
||||
|
||||
@@ -51,40 +57,88 @@ namespace Content.Server.GameObjects.Components.Observer
|
||||
case PlayerDetachedMsg msg:
|
||||
msg.OldPlayer.VisibilityMask &= ~(int) VisibilityFlags.Ghost;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public override void HandleNetworkMessage(ComponentMessage message, INetChannel netChannel,
|
||||
ICommonSession session = null)
|
||||
public override void HandleNetworkMessage(ComponentMessage message, INetChannel netChannel, ICommonSession? session = null!)
|
||||
{
|
||||
base.HandleNetworkMessage(message, netChannel, session);
|
||||
|
||||
switch (message)
|
||||
{
|
||||
case ReturnToBodyComponentMessage reenter:
|
||||
if (!Owner.TryGetComponent(out IActorComponent actor) || !CanReturnToBody) break;
|
||||
if (netChannel == null || netChannel == actor.playerSession.ConnectedClient)
|
||||
case ReturnToBodyComponentMessage _:
|
||||
if (!Owner.TryGetComponent(out IActorComponent? actor) ||
|
||||
!CanReturnToBody)
|
||||
{
|
||||
actor.playerSession.ContentData().Mind.UnVisit();
|
||||
Owner.Delete();
|
||||
break;
|
||||
}
|
||||
|
||||
if (netChannel == actor.playerSession.ConnectedClient)
|
||||
{
|
||||
var o = actor.playerSession.ContentData()!.Mind;
|
||||
o?.UnVisit();
|
||||
Owner.Delete();
|
||||
}
|
||||
break;
|
||||
case ReturnToCloneComponentMessage reenter:
|
||||
case ReturnToCloneComponentMessage _:
|
||||
|
||||
if (Owner.TryGetComponent(out VisitingMindComponent mind))
|
||||
if (Owner.TryGetComponent(out VisitingMindComponent? mind))
|
||||
{
|
||||
Owner.EntityManager.EventBus.RaiseEvent(EventSource.Local, new GhostReturnMessage(mind.Mind));
|
||||
}
|
||||
|
||||
break;
|
||||
default:
|
||||
case GhostWarpRequestMessage warp:
|
||||
if (warp.PlayerTarget != default)
|
||||
{
|
||||
foreach (var player in _playerManager.GetAllPlayers())
|
||||
{
|
||||
if (player.AttachedEntity != null && warp.PlayerTarget == player.AttachedEntity.Uid)
|
||||
{
|
||||
session?.AttachedEntity!.Transform.Coordinates =
|
||||
player.AttachedEntity.Transform.Coordinates;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach (var warpPoint in FindWaypoints())
|
||||
{
|
||||
if (warp.WarpName == warpPoint.Location)
|
||||
{
|
||||
session?.AttachedEntity!.Transform.Coordinates = warpPoint.Owner.Transform.Coordinates ;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case GhostRequestPlayerNameData _:
|
||||
var playerNames = new Dictionary<EntityUid, string>();
|
||||
foreach (var names in _playerManager.GetAllPlayers())
|
||||
{
|
||||
if (names.AttachedEntity != null && names.UserId != netChannel.UserId)
|
||||
{
|
||||
playerNames.Add(names.AttachedEntity.Uid,names.AttachedEntity.Name);
|
||||
}
|
||||
}
|
||||
SendNetworkMessage(new GhostReplyPlayerNameData(playerNames));
|
||||
break;
|
||||
case GhostRequestWarpPointData _:
|
||||
var warpPoints = FindWaypoints();
|
||||
var warpName = new List<string>();
|
||||
foreach (var point in warpPoints)
|
||||
{
|
||||
warpName.Add(point.Location);
|
||||
}
|
||||
SendNetworkMessage(new GhostReplyWarpPointData(warpName));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private List<WarpPointComponent> FindWaypoints()
|
||||
{
|
||||
var comp = IoCManager.Resolve<IComponentManager>();
|
||||
return comp.EntityQuery<WarpPointComponent>().ToList();
|
||||
}
|
||||
|
||||
public class GhostReturnMessage : EntitySystemMessage
|
||||
{
|
||||
public GhostReturnMessage(Mind sender)
|
||||
|
||||
Reference in New Issue
Block a user