]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
MeleeSoundComponent Working With 0 Damage (#24872)
authorBixkitts <72874643+Bixkitts@users.noreply.github.com>
Sat, 3 Feb 2024 01:00:14 +0000 (02:00 +0100)
committerGitHub <noreply@github.com>
Sat, 3 Feb 2024 01:00:14 +0000 (12:00 +1100)
* made hit sound logic potentially better

* Function already tries all fallbacks, no reason to return bool

* NoDamageSound execution path

Content.Shared/Weapons/Melee/SharedMeleeWeaponSystem.cs

index f7ac249f5f23ff8af15e0cac33ce129c37be09fc..12455a1f49699a58bc9243f27f5a774388a07f61 100644 (file)
@@ -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.