Fix penetration (#336)

* Fix penetration

* Fix another bug
This commit is contained in:
Aviu00
2023-08-27 00:01:55 +03:00
committed by Aviu00
parent e3890767af
commit 275af726ab
2 changed files with 15 additions and 6 deletions

View File

@@ -4,6 +4,7 @@ using Content.Shared.Damage;
using Content.Shared.DoAfter;
using Content.Shared.Hands.EntitySystems;
using Content.Shared.Interaction;
using Content.Shared.Movement.Components;
using Content.Shared.Throwing;
using Content.Shared.White.Crossbow;
using Robust.Shared.Audio.Systems;
@@ -56,7 +57,8 @@ public abstract partial class SharedProjectileSystem : EntitySystem
args.Handled = true;
AttemptEmbedRemove(uid, args.User, component);
if (!AttemptEmbedRemove(uid, args.User, component))
FreePenetrated(component);
// WD EDIT END
}
@@ -129,6 +131,8 @@ public abstract partial class SharedProjectileSystem : EntitySystem
if (component.PenetratedUid == args.Target)
args.Handled = true;
else if (HasComp<MobMoverComponent>(args.Target) || HasComp<InputMoverComponent>(args.Target))
FreePenetrated(component);
// WD END
Embed(uid, args.Target, component);
@@ -242,16 +246,16 @@ public abstract partial class SharedProjectileSystem : EntitySystem
Embed(uid, penetratedUid, component);
}
public void AttemptEmbedRemove(EntityUid uid, EntityUid user, EmbeddableProjectileComponent? component = null)
public bool AttemptEmbedRemove(EntityUid uid, EntityUid user, EmbeddableProjectileComponent? component = null)
{
if (!Resolve(uid, ref component, false))
return;
return false;
// Nuh uh
if (component.RemovalTime == null)
return;
return false;
_doAfter.TryStartDoAfter(new DoAfterArgs(EntityManager, user, component.RemovalTime.Value,
return _doAfter.TryStartDoAfter(new DoAfterArgs(EntityManager, user, component.RemovalTime.Value,
new RemoveEmbeddedProjectileEvent(), eventTarget: uid, target: uid)
{
DistanceThreshold = SharedInteractionSystem.InteractionRange,

View File

@@ -22,10 +22,15 @@ public sealed class PenetratedSystem : EntitySystem
private void OnMoveInput(EntityUid uid, PenetratedComponent component, ref MoveInputEvent args)
{
if (component is {ProjectileUid: not null, IsPinned: true})
_projectile.AttemptEmbedRemove(component.ProjectileUid.Value, uid);
{
if (!_projectile.AttemptEmbedRemove(component.ProjectileUid.Value, uid))
FreePenetrated(uid, component);
}
else if (component.ProjectileUid == null && TryComp(uid, out PhysicsComponent? physics) &&
physics.BodyType == BodyType.Static)
{
FreePenetrated(uid, component, physics);
}
}
public void FreePenetrated(EntityUid uid, PenetratedComponent? penetrated = null, PhysicsComponent? physics = null)