Fix projectile exception (#12956)

This commit is contained in:
Leon Friedrich
2022-12-11 11:56:09 +13:00
committed by GitHub
parent b6e382fe82
commit bc7754a70d
2 changed files with 21 additions and 20 deletions

View File

@@ -42,27 +42,27 @@ namespace Content.Server.Projectiles
return;
var otherEntity = args.OtherFixture.Body.Owner;
var otherName = ToPrettyString(otherEntity);
var direction = args.OurFixture.Body.LinearVelocity.Normalized;
var modifiedDamage = _damageableSystem.TryChangeDamage(otherEntity, component.Damage, component.IgnoreResistances, origin: component.Shooter);
component.DamagedEntity = true;
var deleted = Deleted(otherEntity);
if (modifiedDamage is not null && EntityManager.EntityExists(component.Shooter))
{
if (modifiedDamage.Total > FixedPoint2.Zero)
if (modifiedDamage.Total > FixedPoint2.Zero && !deleted)
{
RaiseNetworkEvent(new DamageEffectEvent(Color.Red, new List<EntityUid> {otherEntity}), Filter.Pvs(otherEntity, entityManager: EntityManager));
}
_adminLogger.Add(LogType.BulletHit,
HasComp<ActorComponent>(otherEntity) ? LogImpact.Extreme : LogImpact.High,
$"Projectile {ToPrettyString(uid):projectile} shot by {ToPrettyString(component.Shooter):user} hit {ToPrettyString(otherEntity):target} and dealt {modifiedDamage.Total:damage} damage");
$"Projectile {ToPrettyString(uid):projectile} shot by {ToPrettyString(component.Shooter):user} hit {otherName:target} and dealt {modifiedDamage.Total:damage} damage");
}
_guns.PlayImpactSound(otherEntity, modifiedDamage, component.SoundHit, component.ForceSound);
// Damaging it can delete it
if (HasComp<CameraRecoilComponent>(otherEntity))
if (!deleted)
{
_guns.PlayImpactSound(otherEntity, modifiedDamage, component.SoundHit, component.ForceSound);
_sharedCameraRecoil.KickCamera(otherEntity, direction);
}

View File

@@ -192,27 +192,34 @@ public sealed partial class GunSystem : SharedGunSystem
var dmg = hitscan.Damage;
bool deleted = false;
string hitName = ToPrettyString(hitEntity);
if (dmg != null)
dmg = Damageable.TryChangeDamage(hitEntity, dmg, origin: user);
// check null again, as TryChangeDamage returns modified damage values
if (dmg != null)
{
if (dmg.Total > FixedPoint2.Zero)
{
RaiseNetworkEvent(new DamageEffectEvent(Color.Red, new List<EntityUid> {result.HitEntity}), Filter.Pvs(hitEntity, entityManager: EntityManager));
}
deleted = Deleted(hitEntity);
PlayImpactSound(hitEntity, dmg, hitscan.Sound, hitscan.ForceSound);
if (!deleted)
{
if (dmg.Total > FixedPoint2.Zero)
RaiseNetworkEvent(new DamageEffectEvent(Color.Red, new List<EntityUid> {result.HitEntity}), Filter.Pvs(hitEntity, entityManager: EntityManager));
// TODO get fallback position for playing hit sound.
PlayImpactSound(hitEntity, dmg, hitscan.Sound, hitscan.ForceSound);
}
if (user != null)
{
Logs.Add(LogType.HitScanHit,
$"{ToPrettyString(user.Value):user} hit {ToPrettyString(hitEntity):target} using hitscan and dealt {dmg.Total:damage} damage");
$"{ToPrettyString(user.Value):user} hit {hitName:target} using hitscan and dealt {dmg.Total:damage} damage");
}
else
{
Logs.Add(LogType.HitScanHit,
$"Hit {ToPrettyString(hitEntity):target} using hitscan and dealt {dmg.Total:damage} damage");
$"Hit {hitName:target} using hitscan and dealt {dmg.Total:damage} damage");
}
}
}
@@ -301,8 +308,7 @@ public sealed partial class GunSystem : SharedGunSystem
public void PlayImpactSound(EntityUid otherEntity, DamageSpecifier? modifiedDamage, SoundSpecifier? weaponSound, bool forceWeaponSound)
{
if (Deleted(otherEntity))
return;
DebugTools.Assert(!Deleted(otherEntity), "Impact sound entity was deleted");
// Like projectiles and melee,
// 1. Entity specific sound
@@ -310,11 +316,6 @@ public sealed partial class GunSystem : SharedGunSystem
// 3. Nothing
var playedSound = false;
// woops the other entity is deleted
// someone needs to handle this better. for now i'm just gonna make it not crash the server -rane
if (Deleted(otherEntity))
return;
if (!forceWeaponSound && modifiedDamage != null && modifiedDamage.Total > 0 && TryComp<RangedDamageSoundComponent>(otherEntity, out var rangedSound))
{
var type = MeleeWeaponSystem.GetHighestDamageSound(modifiedDamage, ProtoManager);