From 1faa1b5df6e74b9cb1309d0400b12ee0b96039e4 Mon Sep 17 00:00:00 2001 From: Leon Friedrich <60421075+ElectroJr@users.noreply.github.com> Date: Wed, 3 Jul 2024 18:44:55 +1200 Subject: [PATCH] Allow `zoom` command to modify an eye's PVS range (#29245) Allow zoom command to modify an eye's PVS range Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com> --- Content.Client/Commands/ZoomCommand.cs | 11 ++++++++-- .../Movement/Systems/ContentEyeSystem.cs | 10 ++++++++- .../Camera/CameraRecoilComponent.cs | 7 ++++++ .../Camera/SharedCameraRecoilSystem.cs | 4 ++-- .../Systems/SharedContentEyeSystem.cs | 22 ++++++++++++++++++- .../Locale/en-US/commands/zoom-command.ftl | 4 ++-- 6 files changed, 50 insertions(+), 8 deletions(-) diff --git a/Content.Client/Commands/ZoomCommand.cs b/Content.Client/Commands/ZoomCommand.cs index 2bdc85e1fe..c63eeea836 100644 --- a/Content.Client/Commands/ZoomCommand.cs +++ b/Content.Client/Commands/ZoomCommand.cs @@ -20,7 +20,7 @@ public sealed class ZoomCommand : LocalizedCommands public override void Execute(IConsoleShell shell, string argStr, string[] args) { Vector2 zoom; - if (args.Length is not (1 or 2)) + if (args.Length is not (1 or 2 or 3)) { shell.WriteLine(Help); return; @@ -57,11 +57,18 @@ public sealed class ZoomCommand : LocalizedCommands } } + var scalePvs = true; + if (args.Length == 3 && !bool.TryParse(args[2], out scalePvs)) + { + shell.WriteError(LocalizationManager.GetString("cmd-parse-failure-bool", ("arg", args[2]))); + return; + } + var player = _playerManager.LocalSession?.AttachedEntity; if (_entityManager.TryGetComponent(player, out var content)) { - _entityManager.System().RequestZoom(player.Value, zoom, true, content); + _entityManager.System().RequestZoom(player.Value, zoom, true, scalePvs, content); return; } diff --git a/Content.Client/Movement/Systems/ContentEyeSystem.cs b/Content.Client/Movement/Systems/ContentEyeSystem.cs index 182ac92ae0..9fbd4b5c37 100644 --- a/Content.Client/Movement/Systems/ContentEyeSystem.cs +++ b/Content.Client/Movement/Systems/ContentEyeSystem.cs @@ -9,7 +9,7 @@ public sealed class ContentEyeSystem : SharedContentEyeSystem { [Dependency] private readonly IPlayerManager _player = default!; - public void RequestZoom(EntityUid uid, Vector2 zoom, bool ignoreLimit, ContentEyeComponent? content = null) + public void RequestZoom(EntityUid uid, Vector2 zoom, bool ignoreLimit, bool scalePvs, ContentEyeComponent? content = null) { if (!Resolve(uid, ref content, false)) return; @@ -19,6 +19,14 @@ public sealed class ContentEyeSystem : SharedContentEyeSystem TargetZoom = zoom, IgnoreLimit = ignoreLimit, }); + + if (scalePvs) + RequestPvsScale(Math.Max(zoom.X, zoom.Y)); + } + + public void RequestPvsScale(float scale) + { + RaiseNetworkEvent(new RequestPvsScaleEvent(scale)); } public void RequestToggleFov() diff --git a/Content.Shared/Camera/CameraRecoilComponent.cs b/Content.Shared/Camera/CameraRecoilComponent.cs index 8b8b290845..2cbb632408 100644 --- a/Content.Shared/Camera/CameraRecoilComponent.cs +++ b/Content.Shared/Camera/CameraRecoilComponent.cs @@ -7,12 +7,19 @@ namespace Content.Shared.Camera; [NetworkedComponent] public sealed partial class CameraRecoilComponent : Component { + [ViewVariables(VVAccess.ReadWrite)] public Vector2 CurrentKick { get; set; } + + [ViewVariables(VVAccess.ReadWrite)] public Vector2 LastKick { get; set; } + + [ViewVariables(VVAccess.ReadWrite)] public float LastKickTime { get; set; } /// /// Basically I needed a way to chain this effect for the attack lunge animation. Sorry! /// + /// + [ViewVariables(VVAccess.ReadWrite)] public Vector2 BaseOffset { get; set; } } diff --git a/Content.Shared/Camera/SharedCameraRecoilSystem.cs b/Content.Shared/Camera/SharedCameraRecoilSystem.cs index 5ba97dabe2..a2ce0e77e2 100644 --- a/Content.Shared/Camera/SharedCameraRecoilSystem.cs +++ b/Content.Shared/Camera/SharedCameraRecoilSystem.cs @@ -52,9 +52,9 @@ public abstract class SharedCameraRecoilSystem : EntitySystem private void UpdateEyes(float frameTime) { - var query = AllEntityQuery(); + var query = AllEntityQuery(); - while (query.MoveNext(out var uid, out var eye, out var recoil)) + while (query.MoveNext(out var uid, out var recoil, out var eye)) { var magnitude = recoil.CurrentKick.Length(); if (magnitude <= 0.005f) diff --git a/Content.Shared/Movement/Systems/SharedContentEyeSystem.cs b/Content.Shared/Movement/Systems/SharedContentEyeSystem.cs index 0c4304d374..faade44c85 100644 --- a/Content.Shared/Movement/Systems/SharedContentEyeSystem.cs +++ b/Content.Shared/Movement/Systems/SharedContentEyeSystem.cs @@ -18,6 +18,9 @@ public abstract class SharedContentEyeSystem : EntitySystem { [Dependency] private readonly ISharedAdminManager _admin = default!; + // Admin flags required to ignore normal eye restrictions. + public const AdminFlags EyeFlag = AdminFlags.Debug; + public const float ZoomMod = 1.5f; public static readonly Vector2 DefaultZoom = Vector2.One; public static readonly Vector2 MinZoom = DefaultZoom * (float)Math.Pow(ZoomMod, -3); @@ -29,6 +32,7 @@ public abstract class SharedContentEyeSystem : EntitySystem base.Initialize(); SubscribeLocalEvent(OnContentEyeStartup); SubscribeAllEvent(OnContentZoomRequest); + SubscribeAllEvent(OnPvsScale); SubscribeAllEvent(OnRequestEye); CommandBinds.Builder @@ -84,12 +88,18 @@ public abstract class SharedContentEyeSystem : EntitySystem private void OnContentZoomRequest(RequestTargetZoomEvent msg, EntitySessionEventArgs args) { - var ignoreLimit = msg.IgnoreLimit && _admin.HasAdminFlag(args.SenderSession, AdminFlags.Debug); + var ignoreLimit = msg.IgnoreLimit && _admin.HasAdminFlag(args.SenderSession, EyeFlag); if (TryComp(args.SenderSession.AttachedEntity, out var content)) SetZoom(args.SenderSession.AttachedEntity.Value, msg.TargetZoom, ignoreLimit, eye: content); } + private void OnPvsScale(RequestPvsScaleEvent ev, EntitySessionEventArgs args) + { + if (args.SenderSession.AttachedEntity is {} uid && _admin.HasAdminFlag(args.SenderSession, EyeFlag)) + _eye.SetPvsScale(uid, ev.Scale); + } + private void OnRequestEye(RequestEyeEvent msg, EntitySessionEventArgs args) { if (args.SenderSession.AttachedEntity is not { } player) @@ -116,6 +126,7 @@ public abstract class SharedContentEyeSystem : EntitySystem public void ResetZoom(EntityUid uid, ContentEyeComponent? component = null) { + _eye.SetPvsScale(uid, 1); SetZoom(uid, DefaultZoom, eye: component); } @@ -146,6 +157,15 @@ public abstract class SharedContentEyeSystem : EntitySystem public bool IgnoreLimit; } + /// + /// Client->Server request for new PVS scale. + /// + [Serializable, NetSerializable] + public sealed class RequestPvsScaleEvent(float scale) : EntityEventArgs + { + public float Scale = scale; + } + /// /// Sendable from client to server to request changing fov. /// diff --git a/Resources/Locale/en-US/commands/zoom-command.ftl b/Resources/Locale/en-US/commands/zoom-command.ftl index 0132f22240..64bf6bca7a 100644 --- a/Resources/Locale/en-US/commands/zoom-command.ftl +++ b/Resources/Locale/en-US/commands/zoom-command.ftl @@ -1,3 +1,3 @@ -cmd-zoom-desc = Sets the zoom of the main eye. -cmd-zoom-help = zoom ( | ) +cmd-zoom-desc = Sets the zoom of the main eye. Optionally also changes the eye's PVS range. +cmd-zoom-help = zoom ( | [bool]) cmd-zoom-error = scale has to be greater than 0