Add blacklist support for steptriggers (#14354)

This commit is contained in:
metalgearsloth
2023-03-07 06:11:27 +11:00
committed by GitHub
parent f4ccfc5e35
commit 320217cd69
5 changed files with 41 additions and 4 deletions

View File

@@ -1,4 +1,5 @@
using Content.Shared.StepTrigger.Systems;
using Content.Shared.Whitelist;
using Robust.Shared.GameStates;
using Robust.Shared.Serialization;
@@ -39,6 +40,12 @@ public sealed class StepTriggerComponent : Component
/// </summary>
[DataField("requiredTriggeredSpeed")]
public float RequiredTriggerSpeed = 3.5f;
/// <summary>
/// If any entities occupy the blacklist on the same tile then steptrigger won't work.
/// </summary>
[DataField("blacklist")]
public EntityWhitelist? Blacklist;
}
[RegisterComponent]

View File

@@ -1,6 +1,8 @@
using Content.Shared.StepTrigger.Components;
using Content.Shared.Tag;
using Robust.Shared.Collections;
using Robust.Shared.GameStates;
using Robust.Shared.Map.Components;
using Robust.Shared.Physics;
using Robust.Shared.Physics.Components;
using Robust.Shared.Physics.Events;
@@ -37,20 +39,38 @@ public sealed class StepTriggerSystem : EntitySystem
var query = GetEntityQuery<PhysicsComponent>();
var enumerator = EntityQueryEnumerator<StepTriggerActiveComponent, StepTriggerComponent, TransformComponent>();
while (enumerator.MoveNext(out var active, out var trigger, out var transform))
while (enumerator.MoveNext(out var uid, out var active, out var trigger, out var transform))
{
if (!Update(trigger, transform, query))
if (!Update(uid, trigger, transform, query))
continue;
RemCompDeferred(trigger.Owner, active);
RemCompDeferred(uid, active);
}
}
private bool Update(StepTriggerComponent component, TransformComponent transform, EntityQuery<PhysicsComponent> query)
private bool Update(EntityUid uid, StepTriggerComponent component, TransformComponent transform, EntityQuery<PhysicsComponent> query)
{
if (!component.Active ||
component.Colliding.Count == 0)
{
return true;
}
if (component.Blacklist != null && TryComp<MapGridComponent>(transform.GridUid, out var grid))
{
var anch = grid.GetAnchoredEntitiesEnumerator(grid.LocalToTile(transform.Coordinates));
while (anch.MoveNext(out var ent))
{
if (ent == uid)
continue;
if (component.Blacklist.IsValid(ent.Value, EntityManager) == true)
{
return false;
}
}
}
foreach (var otherUid in component.Colliding)
{

View File

@@ -22,6 +22,9 @@
- type: FootstepModifier
footstepSoundCollection:
collection: FootstepCatwalk
- type: Tag
tags:
- Catwalk
- type: Construction
graph: Catwalk
node: Catwalk

View File

@@ -9,6 +9,9 @@
- type: StepTrigger
requiredTriggeredSpeed: 0
intersectRatio: 0.1
blacklist:
tags:
- Catwalk
- type: Lava
- type: Transform
anchored: true

View File

@@ -111,6 +111,10 @@
- type: Tag
id: CartridgeRocket
# Allows you to walk over tile entities such as lava without steptrigger
- type: Tag
id: Catwalk
- type: Tag
id: Cigarette