-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
…ce component.
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
using Content.Shared.Timing; | ||
using Robust.Shared.Audio; | ||
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom; | ||
|
||
[RegisterComponent] | ||
[AutoGenerateComponentState, AutoGenerateComponentPause] | ||
public sealed partial class AutoDeleteComponent : Component | ||
{ | ||
[DataField, ViewVariables(VVAccess.ReadWrite)] | ||
public bool IsHumanoidNear = false; | ||
|
||
[DataField, ViewVariables(VVAccess.ReadWrite)] | ||
public bool ReadyToDelete = false; | ||
|
||
[DataField, ViewVariables(VVAccess.ReadWrite)] | ||
[AutoPausedField] | ||
public TimeSpan NextTimeToDelete; | ||
|
||
[DataField, ViewVariables(VVAccess.ReadWrite)] | ||
[AutoPausedField] | ||
public TimeSpan NextTimeToCheck; | ||
|
||
[DataField, ViewVariables(VVAccess.ReadWrite)] | ||
public TimeSpan DelayToCheck = TimeSpan.FromSeconds(10f); | ||
|
||
[DataField, ViewVariables(VVAccess.ReadWrite)] | ||
public TimeSpan DelayToDelete = TimeSpan.FromSeconds(20f); | ||
|
||
[DataField, ViewVariables(VVAccess.ReadWrite)] | ||
public int DistanceToCheck = 5; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
using Content.Server.Construction.Completions; | ||
using Content.Shared.Humanoid; | ||
using Content.Shared.Mobs.Systems; | ||
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; | ||
|
||
if (_lookup.GetEntitiesInRangeInt(xform.Coordinates, autoDeleteComponent.DistanceToCheck, humanoids) > 0) | ||
Check failure on line 36 in Content.Server/Corvax/AutoDeleteItems/AutoDeleteSystem.cs GitHub Actions / Test Packaging
Check failure on line 36 in Content.Server/Corvax/AutoDeleteItems/AutoDeleteSystem.cs GitHub Actions / Test Packaging
Check failure on line 36 in Content.Server/Corvax/AutoDeleteItems/AutoDeleteSystem.cs GitHub Actions / build (ubuntu-latest)
Check failure on line 36 in Content.Server/Corvax/AutoDeleteItems/AutoDeleteSystem.cs GitHub Actions / build (ubuntu-latest)
Check failure on line 36 in Content.Server/Corvax/AutoDeleteItems/AutoDeleteSystem.cs GitHub Actions / YAML Linter
Check failure on line 36 in Content.Server/Corvax/AutoDeleteItems/AutoDeleteSystem.cs GitHub Actions / YAML Linter
Check failure on line 36 in Content.Server/Corvax/AutoDeleteItems/AutoDeleteSystem.cs GitHub Actions / build (ubuntu-latest)
Check failure on line 36 in Content.Server/Corvax/AutoDeleteItems/AutoDeleteSystem.cs GitHub Actions / build (ubuntu-latest)
|
||
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; | ||
} | ||
} | ||
} |