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,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)