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)
|
private void OnRemoveItemBuiMessage(Entity<CryostorageComponent> ent, ref CryostorageRemoveItemBuiMessage args)
|
||||||
{
|
{
|
||||||
var comp = ent.Comp;
|
var (_, comp) = ent;
|
||||||
if (args.Session.AttachedEntity is not { } attachedEntity)
|
if (args.Session.AttachedEntity is not { } attachedEntity)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
var cryoContained = GetEntity(args.Entity);
|
var cryoContained = GetEntity(args.StoredEntity);
|
||||||
|
|
||||||
if (!comp.StoredPlayers.Contains(cryoContained))
|
if (!comp.StoredPlayers.Contains(cryoContained) || !IsInPausedMap(cryoContained))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (!HasComp<HandsComponent>(attachedEntity))
|
if (!HasComp<HandsComponent>(attachedEntity))
|
||||||
@@ -134,6 +134,7 @@ public sealed class CryostorageSystem : SharedCryostorageSystem
|
|||||||
|
|
||||||
if (comp.GracePeriodEndTime != null)
|
if (comp.GracePeriodEndTime != null)
|
||||||
comp.GracePeriodEndTime = Timing.CurTime + cryostorageComponent.NoMindGracePeriod;
|
comp.GracePeriodEndTime = Timing.CurTime + cryostorageComponent.NoMindGracePeriod;
|
||||||
|
comp.AllowReEnteringBody = false;
|
||||||
comp.UserId = args.Mind.Comp.UserId;
|
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 (args.NewStatus is SessionStatus.Disconnected or SessionStatus.Zombie)
|
||||||
{
|
{
|
||||||
if (CryoSleepRejoiningEnabled)
|
containedComponent.AllowReEnteringBody = true;
|
||||||
containedComponent.StoredWhileDisconnected = true;
|
|
||||||
|
|
||||||
var delay = CompOrNull<CryostorageComponent>(containedComponent.Cryostorage)?.NoMindGracePeriod ?? TimeSpan.Zero;
|
var delay = CompOrNull<CryostorageComponent>(containedComponent.Cryostorage)?.NoMindGracePeriod ?? TimeSpan.Zero;
|
||||||
containedComponent.GracePeriodEndTime = Timing.CurTime + delay;
|
containedComponent.GracePeriodEndTime = Timing.CurTime + delay;
|
||||||
containedComponent.UserId = args.Session.UserId;
|
containedComponent.UserId = args.Session.UserId;
|
||||||
@@ -196,15 +195,17 @@ public sealed class CryostorageSystem : SharedCryostorageSystem
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!comp.StoredWhileDisconnected &&
|
if (!CryoSleepRejoiningEnabled || !comp.AllowReEnteringBody)
|
||||||
userId != null &&
|
|
||||||
Mind.TryGetMind(userId.Value, out var mind) &&
|
|
||||||
mind.Value.Comp.Session?.AttachedEntity == ent)
|
|
||||||
{
|
{
|
||||||
_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);
|
_transform.SetParent(ent, PausedMap.Value);
|
||||||
cryostorageComponent.StoredPlayers.Add(ent);
|
cryostorageComponent.StoredPlayers.Add(ent);
|
||||||
|
Dirty(ent, comp);
|
||||||
UpdateCryostorageUIState((cryostorageEnt.Value, cryostorageComponent));
|
UpdateCryostorageUIState((cryostorageEnt.Value, cryostorageComponent));
|
||||||
AdminLog.Add(LogType.Action, LogImpact.High, $"{ToPrettyString(ent):player} was entered into cryostorage inside of {ToPrettyString(cryostorageEnt.Value)}");
|
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)
|
private void HandleCryostorageReconnection(Entity<CryostorageContainedComponent> entity)
|
||||||
{
|
{
|
||||||
var (uid, comp) = entity;
|
var (uid, comp) = entity;
|
||||||
if (!CryoSleepRejoiningEnabled || !comp.StoredWhileDisconnected)
|
if (!CryoSleepRejoiningEnabled || !IsInPausedMap(uid))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// how did you destroy these? they're indestructible.
|
// how did you destroy these? they're indestructible.
|
||||||
if (comp.Cryostorage is not { } cryostorage ||
|
if (comp.Cryostorage is not { } cryostorage ||
|
||||||
TerminatingOrDeleted(cryostorage) ||
|
TerminatingOrDeleted(cryostorage) ||
|
||||||
!TryComp<CryostorageComponent>(comp.Cryostorage, out var cryostorageComponent))
|
!TryComp<CryostorageComponent>(cryostorage, out var cryostorageComponent))
|
||||||
{
|
{
|
||||||
QueueDel(entity);
|
QueueDel(entity);
|
||||||
return;
|
return;
|
||||||
@@ -234,8 +235,7 @@ public sealed class CryostorageSystem : SharedCryostorageSystem
|
|||||||
}
|
}
|
||||||
|
|
||||||
comp.GracePeriodEndTime = null;
|
comp.GracePeriodEndTime = null;
|
||||||
comp.StoredWhileDisconnected = false;
|
cryostorageComponent.StoredPlayers.Remove(uid);
|
||||||
cryostorageComponent.StoredPlayers.Remove(entity);
|
|
||||||
AdminLog.Add(LogType.Action, LogImpact.High, $"{ToPrettyString(entity):player} re-entered the game from cryostorage {ToPrettyString(cryostorage)}");
|
AdminLog.Add(LogType.Action, LogImpact.High, $"{ToPrettyString(entity):player} re-entered the game from cryostorage {ToPrettyString(cryostorage)}");
|
||||||
UpdateCryostorageUIState((cryostorage, cryostorageComponent));
|
UpdateCryostorageUIState((cryostorage, cryostorageComponent));
|
||||||
}
|
}
|
||||||
@@ -295,7 +295,7 @@ public sealed class CryostorageSystem : SharedCryostorageSystem
|
|||||||
var query = EntityQueryEnumerator<CryostorageContainedComponent>();
|
var query = EntityQueryEnumerator<CryostorageContainedComponent>();
|
||||||
while (query.MoveNext(out var uid, out var containedComp))
|
while (query.MoveNext(out var uid, out var containedComp))
|
||||||
{
|
{
|
||||||
if (containedComp.GracePeriodEndTime == null || containedComp.StoredWhileDisconnected)
|
if (containedComp.GracePeriodEndTime == null)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (Timing.CurTime < containedComp.GracePeriodEndTime)
|
if (Timing.CurTime < containedComp.GracePeriodEndTime)
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ namespace Content.Shared.Bed.Cryostorage;
|
|||||||
/// will delete their body and redistribute their items.
|
/// will delete their body and redistribute their items.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[RegisterComponent, NetworkedComponent]
|
[RegisterComponent, NetworkedComponent]
|
||||||
|
[AutoGenerateComponentState]
|
||||||
public sealed partial class CryostorageComponent : Component
|
public sealed partial class CryostorageComponent : Component
|
||||||
{
|
{
|
||||||
[DataField, ViewVariables(VVAccess.ReadWrite)]
|
[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.
|
/// How long a player can remain inside Cryostorage before automatically being taken care of, given that they have no mind.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[DataField, ViewVariables(VVAccess.ReadWrite)]
|
[DataField, ViewVariables(VVAccess.ReadWrite)]
|
||||||
|
[AutoNetworkedField]
|
||||||
public TimeSpan NoMindGracePeriod = TimeSpan.FromSeconds(30f);
|
public TimeSpan NoMindGracePeriod = TimeSpan.FromSeconds(30f);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// How long a player can remain inside Cryostorage before automatically being taken care of.
|
/// How long a player can remain inside Cryostorage before automatically being taken care of.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[DataField, ViewVariables(VVAccess.ReadWrite)]
|
[DataField, ViewVariables(VVAccess.ReadWrite)]
|
||||||
|
[AutoNetworkedField]
|
||||||
public TimeSpan GracePeriod = TimeSpan.FromMinutes(5f);
|
public TimeSpan GracePeriod = TimeSpan.FromMinutes(5f);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// A list of players who have actively entered cryostorage.
|
/// A list of players who have actively entered cryostorage.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[DataField]
|
[DataField]
|
||||||
|
[AutoNetworkedField]
|
||||||
public List<EntityUid> StoredPlayers = new();
|
public List<EntityUid> StoredPlayers = new();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -83,7 +87,7 @@ public sealed class CryostorageBuiState : BoundUserInterfaceState
|
|||||||
[Serializable, NetSerializable]
|
[Serializable, NetSerializable]
|
||||||
public sealed class CryostorageRemoveItemBuiMessage : BoundUserInterfaceMessage
|
public sealed class CryostorageRemoveItemBuiMessage : BoundUserInterfaceMessage
|
||||||
{
|
{
|
||||||
public NetEntity Entity;
|
public NetEntity StoredEntity;
|
||||||
|
|
||||||
public string Key;
|
public string Key;
|
||||||
|
|
||||||
@@ -95,9 +99,9 @@ public sealed class CryostorageRemoveItemBuiMessage : BoundUserInterfaceMessage
|
|||||||
Inventory
|
Inventory
|
||||||
}
|
}
|
||||||
|
|
||||||
public CryostorageRemoveItemBuiMessage(NetEntity entity, string key, RemovalType type)
|
public CryostorageRemoveItemBuiMessage(NetEntity storedEntity, string key, RemovalType type)
|
||||||
{
|
{
|
||||||
Entity = entity;
|
StoredEntity = storedEntity;
|
||||||
Key = key;
|
Key = key;
|
||||||
Type = type;
|
Type = type;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,10 +12,11 @@ namespace Content.Shared.Bed.Cryostorage;
|
|||||||
public sealed partial class CryostorageContainedComponent : Component
|
public sealed partial class CryostorageContainedComponent : Component
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <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>
|
/// </summary>
|
||||||
[DataField, AutoNetworkedField]
|
[DataField]
|
||||||
public bool StoredWhileDisconnected;
|
public bool AllowReEnteringBody;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The time at which the cryostorage grace period ends.
|
/// The time at which the cryostorage grace period ends.
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ public abstract class SharedCryostorageSystem : EntitySystem
|
|||||||
|
|
||||||
SubscribeLocalEvent<RoundRestartCleanupEvent>(OnRoundRestart);
|
SubscribeLocalEvent<RoundRestartCleanupEvent>(OnRoundRestart);
|
||||||
|
|
||||||
_configuration.OnValueChanged(CCVars.GameCryoSleepRejoining, OnCvarChanged);
|
_configuration.OnValueChanged(CCVars.GameCryoSleepRejoining, OnCvarChanged, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Shutdown()
|
public override void Shutdown()
|
||||||
@@ -132,8 +132,8 @@ public abstract class SharedCryostorageSystem : EntitySystem
|
|||||||
|
|
||||||
private void OnRemovedContained(Entity<CryostorageContainedComponent> ent, ref EntGotRemovedFromContainerMessage args)
|
private void OnRemovedContained(Entity<CryostorageContainedComponent> ent, ref EntGotRemovedFromContainerMessage args)
|
||||||
{
|
{
|
||||||
var (_, comp) = ent;
|
var (uid, comp) = ent;
|
||||||
if (!comp.StoredWhileDisconnected)
|
if (!IsInPausedMap(uid))
|
||||||
RemCompDeferred(ent, comp);
|
RemCompDeferred(ent, comp);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -176,4 +176,12 @@ public abstract class SharedCryostorageSystem : EntitySystem
|
|||||||
_mapManager.SetMapPaused(map, true);
|
_mapManager.SetMapPaused(map, true);
|
||||||
PausedMap = _mapManager.GetMapEntityId(map);
|
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