More robust bullet impact sounds (#8325)

This commit is contained in:
metalgearsloth
2022-05-22 18:23:37 +10:00
committed by GitHub
parent 4a86f38251
commit 0084ca721b
27 changed files with 322 additions and 185 deletions

View File

@@ -1,3 +1,4 @@
using Content.Server.Weapon.Ranged;
using Content.Shared.Damage;
using Content.Shared.Physics;
using Content.Shared.Sound;
@@ -38,8 +39,12 @@ namespace Content.Server.Projectiles.Components
private string? _muzzleFlash;
[DataField("impactFlash")]
private string? _impactFlash;
[DataField("soundHitWall")]
private SoundSpecifier _soundHitWall = new SoundPathSpecifier("/Audio/Weapons/Guns/Hits/laser_sear_wall.ogg");
[DataField("soundHit")]
public SoundSpecifier? SoundHit;
[DataField("soundForce")]
public bool ForceSound = false;
public void FireEffects(EntityUid user, float distance, Angle angle, EntityUid? hitEntity = null)
{
@@ -80,14 +85,6 @@ namespace Content.Server.Projectiles.Components
}
}
if (hitEntity != null && _soundHitWall != null)
{
// TODO: No wall component so ?
var offset = localAngle.ToVec().Normalized / 2;
var coordinates = localCoordinates.Offset(offset);
SoundSystem.Play(Filter.Pvs(coordinates), _soundHitWall.GetSound(), coordinates);
}
Owner.SpawnTimer((int) _deathTime.TotalMilliseconds, () =>
{
if (!_entMan.Deleted(Owner))

View File

@@ -17,7 +17,9 @@ namespace Content.Server.Projectiles.Components
// Get that juicy FPS hit sound
[DataField("soundHit")] public SoundSpecifier? SoundHit;
[DataField("soundHitSpecies")] public SoundSpecifier? SoundHitSpecies;
[DataField("soundForce")]
public bool ForceSound = false;
public bool DamagedEntity;

View File

@@ -1,5 +1,8 @@
using Content.Server.Administration.Logs;
using Content.Server.Projectiles.Components;
using Content.Server.Weapon.Melee;
using Content.Server.Weapon.Ranged;
using Content.Shared.Audio;
using Content.Shared.Body.Components;
using Content.Shared.Camera;
using Content.Shared.Damage;
@@ -10,6 +13,7 @@ using Robust.Server.GameObjects;
using Robust.Shared.Audio;
using Robust.Shared.Physics.Dynamics;
using Robust.Shared.Player;
using Robust.Shared.Prototypes;
namespace Content.Server.Projectiles
{
@@ -19,6 +23,7 @@ namespace Content.Server.Projectiles
[Dependency] private readonly DamageableSystem _damageableSystem = default!;
[Dependency] private readonly AdminLogSystem _adminLogSystem = default!;
[Dependency] private readonly CameraRecoilSystem _cameraRecoil = default!;
[Dependency] private readonly GunSystem _guns = default!;
public override void Initialize()
{
@@ -36,42 +41,27 @@ namespace Content.Server.Projectiles
var otherEntity = args.OtherFixture.Body.Owner;
var coordinates = EntityManager.GetComponent<TransformComponent>(args.OtherFixture.Body.Owner).Coordinates;
var playerFilter = Filter.Pvs(coordinates, entityMan: EntityManager);
var modifiedDamage = _damageableSystem.TryChangeDamage(otherEntity, component.Damage);
component.DamagedEntity = true;
if (!EntityManager.GetComponent<MetaDataComponent>(otherEntity).EntityDeleted && component.SoundHitSpecies != null &&
EntityManager.HasComponent<SharedBodyComponent>(otherEntity))
if (modifiedDamage is not null && EntityManager.EntityExists(component.Shooter))
{
SoundSystem.Play(playerFilter, component.SoundHitSpecies.GetSound(), coordinates);
}
else
{
var soundHit = component.SoundHit?.GetSound();
if (!string.IsNullOrEmpty(soundHit))
SoundSystem.Play(playerFilter, soundHit, coordinates);
_adminLogSystem.Add(LogType.BulletHit,
HasComp<ActorComponent>(otherEntity) ? LogImpact.Extreme : LogImpact.High,
$"Projectile {ToPrettyString(component.Owner):projectile} shot by {ToPrettyString(component.Shooter):user} hit {ToPrettyString(otherEntity):target} and dealt {modifiedDamage.Total:damage} damage");
}
if (!EntityManager.GetComponent<MetaDataComponent>(otherEntity).EntityDeleted)
{
var dmg = _damageableSystem.TryChangeDamage(otherEntity, component.Damage);
component.DamagedEntity = true;
if (dmg is not null && EntityManager.EntityExists(component.Shooter))
_adminLogSystem.Add(LogType.BulletHit,
HasComp<ActorComponent>(otherEntity) ? LogImpact.Extreme : LogImpact.High,
$"Projectile {ToPrettyString(component.Owner):projectile} shot by {ToPrettyString(component.Shooter):user} hit {ToPrettyString(otherEntity):target} and dealt {dmg.Total:damage} damage");
}
_guns.PlaySound(otherEntity, modifiedDamage, component.SoundHit, component.ForceSound);
// Damaging it can delete it
if (!Deleted(otherEntity) && HasComp<CameraRecoilComponent>(otherEntity))
if (HasComp<CameraRecoilComponent>(otherEntity))
{
var direction = args.OurFixture.Body.LinearVelocity.Normalized;
_cameraRecoil.KickCamera(otherEntity, direction);
}
if (component.DeleteOnCollide)
EntityManager.QueueDeleteEntity(uid);
QueueDel(uid);
}
public override void Update(float frameTime)