This repository has been archived by the owner on Nov 1, 2024. It is now read-only.
forked from new-frontiers-14/frontier-station-14
-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
68 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<AutoDeleteComponent>(); | ||
while (query.MoveNext(out var uid, out var autoDeleteComponent)) | ||
{ | ||
var xformQuery = GetEntityQuery<TransformComponent>(); | ||
|
||
if (!xformQuery.TryGetComponent(uid, out var xform) || | ||
xform.MapUid == null) | ||
{ | ||
return; | ||
} | ||
var humanoids = new HashSet<Entity<HumanoidAppearanceComponent>>(); | ||
|
||
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; | ||
} | ||
} | ||
} |