Damage other on hit player feedback (#18539)
This commit is contained in:
@@ -1,9 +1,14 @@
|
||||
using Content.Server.Administration.Logs;
|
||||
using Content.Server.Damage.Components;
|
||||
using Content.Server.Weapons.Ranged.Systems;
|
||||
using Content.Shared.Camera;
|
||||
using Content.Shared.Damage;
|
||||
using Content.Shared.Database;
|
||||
using Content.Shared.Effects;
|
||||
using Content.Shared.Mobs.Components;
|
||||
using Content.Shared.Throwing;
|
||||
using Robust.Shared.Physics.Components;
|
||||
using Robust.Shared.Player;
|
||||
|
||||
namespace Content.Server.Damage.Systems
|
||||
{
|
||||
@@ -11,6 +16,9 @@ namespace Content.Server.Damage.Systems
|
||||
{
|
||||
[Dependency] private readonly DamageableSystem _damageableSystem = default!;
|
||||
[Dependency] private readonly IAdminLogManager _adminLogger = default!;
|
||||
[Dependency] private readonly GunSystem _guns = default!;
|
||||
[Dependency] private readonly SharedCameraRecoilSystem _sharedCameraRecoil = default!;
|
||||
[Dependency] private readonly ThrownItemSystem _thrownItem = default!;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
@@ -19,11 +27,21 @@ namespace Content.Server.Damage.Systems
|
||||
|
||||
private void OnDoHit(EntityUid uid, DamageOtherOnHitComponent component, ThrowDoHitEvent args)
|
||||
{
|
||||
var dmg = _damageableSystem.TryChangeDamage(args.Target, component.Damage, component.IgnoreResistances, origin: args.User);
|
||||
var dmg = _damageableSystem.TryChangeDamage(args.Target, component.Damage, component.IgnoreResistances, origin: args.Component.Thrower);
|
||||
|
||||
// Log damage only for mobs. Useful for when people throw spears at each other, but also avoids log-spam when explosions send glass shards flying.
|
||||
if (dmg != null && HasComp<MobStateComponent>(args.Target))
|
||||
_adminLogger.Add(LogType.ThrowHit, $"{ToPrettyString(args.Target):target} received {dmg.Total:damage} damage from collision");
|
||||
|
||||
RaiseNetworkEvent(new ColorFlashEffectEvent(Color.Red, new List<EntityUid> { args.Target }), Filter.Pvs(args.Target, entityManager: EntityManager));
|
||||
_guns.PlayImpactSound(args.Target, dmg, null, false);
|
||||
if (TryComp<PhysicsComponent>(uid, out var body) && body.LinearVelocity.LengthSquared() > 0f)
|
||||
{
|
||||
var direction = body.LinearVelocity.Normalized();
|
||||
_sharedCameraRecoil.KickCamera(args.Target, direction);
|
||||
}
|
||||
|
||||
_thrownItem.LandComponent(args.Thrown, args.Component, playSound: false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -309,8 +309,8 @@ public sealed class DisposalUnitSystem : SharedDisposalUnitSystem
|
||||
return;
|
||||
}
|
||||
|
||||
if (args.User != null)
|
||||
_adminLogger.Add(LogType.Landed, LogImpact.Low, $"{ToPrettyString(args.Thrown)} thrown by {ToPrettyString(args.User.Value):player} landed in {ToPrettyString(uid)}");
|
||||
if (args.Component.Thrower != null)
|
||||
_adminLogger.Add(LogType.Landed, LogImpact.Low, $"{ToPrettyString(args.Thrown)} thrown by {ToPrettyString(args.Component.Thrower.Value):player} landed in {ToPrettyString(uid)}");
|
||||
|
||||
AfterInsert(uid, component, args.Thrown);
|
||||
}
|
||||
|
||||
@@ -5,26 +5,15 @@ namespace Content.Shared.Throwing
|
||||
/// </summary>
|
||||
public abstract class ThrowEvent : HandledEntityEventArgs
|
||||
{
|
||||
/// <summary>
|
||||
/// The entity that threw <see cref="Thrown"/>.
|
||||
/// </summary>
|
||||
public EntityUid? User { get; }
|
||||
public readonly EntityUid Thrown;
|
||||
public readonly EntityUid Target;
|
||||
public ThrownItemComponent Component;
|
||||
|
||||
/// <summary>
|
||||
/// The entity thrown by <see cref="User"/> that hit <see cref="Target"/>
|
||||
/// </summary>
|
||||
public EntityUid Thrown { get; }
|
||||
|
||||
/// <summary>
|
||||
/// The entity hit with <see cref="Thrown"/> by <see cref="User"/>
|
||||
/// </summary>
|
||||
public EntityUid Target { get; }
|
||||
|
||||
public ThrowEvent(EntityUid? user, EntityUid thrown, EntityUid target)
|
||||
public ThrowEvent(EntityUid thrown, EntityUid target, ThrownItemComponent component)
|
||||
{
|
||||
User = user;
|
||||
Thrown = thrown;
|
||||
Target = target;
|
||||
Component = component;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,7 +22,7 @@ namespace Content.Shared.Throwing
|
||||
/// </summary>
|
||||
public sealed class ThrowHitByEvent : ThrowEvent
|
||||
{
|
||||
public ThrowHitByEvent(EntityUid? user, EntityUid thrown, EntityUid target) : base(user, thrown, target)
|
||||
public ThrowHitByEvent(EntityUid thrown, EntityUid target, ThrownItemComponent component) : base(thrown, target, component)
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -43,7 +32,7 @@ namespace Content.Shared.Throwing
|
||||
/// </summary>
|
||||
public sealed class ThrowDoHitEvent : ThrowEvent
|
||||
{
|
||||
public ThrowDoHitEvent(EntityUid? user, EntityUid thrown, EntityUid target) : base(user, thrown, target)
|
||||
public ThrowDoHitEvent(EntityUid thrown, EntityUid target, ThrownItemComponent component) : base(thrown, target, component)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
@@ -73,11 +73,10 @@ namespace Content.Shared.Throwing
|
||||
if (args.OtherFixture.Hard == false)
|
||||
return;
|
||||
|
||||
var thrower = component.Thrower;
|
||||
if (args.OtherEntity == thrower)
|
||||
if (args.OtherEntity == component.Thrower)
|
||||
return;
|
||||
|
||||
ThrowCollideInteraction(thrower, args.OurBody, args.OtherBody);
|
||||
ThrowCollideInteraction(component, args.OurEntity, args.OtherEntity);
|
||||
}
|
||||
|
||||
private void PreventCollision(EntityUid uid, ThrownItemComponent component, ref PreventCollideEvent args)
|
||||
@@ -116,8 +115,13 @@ namespace Content.Shared.Throwing
|
||||
EntityManager.RemoveComponent<ThrownItemComponent>(uid);
|
||||
}
|
||||
|
||||
public void LandComponent(EntityUid uid, ThrownItemComponent thrownItem, PhysicsComponent physics, bool playSound)
|
||||
public void LandComponent(EntityUid uid, ThrownItemComponent thrownItem, PhysicsComponent? physics = null, bool playSound = true)
|
||||
{
|
||||
if (!Resolve(uid, ref physics))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_physics.SetBodyStatus(physics, BodyStatus.OnGround);
|
||||
|
||||
if (thrownItem.Deleted || Deleted(uid) || _containerSystem.IsEntityInContainer(uid))
|
||||
@@ -145,14 +149,14 @@ namespace Content.Shared.Throwing
|
||||
/// <summary>
|
||||
/// Raises collision events on the thrown and target entities.
|
||||
/// </summary>
|
||||
public void ThrowCollideInteraction(EntityUid? user, PhysicsComponent thrown, PhysicsComponent target)
|
||||
public void ThrowCollideInteraction(ThrownItemComponent component, EntityUid thrown, EntityUid target)
|
||||
{
|
||||
if (user is not null)
|
||||
if (component.Thrower is not null)
|
||||
_adminLogger.Add(LogType.ThrowHit, LogImpact.Low,
|
||||
$"{ToPrettyString(thrown.Owner):thrown} thrown by {ToPrettyString(user.Value):thrower} hit {ToPrettyString(target.Owner):target}.");
|
||||
// TODO: Just pass in the bodies directly
|
||||
RaiseLocalEvent(target.Owner, new ThrowHitByEvent(user, thrown.Owner, target.Owner), true);
|
||||
RaiseLocalEvent(thrown.Owner, new ThrowDoHitEvent(user, thrown.Owner, target.Owner), true);
|
||||
$"{ToPrettyString(thrown):thrown} thrown by {ToPrettyString(component.Thrower.Value):thrower} hit {ToPrettyString(target):target}.");
|
||||
|
||||
RaiseLocalEvent(target, new ThrowHitByEvent(thrown, target, component), true);
|
||||
RaiseLocalEvent(thrown, new ThrowDoHitEvent(thrown, target, component), true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user