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
This commit is contained in:
Bixkitts
2024-02-03 02:00:14 +01:00
committed by GitHub
parent 3ffa15ce34
commit b98dc66974

View 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.