Esempio n. 1
0
    public void PlayImpactSound(EntityUid otherEntity, DamageSpecifier?modifiedDamage, SoundSpecifier?weaponSound, bool forceWeaponSound)
    {
        // Like projectiles and melee,
        // 1. Entity specific sound
        // 2. Ammo's sound
        // 3. Nothing
        var playedSound = false;

        if (!forceWeaponSound && modifiedDamage != null && modifiedDamage.Total > 0 && TryComp <RangedDamageSoundComponent>(otherEntity, out var rangedSound))
        {
            var type = MeleeWeaponSystem.GetHighestDamageSound(modifiedDamage, ProtoManager);

            if (type != null && rangedSound.SoundTypes?.TryGetValue(type, out var damageSoundType) == true)
            {
                SoundSystem.Play(damageSoundType !.GetSound(),
                                 Filter.Pvs(otherEntity, entityManager: EntityManager),
                                 otherEntity, AudioHelpers.WithVariation(DamagePitchVariation));

                playedSound = true;
            }
            else if (type != null && rangedSound.SoundGroups?.TryGetValue(type, out var damageSoundGroup) == true)
            {
                SoundSystem.Play(damageSoundGroup !.GetSound(),
                                 Filter.Pvs(otherEntity, entityManager: EntityManager),
                                 otherEntity, AudioHelpers.WithVariation(DamagePitchVariation));

                playedSound = true;
            }
        }

        if (!playedSound && weaponSound != null)
        {
            SoundSystem.Play(weaponSound.GetSound(), Filter.Pvs(otherEntity, entityManager: EntityManager), otherEntity);
        }
    }