From ce5bc4f5ff91bea8172fa9890cdb9e487e6eccb8 Mon Sep 17 00:00:00 2001 From: Finket Date: Mon, 26 Feb 2024 07:23:09 +0200 Subject: [PATCH] Move LostAndFound to be handled in original cryostorage systems --- .../Bed/Cryostorage/CryostorageSystem.cs | 115 ++++++++++++++-- .../Bed/Cryostorage/LostAndFoundSystem.cs | 124 ------------------ .../Bed/Cryostorage/CryostorageComponent.cs | 8 +- .../Cryostorage/SharedCryostorageSystem.cs | 67 +++++++++- .../Cryostorage/SharedLostAndFoundSystem.cs | 81 ------------ 5 files changed, 179 insertions(+), 216 deletions(-) delete mode 100644 Content.Server/Bed/Cryostorage/LostAndFoundSystem.cs delete mode 100644 Content.Shared/Bed/Cryostorage/SharedLostAndFoundSystem.cs diff --git a/Content.Server/Bed/Cryostorage/CryostorageSystem.cs b/Content.Server/Bed/Cryostorage/CryostorageSystem.cs index 794cb62ab0..ff92f69289 100644 --- a/Content.Server/Bed/Cryostorage/CryostorageSystem.cs +++ b/Content.Server/Bed/Cryostorage/CryostorageSystem.cs @@ -1,11 +1,17 @@ +using System.Linq; using Content.Server.Chat.Managers; using Content.Server.GameTicking; +using Content.Server.Hands.Systems; +using Content.Server.Popups; using Content.Server.Station.Components; using Content.Server.Station.Systems; +using Content.Shared.UserInterface; +using Content.Shared.Access.Systems; using Content.Shared.Bed.Cryostorage; using Content.Shared.Chat; using Content.Shared.Climbing.Systems; using Content.Shared.Database; +using Content.Shared.Hands.Components; using Content.Shared.Inventory; using Content.Shared.Mind.Components; using Robust.Server.Containers; @@ -25,21 +31,27 @@ public sealed class CryostorageSystem : SharedCryostorageSystem { [Dependency] private readonly IChatManager _chatManager = default!; [Dependency] private readonly IPlayerManager _playerManager = default!; + [Dependency] private readonly AccessReaderSystem _accessReader = default!; [Dependency] private readonly InventorySystem _inventory = default!; [Dependency] private readonly SharedAudioSystem _audio = default!; [Dependency] private readonly ClimbSystem _climb = default!; [Dependency] private readonly ContainerSystem _container = default!; [Dependency] private readonly GameTicker _gameTicker = default!; + [Dependency] private readonly HandsSystem _hands = default!; + [Dependency] private readonly PopupSystem _popup = default!; [Dependency] private readonly StationSystem _station = default!; [Dependency] private readonly StationJobsSystem _stationJobs = default!; [Dependency] private readonly TransformSystem _transform = default!; - [Dependency] private readonly LostAndFoundSystem _lostAndFound = default!; + [Dependency] private readonly UserInterfaceSystem _ui = default!; /// public override void Initialize() { base.Initialize(); + SubscribeLocalEvent(OnBeforeUIOpened); + SubscribeLocalEvent(OnRemoveItemBuiMessage); + SubscribeLocalEvent(OnPlayerSpawned); SubscribeLocalEvent(OnMindRemoved); @@ -53,6 +65,63 @@ public override void Shutdown() _playerManager.PlayerStatusChanged -= PlayerStatusChanged; } + private void OnBeforeUIOpened(Entity ent, ref BeforeActivatableUIOpenEvent args) + { + UpdateCryostorageUIState(ent); + } + + private void OnRemoveItemBuiMessage(Entity ent, ref CryostorageRemoveItemBuiMessage args) + { + Log.Debug("on remove item bui message"); + + var (_, comp) = ent; + if (args.Session.AttachedEntity is not { } attachedEntity) + return; + + var cryoContained = GetEntity(args.StoredEntity); + + if (!comp.StoredPlayers.Contains(cryoContained) || !IsInPausedMap(cryoContained)) + return; + + if (!HasComp(attachedEntity)) + return; + + if (!_accessReader.IsAllowed(attachedEntity, ent)) + { + _popup.PopupEntity(Loc.GetString("cryostorage-popup-access-denied"), attachedEntity, attachedEntity); + return; + } + + EntityUid? entity = null; + if (args.Type == CryostorageRemoveItemBuiMessage.RemovalType.Hand) + { + if (_hands.TryGetHand(cryoContained, args.Key, out var hand)) + entity = hand.HeldEntity; + } + else + { + if (_inventory.TryGetSlotContainer(cryoContained, args.Key, out var slot, out _)) + entity = slot.ContainedEntity; + } + + if (entity == null) + return; + + AdminLog.Add(LogType.Action, LogImpact.High, + $"{ToPrettyString(attachedEntity):player} removed item {ToPrettyString(entity)} from cryostorage-contained player " + + $"{ToPrettyString(cryoContained):player}, stored in cryostorage {ToPrettyString(ent)}"); + _container.TryRemoveFromContainer(entity.Value); + _transform.SetCoordinates(entity.Value, Transform(attachedEntity).Coordinates); + _hands.PickupOrDrop(attachedEntity, entity.Value); + UpdateCryostorageUIState(ent); + } + + public void UpdateCryostorageUIState(Entity ent) + { + var state = new CryostorageBuiState(GetAllContainedData(ent).ToList()); + _ui.TrySetUiState(ent, CryostorageUIKey.Key, state); + } + private void OnPlayerSpawned(Entity ent, ref PlayerSpawnCompleteEvent args) { // if you spawned into cryostorage, we're not gonna round-remove you. @@ -120,10 +189,10 @@ public void HandleEnterCryostorage(Entity ent, Ne } } - _audio.PlayPvs("/Audio/SimpleStation14/Effects/cryostasis.ogg", cryostorageEnt.Value, AudioParams.Default.WithVolume(6f)); + _audio.PlayPvs(cryostorageComponent.RemoveSound, cryostorageEnt.Value, AudioParams.Default.WithVolume(6f)); - _lostAndFound.EnsurePausedMap(); - if (_lostAndFound.PausedMap == null) + EnsurePausedMap(); + if (PausedMap == null) { Log.Error("CryoSleep map was unexpectedly null"); return; @@ -137,7 +206,7 @@ public void HandleEnterCryostorage(Entity ent, Ne } } comp.AllowReEnteringBody = false; - _transform.SetParent(ent, _lostAndFound.PausedMap.Value); + _transform.SetParent(ent, PausedMap.Value); // try to get the lost and found and add the player to it var query = EntityQueryEnumerator(); @@ -147,7 +216,7 @@ public void HandleEnterCryostorage(Entity ent, Ne { lostAndFoundComp.StoredPlayers.Add(ent); Dirty(ent, comp); - _lostAndFound.UpdateCryostorageUIState((storage, lostAndFoundComp)); + UpdateCryostorageUIState((storage, lostAndFoundComp)); } else // if there is no lost and found, just drop the items instead of deleting them { @@ -175,7 +244,7 @@ private void DropItems(EntityUid uid, EntityUid cryopod) private void HandleCryostorageReconnection(Entity entity) { var (uid, comp) = entity; - if (!CryoSleepRejoiningEnabled || !_lostAndFound.IsInPausedMap(uid)) + if (!CryoSleepRejoiningEnabled || !IsInPausedMap(uid)) return; // how did you destroy these? they're indestructible. @@ -205,7 +274,7 @@ private void HandleCryostorageReconnection(Entity if (TryComp(storage, out var lostAndFoundComp)) { lostAndFoundComp.StoredPlayers.Remove(uid); - _lostAndFound.UpdateCryostorageUIState((storage, lostAndFoundComp)); + UpdateCryostorageUIState((storage, lostAndFoundComp)); } AdminLog.Add(LogType.Action, LogImpact.High, $"{ToPrettyString(entity):player} re-entered the game from cryostorage {ToPrettyString(cryostorage)}"); @@ -228,6 +297,36 @@ protected override void OnInsertedContainer(Entity ent, re _chatManager.ChatMessageToOne(ChatChannel.Server, msg, msg, uid, false, actor.PlayerSession.Channel); } + private IEnumerable GetAllContainedData(Entity ent) + { + foreach (var contained in ent.Comp.StoredPlayers) + { + yield return GetContainedData(contained); + } + } + + private CryostorageContainedPlayerData GetContainedData(EntityUid uid) + { + var data = new CryostorageContainedPlayerData(); + data.PlayerName = Name(uid); + data.PlayerEnt = GetNetEntity(uid); + + var enumerator = _inventory.GetSlotEnumerator(uid); + while (enumerator.NextItem(out var item, out var slotDef)) + { + data.ItemSlots.Add(slotDef.Name, Name(item)); + } + + foreach (var hand in _hands.EnumerateHands(uid)) + { + if (hand.HeldEntity == null) + continue; + + data.HeldItems.Add(hand.Name, Name(hand.HeldEntity.Value)); + } + + return data; + } public override void Update(float frameTime) { diff --git a/Content.Server/Bed/Cryostorage/LostAndFoundSystem.cs b/Content.Server/Bed/Cryostorage/LostAndFoundSystem.cs deleted file mode 100644 index 0fd33f793e..0000000000 --- a/Content.Server/Bed/Cryostorage/LostAndFoundSystem.cs +++ /dev/null @@ -1,124 +0,0 @@ -using System.Linq; -using Content.Server.Hands.Systems; -using Content.Server.Inventory; -using Content.Server.Popups; -using Content.Shared.Access.Systems; -using Content.Shared.UserInterface; -using Content.Shared.Bed.Cryostorage; -using Content.Shared.Database; -using Content.Shared.Hands.Components; -using Robust.Server.Containers; -using Robust.Server.GameObjects; - -namespace Content.Server.Bed.Cryostorage; - -/// -public sealed class LostAndFoundSystem : SharedLostAndFoundSystem -{ - [Dependency] private readonly ServerInventorySystem _inventory = default!; - [Dependency] private readonly UserInterfaceSystem _ui = default!; - [Dependency] private readonly HandsSystem _hands = default!; - [Dependency] private readonly AccessReaderSystem _accessReader = default!; - [Dependency] private readonly PopupSystem _popup = default!; - [Dependency] private readonly ContainerSystem _container = default!; - [Dependency] private readonly TransformSystem _transform = default!; - - /// - public override void Initialize() - { - base.Initialize(); - - SubscribeLocalEvent(OnBeforeUIOpened); - SubscribeLocalEvent(OnRemoveItemBuiMessage); - } - - private void OnBeforeUIOpened(Entity ent, ref BeforeActivatableUIOpenEvent args) - { - UpdateCryostorageUIState(ent); - } - - private void OnRemoveItemBuiMessage(Entity ent, ref CryostorageRemoveItemBuiMessage args) - { - Log.Debug("on remove item bui message"); - - var (_, comp) = ent; - if (args.Session.AttachedEntity is not { } attachedEntity) - return; - - var cryoContained = GetEntity(args.StoredEntity); - - if (!comp.StoredPlayers.Contains(cryoContained) || !IsInPausedMap(cryoContained)) - return; - - if (!HasComp(attachedEntity)) - return; - - if (!_accessReader.IsAllowed(attachedEntity, ent)) - { - _popup.PopupEntity(Loc.GetString("cryostorage-popup-access-denied"), attachedEntity, attachedEntity); - return; - } - - EntityUid? entity = null; - if (args.Type == CryostorageRemoveItemBuiMessage.RemovalType.Hand) - { - if (_hands.TryGetHand(cryoContained, args.Key, out var hand)) - entity = hand.HeldEntity; - } - else - { - if (_inventory.TryGetSlotContainer(cryoContained, args.Key, out var slot, out _)) - entity = slot.ContainedEntity; - } - - if (entity == null) - return; - - AdminLog.Add(LogType.Action, LogImpact.High, - $"{ToPrettyString(attachedEntity):player} removed item {ToPrettyString(entity)} from cryostorage-contained player " + - $"{ToPrettyString(cryoContained):player}, stored in cryostorage {ToPrettyString(ent)}"); - _container.TryRemoveFromContainer(entity.Value); - _transform.SetCoordinates(entity.Value, Transform(attachedEntity).Coordinates); - _hands.PickupOrDrop(attachedEntity, entity.Value); - UpdateCryostorageUIState(ent); - } - - - public void UpdateCryostorageUIState(Entity ent) - { - var state = new CryostorageBuiState(GetAllContainedData(ent).ToList()); - _ui.TrySetUiState(ent, CryostorageUIKey.Key, state); - } - - private IEnumerable GetAllContainedData(Entity ent) - { - foreach (var contained in ent.Comp.StoredPlayers) - { - yield return GetContainedData(contained); - } - } - - private CryostorageContainedPlayerData GetContainedData(EntityUid uid) - { - var data = new CryostorageContainedPlayerData(); - data.PlayerName = Name(uid); - data.PlayerEnt = GetNetEntity(uid); - - var enumerator = _inventory.GetSlotEnumerator(uid); - while (enumerator.NextItem(out var item, out var slotDef)) - { - data.ItemSlots.Add(slotDef.Name, Name(item)); - } - - foreach (var hand in _hands.EnumerateHands(uid)) - { - if (hand.HeldEntity == null) - continue; - - data.HeldItems.Add(hand.Name, Name(hand.HeldEntity.Value)); - } - - return data; - } - -} diff --git a/Content.Shared/Bed/Cryostorage/CryostorageComponent.cs b/Content.Shared/Bed/Cryostorage/CryostorageComponent.cs index ca1838a00d..ad3e23b3f7 100644 --- a/Content.Shared/Bed/Cryostorage/CryostorageComponent.cs +++ b/Content.Shared/Bed/Cryostorage/CryostorageComponent.cs @@ -33,7 +33,13 @@ public sealed partial class CryostorageComponent : Component /// Sound that is played when a player is removed by a cryostorage. /// [DataField] - public SoundSpecifier? RemoveSound = new SoundPathSpecifier("/Audio/Effects/teleport_departure.ogg"); + public SoundSpecifier? RemoveSound = new SoundPathSpecifier("/Audio/SimpleStation14/Effects/cryostasis.ogg"); + + /// + /// Sound that is played when a player goes inside of the cryostorage pod. + /// + [DataField] + public static SoundSpecifier? EnterSound = new SoundPathSpecifier("/Audio/SimpleStation14/Effects/cryosleep_open.ogg"); } [Serializable, NetSerializable] diff --git a/Content.Shared/Bed/Cryostorage/SharedCryostorageSystem.cs b/Content.Shared/Bed/Cryostorage/SharedCryostorageSystem.cs index 36427f9d57..75ba0df749 100644 --- a/Content.Shared/Bed/Cryostorage/SharedCryostorageSystem.cs +++ b/Content.Shared/Bed/Cryostorage/SharedCryostorageSystem.cs @@ -1,28 +1,33 @@ 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; /// -/// This handles +/// This handles and /// 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!; + public EntityUid? PausedMap { get; private set; } + protected bool CryoSleepRejoiningEnabled; /// @@ -36,6 +41,10 @@ public override void Initialize() SubscribeLocalEvent(OnUnpaused); SubscribeLocalEvent(OnShutdownContained); + SubscribeLocalEvent(OnShutdownContainer); + SubscribeLocalEvent(OnRemovedContained); + + SubscribeLocalEvent(OnRoundRestart); _configuration.OnValueChanged(CCVars.GameCryoSleepRejoining, OnCvarChanged, true); } @@ -72,7 +81,7 @@ protected virtual void OnInsertedContainer(Entity ent, ref if (!Timing.InPrediction) return; - _audio.PlayPvs("/Audio/SimpleStation14/Effects/cryosleep_open.ogg", ent, AudioParams.Default.WithVolume(6f)); + _audio.PlayPvs(CryostorageComponent.EnterSound, ent, AudioParams.Default.WithVolume(6f)); } private void OnRemovedContainer(Entity ent, ref EntRemovedFromContainerMessage args) @@ -103,6 +112,22 @@ private void OnInsertAttempt(Entity ent, ref ContainerIsIn } } + private void OnShutdownContainer(Entity ent, ref ComponentShutdown args) + { + var comp = ent.Comp; + foreach (var stored in comp.StoredPlayers) + { + if (TryComp(stored, out var containedComponent)) + { + containedComponent.Cryostorage = null; + Dirty(stored, containedComponent); + } + } + + comp.StoredPlayers.Clear(); + Dirty(ent, comp); + } + private void OnCanDropTarget(Entity ent, ref CanDropTargetEvent args) { if (args.Dragged == args.User) @@ -115,6 +140,12 @@ private void OnCanDropTarget(Entity ent, ref CanDropTarget args.Handled = true; } + private void OnRemovedContained(Entity ent, ref EntGotRemovedFromContainerMessage args) + { + var (uid, comp) = ent; + if (!IsInPausedMap(uid)) + RemCompDeferred(ent, comp); + } private void OnUnpaused(Entity ent, ref EntityUnpausedEvent args) { @@ -135,4 +166,36 @@ private void OnShutdownContained(Entity 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; + } + + public void EnsurePausedMap() + { + if (PausedMap != null && Exists(PausedMap)) + return; + + var map = _mapManager.CreateMap(); + _mapManager.SetMapPaused(map, true); + PausedMap = _mapManager.GetMapEntityId(map); + } + + public bool IsInPausedMap(Entity entity) + { + var (_, comp) = entity; + comp ??= Transform(entity); + + return comp.MapUid != null && comp.MapUid == PausedMap; + } } diff --git a/Content.Shared/Bed/Cryostorage/SharedLostAndFoundSystem.cs b/Content.Shared/Bed/Cryostorage/SharedLostAndFoundSystem.cs deleted file mode 100644 index a43ed6d0c8..0000000000 --- a/Content.Shared/Bed/Cryostorage/SharedLostAndFoundSystem.cs +++ /dev/null @@ -1,81 +0,0 @@ -using Content.Shared.Administration.Logs; -using Content.Shared.GameTicking; -using Robust.Shared.Containers; -using Robust.Shared.Map; - -namespace Content.Shared.Bed.Cryostorage; - -/// -/// This handles -/// -public abstract class SharedLostAndFoundSystem : EntitySystem -{ - [Dependency] protected readonly ISharedAdminLogManager AdminLog = default!; - [Dependency] private readonly IMapManager _mapManager = default!; - - public EntityUid? PausedMap { get; private set; } - - /// - public override void Initialize() - { - SubscribeLocalEvent(OnShutdownContainer); - SubscribeLocalEvent(OnRemovedContained); - - SubscribeLocalEvent(OnRoundRestart); - } - - private void OnShutdownContainer(Entity ent, ref ComponentShutdown args) - { - var comp = ent.Comp; - foreach (var stored in comp.StoredPlayers) - { - if (TryComp(stored, out var containedComponent)) - { - containedComponent.Cryostorage = null; - Dirty(stored, containedComponent); - } - } - - comp.StoredPlayers.Clear(); - Dirty(ent, comp); - } - - public bool IsInPausedMap(Entity entity) - { - var (_, comp) = entity; - comp ??= Transform(entity); - - return comp.MapUid != null && comp.MapUid == PausedMap; - } - - private void OnRemovedContained(Entity 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); - } -}