mirror of
https://github.com/WWhiteDreamProject/wwdpublic.git
synced 2026-04-17 13:37:47 +03:00
62 lines
2.2 KiB
C#
62 lines
2.2 KiB
C#
using Content.Shared._White.Repulse.Components;
|
|
using Content.Shared.Interaction;
|
|
using Content.Shared.Standing;
|
|
using Content.Shared.Stunnable;
|
|
using Content.Shared.Whitelist;
|
|
using Robust.Shared.Physics.Events;
|
|
using Robust.Shared.Physics.Systems;
|
|
|
|
namespace Content.Shared._White.Repulse;
|
|
|
|
public sealed class RepulseSystem : EntitySystem
|
|
{
|
|
[Dependency] private readonly EntityWhitelistSystem _entityWhitelist = default!;
|
|
[Dependency] private readonly SharedTransformSystem _transform = default!;
|
|
[Dependency] private readonly SharedStunSystem _stunSystem = default!;
|
|
[Dependency] private readonly SharedPhysicsSystem _physics = default!;
|
|
|
|
public override void Initialize()
|
|
{
|
|
base.Initialize();
|
|
|
|
SubscribeLocalEvent<RepulseOnTouchComponent, StartCollideEvent>(HandleCollision);
|
|
SubscribeLocalEvent<RepulseComponent, InteractHandEvent>(OnHandInteract);
|
|
}
|
|
|
|
private void HandleCollision(Entity<RepulseOnTouchComponent> touchRepulsor, ref StartCollideEvent args)
|
|
{
|
|
if (!TryComp(touchRepulsor, out RepulseComponent? repulse))
|
|
return;
|
|
|
|
Repulse((touchRepulsor.Owner, repulse), args.OtherEntity);
|
|
}
|
|
|
|
private void OnHandInteract(Entity<RepulseComponent> repulsor, ref InteractHandEvent args)
|
|
{
|
|
Repulse(repulsor, args.User);
|
|
}
|
|
|
|
public void Repulse(Entity<RepulseComponent> repulsor, EntityUid user)
|
|
{
|
|
if (_entityWhitelist.IsBlacklistPass(repulsor.Comp.TargetBlacklist, user))
|
|
return;
|
|
|
|
var ev = new BeforeRepulseEvent(user);
|
|
RaiseLocalEvent(repulsor, ev);
|
|
if (ev.Cancelled)
|
|
return;
|
|
|
|
var direction = _transform.GetMapCoordinates(user).Position - _transform.GetMapCoordinates(repulsor).Position;
|
|
var impulse = direction * repulsor.Comp.ForceMultiplier;
|
|
|
|
_physics.ApplyLinearImpulse(user, impulse);
|
|
_stunSystem.TryStun(user, repulsor.Comp.StunDuration, true);
|
|
_stunSystem.TryKnockdown(user, repulsor.Comp.KnockdownDuration, true, DropHeldItemsBehavior.DropIfStanding);
|
|
}
|
|
}
|
|
|
|
public sealed class BeforeRepulseEvent(EntityUid target) : CancellableEntityEventArgs
|
|
{
|
|
public EntityUid Target = target;
|
|
}
|