* Initial * Cleanup a bunch of things * some changes dunno * RequireAnchored * a * stuff * more work * Lots of progress * delete pipe visualizer * a * b * pipenet and pipenode cleanup * Fixes * Adds GasValve * Adds GasMiner * Fix stuff, maybe? * More fixes * Ignored components on the client * Adds thermomachine behavior, change a bunch of stuff * Remove Anchored * some work, but it's shitcode * significantly more ECS * ECS AtmosDevices * Cleanup * fix appearance * when the pipe direction is sus * Gas tanks and canisters * pipe anchoring and stuff * coding is my passion * Unsafe pipes take longer to unanchor * turns out we're no longer using eris canisters * Gas canister inserted tank appearance, improvements * Work on a bunch of appearances * Scrubber appearance * Reorganize AtmosphereSystem.Piping into a bunch of different systems * Appearance for vent/scrubber/pump turns off when leaving atmosphere * ThermoMachine appearance * Cleanup gas tanks * Remove passive gate unused imports * remove old canister UI functionality * PipeNode environment air, make everything use AssumeAir instead of merging manually * a * Reorganize atmos to follow new structure * ????? * Canister UI, restructure client * Restructure shared * Fix build tho * listen, at least the canister UI works entirely... * fix build : ) * Atmos device prototypes have names and descriptions * gas canister ui slider doesn't jitter * trinary prototypes * sprite for miners * ignore components * fix YAML * Fix port system doing useless thing * Fix build * fix thinking moment * fix build again because * canister direction * pipenode is a word * GasTank Air will throw on invalid states * fix build.... * Unhardcode volume pump thresholds * Volume pump and filter take time into account * Rename Join/Leave atmosphere events to AtmosDeviceEnabled/Disabled Event * Gas tank node volume is set by initial mixtuer * I love node container
222 lines
8.2 KiB
C#
222 lines
8.2 KiB
C#
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using Content.Server.Ghost.Components;
|
|
using Content.Server.Mind.Components;
|
|
using Content.Server.Players;
|
|
using Content.Server.Visible;
|
|
using Content.Server.Warps;
|
|
using Content.Shared.Examine;
|
|
using Content.Shared.Ghost;
|
|
using JetBrains.Annotations;
|
|
using Robust.Server.GameObjects;
|
|
using Robust.Server.Player;
|
|
using Robust.Shared.GameObjects;
|
|
using Robust.Shared.IoC;
|
|
using Robust.Shared.Localization;
|
|
using Robust.Shared.Log;
|
|
using Robust.Shared.Timing;
|
|
|
|
namespace Content.Server.Ghost
|
|
{
|
|
[UsedImplicitly]
|
|
public class GhostSystem : SharedGhostSystem
|
|
{
|
|
[Dependency] private readonly IGameTiming _gameTiming = default!;
|
|
[Dependency] private readonly IPlayerManager _playerManager = default!;
|
|
|
|
public override void Initialize()
|
|
{
|
|
base.Initialize();
|
|
|
|
SubscribeLocalEvent<GhostComponent, ComponentStartup>(OnGhostStartup);
|
|
SubscribeLocalEvent<GhostComponent, ComponentShutdown>(OnGhostShutdown);
|
|
|
|
SubscribeLocalEvent<GhostComponent, ExaminedEvent>(OnGhostExamine);
|
|
|
|
SubscribeLocalEvent<GhostComponent, MindRemovedMessage>(OnMindRemovedMessage);
|
|
SubscribeLocalEvent<GhostComponent, MindUnvisitedMessage>(OnMindUnvisitedMessage);
|
|
|
|
SubscribeNetworkEvent<GhostWarpsRequestEvent>(OnGhostWarpsRequest);
|
|
SubscribeNetworkEvent<GhostReturnToBodyRequest>(OnGhostReturnToBodyRequest);
|
|
SubscribeNetworkEvent<GhostWarpToLocationRequestEvent>(OnGhostWarpToLocationRequest);
|
|
SubscribeNetworkEvent<GhostWarpToTargetRequestEvent>(OnGhostWarpToTargetRequest);
|
|
}
|
|
|
|
private void OnGhostStartup(EntityUid uid, GhostComponent component, ComponentStartup args)
|
|
{
|
|
// Allow this entity to be seen by other ghosts.
|
|
if (component.Owner.TryGetComponent(out VisibilityComponent? visibility))
|
|
{
|
|
visibility.Layer |= (int) VisibilityFlags.Ghost;
|
|
visibility.Layer &= ~(int) VisibilityFlags.Normal;
|
|
}
|
|
|
|
if (component.Owner.TryGetComponent(out EyeComponent? eye))
|
|
{
|
|
eye.VisibilityMask |= (uint) VisibilityFlags.Ghost;
|
|
}
|
|
|
|
component.TimeOfDeath = _gameTiming.RealTime;
|
|
}
|
|
|
|
private void OnGhostShutdown(EntityUid uid, GhostComponent component, ComponentShutdown args)
|
|
{
|
|
// Perf: If the entity is deleting itself, no reason to change these back.
|
|
if (component.Owner.LifeStage < EntityLifeStage.Terminating)
|
|
{
|
|
// Entity can't be seen by ghosts anymore.
|
|
if (component.Owner.TryGetComponent(out VisibilityComponent? visibility))
|
|
{
|
|
visibility.Layer &= ~(int) VisibilityFlags.Ghost;
|
|
visibility.Layer |= (int) VisibilityFlags.Normal;
|
|
}
|
|
|
|
// Entity can't see ghosts anymore.
|
|
if (component.Owner.TryGetComponent(out EyeComponent? eye))
|
|
{
|
|
eye.VisibilityMask &= ~(uint) VisibilityFlags.Ghost;
|
|
}
|
|
}
|
|
}
|
|
|
|
private void OnGhostExamine(EntityUid uid, GhostComponent component, ExaminedEvent args)
|
|
{
|
|
var timeSinceDeath = _gameTiming.RealTime.Subtract(component.TimeOfDeath);
|
|
var deathTimeInfo = timeSinceDeath.Minutes > 0
|
|
? Loc.GetString("comp-ghost-examine-time-minutes", ("minutes", timeSinceDeath.Minutes))
|
|
: Loc.GetString("comp-ghost-examine-time-seconds", ("seconds", timeSinceDeath.Seconds));
|
|
|
|
args.Message.AddMarkup(deathTimeInfo);
|
|
}
|
|
|
|
private void OnMindRemovedMessage(EntityUid uid, GhostComponent component, MindRemovedMessage args)
|
|
{
|
|
DeleteEntity(uid);
|
|
}
|
|
|
|
private void OnMindUnvisitedMessage(EntityUid uid, GhostComponent component, MindUnvisitedMessage args)
|
|
{
|
|
DeleteEntity(uid);
|
|
}
|
|
|
|
private void OnGhostWarpsRequest(GhostWarpsRequestEvent msg, EntitySessionEventArgs args)
|
|
{
|
|
var entity = args.SenderSession.AttachedEntity;
|
|
|
|
if (entity == null ||
|
|
!entity.HasComponent<GhostComponent>())
|
|
{
|
|
Logger.Warning($"User {args.SenderSession.Name} sent a {nameof(GhostWarpsRequestEvent)} without being a ghost.");
|
|
return;
|
|
}
|
|
|
|
var response = new GhostWarpsResponseEvent(GetLocationNames().ToList(), GetPlayerWarps(entity.Uid));
|
|
RaiseNetworkEvent(response, args.SenderSession.ConnectedClient);
|
|
}
|
|
|
|
private void OnGhostReturnToBodyRequest(GhostReturnToBodyRequest msg, EntitySessionEventArgs args)
|
|
{
|
|
var entity = args.SenderSession.AttachedEntity;
|
|
|
|
if (entity == null ||
|
|
!entity.TryGetComponent(out GhostComponent? ghost) ||
|
|
!ghost.CanReturnToBody ||
|
|
!entity.TryGetComponent(out ActorComponent? actor))
|
|
{
|
|
Logger.Warning($"User {args.SenderSession.Name} sent an invalid {nameof(GhostReturnToBodyRequest)}");
|
|
return;
|
|
}
|
|
|
|
actor.PlayerSession.ContentData()!.Mind?.UnVisit();
|
|
}
|
|
|
|
private void OnGhostWarpToLocationRequest(GhostWarpToLocationRequestEvent msg, EntitySessionEventArgs args)
|
|
{
|
|
if (args.SenderSession.AttachedEntity == null ||
|
|
!args.SenderSession.AttachedEntity.TryGetComponent(out GhostComponent? ghost))
|
|
{
|
|
Logger.Warning($"User {args.SenderSession.Name} tried to warp to {msg.Name} without being a ghost.");
|
|
return;
|
|
}
|
|
|
|
if (FindLocation(msg.Name) is { } warp)
|
|
{
|
|
ghost.Owner.Transform.Coordinates = warp.Owner.Transform.Coordinates;
|
|
}
|
|
|
|
Logger.Warning($"User {args.SenderSession.Name} tried to warp to an invalid warp: {msg.Name}");
|
|
}
|
|
|
|
private void OnGhostWarpToTargetRequest(GhostWarpToTargetRequestEvent msg, EntitySessionEventArgs args)
|
|
{
|
|
if (args.SenderSession.AttachedEntity == null ||
|
|
!args.SenderSession.AttachedEntity.TryGetComponent(out GhostComponent? ghost))
|
|
{
|
|
Logger.Warning($"User {args.SenderSession.Name} tried to warp to {msg.Target} without being a ghost.");
|
|
return;
|
|
}
|
|
|
|
if (!EntityManager.TryGetEntity(msg.Target, out var entity))
|
|
{
|
|
Logger.Warning($"User {args.SenderSession.Name} tried to warp to an invalid entity id: {msg.Target}");
|
|
return;
|
|
}
|
|
|
|
ghost.Owner.Transform.Coordinates = entity.Transform.Coordinates;
|
|
}
|
|
|
|
private void DeleteEntity(EntityUid uid)
|
|
{
|
|
if (!EntityManager.TryGetEntity(uid, out var entity)
|
|
|| entity.Deleted
|
|
|| entity.LifeStage == EntityLifeStage.Terminating)
|
|
return;
|
|
|
|
if (entity.TryGetComponent<MindComponent>(out var mind))
|
|
mind.GhostOnShutdown = false;
|
|
entity.Delete();
|
|
}
|
|
|
|
private IEnumerable<string> GetLocationNames()
|
|
{
|
|
foreach (var warp in ComponentManager.EntityQuery<WarpPointComponent>())
|
|
{
|
|
if (warp.Location != null)
|
|
{
|
|
yield return warp.Location;
|
|
}
|
|
}
|
|
}
|
|
|
|
private WarpPointComponent? FindLocation(string name)
|
|
{
|
|
foreach (var warp in ComponentManager.EntityQuery<WarpPointComponent>(true))
|
|
{
|
|
if (warp.Location == name)
|
|
{
|
|
return warp;
|
|
}
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
private Dictionary<EntityUid, string> GetPlayerWarps(EntityUid except)
|
|
{
|
|
var players = new Dictionary<EntityUid, string>();
|
|
|
|
foreach (var player in _playerManager.GetAllPlayers())
|
|
{
|
|
if (player.AttachedEntity != null)
|
|
{
|
|
players.Add(player.AttachedEntity.Uid, player.AttachedEntity.Name);
|
|
}
|
|
}
|
|
|
|
players.Remove(except);
|
|
|
|
return players;
|
|
}
|
|
}
|
|
}
|