ECSatize CameraRecoilSystem (#5448)
Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com>
This commit is contained in:
@@ -1,19 +0,0 @@
|
||||
using Content.Shared.Camera;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Maths;
|
||||
|
||||
namespace Content.Server.Camera
|
||||
{
|
||||
[RegisterComponent]
|
||||
[ComponentReference(typeof(SharedCameraRecoilComponent))]
|
||||
public sealed class CameraRecoilComponent : SharedCameraRecoilComponent
|
||||
{
|
||||
public override void Kick(Vector2 recoil)
|
||||
{
|
||||
var msg = new RecoilKickMessage(recoil);
|
||||
#pragma warning disable 618
|
||||
SendNetworkMessage(msg);
|
||||
#pragma warning restore 618
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,9 +2,9 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Content.Server.Administration.Logs;
|
||||
using Content.Server.Camera;
|
||||
using Content.Server.Explosion.Components;
|
||||
using Content.Shared.Acts;
|
||||
using Content.Shared.Camera;
|
||||
using Content.Shared.Database;
|
||||
using Content.Shared.Interaction.Helpers;
|
||||
using Content.Shared.Maps;
|
||||
@@ -51,6 +51,7 @@ namespace Content.Server.Explosion.EntitySystems
|
||||
[Dependency] private readonly EffectSystem _effects = default!;
|
||||
[Dependency] private readonly TriggerSystem _triggers = default!;
|
||||
[Dependency] private readonly AdminLogSystem _logSystem = default!;
|
||||
[Dependency] private readonly CameraRecoilSystem _cameraRecoil = default!;
|
||||
|
||||
private bool IgnoreExplosivePassable(EntityUid e)
|
||||
{
|
||||
@@ -82,7 +83,7 @@ namespace Content.Server.Explosion.EntitySystems
|
||||
foreach (var player in players)
|
||||
{
|
||||
if (player.AttachedEntity is not {Valid: true} playerEntity ||
|
||||
!EntityManager.TryGetComponent(playerEntity, out CameraRecoilComponent? recoil))
|
||||
!EntityManager.HasComponent<CameraRecoilComponent>(playerEntity))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
@@ -99,7 +100,7 @@ namespace Content.Server.Explosion.EntitySystems
|
||||
if (effect > 0.01f)
|
||||
{
|
||||
var kick = -delta.Normalized * effect;
|
||||
recoil.Kick(kick);
|
||||
_cameraRecoil.KickCamera(player.AttachedEntity.Value, kick);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
using System.Collections.Generic;
|
||||
using Content.Server.Camera;
|
||||
using Content.Shared.Camera;
|
||||
using Content.Shared.Gravity;
|
||||
using Robust.Server.Player;
|
||||
using Robust.Shared.Audio;
|
||||
@@ -20,6 +20,8 @@ namespace Content.Server.Gravity.EntitySystems
|
||||
[Dependency] private readonly IPlayerManager _playerManager = default!;
|
||||
[Dependency] private readonly IRobustRandom _random = default!;
|
||||
|
||||
[Dependency] private readonly CameraRecoilSystem _cameraRecoil = default!;
|
||||
|
||||
private Dictionary<GridId, uint> _gridsToShake = new();
|
||||
|
||||
private const float GravityKick = 100.0f;
|
||||
@@ -81,12 +83,13 @@ namespace Content.Server.Gravity.EntitySystems
|
||||
{
|
||||
if (player.AttachedEntity is not {Valid: true} attached
|
||||
|| EntityManager.GetComponent<TransformComponent>(attached).GridID != gridId
|
||||
|| !EntityManager.TryGetComponent(attached, out CameraRecoilComponent? recoil))
|
||||
|| !EntityManager.HasComponent<CameraRecoilComponent>(attached))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
recoil.Kick(new Vector2(_random.NextFloat(), _random.NextFloat()) * GravityKick);
|
||||
var kick = new Vector2(_random.NextFloat(), _random.NextFloat()) * GravityKick;
|
||||
_cameraRecoil.KickCamera(player.AttachedEntity.Value, kick);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Content.Server.Atmos.Components;
|
||||
using Content.Server.Atmos.EntitySystems;
|
||||
using Content.Server.Camera;
|
||||
using Content.Server.Hands.Components;
|
||||
using Content.Server.Items;
|
||||
using Content.Server.Nutrition.Components;
|
||||
@@ -11,6 +10,7 @@ using Content.Server.Storage.Components;
|
||||
using Content.Server.Stunnable;
|
||||
using Content.Server.Throwing;
|
||||
using Content.Server.Tools.Components;
|
||||
using Content.Shared.Camera;
|
||||
using Content.Shared.CombatMode;
|
||||
using Content.Shared.Interaction;
|
||||
using Content.Shared.PneumaticCannon;
|
||||
@@ -34,6 +34,7 @@ namespace Content.Server.PneumaticCannon
|
||||
[Dependency] private readonly IRobustRandom _random = default!;
|
||||
[Dependency] private readonly StunSystem _stun = default!;
|
||||
[Dependency] private readonly AtmosphereSystem _atmos = default!;
|
||||
[Dependency] private readonly CameraRecoilSystem _cameraRecoil = default!;
|
||||
|
||||
private HashSet<PneumaticCannonComponent> _currentlyFiring = new();
|
||||
|
||||
@@ -229,9 +230,10 @@ namespace Content.Server.PneumaticCannon
|
||||
storage.Remove(ent);
|
||||
|
||||
SoundSystem.Play(Filter.Pvs(data.User), comp.FireSound.GetSound(), ((IComponent) comp).Owner, AudioParams.Default);
|
||||
if (EntityManager.TryGetComponent<CameraRecoilComponent?>(data.User, out var recoil))
|
||||
if (EntityManager.HasComponent<CameraRecoilComponent>(data.User))
|
||||
{
|
||||
recoil.Kick(Vector2.One * data.Strength);
|
||||
var kick = Vector2.One * data.Strength;
|
||||
_cameraRecoil.KickCamera(data.User, kick);
|
||||
}
|
||||
|
||||
ent.TryThrow(data.Direction, data.Strength, data.User, GetPushbackRatioFromPower(comp.Power));
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
using Content.Server.Administration.Logs;
|
||||
using Content.Server.Camera;
|
||||
using Content.Server.Projectiles.Components;
|
||||
using Content.Shared.Body.Components;
|
||||
using Content.Shared.Camera;
|
||||
using Content.Shared.Damage;
|
||||
using Content.Shared.Database;
|
||||
using JetBrains.Annotations;
|
||||
@@ -9,6 +9,7 @@ using Robust.Server.GameObjects;
|
||||
using Robust.Shared.Audio;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Maths;
|
||||
using Robust.Shared.Physics.Dynamics;
|
||||
using Robust.Shared.Player;
|
||||
|
||||
@@ -19,6 +20,7 @@ namespace Content.Server.Projectiles
|
||||
{
|
||||
[Dependency] private readonly DamageableSystem _damageableSystem = default!;
|
||||
[Dependency] private readonly AdminLogSystem _adminLogSystem = default!;
|
||||
[Dependency] private readonly CameraRecoilSystem _cameraRecoil = default!;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
@@ -65,10 +67,10 @@ namespace Content.Server.Projectiles
|
||||
|
||||
// Damaging it can delete it
|
||||
if (!EntityManager.GetComponent<MetaDataComponent>(otherEntity).EntityDeleted &&
|
||||
EntityManager.TryGetComponent(otherEntity, out CameraRecoilComponent? recoilComponent))
|
||||
EntityManager.HasComponent<CameraRecoilComponent>(otherEntity))
|
||||
{
|
||||
var direction = args.OurFixture.Body.LinearVelocity.Normalized;
|
||||
recoilComponent.Kick(direction);
|
||||
_cameraRecoil.KickCamera(otherEntity, direction);
|
||||
}
|
||||
|
||||
if (component.DeleteOnCollide)
|
||||
|
||||
@@ -3,9 +3,9 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Content.Server.Administration.Logs;
|
||||
using Content.Server.Camera;
|
||||
using Content.Server.Projectiles.Components;
|
||||
using Content.Server.Weapon.Ranged.Ammunition.Components;
|
||||
using Content.Shared.Camera;
|
||||
using Content.Shared.Damage;
|
||||
using Content.Shared.Database;
|
||||
using Content.Shared.Examine;
|
||||
@@ -208,9 +208,10 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components
|
||||
var direction = (targetPos - Entities.GetComponent<TransformComponent>(shooter).WorldPosition).ToAngle();
|
||||
var angle = GetRecoilAngle(direction);
|
||||
// This should really be client-side but for now we'll just leave it here
|
||||
if (Entities.TryGetComponent(shooter, out CameraRecoilComponent? recoilComponent))
|
||||
if (Entities.HasComponent<CameraRecoilComponent>(shooter))
|
||||
{
|
||||
recoilComponent.Kick(-angle.ToVec() * 0.15f);
|
||||
var kick = -angle.ToVec() * 0.15f;
|
||||
EntitySystem.Get<CameraRecoilSystem>().KickCamera(shooter, kick);
|
||||
}
|
||||
|
||||
// This section probably needs tweaking so there can be caseless hitscan etc.
|
||||
|
||||
Reference in New Issue
Block a user