2024-12-05 12:35:38 +03:00
|
|
|
using Content.Server.Body.Systems;
|
2024-11-01 09:23:22 +03:00
|
|
|
using Content.Shared._CP14.Demiplane.Components;
|
|
|
|
|
using Content.Shared.Mobs.Systems;
|
|
|
|
|
|
|
|
|
|
namespace Content.Server._CP14.Demiplane;
|
|
|
|
|
|
|
|
|
|
public sealed partial class CP14DemiplaneSystem
|
|
|
|
|
{
|
|
|
|
|
private readonly TimeSpan _checkFrequency = TimeSpan.FromSeconds(15f);
|
|
|
|
|
private TimeSpan _nextCheckTime = TimeSpan.Zero;
|
|
|
|
|
|
|
|
|
|
[Dependency] private readonly MobStateSystem _mobState = default!;
|
2024-12-05 12:35:38 +03:00
|
|
|
[Dependency] private readonly BodySystem _body = default!;
|
2024-11-01 09:23:22 +03:00
|
|
|
|
|
|
|
|
private void InitStabilization()
|
|
|
|
|
{
|
|
|
|
|
_nextCheckTime = _timing.CurTime + _checkFrequency;
|
|
|
|
|
|
|
|
|
|
SubscribeLocalEvent<CP14DemiplaneDestroyWithoutStabilizationComponent, MapInitEvent>(OnStabilizationMapInit);
|
|
|
|
|
}
|
|
|
|
|
|
2025-01-18 17:55:41 +03:00
|
|
|
private void OnStabilizationMapInit(Entity<CP14DemiplaneDestroyWithoutStabilizationComponent> ent,
|
|
|
|
|
ref MapInitEvent args)
|
2024-11-01 09:23:22 +03:00
|
|
|
{
|
|
|
|
|
ent.Comp.EndProtectionTime = _timing.CurTime + ent.Comp.ProtectedSpawnTime;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void UpdateStabilization(float frameTime)
|
|
|
|
|
{
|
|
|
|
|
if (_timing.CurTime < _nextCheckTime)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
_nextCheckTime = _timing.CurTime + _checkFrequency;
|
|
|
|
|
|
|
|
|
|
HashSet<EntityUid> stabilizedMaps = new();
|
|
|
|
|
|
|
|
|
|
var query = EntityQueryEnumerator<CP14DemiplaneStabilizerComponent, TransformComponent>();
|
|
|
|
|
while (query.MoveNext(out var uid, out var stabilizer, out var transform))
|
|
|
|
|
{
|
|
|
|
|
var map = transform.MapUid;
|
|
|
|
|
|
|
|
|
|
if (map is null)
|
|
|
|
|
continue;
|
|
|
|
|
|
2025-02-25 23:37:05 +03:00
|
|
|
if (!stabilizer.Enabled)
|
|
|
|
|
continue;
|
|
|
|
|
|
2024-11-01 09:23:22 +03:00
|
|
|
if (stabilizer.RequireAlive && !(_mobState.IsAlive(uid) || _mobState.IsCritical(uid)))
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
if (stabilizedMaps.Contains(map.Value))
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
stabilizedMaps.Add(map.Value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var query2 = EntityQueryEnumerator<CP14DemiplaneComponent, CP14DemiplaneDestroyWithoutStabilizationComponent>();
|
2024-12-05 12:35:38 +03:00
|
|
|
while (query2.MoveNext(out var uid, out var demiplane, out var stabilization))
|
2024-11-01 09:23:22 +03:00
|
|
|
{
|
|
|
|
|
if (_timing.CurTime < stabilization.EndProtectionTime)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
if (!stabilizedMaps.Contains(uid))
|
2024-12-05 12:35:38 +03:00
|
|
|
DeleteDemiplane((uid, demiplane));
|
2024-11-01 09:23:22 +03:00
|
|
|
}
|
|
|
|
|
}
|
2024-12-05 12:35:38 +03:00
|
|
|
|
2025-01-18 17:55:41 +03:00
|
|
|
public void DeleteAllDemiplanes(bool safe = true)
|
|
|
|
|
{
|
|
|
|
|
var query = EntityQueryEnumerator<CP14DemiplaneComponent>();
|
|
|
|
|
|
|
|
|
|
while (query.MoveNext(out var uid, out var demiplane))
|
|
|
|
|
{
|
|
|
|
|
DeleteDemiplane((uid, demiplane), safe);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-05-05 15:19:44 +03:00
|
|
|
public void DeleteDemiplane(Entity<CP14DemiplaneComponent> demiplane, bool safe = false)
|
2024-12-05 12:35:38 +03:00
|
|
|
{
|
|
|
|
|
var query = EntityQueryEnumerator<CP14DemiplaneStabilizerComponent, TransformComponent>();
|
|
|
|
|
|
|
|
|
|
while (query.MoveNext(out var uid, out var stabilizer, out var xform))
|
|
|
|
|
{
|
2025-03-27 17:20:20 +03:00
|
|
|
if (!stabilizer.Enabled)
|
|
|
|
|
continue;
|
|
|
|
|
|
2024-12-06 17:16:38 +03:00
|
|
|
if (TryTeleportOutDemiplane(demiplane, uid))
|
2025-01-18 17:55:41 +03:00
|
|
|
{
|
|
|
|
|
if (!safe)
|
2025-02-01 17:52:01 +03:00
|
|
|
{
|
|
|
|
|
var ev = new CP14DemiplaneUnsafeExit();
|
|
|
|
|
RaiseLocalEvent(uid, ev);
|
|
|
|
|
|
2025-01-18 17:55:41 +03:00
|
|
|
_body.GibBody(uid);
|
2025-02-01 17:52:01 +03:00
|
|
|
}
|
2025-01-18 17:55:41 +03:00
|
|
|
}
|
2024-12-05 12:35:38 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QueueDel(demiplane);
|
|
|
|
|
}
|
2024-11-01 09:23:22 +03:00
|
|
|
}
|
2025-02-01 17:52:01 +03:00
|
|
|
|
|
|
|
|
public sealed class CP14DemiplaneUnsafeExit : EntityEventArgs
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|