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

@@ -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)
{
}
}

View File

@@ -45,7 +45,7 @@ namespace Content.Shared.Throwing
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())
{
return;
@@ -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);
}
}
}