Skip to content
This repository has been archived by the owner on Nov 1, 2024. It is now read-only.

Commit

Permalink
Autodelete items (and grids too) if near entity have HumanoidAppearan…
Browse files Browse the repository at this point in the history
…ce component.
  • Loading branch information
Sh1ntra committed May 2, 2024
1 parent 84765cc commit af7f10c
Show file tree
Hide file tree
Showing 2 changed files with 97 additions and 0 deletions.
31 changes: 31 additions & 0 deletions Content.Server/Corvax/AutoDeleteItems/AutoDeleteComponent.cs
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;
}
66 changes: 66 additions & 0 deletions Content.Server/Corvax/AutoDeleteItems/AutoDeleteSystem.cs
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

View workflow job for this annotation

GitHub Actions / Test Packaging

'EntityLookupSystem' does not contain a definition for 'GetEntitiesInRangeInt' and no accessible extension method 'GetEntitiesInRangeInt' accepting a first argument of type 'EntityLookupSystem' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 36 in Content.Server/Corvax/AutoDeleteItems/AutoDeleteSystem.cs

View workflow job for this annotation

GitHub Actions / Test Packaging

'EntityLookupSystem' does not contain a definition for 'GetEntitiesInRangeInt' and no accessible extension method 'GetEntitiesInRangeInt' accepting a first argument of type 'EntityLookupSystem' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 36 in Content.Server/Corvax/AutoDeleteItems/AutoDeleteSystem.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

'EntityLookupSystem' does not contain a definition for 'GetEntitiesInRangeInt' and no accessible extension method 'GetEntitiesInRangeInt' accepting a first argument of type 'EntityLookupSystem' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 36 in Content.Server/Corvax/AutoDeleteItems/AutoDeleteSystem.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

'EntityLookupSystem' does not contain a definition for 'GetEntitiesInRangeInt' and no accessible extension method 'GetEntitiesInRangeInt' accepting a first argument of type 'EntityLookupSystem' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 36 in Content.Server/Corvax/AutoDeleteItems/AutoDeleteSystem.cs

View workflow job for this annotation

GitHub Actions / YAML Linter

'EntityLookupSystem' does not contain a definition for 'GetEntitiesInRangeInt' and no accessible extension method 'GetEntitiesInRangeInt' accepting a first argument of type 'EntityLookupSystem' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 36 in Content.Server/Corvax/AutoDeleteItems/AutoDeleteSystem.cs

View workflow job for this annotation

GitHub Actions / YAML Linter

'EntityLookupSystem' does not contain a definition for 'GetEntitiesInRangeInt' and no accessible extension method 'GetEntitiesInRangeInt' accepting a first argument of type 'EntityLookupSystem' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 36 in Content.Server/Corvax/AutoDeleteItems/AutoDeleteSystem.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

'EntityLookupSystem' does not contain a definition for 'GetEntitiesInRangeInt' and no accessible extension method 'GetEntitiesInRangeInt' accepting a first argument of type 'EntityLookupSystem' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 36 in Content.Server/Corvax/AutoDeleteItems/AutoDeleteSystem.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

'EntityLookupSystem' does not contain a definition for 'GetEntitiesInRangeInt' and no accessible extension method 'GetEntitiesInRangeInt' accepting a first argument of type 'EntityLookupSystem' could be found (are you missing a using directive or an assembly reference?)
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;
}
}
}

0 comments on commit af7f10c

Please sign in to comment.