Damage other on hit player feedback (#18539)

This commit is contained in:
Slava0135
2023-08-02 12:30:04 +03:00
committed by GitHub
parent 3e09fe4b7c
commit e6159d8581
5 changed files with 45 additions and 34 deletions

View File

@@ -1,16 +1,24 @@
using Content.Server.Administration.Logs; using Content.Server.Administration.Logs;
using Content.Server.Damage.Components; using Content.Server.Damage.Components;
using Content.Server.Weapons.Ranged.Systems;
using Content.Shared.Camera;
using Content.Shared.Damage; using Content.Shared.Damage;
using Content.Shared.Database; using Content.Shared.Database;
using Content.Shared.Effects;
using Content.Shared.Mobs.Components; using Content.Shared.Mobs.Components;
using Content.Shared.Throwing; using Content.Shared.Throwing;
using Robust.Shared.Physics.Components;
using Robust.Shared.Player;
namespace Content.Server.Damage.Systems namespace Content.Server.Damage.Systems
{ {
public sealed class DamageOtherOnHitSystem : EntitySystem public sealed class DamageOtherOnHitSystem : EntitySystem
{ {
[Dependency] private readonly DamageableSystem _damageableSystem = default!; [Dependency] private readonly DamageableSystem _damageableSystem = default!;
[Dependency] private readonly IAdminLogManager _adminLogger= 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() public override void Initialize()
{ {
@@ -19,11 +27,21 @@ namespace Content.Server.Damage.Systems
private void OnDoHit(EntityUid uid, DamageOtherOnHitComponent component, ThrowDoHitEvent args) 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. // 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)) if (dmg != null && HasComp<MobStateComponent>(args.Target))
_adminLogger.Add(LogType.ThrowHit, $"{ToPrettyString(args.Target):target} received {dmg.Total:damage} damage from collision"); _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);
} }
} }
} }

View File

@@ -309,8 +309,8 @@ public sealed class DisposalUnitSystem : SharedDisposalUnitSystem
return; return;
} }
if (args.User != null) if (args.Component.Thrower != null)
_adminLogger.Add(LogType.Landed, LogImpact.Low, $"{ToPrettyString(args.Thrown)} thrown by {ToPrettyString(args.User.Value):player} landed in {ToPrettyString(uid)}"); _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); AfterInsert(uid, component, args.Thrown);
} }

View File

@@ -82,7 +82,7 @@ namespace Content.Server.Nutrition.EntitySystems
protected override void CreamedEntity(EntityUid uid, CreamPiedComponent creamPied, ThrowHitByEvent args) protected override void CreamedEntity(EntityUid uid, CreamPiedComponent creamPied, ThrowHitByEvent args)
{ {
_popup.PopupEntity(Loc.GetString("cream-pied-component-on-hit-by-message",("thrower", args.Thrown)), uid, args.Target); _popup.PopupEntity(Loc.GetString("cream-pied-component-on-hit-by-message", ("thrower", args.Thrown)), uid, args.Target);
var otherPlayers = Filter.Empty().AddPlayersByPvs(uid); var otherPlayers = Filter.Empty().AddPlayersByPvs(uid);
if (TryComp<ActorComponent>(args.Target, out var actor)) if (TryComp<ActorComponent>(args.Target, out var actor))
{ {

View File

@@ -5,26 +5,15 @@ namespace Content.Shared.Throwing
/// </summary> /// </summary>
public abstract class ThrowEvent : HandledEntityEventArgs public abstract class ThrowEvent : HandledEntityEventArgs
{ {
/// <summary> public readonly EntityUid Thrown;
/// The entity that threw <see cref="Thrown"/>. public readonly EntityUid Target;
/// </summary> public ThrownItemComponent Component;
public EntityUid? User { get; }
/// <summary> public ThrowEvent(EntityUid thrown, EntityUid target, ThrownItemComponent component)
/// 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)
{ {
User = user;
Thrown = thrown; Thrown = thrown;
Target = target; Target = target;
Component = component;
} }
} }
@@ -33,7 +22,7 @@ namespace Content.Shared.Throwing
/// </summary> /// </summary>
public sealed class ThrowHitByEvent : ThrowEvent 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> /// </summary>
public sealed class ThrowDoHitEvent : ThrowEvent 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)
{ {
} }
} }

View File

@@ -45,7 +45,7 @@ namespace Content.Shared.Throwing
private void OnHandleState(EntityUid uid, ThrownItemComponent component, ref ComponentHandleState args) private void OnHandleState(EntityUid uid, ThrownItemComponent component, ref ComponentHandleState args)
{ {
if (args.Current is not ThrownItemComponentState {Thrower: not null } state || if (args.Current is not ThrownItemComponentState { Thrower: not null } state ||
!state.Thrower.Value.IsValid()) !state.Thrower.Value.IsValid())
{ {
return; return;
@@ -73,11 +73,10 @@ namespace Content.Shared.Throwing
if (args.OtherFixture.Hard == false) if (args.OtherFixture.Hard == false)
return; return;
var thrower = component.Thrower; if (args.OtherEntity == component.Thrower)
if (args.OtherEntity == thrower)
return; return;
ThrowCollideInteraction(thrower, args.OurBody, args.OtherBody); ThrowCollideInteraction(component, args.OurEntity, args.OtherEntity);
} }
private void PreventCollision(EntityUid uid, ThrownItemComponent component, ref PreventCollideEvent args) private void PreventCollision(EntityUid uid, ThrownItemComponent component, ref PreventCollideEvent args)
@@ -116,8 +115,13 @@ namespace Content.Shared.Throwing
EntityManager.RemoveComponent<ThrownItemComponent>(uid); 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); _physics.SetBodyStatus(physics, BodyStatus.OnGround);
if (thrownItem.Deleted || Deleted(uid) || _containerSystem.IsEntityInContainer(uid)) if (thrownItem.Deleted || Deleted(uid) || _containerSystem.IsEntityInContainer(uid))
@@ -145,14 +149,14 @@ namespace Content.Shared.Throwing
/// <summary> /// <summary>
/// Raises collision events on the thrown and target entities. /// Raises collision events on the thrown and target entities.
/// </summary> /// </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, _adminLogger.Add(LogType.ThrowHit, LogImpact.Low,
$"{ToPrettyString(thrown.Owner):thrown} thrown by {ToPrettyString(user.Value):thrower} hit {ToPrettyString(target.Owner):target}."); $"{ToPrettyString(thrown):thrown} thrown by {ToPrettyString(component.Thrower.Value):thrower} hit {ToPrettyString(target):target}.");
// TODO: Just pass in the bodies directly
RaiseLocalEvent(target.Owner, new ThrowHitByEvent(user, thrown.Owner, target.Owner), true); RaiseLocalEvent(target, new ThrowHitByEvent(thrown, target, component), true);
RaiseLocalEvent(thrown.Owner, new ThrowDoHitEvent(user, thrown.Owner, target.Owner), true); RaiseLocalEvent(thrown, new ThrowDoHitEvent(thrown, target, component), true);
} }
} }
} }