try and purify cryosleeper code (#24165)
This commit is contained in:
@@ -71,13 +71,13 @@ public sealed class CryostorageSystem : SharedCryostorageSystem
|
||||
|
||||
private void OnRemoveItemBuiMessage(Entity<CryostorageComponent> ent, ref CryostorageRemoveItemBuiMessage args)
|
||||
{
|
||||
var comp = ent.Comp;
|
||||
var (_, comp) = ent;
|
||||
if (args.Session.AttachedEntity is not { } attachedEntity)
|
||||
return;
|
||||
|
||||
var cryoContained = GetEntity(args.Entity);
|
||||
var cryoContained = GetEntity(args.StoredEntity);
|
||||
|
||||
if (!comp.StoredPlayers.Contains(cryoContained))
|
||||
if (!comp.StoredPlayers.Contains(cryoContained) || !IsInPausedMap(cryoContained))
|
||||
return;
|
||||
|
||||
if (!HasComp<HandsComponent>(attachedEntity))
|
||||
@@ -134,6 +134,7 @@ public sealed class CryostorageSystem : SharedCryostorageSystem
|
||||
|
||||
if (comp.GracePeriodEndTime != null)
|
||||
comp.GracePeriodEndTime = Timing.CurTime + cryostorageComponent.NoMindGracePeriod;
|
||||
comp.AllowReEnteringBody = false;
|
||||
comp.UserId = args.Mind.Comp.UserId;
|
||||
}
|
||||
|
||||
@@ -147,9 +148,7 @@ public sealed class CryostorageSystem : SharedCryostorageSystem
|
||||
|
||||
if (args.NewStatus is SessionStatus.Disconnected or SessionStatus.Zombie)
|
||||
{
|
||||
if (CryoSleepRejoiningEnabled)
|
||||
containedComponent.StoredWhileDisconnected = true;
|
||||
|
||||
containedComponent.AllowReEnteringBody = true;
|
||||
var delay = CompOrNull<CryostorageComponent>(containedComponent.Cryostorage)?.NoMindGracePeriod ?? TimeSpan.Zero;
|
||||
containedComponent.GracePeriodEndTime = Timing.CurTime + delay;
|
||||
containedComponent.UserId = args.Session.UserId;
|
||||
@@ -196,15 +195,17 @@ public sealed class CryostorageSystem : SharedCryostorageSystem
|
||||
return;
|
||||
}
|
||||
|
||||
if (!comp.StoredWhileDisconnected &&
|
||||
userId != null &&
|
||||
Mind.TryGetMind(userId.Value, out var mind) &&
|
||||
mind.Value.Comp.Session?.AttachedEntity == ent)
|
||||
if (!CryoSleepRejoiningEnabled || !comp.AllowReEnteringBody)
|
||||
{
|
||||
_gameTicker.OnGhostAttempt(mind.Value, false);
|
||||
if (userId != null && Mind.TryGetMind(userId.Value, out var mind))
|
||||
{
|
||||
_gameTicker.OnGhostAttempt(mind.Value, false);
|
||||
}
|
||||
}
|
||||
comp.AllowReEnteringBody = false;
|
||||
_transform.SetParent(ent, PausedMap.Value);
|
||||
cryostorageComponent.StoredPlayers.Add(ent);
|
||||
Dirty(ent, comp);
|
||||
UpdateCryostorageUIState((cryostorageEnt.Value, cryostorageComponent));
|
||||
AdminLog.Add(LogType.Action, LogImpact.High, $"{ToPrettyString(ent):player} was entered into cryostorage inside of {ToPrettyString(cryostorageEnt.Value)}");
|
||||
}
|
||||
@@ -212,13 +213,13 @@ public sealed class CryostorageSystem : SharedCryostorageSystem
|
||||
private void HandleCryostorageReconnection(Entity<CryostorageContainedComponent> entity)
|
||||
{
|
||||
var (uid, comp) = entity;
|
||||
if (!CryoSleepRejoiningEnabled || !comp.StoredWhileDisconnected)
|
||||
if (!CryoSleepRejoiningEnabled || !IsInPausedMap(uid))
|
||||
return;
|
||||
|
||||
// how did you destroy these? they're indestructible.
|
||||
if (comp.Cryostorage is not { } cryostorage ||
|
||||
TerminatingOrDeleted(cryostorage) ||
|
||||
!TryComp<CryostorageComponent>(comp.Cryostorage, out var cryostorageComponent))
|
||||
!TryComp<CryostorageComponent>(cryostorage, out var cryostorageComponent))
|
||||
{
|
||||
QueueDel(entity);
|
||||
return;
|
||||
@@ -234,8 +235,7 @@ public sealed class CryostorageSystem : SharedCryostorageSystem
|
||||
}
|
||||
|
||||
comp.GracePeriodEndTime = null;
|
||||
comp.StoredWhileDisconnected = false;
|
||||
cryostorageComponent.StoredPlayers.Remove(entity);
|
||||
cryostorageComponent.StoredPlayers.Remove(uid);
|
||||
AdminLog.Add(LogType.Action, LogImpact.High, $"{ToPrettyString(entity):player} re-entered the game from cryostorage {ToPrettyString(cryostorage)}");
|
||||
UpdateCryostorageUIState((cryostorage, cryostorageComponent));
|
||||
}
|
||||
@@ -295,7 +295,7 @@ public sealed class CryostorageSystem : SharedCryostorageSystem
|
||||
var query = EntityQueryEnumerator<CryostorageContainedComponent>();
|
||||
while (query.MoveNext(out var uid, out var containedComp))
|
||||
{
|
||||
if (containedComp.GracePeriodEndTime == null || containedComp.StoredWhileDisconnected)
|
||||
if (containedComp.GracePeriodEndTime == null)
|
||||
continue;
|
||||
|
||||
if (Timing.CurTime < containedComp.GracePeriodEndTime)
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user