Files
tbd-station-14/Content.Shared/Chasm/ChasmSystem.cs
KISS 54dd273f66 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>
2024-03-24 16:33:45 +11:00

80 lines
2.5 KiB
C#

using Content.Shared.ActionBlocker;
using Content.Shared.Buckle.Components;
using Content.Shared.Movement.Events;
using Content.Shared.StepTrigger.Systems;
using Robust.Shared.Audio;
using Robust.Shared.Audio.Systems;
using Robust.Shared.Network;
using Robust.Shared.Physics.Components;
using Robust.Shared.Timing;
namespace Content.Shared.Chasm;
/// <summary>
/// Handles making entities fall into chasms when stepped on.
/// </summary>
public sealed class ChasmSystem : EntitySystem
{
[Dependency] private readonly IGameTiming _timing = default!;
[Dependency] private readonly ActionBlockerSystem _blocker = default!;
[Dependency] private readonly INetManager _net = default!;
[Dependency] private readonly SharedAudioSystem _audio = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<ChasmComponent, StepTriggeredOffEvent>(OnStepTriggered);
SubscribeLocalEvent<ChasmComponent, StepTriggerAttemptEvent>(OnStepTriggerAttempt);
SubscribeLocalEvent<ChasmFallingComponent, UpdateCanMoveEvent>(OnUpdateCanMove);
}
public override void Update(float frameTime)
{
base.Update(frameTime);
// don't predict queuedels on client
if (_net.IsClient)
return;
var query = EntityQueryEnumerator<ChasmFallingComponent>();
while (query.MoveNext(out var uid, out var chasm))
{
if (_timing.CurTime < chasm.NextDeletionTime)
continue;
QueueDel(uid);
}
}
private void OnStepTriggered(EntityUid uid, ChasmComponent component, ref StepTriggeredOffEvent args)
{
// already doomed
if (HasComp<ChasmFallingComponent>(args.Tripper))
return;
StartFalling(uid, component, args.Tripper);
}
public void StartFalling(EntityUid chasm, ChasmComponent component, EntityUid tripper, bool playSound = true)
{
var falling = AddComp<ChasmFallingComponent>(tripper);
falling.NextDeletionTime = _timing.CurTime + falling.DeletionTime;
_blocker.UpdateCanMove(tripper);
if (playSound)
_audio.PlayPredicted(component.FallingSound, chasm, tripper);
}
private void OnStepTriggerAttempt(EntityUid uid, ChasmComponent component, ref StepTriggerAttemptEvent args)
{
args.Continue = true;
}
private void OnUpdateCanMove(EntityUid uid, ChasmFallingComponent component, UpdateCanMoveEvent args)
{
args.Cancel();
}
}