From 6682162a1cf17aa2c5122014e5ca67a966be9a5e Mon Sep 17 00:00:00 2001 From: Kill_Me_I_Noobs <118206719+Vonsant@users.noreply.github.com> Date: Thu, 2 May 2024 11:23:22 +0300 Subject: [PATCH] Create AutoDeleteSystem.cs --- .../AutoDeleteItems/AutoDeleteSystem.cs | 68 +++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 Content.Server/Corvax/AutoDeleteItems/AutoDeleteSystem.cs diff --git a/Content.Server/Corvax/AutoDeleteItems/AutoDeleteSystem.cs b/Content.Server/Corvax/AutoDeleteItems/AutoDeleteSystem.cs new file mode 100644 index 00000000000..98cd1e5a8a0 --- /dev/null +++ b/Content.Server/Corvax/AutoDeleteItems/AutoDeleteSystem.cs @@ -0,0 +1,68 @@ +using Content.Server.Construction.Completions; +using Content.Shared.Humanoid; +using Content.Shared.Mobs.Systems; +using FastAccessors; +using Robust.Shared.Timing; + +namespace Content.Server.Corvax.AutoDeleteItems; + +public sealed class AutoDeleteSystem : EntitySystem +{ + [Dependency] private readonly EntityLookupSystem _lookup = default!; + [Dependency] private readonly IGameTiming _gameTiming = default!; + + public override void Initialize() + { + base.Initialize(); + } + + public override void Update(float frameTime) + { + base.Update(frameTime); + var query = EntityQueryEnumerator(); + while (query.MoveNext(out var uid, out var autoDeleteComponent)) + { + var xformQuery = GetEntityQuery(); + + if (!xformQuery.TryGetComponent(uid, out var xform) || + xform.MapUid == null) + { + return; + } + var humanoids = new HashSet>(); + + if (autoDeleteComponent.NextTimeToCheck > _gameTiming.CurTime) + return; + _lookup.GetEntitiesInRange(xform.Coordinates, autoDeleteComponent.DistanceToCheck, humanoids); + + if (humanoids.Count > 0) + autoDeleteComponent.IsHumanoidNear = true; + else + autoDeleteComponent.IsHumanoidNear = false; + + if (autoDeleteComponent.IsHumanoidNear == false && autoDeleteComponent.ReadyToDelete == true && autoDeleteComponent.NextTimeToDelete < _gameTiming.CurTime) + { + EntityManager.DeleteEntity(uid); + } + + if (autoDeleteComponent.IsHumanoidNear == true) + { + if (autoDeleteComponent.ReadyToDelete == true) + autoDeleteComponent.ReadyToDelete = false; + + autoDeleteComponent.NextTimeToDelete = _gameTiming.CurTime + autoDeleteComponent.DelayToDelete; + autoDeleteComponent.NextTimeToCheck = _gameTiming.CurTime + autoDeleteComponent.DelayToCheck; + } + + if (autoDeleteComponent.IsHumanoidNear == false && autoDeleteComponent.ReadyToDelete == false) + { + autoDeleteComponent.NextTimeToDelete = _gameTiming.CurTime + autoDeleteComponent.DelayToDelete; + autoDeleteComponent.NextTimeToCheck = _gameTiming.CurTime + autoDeleteComponent.DelayToCheck; + autoDeleteComponent.ReadyToDelete = true; + } + + //autoDeleteComponent.NextTimeToDelete = _gameTiming.CurTime + autoDeleteComponent.DelayToDelete; + //autoDeleteComponent.NextTimeToCheck = _gameTiming.CurTime + autoDeleteComponent.DelayToCheck; + } + } +}