Fix projectile exception (#12956)
This commit is contained in:
@@ -42,27 +42,27 @@ namespace Content.Server.Projectiles
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
var otherEntity = args.OtherFixture.Body.Owner;
|
var otherEntity = args.OtherFixture.Body.Owner;
|
||||||
|
var otherName = ToPrettyString(otherEntity);
|
||||||
var direction = args.OurFixture.Body.LinearVelocity.Normalized;
|
var direction = args.OurFixture.Body.LinearVelocity.Normalized;
|
||||||
var modifiedDamage = _damageableSystem.TryChangeDamage(otherEntity, component.Damage, component.IgnoreResistances, origin: component.Shooter);
|
var modifiedDamage = _damageableSystem.TryChangeDamage(otherEntity, component.Damage, component.IgnoreResistances, origin: component.Shooter);
|
||||||
component.DamagedEntity = true;
|
component.DamagedEntity = true;
|
||||||
|
var deleted = Deleted(otherEntity);
|
||||||
|
|
||||||
if (modifiedDamage is not null && EntityManager.EntityExists(component.Shooter))
|
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));
|
RaiseNetworkEvent(new DamageEffectEvent(Color.Red, new List<EntityUid> {otherEntity}), Filter.Pvs(otherEntity, entityManager: EntityManager));
|
||||||
}
|
}
|
||||||
|
|
||||||
_adminLogger.Add(LogType.BulletHit,
|
_adminLogger.Add(LogType.BulletHit,
|
||||||
HasComp<ActorComponent>(otherEntity) ? LogImpact.Extreme : LogImpact.High,
|
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);
|
if (!deleted)
|
||||||
|
|
||||||
// Damaging it can delete it
|
|
||||||
if (HasComp<CameraRecoilComponent>(otherEntity))
|
|
||||||
{
|
{
|
||||||
|
_guns.PlayImpactSound(otherEntity, modifiedDamage, component.SoundHit, component.ForceSound);
|
||||||
_sharedCameraRecoil.KickCamera(otherEntity, direction);
|
_sharedCameraRecoil.KickCamera(otherEntity, direction);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -192,27 +192,34 @@ public sealed partial class GunSystem : SharedGunSystem
|
|||||||
|
|
||||||
var dmg = hitscan.Damage;
|
var dmg = hitscan.Damage;
|
||||||
|
|
||||||
|
bool deleted = false;
|
||||||
|
string hitName = ToPrettyString(hitEntity);
|
||||||
if (dmg != null)
|
if (dmg != null)
|
||||||
dmg = Damageable.TryChangeDamage(hitEntity, dmg, origin: user);
|
dmg = Damageable.TryChangeDamage(hitEntity, dmg, origin: user);
|
||||||
|
|
||||||
|
// check null again, as TryChangeDamage returns modified damage values
|
||||||
if (dmg != null)
|
if (dmg != null)
|
||||||
{
|
{
|
||||||
if (dmg.Total > FixedPoint2.Zero)
|
deleted = Deleted(hitEntity);
|
||||||
{
|
|
||||||
RaiseNetworkEvent(new DamageEffectEvent(Color.Red, new List<EntityUid> {result.HitEntity}), Filter.Pvs(hitEntity, entityManager: EntityManager));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
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);
|
PlayImpactSound(hitEntity, dmg, hitscan.Sound, hitscan.ForceSound);
|
||||||
|
}
|
||||||
|
|
||||||
if (user != null)
|
if (user != null)
|
||||||
{
|
{
|
||||||
Logs.Add(LogType.HitScanHit,
|
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
|
else
|
||||||
{
|
{
|
||||||
Logs.Add(LogType.HitScanHit,
|
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)
|
public void PlayImpactSound(EntityUid otherEntity, DamageSpecifier? modifiedDamage, SoundSpecifier? weaponSound, bool forceWeaponSound)
|
||||||
{
|
{
|
||||||
if (Deleted(otherEntity))
|
DebugTools.Assert(!Deleted(otherEntity), "Impact sound entity was deleted");
|
||||||
return;
|
|
||||||
|
|
||||||
// Like projectiles and melee,
|
// Like projectiles and melee,
|
||||||
// 1. Entity specific sound
|
// 1. Entity specific sound
|
||||||
@@ -310,11 +316,6 @@ public sealed partial class GunSystem : SharedGunSystem
|
|||||||
// 3. Nothing
|
// 3. Nothing
|
||||||
var playedSound = false;
|
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))
|
if (!forceWeaponSound && modifiedDamage != null && modifiedDamage.Total > 0 && TryComp<RangedDamageSoundComponent>(otherEntity, out var rangedSound))
|
||||||
{
|
{
|
||||||
var type = MeleeWeaponSystem.GetHighestDamageSound(modifiedDamage, ProtoManager);
|
var type = MeleeWeaponSystem.GetHighestDamageSound(modifiedDamage, ProtoManager);
|
||||||
|
|||||||
Reference in New Issue
Block a user