Port boxer from Nyano (#9080)
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
using Content.Shared.Sound;
|
||||
|
||||
namespace Content.Server.Damage.Components;
|
||||
|
||||
[RegisterComponent]
|
||||
@@ -5,4 +7,10 @@ public sealed class StaminaDamageOnHitComponent : Component
|
||||
{
|
||||
[ViewVariables(VVAccess.ReadWrite), DataField("damage")]
|
||||
public float Damage = 30f;
|
||||
|
||||
/// <summary>
|
||||
/// Play a sound when this knocks down an entity.
|
||||
/// </summary>
|
||||
[DataField("knockdownSound")]
|
||||
public SoundSpecifier? KnockdownSound;
|
||||
}
|
||||
|
||||
30
Content.Server/Damage/Events/StaminaMeleeHitEvent.cs
Normal file
30
Content.Server/Damage/Events/StaminaMeleeHitEvent.cs
Normal file
@@ -0,0 +1,30 @@
|
||||
using Robust.Shared.Collections;
|
||||
using Content.Server.Damage.Components;
|
||||
|
||||
namespace Content.Server.Damage.Events;
|
||||
|
||||
/// <summary>
|
||||
/// The components in the list are going to be hit,
|
||||
/// give opportunities to change the damage or other stuff.
|
||||
/// </summary>
|
||||
public sealed class StaminaMeleeHitEvent : HandledEntityEventArgs
|
||||
{
|
||||
/// <summary>
|
||||
/// List of hit stamina components.
|
||||
public ValueList<StaminaComponent> HitList;
|
||||
|
||||
/// <summmary>
|
||||
/// The multiplier. Generally, try to use *= or /= instead of overwriting.
|
||||
/// </summary>
|
||||
public float Multiplier = 1;
|
||||
|
||||
/// <summary>
|
||||
/// The flat modifier. Generally, try to use += or -= instead of overwriting.
|
||||
/// </summary>
|
||||
public float FlatModifier = 0;
|
||||
|
||||
public StaminaMeleeHitEvent(ValueList<StaminaComponent> hitList)
|
||||
{
|
||||
HitList = hitList;
|
||||
}
|
||||
}
|
||||
@@ -5,10 +5,13 @@ using Content.Server.Weapon.Melee;
|
||||
using Content.Shared.Alert;
|
||||
using Content.Shared.Rounding;
|
||||
using Content.Shared.Stunnable;
|
||||
using Content.Shared.Sound;
|
||||
using Robust.Shared.Collections;
|
||||
using Robust.Shared.Physics.Dynamics;
|
||||
using Robust.Shared.Player;
|
||||
using Robust.Shared.Timing;
|
||||
using Robust.Shared.Audio;
|
||||
|
||||
|
||||
namespace Content.Server.Damage.Systems;
|
||||
|
||||
@@ -70,10 +73,22 @@ public sealed class StaminaSystem : EntitySystem
|
||||
toHit.Add(stam);
|
||||
}
|
||||
|
||||
var hitEvent = new StaminaMeleeHitEvent(toHit);
|
||||
RaiseLocalEvent(uid, hitEvent, false);
|
||||
|
||||
if (hitEvent.Handled)
|
||||
return;
|
||||
|
||||
var damage = component.Damage;
|
||||
|
||||
damage *= hitEvent.Multiplier;
|
||||
|
||||
damage += hitEvent.FlatModifier;
|
||||
|
||||
foreach (var comp in toHit)
|
||||
{
|
||||
var oldDamage = comp.StaminaDamage;
|
||||
TakeStaminaDamage(comp.Owner, component.Damage / toHit.Count, comp);
|
||||
TakeStaminaDamage(comp.Owner, damage / toHit.Count, comp, component.KnockdownSound);
|
||||
if (comp.StaminaDamage.Equals(oldDamage))
|
||||
{
|
||||
_popup.PopupEntity(Loc.GetString("stamina-resist"), comp.Owner, Filter.Entities(args.User));
|
||||
@@ -100,7 +115,7 @@ public sealed class StaminaSystem : EntitySystem
|
||||
_alerts.ShowAlert(uid, AlertType.Stamina, (short) severity);
|
||||
}
|
||||
|
||||
public void TakeStaminaDamage(EntityUid uid, float value, StaminaComponent? component = null)
|
||||
public void TakeStaminaDamage(EntityUid uid, float value, StaminaComponent? component = null, SoundSpecifier? knockdownSound = null)
|
||||
{
|
||||
if (!Resolve(uid, ref component, false) || component.Critical) return;
|
||||
|
||||
@@ -131,6 +146,8 @@ public sealed class StaminaSystem : EntitySystem
|
||||
{
|
||||
if (component.StaminaDamage >= component.CritThreshold)
|
||||
{
|
||||
if (knockdownSound != null)
|
||||
SoundSystem.Play(knockdownSound.GetSound(), Filter.Pvs(uid, entityManager: EntityManager), uid, knockdownSound.Params);
|
||||
EnterStamCrit(uid, component);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user