Skip to content

Commit

Permalink
Add pausedMap checks to lost and found systems instead
Browse files Browse the repository at this point in the history
  • Loading branch information
vaketola committed Feb 21, 2024
1 parent 8f80035 commit 3d05478
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 50 deletions.
8 changes: 4 additions & 4 deletions Content.Server/Bed/Cryostorage/CryostorageSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,8 @@ public void HandleEnterCryostorage(Entity<CryostorageContainedComponent> ent, Ne
// play the cryostasis sound effect; need to use coordinates since the body gets deleted
_audio.PlayPvs("/Audio/SimpleStation14/Effects/cryostasis.ogg", Transform(ent).Coordinates, AudioParams.Default.WithVolume(6f));

EnsurePausedMap();
if (PausedMap == null)
_lostAndFound.EnsurePausedMap();
if (_lostAndFound.PausedMap == null)
{
Log.Error("CryoSleep map was unexpectedly null");
return;
Expand All @@ -136,7 +136,7 @@ public void HandleEnterCryostorage(Entity<CryostorageContainedComponent> ent, Ne
}
}
comp.AllowReEnteringBody = false;
_transform.SetParent(ent, PausedMap.Value);
_transform.SetParent(ent, _lostAndFound.PausedMap.Value);

// try to get the lost and found and add the player to it
var query = EntityQueryEnumerator<LostAndFoundComponent>();
Expand All @@ -156,7 +156,7 @@ public void HandleEnterCryostorage(Entity<CryostorageContainedComponent> ent, Ne
private void HandleCryostorageReconnection(Entity<CryostorageContainedComponent> entity)
{
var (uid, comp) = entity;
if (!CryoSleepRejoiningEnabled || !IsInPausedMap(uid))
if (!CryoSleepRejoiningEnabled || !_lostAndFound.IsInPausedMap(uid))
return;

// how did you destroy these? they're indestructible.
Expand Down
45 changes: 0 additions & 45 deletions Content.Shared/Bed/Cryostorage/SharedCryostorageSystem.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
using Content.Shared.Administration.Logs;
using Content.Shared.CCVar;
using Content.Shared.DragDrop;
using Content.Shared.GameTicking;
using Content.Shared.Mind;
using Content.Shared.Mind.Components;
using Robust.Shared.Audio;
using Robust.Shared.Audio.Systems;
using Robust.Shared.Configuration;
using Robust.Shared.Containers;
using Robust.Shared.Map;
using Robust.Shared.Timing;

namespace Content.Shared.Bed.Cryostorage;
Expand All @@ -21,13 +19,10 @@ public abstract class SharedCryostorageSystem : EntitySystem
[Dependency] protected readonly ISharedAdminLogManager AdminLog = default!;
[Dependency] private readonly IConfigurationManager _configuration = default!;
[Dependency] protected readonly IGameTiming Timing = default!;
[Dependency] private readonly IMapManager _mapManager = default!;
[Dependency] private readonly SharedAppearanceSystem _appearance = default!;
[Dependency] protected readonly SharedMindSystem Mind = default!;
[Dependency] private readonly SharedAudioSystem _audio = default!;

protected EntityUid? PausedMap { get; private set; }

protected bool CryoSleepRejoiningEnabled;

/// <inheritdoc/>
Expand All @@ -38,11 +33,9 @@ public override void Initialize()
SubscribeLocalEvent<CryostorageComponent, ContainerIsInsertingAttemptEvent>(OnInsertAttempt);
SubscribeLocalEvent<CryostorageComponent, CanDropTargetEvent>(OnCanDropTarget);

SubscribeLocalEvent<CryostorageContainedComponent, EntGotRemovedFromContainerMessage>(OnRemovedContained);
SubscribeLocalEvent<CryostorageContainedComponent, EntityUnpausedEvent>(OnUnpaused);
SubscribeLocalEvent<CryostorageContainedComponent, ComponentShutdown>(OnShutdownContained);

SubscribeLocalEvent<RoundRestartCleanupEvent>(OnRoundRestart);

_configuration.OnValueChanged(CCVars.GameCryoSleepRejoining, OnCvarChanged, true);
}
Expand Down Expand Up @@ -122,12 +115,6 @@ private void OnCanDropTarget(Entity<CryostorageComponent> ent, ref CanDropTarget
args.Handled = true;
}

private void OnRemovedContained(Entity<CryostorageContainedComponent> ent, ref EntGotRemovedFromContainerMessage args)
{
var (uid, comp) = ent;
if (!IsInPausedMap(uid))
RemCompDeferred(ent, comp);
}

private void OnUnpaused(Entity<CryostorageContainedComponent> ent, ref EntityUnpausedEvent args)
{
Expand All @@ -148,36 +135,4 @@ private void OnShutdownContained(Entity<CryostorageContainedComponent> ent, ref
ent.Comp.Cryostorage = null;
Dirty(ent, comp);
}

private void OnRoundRestart(RoundRestartCleanupEvent _)
{
DeletePausedMap();
}

private void DeletePausedMap()
{
if (PausedMap == null || !Exists(PausedMap))
return;

EntityManager.DeleteEntity(PausedMap.Value);
PausedMap = null;
}

protected void EnsurePausedMap()
{
if (PausedMap != null && Exists(PausedMap))
return;

var map = _mapManager.CreateMap();
_mapManager.SetMapPaused(map, true);
PausedMap = _mapManager.GetMapEntityId(map);
}

public bool IsInPausedMap(Entity<TransformComponent?> entity)
{
var (_, comp) = entity;
comp ??= Transform(entity);

return comp.MapUid != null && comp.MapUid == PausedMap;
}
}
40 changes: 39 additions & 1 deletion Content.Shared/Bed/Cryostorage/SharedLostAndFoundSystem.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
using Content.Shared.Administration.Logs;
using Content.Shared.GameTicking;
using Robust.Shared.Containers;
using Robust.Shared.Map;

namespace Content.Shared.Bed.Cryostorage;

Expand All @@ -8,13 +11,17 @@ namespace Content.Shared.Bed.Cryostorage;
public abstract class SharedLostAndFoundSystem : EntitySystem
{
[Dependency] protected readonly ISharedAdminLogManager AdminLog = default!;
[Dependency] private readonly IMapManager _mapManager = default!;

protected EntityUid? PausedMap { get; private set; }
public EntityUid? PausedMap { get; private set; }

/// <inheritdoc/>
public override void Initialize()
{
SubscribeLocalEvent<LostAndFoundComponent, ComponentShutdown>(OnShutdownContainer);
SubscribeLocalEvent<LostAndFoundComponent, EntGotRemovedFromContainerMessage>(OnRemovedContained);

SubscribeLocalEvent<RoundRestartCleanupEvent>(OnRoundRestart);
}

private void OnShutdownContainer(Entity<LostAndFoundComponent> ent, ref ComponentShutdown args)
Expand All @@ -40,4 +47,35 @@ public bool IsInPausedMap(Entity<TransformComponent?> entity)

return comp.MapUid != null && comp.MapUid == PausedMap;
}

private void OnRemovedContained(Entity<LostAndFoundComponent> ent, ref EntGotRemovedFromContainerMessage args)
{
var (uid, comp) = ent;
if (!IsInPausedMap(uid))
RemCompDeferred(ent, comp);
}

private void OnRoundRestart(RoundRestartCleanupEvent _)
{
DeletePausedMap();
}

private void DeletePausedMap()
{
if (PausedMap == null || !Exists(PausedMap))
return;

EntityManager.DeleteEntity(PausedMap.Value);
PausedMap = null;
}

public void EnsurePausedMap()
{
if (PausedMap != null && Exists(PausedMap))
return;

var map = _mapManager.CreateMap();
_mapManager.SetMapPaused(map, true);
PausedMap = _mapManager.GetMapEntityId(map);
}
}

0 comments on commit 3d05478

Please sign in to comment.