Landmine stepoff (#22962)

* make landmine work on stepping off

* update methods naming

* made both step modes possible

* updated stepoff event raise to not interfere with game physics internals

* added comments

* figuring out how audiosystem works

* added beep sound effect, updated how stepoff trigger works to make it more consistent

* updated source in attributions.yml

* made stepoff working every time

* introduced suggested changes

* updated janitor's WetSignMine to have audio

* made cleaner events and bashing my head at OnEndCollide event raise

* inverted conditional where applicable

* review

---------

Co-authored-by: Yurii Kis <yurii.kis@smartteksas.com>
Co-authored-by: metalgearsloth <comedian_vs_clown@hotmail.com>
This commit is contained in:
KISS
2024-03-24 07:33:45 +02:00
committed by GitHub
parent f96cf360e9
commit 54dd273f66
13 changed files with 97 additions and 49 deletions

View File

@@ -11,6 +11,7 @@ public sealed class StepTriggerSystem : EntitySystem
{
[Dependency] private readonly EntityLookupSystem _entityLookup = default!;
[Dependency] private readonly SharedGravitySystem _gravity = default!;
[Dependency] private readonly SharedMapSystem _map = default!;
public override void Initialize()
{
@@ -40,7 +41,9 @@ public sealed class StepTriggerSystem : EntitySystem
while (enumerator.MoveNext(out var uid, out var active, out var trigger, out var transform))
{
if (!Update(uid, trigger, transform, query))
{
continue;
}
RemCompDeferred(uid, active);
}
@@ -56,7 +59,8 @@ public sealed class StepTriggerSystem : EntitySystem
if (component.Blacklist != null && TryComp<MapGridComponent>(transform.GridUid, out var grid))
{
var anch = grid.GetAnchoredEntitiesEnumerator(grid.LocalToTile(transform.Coordinates));
var positon = _map.LocalToTile(uid, grid, transform.Coordinates);
var anch = _map.GetAnchoredEntitiesEnumerator(uid, grid, positon);
while (anch.MoveNext(out var ent))
{
@@ -109,8 +113,16 @@ public sealed class StepTriggerSystem : EntitySystem
return;
}
var ev = new StepTriggeredEvent { Source = uid, Tripper = otherUid };
RaiseLocalEvent(uid, ref ev, true);
if (component.StepOn)
{
var evStep = new StepTriggeredOnEvent(uid, otherUid);
RaiseLocalEvent(uid, ref evStep);
}
else
{
var evStep = new StepTriggeredOffEvent(uid, otherUid);
RaiseLocalEvent(uid, ref evStep);
}
component.CurrentlySteppedOn.Add(otherUid);
Dirty(uid, component);
@@ -130,7 +142,7 @@ public sealed class StepTriggerSystem : EntitySystem
var msg = new StepTriggerAttemptEvent { Source = uid, Tripper = otherUid };
RaiseLocalEvent(uid, ref msg, true);
RaiseLocalEvent(uid, ref msg);
return msg.Continue && !msg.Cancelled;
}
@@ -163,6 +175,12 @@ public sealed class StepTriggerSystem : EntitySystem
component.CurrentlySteppedOn.Remove(otherUid);
Dirty(uid, component);
if (component.StepOn)
{
var evStepOff = new StepTriggeredOffEvent(uid, otherUid);
RaiseLocalEvent(uid, ref evStepOff);
}
if (component.Colliding.Count == 0)
{
RemCompDeferred<StepTriggerActiveComponent>(uid);
@@ -230,9 +248,14 @@ public struct StepTriggerAttemptEvent
public bool Cancelled;
}
/// <summary>
/// Raised when an entity stands on a steptrigger initially (assuming it has both on and off states).
/// </summary>
[ByRefEvent]
public struct StepTriggeredEvent
{
public EntityUid Source;
public EntityUid Tripper;
}
public readonly record struct StepTriggeredOnEvent(EntityUid Source, EntityUid Tripper);
/// <summary>
/// Raised when an entity leaves a steptrigger if it has on and off states OR when an entity intersects a steptrigger.
/// </summary>
[ByRefEvent]
public readonly record struct StepTriggeredOffEvent(EntityUid Source, EntityUid Tripper);