try and purify cryosleeper code (#24165)

This commit is contained in:
Nemanja
2024-01-16 18:02:26 -05:00
committed by GitHub
parent ef70629702
commit e145a8f696
4 changed files with 38 additions and 25 deletions

View File

@@ -9,6 +9,7 @@ namespace Content.Shared.Bed.Cryostorage;
/// will delete their body and redistribute their items.
/// </summary>
[RegisterComponent, NetworkedComponent]
[AutoGenerateComponentState]
public sealed partial class CryostorageComponent : Component
{
[DataField, ViewVariables(VVAccess.ReadWrite)]
@@ -18,18 +19,21 @@ public sealed partial class CryostorageComponent : Component
/// How long a player can remain inside Cryostorage before automatically being taken care of, given that they have no mind.
/// </summary>
[DataField, ViewVariables(VVAccess.ReadWrite)]
[AutoNetworkedField]
public TimeSpan NoMindGracePeriod = TimeSpan.FromSeconds(30f);
/// <summary>
/// How long a player can remain inside Cryostorage before automatically being taken care of.
/// </summary>
[DataField, ViewVariables(VVAccess.ReadWrite)]
[AutoNetworkedField]
public TimeSpan GracePeriod = TimeSpan.FromMinutes(5f);
/// <summary>
/// A list of players who have actively entered cryostorage.
/// </summary>
[DataField]
[AutoNetworkedField]
public List<EntityUid> StoredPlayers = new();
/// <summary>
@@ -83,7 +87,7 @@ public sealed class CryostorageBuiState : BoundUserInterfaceState
[Serializable, NetSerializable]
public sealed class CryostorageRemoveItemBuiMessage : BoundUserInterfaceMessage
{
public NetEntity Entity;
public NetEntity StoredEntity;
public string Key;
@@ -95,9 +99,9 @@ public sealed class CryostorageRemoveItemBuiMessage : BoundUserInterfaceMessage
Inventory
}
public CryostorageRemoveItemBuiMessage(NetEntity entity, string key, RemovalType type)
public CryostorageRemoveItemBuiMessage(NetEntity storedEntity, string key, RemovalType type)
{
Entity = entity;
StoredEntity = storedEntity;
Key = key;
Type = type;
}

View File

@@ -12,10 +12,11 @@ namespace Content.Shared.Bed.Cryostorage;
public sealed partial class CryostorageContainedComponent : Component
{
/// <summary>
/// Whether or not this entity is being stored on another map or is just chilling in a container
/// If true, the player's mind won't be removed from their body when they are moved into cryosleep
/// allowing them to rejoin later.
/// </summary>
[DataField, AutoNetworkedField]
public bool StoredWhileDisconnected;
[DataField]
public bool AllowReEnteringBody;
/// <summary>
/// The time at which the cryostorage grace period ends.

View File

@@ -42,7 +42,7 @@ public abstract class SharedCryostorageSystem : EntitySystem
SubscribeLocalEvent<RoundRestartCleanupEvent>(OnRoundRestart);
_configuration.OnValueChanged(CCVars.GameCryoSleepRejoining, OnCvarChanged);
_configuration.OnValueChanged(CCVars.GameCryoSleepRejoining, OnCvarChanged, true);
}
public override void Shutdown()
@@ -132,8 +132,8 @@ public abstract class SharedCryostorageSystem : EntitySystem
private void OnRemovedContained(Entity<CryostorageContainedComponent> ent, ref EntGotRemovedFromContainerMessage args)
{
var (_, comp) = ent;
if (!comp.StoredWhileDisconnected)
var (uid, comp) = ent;
if (!IsInPausedMap(uid))
RemCompDeferred(ent, comp);
}
@@ -176,4 +176,12 @@ public abstract class SharedCryostorageSystem : EntitySystem
_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;
}
}