mirror of
https://github.com/corvax-team/ss14-wl.git
synced 2026-09-15 14:52:26 +02:00
* IoC source gen compatibility Can be merged before or after https://github.com/space-wizards/RobustToolbox/pull/6549 doesn't really matter. * Missed a spot
85 lines
2.6 KiB
C#
85 lines
2.6 KiB
C#
using Content.Shared.ActionBlocker;
|
|
using Content.Shared.Movement.Events;
|
|
using Content.Shared.StepTrigger.Systems;
|
|
using Content.Shared.Weapons.Misc;
|
|
using Robust.Shared.Audio.Systems;
|
|
using Robust.Shared.Network;
|
|
using Robust.Shared.Timing;
|
|
|
|
namespace Content.Shared.Chasm;
|
|
|
|
/// <summary>
|
|
/// Handles making entities fall into chasms when stepped on.
|
|
/// </summary>
|
|
public sealed partial class ChasmSystem : EntitySystem
|
|
{
|
|
[Dependency] private IGameTiming _timing = default!;
|
|
[Dependency] private ActionBlockerSystem _blocker = default!;
|
|
[Dependency] private INetManager _net = default!;
|
|
[Dependency] private SharedAudioSystem _audio = default!;
|
|
[Dependency] private SharedGrapplingGunSystem _grapple = 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)
|
|
{
|
|
if (_grapple.IsEntityHooked(args.Tripper))
|
|
{
|
|
args.Cancelled = true;
|
|
return;
|
|
}
|
|
|
|
args.Continue = true;
|
|
}
|
|
|
|
private void OnUpdateCanMove(EntityUid uid, ChasmFallingComponent component, UpdateCanMoveEvent args)
|
|
{
|
|
args.Cancel();
|
|
}
|
|
}
|