Fix ghost FOV toggling (#15751)

This commit is contained in:
Leon Friedrich
2023-04-25 13:11:42 +12:00
committed by GitHub
parent 53a33a5853
commit c7ba2a666b
4 changed files with 55 additions and 5 deletions

View File

@@ -1,3 +1,5 @@
using Content.Shared.Administration.Managers;
using Content.Shared.Ghost;
using Content.Shared.Input;
using Content.Shared.Movement.Components;
using Robust.Shared.Input;
@@ -12,6 +14,8 @@ namespace Content.Shared.Movement.Systems;
/// </summary>
public abstract class SharedContentEyeSystem : EntitySystem
{
[Dependency] private readonly ISharedAdminManager _admin = default!;
private const float ZoomMod = 1.2f;
private const byte ZoomMultiple = 10;
@@ -24,6 +28,7 @@ public abstract class SharedContentEyeSystem : EntitySystem
base.Initialize();
SubscribeLocalEvent<ContentEyeComponent, ComponentStartup>(OnContentEyeStartup);
SubscribeAllEvent<RequestTargetZoomEvent>(OnContentZoomRequest);
SubscribeAllEvent<RequestFovEvent>(OnRequestFov);
CommandBinds.Builder
.Bind(ContentKeyFunctions.ZoomIn, new ScrollInputCmdHandler(true, this))
@@ -43,6 +48,21 @@ public abstract class SharedContentEyeSystem : EntitySystem
Dirty(content);
}
private void OnRequestFov(RequestFovEvent msg, EntitySessionEventArgs args)
{
if (args.SenderSession.AttachedEntity is not { } player)
return;
if (!HasComp<SharedGhostComponent>(player) && !_admin.IsAdmin(player))
return;
if (TryComp<SharedEyeComponent>(player, out var eyeComp))
{
eyeComp.DrawFov = msg.Fov;
Dirty(eyeComp);
}
}
public override void Shutdown()
{
base.Shutdown();
@@ -179,4 +199,13 @@ public abstract class SharedContentEyeSystem : EntitySystem
{
public Vector2 TargetZoom;
}
/// <summary>
/// Sendable from client to server to request changing fov.
/// </summary>
[Serializable, NetSerializable]
public sealed class RequestFovEvent : EntityEventArgs
{
public bool Fov;
}
}