Files
OldThink/Content.Shared/Standing/Systems/StandingStateSystem.Colliding.cs
Aviu00 7f1825b713 Фиксы (#314)
* - fix: Fix surplus discount.

* - fix: Fix clumsy bolt barrage.

* - fix: Bookshelf fix error.

* - fix: Fix lying.

* - add: Monkeys can lie down.

* Revert "- fix: Fix surplus discount."

This reverts commit b89f9dc75fa7908198cfe054a7623d4effbe63d6.

* - remove: No shuttle wall reflect.
2024-05-30 15:12:24 +03:00

68 lines
2.0 KiB
C#

using Content.Shared.Mobs.Systems;
using Content.Shared.Movement.Pulling.Components;
using Content.Shared.Projectiles;
using Content.Shared.Weapons.Ranged.Systems;
using Robust.Shared.Physics.Components;
using Robust.Shared.Random;
namespace Content.Shared.Standing.Systems;
// WD ADDED
public abstract partial class SharedStandingStateSystem
{
[Dependency] protected readonly IRobustRandom Random = default!;
private void InitializeColliding()
{
SubscribeLocalEvent<StandingStateComponent, ProjectileCollideAttemptEvent>(OnProjectileCollideAttempt);
SubscribeLocalEvent<StandingStateComponent, HitscanHitAttemptEvent>(OnHitscanHitAttempt);
}
private void OnProjectileCollideAttempt(EntityUid uid, StandingStateComponent component,
ref ProjectileCollideAttemptEvent args)
{
if (component.CurrentState is StandingState.Standing)
{
return;
}
if (!TryHit(uid, args.Component.Target, args.Component.IgnoreTarget))
{
args.Cancelled = true;
}
}
private void OnHitscanHitAttempt(EntityUid uid, StandingStateComponent component, ref HitscanHitAttemptEvent args)
{
if (component.CurrentState is StandingState.Standing)
{
return;
}
if (!TryHit(uid, args.Target))
{
args.Cancelled = true;
}
}
private bool TryHit(EntityUid uid, EntityUid? target, bool ignoreTarget = false)
{
// Lying and being pulled
if (!ignoreTarget && TryComp(uid, out PullableComponent? pullable) && pullable.BeingPulled)
return uid == target;
if (!TryComp(uid, out PhysicsComponent? physics))
return true;
// If alive and moving
if (_mobState.IsAlive(uid) && (ignoreTarget || physics.LinearVelocity.LengthSquared() > 0.01f))
{
// We should hit
return true;
}
// Only hit if we're target
return uid == target;
}
}