Files
Delta-v/Content.Server/Damage/Systems/DamageOtherOnHitSystem.cs
T
9146c59ecf feat: Fancy Screenshake from Ephemeral Space (#5503)
* cherry-pick: Screenshake (EphemeralSpace/ephemeral-space#627)

* commit your shit at some point maybe

* y

* who knows

* rename?

* debugging  + shit api

* i hope no one fucks my ass

* erm

* p

* replace with shit that makes way more sense

* stuff

* pretty sure this is just fine

* actual fix noise shit

* uhhh hmaybe if i feel like it wrong then later

* explosion shake

* grav shake

* gun shake

* idk

* projectile melee

Co-authored-by: DisposableCrewmember42 <disposablecrewmember42@proton.me>

* tweak: tune recoil on weapons

* docs: add _ES license info to LEGAL.md

* fix: screenshake on spawn fix from ss14Starlight/space-station-14#3664

Co-authored-by: neomoth <69372252+neomoth@users.noreply.github.com>

* feat: add client cvar to disable screenshake

* feat: add screenshake toggle to accessibility settings

* fix: upmerge compatibility

* docs: properly document cvar

* docs: add missing import comments

---------

Co-authored-by: mirrorcult <mirrorcult@pm.me>
Co-authored-by: neomoth <69372252+neomoth@users.noreply.github.com>
2026-05-15 23:32:40 +02:00

64 lines
2.7 KiB
C#

using Content.Server.Administration.Logs;
using Content.Server.Weapons.Ranged.Systems;
using Content.Shared._ES.Camera; // ES - Screenshake
using Content.Shared.Camera;
using Content.Shared.Damage;
using Content.Shared.Damage.Components;
using Content.Shared.Damage.Systems;
using Content.Shared.Database;
using Content.Shared.Effects;
using Content.Shared.Mobs.Components;
using Content.Shared.Throwing;
using Robust.Shared.Physics.Components;
using Robust.Shared.Player;
namespace Content.Server.Damage.Systems;
public sealed class DamageOtherOnHitSystem : SharedDamageOtherOnHitSystem
{
// ES START
[Dependency] private readonly SharedESScreenshakeSystem _shake = default!;
// ES END
[Dependency] private readonly IAdminLogManager _adminLogger = default!;
[Dependency] private readonly GunSystem _guns = default!;
[Dependency] private readonly Shared.Damage.Systems.DamageableSystem _damageable = default!;
[Dependency] private readonly SharedCameraRecoilSystem _sharedCameraRecoil = default!;
[Dependency] private readonly SharedColorFlashEffectSystem _color = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<DamageOtherOnHitComponent, ThrowDoHitEvent>(OnDoHit);
}
private void OnDoHit(EntityUid uid, DamageOtherOnHitComponent component, ThrowDoHitEvent args)
{
if (TerminatingOrDeleted(args.Target))
return;
var dmg = _damageable.ChangeDamage(args.Target, component.Damage * _damageable.UniversalThrownDamageModifier, component.IgnoreResistances, origin: args.Component.Thrower);
// 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 (HasComp<MobStateComponent>(args.Target))
_adminLogger.Add(LogType.ThrowHit, $"{ToPrettyString(args.Target):target} received {dmg.GetTotal():damage} damage from collision");
if (!dmg.Empty)
{
_color.RaiseEffect(Color.Red, [args.Target], Filter.Pvs(args.Target, entityManager: EntityManager));
}
_guns.PlayImpactSound(args.Target, dmg, null, false);
if (TryComp<PhysicsComponent>(uid, out var body) && body.LinearVelocity.LengthSquared() > 0f)
{
var direction = body.LinearVelocity.Normalized();
// ES START
// lower recoil + shake
_sharedCameraRecoil.KickCamera(args.Target, direction * 0.1f);
var otherHitShake = new ESScreenshakeParameters() { Trauma = 0.35f, DecayRate = 1.4f, Frequency = 0.014f };
_shake.Screenshake(args.Target, otherHitShake, null);
// ES END
}
}
}