From b98dc669741a3e5199e9fa03d82703821ab5284c Mon Sep 17 00:00:00 2001 From: Bixkitts <72874643+Bixkitts@users.noreply.github.com> Date: Sat, 3 Feb 2024 02:00:14 +0100 Subject: [PATCH] MeleeSoundComponent Working With 0 Damage (#24872) * made hit sound logic potentially better * Function already tries all fallbacks, no reason to return bool * NoDamageSound execution path --- .../Weapons/Melee/SharedMeleeWeaponSystem.cs | 43 +++++-------------- 1 file changed, 10 insertions(+), 33 deletions(-) diff --git a/Content.Shared/Weapons/Melee/SharedMeleeWeaponSystem.cs b/Content.Shared/Weapons/Melee/SharedMeleeWeaponSystem.cs index f7ac249f5f..12455a1f49 100644 --- a/Content.Shared/Weapons/Melee/SharedMeleeWeaponSystem.cs +++ b/Content.Shared/Weapons/Melee/SharedMeleeWeaponSystem.cs @@ -524,24 +524,10 @@ public abstract class SharedMeleeWeaponSystem : EntitySystem $"{ToPrettyString(user):actor} melee attacked (light) {ToPrettyString(target.Value):subject} using {ToPrettyString(meleeUid):tool} and dealt {damageResult.GetTotal():damage} damage"); } - PlayHitSound(target.Value, user, GetHighestDamageSound(modifiedDamage, _protoManager), hitEvent.HitSoundOverride, component.HitSound); - } - else - { - if (hitEvent.HitSoundOverride != null) - { - Audio.PlayPredicted(hitEvent.HitSoundOverride, meleeUid, user); - } - else if (!GetDamage(meleeUid, user, component).Any() && component.HitSound != null) - { - Audio.PlayPredicted(component.HitSound, meleeUid, user); - } - else - { - Audio.PlayPredicted(component.NoDamageSound, meleeUid, user); - } } + PlayHitSound(target.Value, user, GetHighestDamageSound(modifiedDamage, _protoManager), hitEvent.HitSoundOverride, component.HitSound, component.NoDamageSound); + if (damageResult?.GetTotal() > FixedPoint2.Zero) { DoDamageEffect(targets, user, targetXform); @@ -677,22 +663,8 @@ public abstract class SharedMeleeWeaponSystem : EntitySystem if (entities.Count != 0) { - if (appliedDamage.GetTotal() > FixedPoint2.Zero) - { - var target = entities.First(); - PlayHitSound(target, user, GetHighestDamageSound(appliedDamage, _protoManager), hitEvent.HitSoundOverride, component.HitSound); - } - else - { - if (hitEvent.HitSoundOverride != null) - { - Audio.PlayPredicted(hitEvent.HitSoundOverride, meleeUid, user); - } - else - { - Audio.PlayPredicted(component.NoDamageSound, meleeUid, user); - } - } + var target = entities.First(); + PlayHitSound(target, user, GetHighestDamageSound(appliedDamage, _protoManager), hitEvent.HitSoundOverride, component.HitSound, component.NoDamageSound); } if (appliedDamage.GetTotal() > FixedPoint2.Zero) @@ -736,7 +708,7 @@ public abstract class SharedMeleeWeaponSystem : EntitySystem return true; } - public void PlayHitSound(EntityUid target, EntityUid? user, string? type, SoundSpecifier? hitSoundOverride, SoundSpecifier? hitSound) + public void PlayHitSound(EntityUid target, EntityUid? user, string? type, SoundSpecifier? hitSoundOverride, SoundSpecifier? hitSound, SoundSpecifier? noDamageSound) { var playedSound = false; @@ -778,6 +750,11 @@ public abstract class SharedMeleeWeaponSystem : EntitySystem Audio.PlayPredicted(hitSound, coords, user, AudioParams.Default.WithVariation(DamagePitchVariation)); playedSound = true; } + else if (noDamageSound != null) + { + Audio.PlayPredicted(noDamageSound, coords, user, AudioParams.Default.WithVariation(DamagePitchVariation)); + playedSound = true; + } } // Fallback to generic sounds.