diff --git a/Content.Shared/Projectiles/EmbeddableProjectileComponent.cs b/Content.Shared/Projectiles/EmbeddableProjectileComponent.cs index 0ea90bcbd7..e6ca452da5 100644 --- a/Content.Shared/Projectiles/EmbeddableProjectileComponent.cs +++ b/Content.Shared/Projectiles/EmbeddableProjectileComponent.cs @@ -48,13 +48,13 @@ public sealed partial class EmbeddableProjectileComponent : Component public SoundSpecifier? Sound; // WD START - [AutoNetworkedField] + [ViewVariables, AutoNetworkedField] public bool PreventEmbedding; - [AutoNetworkedField] + [ViewVariables, AutoNetworkedField] public bool Penetrate; - [AutoNetworkedField] + [ViewVariables, AutoNetworkedField] public EntityUid? PenetratedUid; // WD END } diff --git a/Content.Shared/Projectiles/SharedProjectileSystem.cs b/Content.Shared/Projectiles/SharedProjectileSystem.cs index f2bd664cf8..efda021683 100644 --- a/Content.Shared/Projectiles/SharedProjectileSystem.cs +++ b/Content.Shared/Projectiles/SharedProjectileSystem.cs @@ -49,7 +49,10 @@ public abstract partial class SharedProjectileSystem : EntitySystem { // WD EDIT START if (args.Handled || !TryComp(uid, out var physics) || physics.BodyType != BodyType.Static) + { + FreePenetrated(component); return; + } args.Handled = true; @@ -66,6 +69,10 @@ public abstract partial class SharedProjectileSystem : EntitySystem if (component.DeleteOnRemove) { QueueDel(uid); + // WD START + FreePenetrated(component); + RaiseLocalEvent(uid, new EmbedRemovedEvent()); + // WD END return; } @@ -83,12 +90,7 @@ public abstract partial class SharedProjectileSystem : EntitySystem } // WD START - if (component.PenetratedUid != null) - { - _penetratedSystem.FreePenetrated(component.PenetratedUid.Value); - component.PenetratedUid = null; - } - + FreePenetrated(component); RaiseLocalEvent(uid, new EmbedRemovedEvent()); // WD END @@ -121,6 +123,7 @@ public abstract partial class SharedProjectileSystem : EntitySystem _transform.SetLocalPosition(args.Target, xform.LocalPosition + Transform(uid).LocalRotation.RotateVec(new Vector2(0.5f, 0.5f)), xform); Dirty(uid, component); + Dirty(args.Target, penetrated); return; } @@ -207,12 +210,14 @@ public abstract partial class SharedProjectileSystem : EntitySystem private void OnEntityTerminating(EntityUid uid, EmbeddableProjectileComponent component, ref EntityTerminatingEvent args) { - FreePenetrated(component); + if (!_netManager.IsClient) + FreePenetrated(component); } private void OnRemove(EntityUid uid, EmbeddableProjectileComponent component, ComponentRemove args) { - FreePenetrated(component); + if (!_netManager.IsClient) + FreePenetrated(component); } private void FreePenetrated(EmbeddableProjectileComponent component) @@ -223,7 +228,7 @@ public abstract partial class SharedProjectileSystem : EntitySystem _penetratedSystem.FreePenetrated(component.PenetratedUid.Value); component.PenetratedUid = null; } - + private void OnLand(EntityUid uid, EmbeddableProjectileComponent component, ref LandEvent args) { if (component.PenetratedUid == null) diff --git a/Content.Shared/White/Crossbow/PenetratedComponent.cs b/Content.Shared/White/Crossbow/PenetratedComponent.cs index 334bbc0992..4eb704e82d 100644 --- a/Content.Shared/White/Crossbow/PenetratedComponent.cs +++ b/Content.Shared/White/Crossbow/PenetratedComponent.cs @@ -1,9 +1,13 @@ +using Robust.Shared.GameStates; + namespace Content.Shared.White.Crossbow; -[RegisterComponent] +[RegisterComponent, NetworkedComponent, AutoGenerateComponentState] public sealed partial class PenetratedComponent : Component { + [ViewVariables(VVAccess.ReadWrite), AutoNetworkedField] public EntityUid? ProjectileUid; + [ViewVariables(VVAccess.ReadWrite), AutoNetworkedField] public bool IsPinned; } diff --git a/Content.Shared/White/Crossbow/PenetratedSystem.cs b/Content.Shared/White/Crossbow/PenetratedSystem.cs index ad679fe122..cab117f6b4 100644 --- a/Content.Shared/White/Crossbow/PenetratedSystem.cs +++ b/Content.Shared/White/Crossbow/PenetratedSystem.cs @@ -23,19 +23,27 @@ public sealed class PenetratedSystem : EntitySystem { if (component is {ProjectileUid: not null, IsPinned: true}) _projectile.AttemptEmbedRemove(component.ProjectileUid.Value, uid); + 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) + public void FreePenetrated(EntityUid uid, PenetratedComponent? penetrated = null, PhysicsComponent? physics = null) { + var xform = Transform(uid); + _transform.AttachToGridOrMap(uid, xform); + + if (Resolve(uid, ref physics, false)) + { + _physics.SetBodyType(uid, BodyType.KinematicController, body: physics, xform: xform); + _physics.WakeBody(uid, body: physics); + } + if (!Resolve(uid, ref penetrated, false)) return; - var xform = Transform(uid); - TryComp(uid, out var physics); - _physics.SetBodyType(uid, BodyType.Dynamic, body: physics, xform: xform); - _transform.AttachToGridOrMap(uid, xform); penetrated.ProjectileUid = null; penetrated.IsPinned = false; - _physics.WakeBody(uid, body: physics); + Dirty(uid, penetrated); } }