Add blacklist support for steptriggers (#14354)
This commit is contained in:
@@ -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]
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user