namespace Content.Server.Ghost
{
- public sealed partial class GhostSystem : SharedGhostSystem
+ public sealed class GhostSystem : SharedGhostSystem
{
- [Dependency] private readonly IGameTiming _gameTiming = default!;
- [Dependency] private readonly IPlayerManager _playerManager = default!;
- [Dependency] private readonly GameTicker _ticker = default!;
- [Dependency] private readonly SharedMindSystem _mindSystem = default!;
[Dependency] private readonly SharedActionsSystem _actions = default!;
- [Dependency] private readonly VisibilitySystem _visibilitySystem = default!;
- [Dependency] private readonly EntityLookupSystem _lookup = default!;
+ [Dependency] private readonly SharedEyeSystem _eye = default!;
[Dependency] private readonly FollowerSystem _followerSystem = default!;
+ [Dependency] private readonly IGameTiming _gameTiming = default!;
+ [Dependency] private readonly JobSystem _jobs = default!;
+ [Dependency] private readonly EntityLookupSystem _lookup = default!;
+ [Dependency] private readonly MindSystem _minds = default!;
+ [Dependency] private readonly SharedMindSystem _mindSystem = default!;
[Dependency] private readonly MobStateSystem _mobState = default!;
- [Dependency] private readonly SharedEyeSystem _eye = default!;
[Dependency] private readonly SharedPhysicsSystem _physics = default!;
- [Dependency] private readonly MindSystem _minds = default!;
- [Dependency] private readonly JobSystem _jobs = default!;
+ [Dependency] private readonly IPlayerManager _playerManager = default!;
+ [Dependency] private readonly GameTicker _ticker = default!;
+ [Dependency] private readonly TransformSystem _transformSystem = default!;
+ [Dependency] private readonly VisibilitySystem _visibilitySystem = default!;
public override void Initialize()
{
if (args.Handled)
return;
- var ents = _lookup.GetEntitiesInRange(args.Performer, component.BooRadius);
+ var entities = _lookup.GetEntitiesInRange(args.Performer, component.BooRadius);
var booCounter = 0;
- foreach (var ent in ents)
+ foreach (var ent in entities)
{
var handled = DoGhostBooEvent(ent);
private void OnRelayMoveInput(EntityUid uid, GhostOnMoveComponent component, ref MoveInputEvent args)
{
// Let's not ghost if our mind is visiting...
- if (EntityManager.HasComponent<VisitingMindComponent>(uid))
+ if (HasComp<VisitingMindComponent>(uid))
return;
if (!_minds.TryGetMind(uid, out var mindId, out var mind) || mind.IsVisitingEntity)
private void OnGhostStartup(EntityUid uid, GhostComponent component, ComponentStartup args)
{
// Allow this entity to be seen by other ghosts.
- var visibility = EntityManager.EnsureComponent<VisibilityComponent>(uid);
+ var visibility = EnsureComp<VisibilityComponent>(uid);
if (_ticker.RunLevel != GameRunLevel.PostRound)
{
- _visibilitySystem.AddLayer(visibility, (int) VisibilityFlags.Ghost, false);
- _visibilitySystem.RemoveLayer(visibility, (int) VisibilityFlags.Normal, false);
- _visibilitySystem.RefreshVisibility(visibility);
+ _visibilitySystem.AddLayer(uid, visibility, (int) VisibilityFlags.Ghost, false);
+ _visibilitySystem.RemoveLayer(uid, visibility, (int) VisibilityFlags.Normal, false);
+ _visibilitySystem.RefreshVisibility(uid, visibilityComponent: visibility);
}
- if (EntityManager.TryGetComponent(uid, out EyeComponent? eye))
- {
- _eye.SetVisibilityMask(uid, eye.VisibilityMask | (int) VisibilityFlags.Ghost, eye);
- }
+ SetCanSeeGhosts(uid, true);
var time = _gameTiming.CurTime;
component.TimeOfDeath = time;
private void OnGhostShutdown(EntityUid uid, GhostComponent component, ComponentShutdown args)
{
// Perf: If the entity is deleting itself, no reason to change these back.
- if (!Terminating(uid))
+ if (Terminating(uid))
+ return;
+
+ // Entity can't be seen by ghosts anymore.
+ if (TryComp(uid, out VisibilityComponent? visibility))
{
- // Entity can't be seen by ghosts anymore.
- if (EntityManager.TryGetComponent(uid, out VisibilityComponent? visibility))
- {
- _visibilitySystem.RemoveLayer(visibility, (int) VisibilityFlags.Ghost, false);
- _visibilitySystem.AddLayer(visibility, (int) VisibilityFlags.Normal, false);
- _visibilitySystem.RefreshVisibility(visibility);
- }
+ _visibilitySystem.RemoveLayer(uid, visibility, (int) VisibilityFlags.Ghost, false);
+ _visibilitySystem.AddLayer(uid, visibility, (int) VisibilityFlags.Normal, false);
+ _visibilitySystem.RefreshVisibility(uid, visibilityComponent: visibility);
+ }
- // Entity can't see ghosts anymore.
- if (EntityManager.TryGetComponent(uid, out EyeComponent? eye))
- {
- _eye.SetVisibilityMask(uid, eye.VisibilityMask & ~(int) VisibilityFlags.Ghost, eye);
- }
+ // Entity can't see ghosts anymore.
+ SetCanSeeGhosts(uid, false);
- _actions.RemoveAction(uid, component.ActionEntity);
- }
+ _actions.RemoveAction(uid, component.ActionEntity);
+ }
+
+ private void SetCanSeeGhosts(EntityUid uid, bool canSee, EyeComponent? eyeComponent = null)
+ {
+ if (!Resolve(uid, ref eyeComponent, false))
+ return;
+
+ if (canSee)
+ _eye.SetVisibilityMask(uid, eyeComponent.VisibilityMask | (int) VisibilityFlags.Ghost, eyeComponent);
+ else
+ _eye.SetVisibilityMask(uid, eyeComponent.VisibilityMask & ~(int) VisibilityFlags.Ghost, eyeComponent);
}
private void OnGhostExamine(EntityUid uid, GhostComponent component, ExaminedEvent args)
args.PushMarkup(deathTimeInfo);
}
+ #region Ghost Deletion
+
private void OnMindRemovedMessage(EntityUid uid, GhostComponent component, MindRemovedMessage args)
{
DeleteEntity(uid);
DeleteEntity(uid);
}
- private void OnGhostWarpsRequest(GhostWarpsRequestEvent msg, EntitySessionEventArgs args)
+ private void DeleteEntity(EntityUid uid)
{
- if (args.SenderSession.AttachedEntity is not {Valid: true} entity ||
- !EntityManager.HasComponent<GhostComponent>(entity))
- {
- Log.Warning($"User {args.SenderSession.Name} sent a {nameof(GhostWarpsRequestEvent)} without being a ghost.");
+ if (Deleted(uid) || Terminating(uid))
return;
- }
- var response = new GhostWarpsResponseEvent(GetPlayerWarps(entity).Concat(GetLocationWarps()).ToList());
- RaiseNetworkEvent(response, args.SenderSession.ConnectedClient);
+ QueueDel(uid);
}
+ #endregion
+
private void OnGhostReturnToBodyRequest(GhostReturnToBodyRequest msg, EntitySessionEventArgs args)
{
- if (args.SenderSession.AttachedEntity is not {Valid: true} attached ||
- !EntityManager.TryGetComponent(attached, out GhostComponent? ghost) ||
- !ghost.CanReturnToBody ||
- !EntityManager.TryGetComponent(attached, out ActorComponent? actor))
+ if (args.SenderSession.AttachedEntity is not {Valid: true} attached
+ || !TryComp(attached, out GhostComponent? ghost)
+ || !ghost.CanReturnToBody
+ || !TryComp(attached, out ActorComponent? actor))
{
Log.Warning($"User {args.SenderSession.Name} sent an invalid {nameof(GhostReturnToBodyRequest)}");
return;
_mindSystem.UnVisit(actor.PlayerSession);
}
+ #region Warp
+
+ private void OnGhostWarpsRequest(GhostWarpsRequestEvent msg, EntitySessionEventArgs args)
+ {
+ if (args.SenderSession.AttachedEntity is not {Valid: true} entity
+ || !HasComp<GhostComponent>(entity))
+ {
+ Log.Warning($"User {args.SenderSession.Name} sent a {nameof(GhostWarpsRequestEvent)} without being a ghost.");
+ return;
+ }
+
+ var response = new GhostWarpsResponseEvent(GetPlayerWarps(entity).Concat(GetLocationWarps()).ToList());
+ RaiseNetworkEvent(response, args.SenderSession.ConnectedClient);
+ }
+
private void OnGhostWarpToTargetRequest(GhostWarpToTargetRequestEvent msg, EntitySessionEventArgs args)
{
- if (args.SenderSession.AttachedEntity is not {Valid: true} attached ||
- !EntityManager.TryGetComponent(attached, out GhostComponent? ghost))
+ if (args.SenderSession.AttachedEntity is not {Valid: true} attached
+ || !TryComp(attached, out GhostComponent? _))
{
Log.Warning($"User {args.SenderSession.Name} tried to warp to {msg.Target} without being a ghost.");
return;
var target = GetEntity(msg.Target);
- if (!EntityManager.EntityExists(target))
+ if (!Exists(target))
{
Log.Warning($"User {args.SenderSession.Name} tried to warp to an invalid entity id: {msg.Target}");
return;
}
- if (TryComp(target, out WarpPointComponent? warp) && warp.Follow
- || HasComp<MobStateComponent>(target))
+ if ((TryComp(target, out WarpPointComponent? warp) && warp.Follow) || HasComp<MobStateComponent>(target))
{
- _followerSystem.StartFollowingEntity(attached, target);
- return;
+ _followerSystem.StartFollowingEntity(attached, target);
+ return;
}
var xform = Transform(attached);
- xform.Coordinates = Transform(target).Coordinates;
- xform.AttachToGridOrMap();
+ _transformSystem.SetCoordinates(attached, xform, Transform(target).Coordinates);
+ _transformSystem.AttachToGridOrMap(attached, xform);
if (TryComp(attached, out PhysicsComponent? physics))
_physics.SetLinearVelocity(attached, Vector2.Zero, body: physics);
}
- private void DeleteEntity(EntityUid uid)
- {
- if (Deleted(uid) || Terminating(uid))
- return;
-
- QueueDel(uid);
- }
-
private IEnumerable<GhostWarp> GetLocationWarps()
{
var allQuery = AllEntityQuery<WarpPointComponent>();
while (allQuery.MoveNext(out var uid, out var warp))
{
if (warp.Location != null)
- {
yield return new GhostWarp(GetNetEntity(uid), warp.Location, true);
- }
}
}
{
foreach (var player in _playerManager.Sessions)
{
- if (player.AttachedEntity is {Valid: true} attached)
- {
- if (attached == except) continue;
+ if (player.AttachedEntity is not {Valid: true} attached)
+ continue;
- TryComp<MindContainerComponent>(attached, out var mind);
+ if (attached == except) continue;
- var jobName = _jobs.MindTryGetJobName(mind?.Mind);
- var playerInfo = $"{EntityManager.GetComponent<MetaDataComponent>(attached).EntityName} ({jobName})";
+ TryComp<MindContainerComponent>(attached, out var mind);
- if (_mobState.IsAlive(attached) || _mobState.IsCritical(attached))
- yield return new GhostWarp(GetNetEntity(attached), playerInfo, false);
- }
+ var jobName = _jobs.MindTryGetJobName(mind?.Mind);
+ var playerInfo = $"{Comp<MetaDataComponent>(attached).EntityName} ({jobName})";
+
+ if (_mobState.IsAlive(attached) || _mobState.IsCritical(attached))
+ yield return new GhostWarp(GetNetEntity(attached), playerInfo, false);
}
}
+ #endregion
+
private void OnEntityStorageInsertAttempt(EntityUid uid, GhostComponent comp, ref InsertIntoEntityStorageAttemptEvent args)
{
args.Cancelled = true;
/// </summary>
public void MakeVisible(bool visible)
{
- foreach (var (_, vis) in EntityQuery<GhostComponent, VisibilityComponent>())
+ var entityQuery = EntityQueryEnumerator<GhostComponent, VisibilityComponent>();
+ while (entityQuery.MoveNext(out var uid, out _, out var vis))
{
if (visible)
{
- _visibilitySystem.AddLayer(vis, (int) VisibilityFlags.Normal, false);
- _visibilitySystem.RemoveLayer(vis, (int) VisibilityFlags.Ghost, false);
+ _visibilitySystem.AddLayer(uid, vis, (int) VisibilityFlags.Normal, false);
+ _visibilitySystem.RemoveLayer(uid, vis, (int) VisibilityFlags.Ghost, false);
}
else
{
- _visibilitySystem.AddLayer(vis, (int) VisibilityFlags.Ghost, false);
- _visibilitySystem.RemoveLayer(vis, (int) VisibilityFlags.Normal, false);
+ _visibilitySystem.AddLayer(uid, vis, (int) VisibilityFlags.Ghost, false);
+ _visibilitySystem.RemoveLayer(uid, vis, (int) VisibilityFlags.Normal, false);
}
- _visibilitySystem.RefreshVisibility(vis);
+ _visibilitySystem.RefreshVisibility(uid, visibilityComponent: vis);
}
}
public string Command => "toggleghosts";
public string Description => "Toggles ghost visibility";
public string Help => $"{Command}";
+
public void Execute(IConsoleShell shell, string argStr, string[] args)
{
if (shell.Player == null)
if (uid == null
|| !entityManager.HasComponent<GhostComponent>(uid)
|| !entityManager.TryGetComponent<EyeComponent>(uid, out var eyeComponent))
- {
return;
- }
entityManager.System<EyeSystem>().SetVisibilityMask(uid.Value, eyeComponent.VisibilityMask ^ (int) VisibilityFlags.Ghost, eyeComponent);
}