Fix damaging thrown item phasing through walls (#18574)

This commit is contained in:
Slava0135
2023-08-02 15:44:27 +03:00
committed by GitHub
parent 26dd6f2cdf
commit 86f222be9f
2 changed files with 13 additions and 21 deletions

View File

@@ -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<PhysicsComponent>(uid, out var physics))
{
_thrownItem.LandComponent(args.Thrown, args.Component, physics, false);
_physics.ResetDynamics(physics);
}
}
}
}

View File

@@ -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<ThrownItemComponent>(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<HandsComponent>(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);
}
/// <summary>