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:
@@ -24,7 +24,7 @@ public sealed class ChasmSystem : EntitySystem
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
SubscribeLocalEvent<ChasmComponent, StepTriggeredEvent>(OnStepTriggered);
|
||||
SubscribeLocalEvent<ChasmComponent, StepTriggeredOffEvent>(OnStepTriggered);
|
||||
SubscribeLocalEvent<ChasmComponent, StepTriggerAttemptEvent>(OnStepTriggerAttempt);
|
||||
SubscribeLocalEvent<ChasmFallingComponent, UpdateCanMoveEvent>(OnUpdateCanMove);
|
||||
}
|
||||
@@ -47,7 +47,7 @@ public sealed class ChasmSystem : EntitySystem
|
||||
}
|
||||
}
|
||||
|
||||
private void OnStepTriggered(EntityUid uid, ChasmComponent component, ref StepTriggeredEvent args)
|
||||
private void OnStepTriggered(EntityUid uid, ChasmComponent component, ref StepTriggeredOffEvent args)
|
||||
{
|
||||
// already doomed
|
||||
if (HasComp<ChasmFallingComponent>(args.Tripper))
|
||||
|
||||
@@ -31,14 +31,14 @@ public sealed class SlipperySystem : EntitySystem
|
||||
base.Initialize();
|
||||
|
||||
SubscribeLocalEvent<SlipperyComponent, StepTriggerAttemptEvent>(HandleAttemptCollide);
|
||||
SubscribeLocalEvent<SlipperyComponent, StepTriggeredEvent>(HandleStepTrigger);
|
||||
SubscribeLocalEvent<SlipperyComponent, StepTriggeredOffEvent>(HandleStepTrigger);
|
||||
SubscribeLocalEvent<NoSlipComponent, SlipAttemptEvent>(OnNoSlipAttempt);
|
||||
SubscribeLocalEvent<ThrownItemComponent, SlipCausingAttemptEvent>(OnThrownSlipAttempt);
|
||||
// as long as slip-resistant mice are never added, this should be fine (otherwise a mouse-hat will transfer it's power to the wearer).
|
||||
SubscribeLocalEvent<NoSlipComponent, InventoryRelayedEvent<SlipAttemptEvent>>((e, c, ev) => OnNoSlipAttempt(e, c, ev.Args));
|
||||
}
|
||||
|
||||
private void HandleStepTrigger(EntityUid uid, SlipperyComponent component, ref StepTriggeredEvent args)
|
||||
private void HandleStepTrigger(EntityUid uid, SlipperyComponent component, ref StepTriggeredOffEvent args)
|
||||
{
|
||||
TrySlip(uid, component, args.Tripper);
|
||||
}
|
||||
|
||||
@@ -49,8 +49,14 @@ public sealed partial class StepTriggerComponent : Component
|
||||
/// If this is true, steptrigger will still occur on entities that are in air / weightless. They do not
|
||||
/// by default.
|
||||
/// </summary>
|
||||
[DataField]
|
||||
[DataField, AutoNetworkedField]
|
||||
public bool IgnoreWeightless;
|
||||
|
||||
/// <summary>
|
||||
/// Does this have separate "StepOn" and "StepOff" triggers.
|
||||
/// </summary>
|
||||
[DataField, AutoNetworkedField]
|
||||
public bool StepOn = false;
|
||||
}
|
||||
|
||||
[RegisterComponent]
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user