Skip to content

Commit

Permalink
Replace CosmaticDrift code with modification of Wizden code
Browse files Browse the repository at this point in the history
  • Loading branch information
vaketola committed Feb 21, 2024
1 parent 8e6bbae commit 84cbb9a
Show file tree
Hide file tree
Showing 31 changed files with 345 additions and 757 deletions.
39 changes: 0 additions & 39 deletions Content.Client/CosmaticDrift/CryoSleep/AcceptCryoWindow.cs

This file was deleted.

39 changes: 0 additions & 39 deletions Content.Client/CosmaticDrift/CryoSleep/CryoSleepEui.cs

This file was deleted.

138 changes: 30 additions & 108 deletions Content.Server/Bed/Cryostorage/CryostorageSystem.cs
Original file line number Diff line number Diff line change
@@ -1,23 +1,17 @@
using System.Linq;
using Content.Server.Chat.Managers;
using Content.Server.GameTicking;
using Content.Server.Hands.Systems;
using Content.Server.Inventory;
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.Mind.Components;
using Robust.Server.Audio;
using Robust.Server.Containers;
using Robust.Server.GameObjects;
using Robust.Server.Player;
using Robust.Shared.Audio;
using Robust.Shared.Audio.Systems;
using Robust.Shared.Containers;
using Robust.Shared.Enums;
using Robust.Shared.Network;
Expand All @@ -30,27 +24,20 @@ public sealed class CryostorageSystem : SharedCryostorageSystem
{
[Dependency] private readonly IChatManager _chatManager = default!;
[Dependency] private readonly IPlayerManager _playerManager = default!;
[Dependency] private readonly AudioSystem _audio = default!;
[Dependency] private readonly AccessReaderSystem _accessReader = 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 ServerInventorySystem _inventory = 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 UserInterfaceSystem _ui = default!;
[Dependency] private readonly LostAndFoundSystem _lostAndFound = default!;

/// <inheritdoc/>
public override void Initialize()
{
base.Initialize();

SubscribeLocalEvent<CryostorageComponent, BeforeActivatableUIOpenEvent>(OnBeforeUIOpened);
SubscribeLocalEvent<CryostorageComponent, CryostorageRemoveItemBuiMessage>(OnRemoveItemBuiMessage);

SubscribeLocalEvent<CryostorageContainedComponent, PlayerSpawnCompleteEvent>(OnPlayerSpawned);
SubscribeLocalEvent<CryostorageContainedComponent, MindRemovedMessage>(OnMindRemoved);

Expand All @@ -64,61 +51,6 @@ public override void Shutdown()
_playerManager.PlayerStatusChanged -= PlayerStatusChanged;
}

private void OnBeforeUIOpened(Entity<CryostorageComponent> ent, ref BeforeActivatableUIOpenEvent args)
{
UpdateCryostorageUIState(ent);
}

private void OnRemoveItemBuiMessage(Entity<CryostorageComponent> ent, ref CryostorageRemoveItemBuiMessage args)
{
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<HandsComponent>(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);
}

private void UpdateCryostorageUIState(Entity<CryostorageComponent> ent)
{
var state = new CryostorageBuiState(GetAllContainedData(ent).ToList());
_ui.TrySetUiState(ent, CryostorageUIKey.Key, state);
}

private void OnPlayerSpawned(Entity<CryostorageContainedComponent> ent, ref PlayerSpawnCompleteEvent args)
{
// if you spawned into cryostorage, we're not gonna round-remove you.
Expand Down Expand Up @@ -186,7 +118,8 @@ public void HandleEnterCryostorage(Entity<CryostorageContainedComponent> ent, Ne
}
}

_audio.PlayPvs(cryostorageComponent.RemoveSound, ent);
// 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)
Expand All @@ -204,9 +137,19 @@ public void HandleEnterCryostorage(Entity<CryostorageContainedComponent> ent, Ne
}
comp.AllowReEnteringBody = false;
_transform.SetParent(ent, PausedMap.Value);
cryostorageComponent.StoredPlayers.Add(ent);
Dirty(ent, comp);
UpdateCryostorageUIState((cryostorageEnt.Value, cryostorageComponent));

// try to get the lost and found and add the player to it
var query = EntityQueryEnumerator<LostAndFoundComponent>();
query.MoveNext(out var storage, out var lostAndFoundComponent);

if (TryComp<LostAndFoundComponent>(storage, out var lostAndFoundComp))
{
lostAndFoundComp.StoredPlayers.Add(ent);
Dirty(ent, comp);
_lostAndFound.UpdateCryostorageUIState((storage, lostAndFoundComp));

}

AdminLog.Add(LogType.Action, LogImpact.High, $"{ToPrettyString(ent):player} was entered into cryostorage inside of {ToPrettyString(cryostorageEnt.Value)}");
}

Expand Down Expand Up @@ -235,9 +178,18 @@ private void HandleCryostorageReconnection(Entity<CryostorageContainedComponent>
}

comp.GracePeriodEndTime = null;
cryostorageComponent.StoredPlayers.Remove(uid);

// try to get the lost and found and remove the player from it
var query = EntityQueryEnumerator<LostAndFoundComponent>();
query.MoveNext(out var storage, out var lostAndFoundComponent);

if (TryComp<LostAndFoundComponent>(storage, out var lostAndFoundComp))
{
lostAndFoundComp.StoredPlayers.Remove(uid);
_lostAndFound.UpdateCryostorageUIState((storage, lostAndFoundComp));
}

AdminLog.Add(LogType.Action, LogImpact.High, $"{ToPrettyString(entity):player} re-entered the game from cryostorage {ToPrettyString(cryostorage)}");
UpdateCryostorageUIState((cryostorage, cryostorageComponent));
}

protected override void OnInsertedContainer(Entity<CryostorageComponent> ent, ref EntInsertedIntoContainerMessage args)
Expand All @@ -257,36 +209,6 @@ protected override void OnInsertedContainer(Entity<CryostorageComponent> ent, re
_chatManager.ChatMessageToOne(ChatChannel.Server, msg, msg, uid, false, actor.PlayerSession.Channel);
}

private IEnumerable<CryostorageContainedPlayerData> GetAllContainedData(Entity<CryostorageComponent> 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)
{
Expand Down
Loading

0 comments on commit 84cbb9a

Please sign in to comment.