Files
wwdpublic/Content.Server/Projectiles/ProjectileSystem.cs
Aviu00 1a6270309a Yuh
(cherry picked from commit dc051987ca50fc97848285b66eca9694e31f7941)
2025-03-21 17:37:58 +03:00

122 lines
5.1 KiB
C#

using Content.Server.Administration.Logs;
using Content.Server.Effects;
using Content.Server.Weapons.Ranged.Systems;
using Content.Shared.Camera;
using Content.Shared.Damage;
using Content.Shared.Damage.Events;
using Content.Shared.Database;
using Content.Shared.Projectiles;
using Robust.Shared.Physics.Components;
using Robust.Shared.Physics.Events;
using Robust.Shared.Physics.Systems;
using Robust.Shared.Player;
using Robust.Shared.Utility;
namespace Content.Server.Projectiles;
public sealed class ProjectileSystem : SharedProjectileSystem
{
[Dependency] private readonly IAdminLogManager _adminLogger = default!;
[Dependency] private readonly ColorFlashEffectSystem _color = default!;
[Dependency] private readonly DamageableSystem _damageableSystem = default!;
[Dependency] private readonly GunSystem _guns = default!;
[Dependency] private readonly SharedCameraRecoilSystem _sharedCameraRecoil = default!;
[Dependency] private readonly SharedPhysicsSystem _physics = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<ProjectileComponent, StartCollideEvent>(OnStartCollide);
SubscribeLocalEvent<EmbeddableProjectileComponent, DamageExamineEvent>(OnDamageExamine);
// WD EDIT START
SubscribeLocalEvent<EmbeddableProjectileComponent, EmbedEvent>(OnEmbed);
// WD EDIT END
}
private void OnStartCollide(EntityUid uid, ProjectileComponent component, ref StartCollideEvent args)
{
// This is so entities that shouldn't get a collision are ignored.
if (args.OurFixtureId != ProjectileFixture || !args.OtherFixture.Hard
|| component.DamagedEntity || component is { Weapon: null, OnlyCollideWhenShot: true, })
return;
var target = args.OtherEntity;
// it's here so this check is only done once before possible hit
var attemptEv = new ProjectileReflectAttemptEvent(uid, component, false);
RaiseLocalEvent(target, ref attemptEv);
if (attemptEv.Cancelled)
{
SetShooter(uid, component, target);
return;
}
var ev = new ProjectileHitEvent(component.Damage, target, component.Shooter);
RaiseLocalEvent(uid, ref ev);
var otherName = ToPrettyString(target);
var modifiedDamage = _damageableSystem.TryChangeDamage(target, ev.Damage, component.IgnoreResistances, origin: component.Shooter);
var deleted = Deleted(target);
if (modifiedDamage is not null && EntityManager.EntityExists(component.Shooter))
{
if (modifiedDamage.AnyPositive() && !deleted)
_color.RaiseEffect(Color.Red, [ target, ], Filter.Pvs(target, entityManager: EntityManager));
_adminLogger.Add(
LogType.BulletHit,
HasComp<ActorComponent>(target) ? LogImpact.Extreme : LogImpact.High,
$"Projectile {ToPrettyString(uid):projectile} shot by {ToPrettyString(component.Shooter!.Value):user} hit {otherName:target} and dealt {modifiedDamage.GetTotal():damage} damage");
}
if (!deleted)
{
_guns.PlayImpactSound(target, modifiedDamage, component.SoundHit, component.ForceSound);
if (!args.OurBody.LinearVelocity.IsLengthZero())
_sharedCameraRecoil.KickCamera(target, args.OurBody.LinearVelocity.Normalized());
}
// Goobstation start
if (component.Penetrate)
component.IgnoredEntities.Add(target);
else
component.DamagedEntity = true;
// Goobstation end
if (component.DeleteOnCollide)
QueueDel(uid);
if (component.StopFlyingOnImpact && TryComp<PhysicsComponent>(uid, out var physics)) // WWDP
_physics.SetBodyStatus(uid, physics, BodyStatus.OnGround);
if (component.ImpactEffect != null && TryComp(uid, out TransformComponent? xform))
RaiseNetworkEvent(new ImpactEffectEvent(component.ImpactEffect, GetNetCoordinates(xform.Coordinates)), Filter.Pvs(xform.Coordinates, entityMan: EntityManager));
}
private void OnDamageExamine(EntityUid uid, EmbeddableProjectileComponent component, ref DamageExamineEvent args)
{
if (!component.EmbedOnThrow)
return;
if (!args.Message.IsEmpty)
args.Message.PushNewline();
var isHarmful = TryComp<EmbedPassiveDamageComponent>(uid, out var passiveDamage) && passiveDamage.Damage.AnyPositive();
var loc = isHarmful
? "damage-examine-embeddable-harmful"
: "damage-examine-embeddable";
var staminaCostMarkup = FormattedMessage.FromMarkupOrThrow(Loc.GetString(loc));
args.Message.AddMessage(staminaCostMarkup);
}
// WD EDIT START
private void OnEmbed(EntityUid uid, EmbeddableProjectileComponent component, ref EmbedEvent args)
{
var dmg = _damageableSystem.TryChangeDamage(args.Embedded, component.Damage, origin: args.Shooter);
if (dmg is { Empty: false })
_color.RaiseEffect(Color.Red, new List<EntityUid>() { args.Embedded }, Filter.Pvs(args.Embedded, entityManager: EntityManager));
}
// WD EDIT END
}