From 86f222be9f188c83c58a5f479babf9f30111d2f0 Mon Sep 17 00:00:00 2001 From: Slava0135 <40753025+Slava0135@users.noreply.github.com> Date: Wed, 2 Aug 2023 15:44:27 +0300 Subject: [PATCH] Fix damaging thrown item phasing through walls (#18574) --- .../Damage/Systems/DamageOtherOnHitSystem.cs | 8 +++++- Content.Shared/Throwing/ThrownItemSystem.cs | 26 +++++-------------- 2 files changed, 13 insertions(+), 21 deletions(-) diff --git a/Content.Server/Damage/Systems/DamageOtherOnHitSystem.cs b/Content.Server/Damage/Systems/DamageOtherOnHitSystem.cs index 04e6315742..406cce8bb5 100644 --- a/Content.Server/Damage/Systems/DamageOtherOnHitSystem.cs +++ b/Content.Server/Damage/Systems/DamageOtherOnHitSystem.cs @@ -8,6 +8,7 @@ using Content.Shared.Effects; using Content.Shared.Mobs.Components; using Content.Shared.Throwing; using Robust.Shared.Physics.Components; +using Robust.Shared.Physics.Systems; using Robust.Shared.Player; namespace Content.Server.Damage.Systems @@ -19,6 +20,7 @@ namespace Content.Server.Damage.Systems [Dependency] private readonly GunSystem _guns = default!; [Dependency] private readonly SharedCameraRecoilSystem _sharedCameraRecoil = default!; [Dependency] private readonly ThrownItemSystem _thrownItem = default!; + [Dependency] private readonly SharedPhysicsSystem _physics = default!; public override void Initialize() { @@ -41,7 +43,11 @@ namespace Content.Server.Damage.Systems _sharedCameraRecoil.KickCamera(args.Target, direction); } - _thrownItem.LandComponent(args.Thrown, args.Component, playSound: false); + if (TryComp(uid, out var physics)) + { + _thrownItem.LandComponent(args.Thrown, args.Component, physics, false); + _physics.ResetDynamics(physics); + } } } } diff --git a/Content.Shared/Throwing/ThrownItemSystem.cs b/Content.Shared/Throwing/ThrownItemSystem.cs index 0c462a9573..87378d10cf 100644 --- a/Content.Shared/Throwing/ThrownItemSystem.cs +++ b/Content.Shared/Throwing/ThrownItemSystem.cs @@ -1,7 +1,6 @@ using System.Linq; using Content.Shared.Administration.Logs; using Content.Shared.Database; -using Content.Shared.Hands.Components; using Content.Shared.Physics; using Content.Shared.Physics.Pull; using Robust.Shared.Containers; @@ -115,35 +114,22 @@ namespace Content.Shared.Throwing EntityManager.RemoveComponent(uid); } - public void LandComponent(EntityUid uid, ThrownItemComponent thrownItem, PhysicsComponent? physics = null, bool playSound = true) + public void LandComponent(EntityUid uid, ThrownItemComponent thrownItem, PhysicsComponent physics, bool playSound) { - if (!Resolve(uid, ref physics)) - { - return; - } - _physics.SetBodyStatus(physics, BodyStatus.OnGround); - if (thrownItem.Deleted || Deleted(uid) || _containerSystem.IsEntityInContainer(uid)) + if (thrownItem.Deleted || Deleted(uid)) return; - var landing = uid; - - // Unfortunately we can't check for hands containers as they have specific names. - if (uid.TryGetContainerMan(out var containerManager) && - EntityManager.HasComponent(containerManager.Owner)) - { - EntityManager.RemoveComponent(landing, thrownItem); - return; - } - // Assume it's uninteresting if it has no thrower. For now anyway. if (thrownItem.Thrower is not null) - _adminLogger.Add(LogType.Landed, LogImpact.Low, $"{ToPrettyString(landing):entity} thrown by {ToPrettyString(thrownItem.Thrower.Value):thrower} landed."); + _adminLogger.Add(LogType.Landed, LogImpact.Low, $"{ToPrettyString(uid):entity} thrown by {ToPrettyString(thrownItem.Thrower.Value):thrower} landed."); _broadphase.RegenerateContacts(uid, physics); var landEvent = new LandEvent(thrownItem.Thrower, playSound); - RaiseLocalEvent(landing, ref landEvent); + RaiseLocalEvent(uid, ref landEvent); + + StopThrow(uid, thrownItem); } ///