2021-11-29 02:34:44 +13:00
|
|
|
using Content.Server.Administration.Logs;
|
2021-08-21 09:18:23 +02:00
|
|
|
using Content.Server.Damage.Components;
|
2023-08-02 12:30:04 +03:00
|
|
|
using Content.Server.Weapons.Ranged.Systems;
|
|
|
|
|
using Content.Shared.Camera;
|
2021-09-15 03:07:37 +10:00
|
|
|
using Content.Shared.Damage;
|
2023-08-07 12:09:35 +03:00
|
|
|
using Content.Shared.Damage.Events;
|
|
|
|
|
using Content.Shared.Damage.Systems;
|
2021-11-28 14:56:53 +01:00
|
|
|
using Content.Shared.Database;
|
2023-08-02 12:30:04 +03:00
|
|
|
using Content.Shared.Effects;
|
2023-01-13 16:57:10 -08:00
|
|
|
using Content.Shared.Mobs.Components;
|
2021-08-21 09:18:23 +02:00
|
|
|
using Content.Shared.Throwing;
|
2023-08-02 12:30:04 +03:00
|
|
|
using Robust.Shared.Physics.Components;
|
2023-08-02 15:44:27 +03:00
|
|
|
using Robust.Shared.Physics.Systems;
|
2023-08-02 12:30:04 +03:00
|
|
|
using Robust.Shared.Player;
|
2021-08-21 09:18:23 +02:00
|
|
|
|
2021-09-12 16:22:58 +10:00
|
|
|
namespace Content.Server.Damage.Systems
|
2021-08-21 09:18:23 +02:00
|
|
|
{
|
2022-02-16 00:23:23 -07:00
|
|
|
public sealed class DamageOtherOnHitSystem : EntitySystem
|
2021-08-21 09:18:23 +02:00
|
|
|
{
|
2023-08-02 12:30:04 +03:00
|
|
|
[Dependency] private readonly IAdminLogManager _adminLogger = default!;
|
|
|
|
|
[Dependency] private readonly GunSystem _guns = default!;
|
2023-08-07 12:09:35 +03:00
|
|
|
[Dependency] private readonly DamageableSystem _damageable = default!;
|
|
|
|
|
[Dependency] private readonly DamageExamineSystem _damageExamine = default!;
|
2023-08-11 03:44:52 +10:00
|
|
|
[Dependency] private readonly SharedCameraRecoilSystem _sharedCameraRecoil = default!;
|
|
|
|
|
[Dependency] private readonly SharedColorFlashEffectSystem _color = default!;
|
|
|
|
|
[Dependency] private readonly SharedPhysicsSystem _physics = default!;
|
|
|
|
|
[Dependency] private readonly ThrownItemSystem _thrownItem = default!;
|
2021-11-29 02:34:44 +13:00
|
|
|
|
2021-08-21 09:18:23 +02:00
|
|
|
public override void Initialize()
|
|
|
|
|
{
|
|
|
|
|
SubscribeLocalEvent<DamageOtherOnHitComponent, ThrowDoHitEvent>(OnDoHit);
|
2023-08-07 12:09:35 +03:00
|
|
|
SubscribeLocalEvent<DamageOtherOnHitComponent, DamageExamineEvent>(OnDamageExamine);
|
2021-08-21 09:18:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnDoHit(EntityUid uid, DamageOtherOnHitComponent component, ThrowDoHitEvent args)
|
|
|
|
|
{
|
2023-08-07 12:09:35 +03:00
|
|
|
var dmg = _damageable.TryChangeDamage(args.Target, component.Damage, component.IgnoreResistances, origin: args.Component.Thrower);
|
2022-02-07 14:52:58 +13:00
|
|
|
|
|
|
|
|
// Log damage only for mobs. Useful for when people throw spears at each other, but also avoids log-spam when explosions send glass shards flying.
|
|
|
|
|
if (dmg != null && HasComp<MobStateComponent>(args.Target))
|
2022-05-28 23:41:17 -07:00
|
|
|
_adminLogger.Add(LogType.ThrowHit, $"{ToPrettyString(args.Target):target} received {dmg.Total:damage} damage from collision");
|
2023-08-02 12:30:04 +03:00
|
|
|
|
2023-08-11 03:44:52 +10:00
|
|
|
_color.RaiseEffect(Color.Red, new List<EntityUid>() { args.Target }, Filter.Pvs(args.Target, entityManager: EntityManager));
|
2023-08-02 12:30:04 +03:00
|
|
|
_guns.PlayImpactSound(args.Target, dmg, null, false);
|
|
|
|
|
if (TryComp<PhysicsComponent>(uid, out var body) && body.LinearVelocity.LengthSquared() > 0f)
|
|
|
|
|
{
|
|
|
|
|
var direction = body.LinearVelocity.Normalized();
|
|
|
|
|
_sharedCameraRecoil.KickCamera(args.Target, direction);
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-15 09:49:59 +10:00
|
|
|
// TODO: If more stuff touches this then handle it after.
|
2023-08-02 15:44:27 +03:00
|
|
|
if (TryComp<PhysicsComponent>(uid, out var physics))
|
|
|
|
|
{
|
|
|
|
|
_thrownItem.LandComponent(args.Thrown, args.Component, physics, false);
|
|
|
|
|
}
|
2021-08-21 09:18:23 +02:00
|
|
|
}
|
2023-08-07 12:09:35 +03:00
|
|
|
|
|
|
|
|
private void OnDamageExamine(EntityUid uid, DamageOtherOnHitComponent component, ref DamageExamineEvent args)
|
|
|
|
|
{
|
|
|
|
|
_damageExamine.AddDamageExamine(args.Message, component.Damage, Loc.GetString("damage-throw"));
|
|
|
|
|
}
|
2021-08-21 09:18:23 +02:00
|
|
|
}
|
|
|
|
|
}
|