Files
crystall-punk-14/Content.Server/Stunnable/Systems/StunOnCollideSystem.cs

48 lines
1.7 KiB
C#
Raw Normal View History

using Content.Server.Stunnable.Components;
using Content.Shared.Standing;
using Content.Shared.StatusEffect;
using JetBrains.Annotations;
using Robust.Shared.Physics.Dynamics;
using Content.Shared.Throwing;
using Robust.Shared.Physics.Events;
namespace Content.Server.Stunnable
{
[UsedImplicitly]
internal sealed class StunOnCollideSystem : EntitySystem
{
[Dependency] private readonly StunSystem _stunSystem = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<StunOnCollideComponent, StartCollideEvent>(HandleCollide);
SubscribeLocalEvent<StunOnCollideComponent, ThrowDoHitEvent>(HandleThrow);
}
private void TryDoCollideStun(EntityUid uid, StunOnCollideComponent component, EntityUid target)
{
if (!TryComp<StatusEffectsComponent>(target, out var status))
return;
_stunSystem.TryStun(target, component.StunAmount, component.Refresh, status);
_stunSystem.TryKnockdown(target, component.KnockdownAmount, component.Refresh, component.AutoStand);
_stunSystem.TrySlowdown(target, component.SlowdownAmount, component.Refresh, component.WalkSpeedModifier, component.SprintSpeedModifier, status);
}
private void HandleCollide(EntityUid uid, StunOnCollideComponent component, ref StartCollideEvent args)
{
2023-08-23 18:55:58 +10:00
if (args.OurFixtureId != component.FixtureID)
return;
2022-05-21 18:04:47 +10:00
TryDoCollideStun(uid, component, args.OtherEntity);
}
private void HandleThrow(EntityUid uid, StunOnCollideComponent component, ThrowDoHitEvent args)
{
TryDoCollideStun(uid, component, args.Target);
}
}
}