From c9e2a91f13fb4b653cc5e3df4d8697afd29bad8b Mon Sep 17 00:00:00 2001 From: Leon Friedrich <60421075+ElectroJr@users.noreply.github.com> Date: Mon, 13 Nov 2023 05:36:00 +1100 Subject: [PATCH] Fix ghost FOV bug (#21614) --- Content.Client/Ghost/GhostSystem.cs | 56 +++++-------------- .../Movement/Systems/ContentEyeSystem.cs | 16 ++++-- .../Chemistry/Components/Solution.cs | 12 ++++ Content.Shared/Ghost/GhostComponent.cs | 4 -- .../Systems/SharedContentEyeSystem.cs | 18 ++++-- 5 files changed, 49 insertions(+), 57 deletions(-) diff --git a/Content.Client/Ghost/GhostSystem.cs b/Content.Client/Ghost/GhostSystem.cs index 1a82be3da4..f6913d2578 100644 --- a/Content.Client/Ghost/GhostSystem.cs +++ b/Content.Client/Ghost/GhostSystem.cs @@ -14,8 +14,8 @@ namespace Content.Client.Ghost [Dependency] private readonly IClientConsoleHost _console = default!; [Dependency] private readonly IPlayerManager _playerManager = default!; [Dependency] private readonly SharedActionsSystem _actions = default!; - [Dependency] private readonly ILightManager _lightManager = default!; [Dependency] private readonly ContentEyeSystem _contentEye = default!; + [Dependency] private readonly EyeSystem _eye = default!; public int AvailableGhostRoleCount { get; private set; } @@ -36,7 +36,7 @@ namespace Content.Client.Ghost var query = AllEntityQuery(); while (query.MoveNext(out var uid, out _, out var sprite)) { - sprite.Visible = value || uid == _playerManager.LocalPlayer?.ControlledEntity; + sprite.Visible = value || uid == _playerManager.LocalEntity; } } } @@ -62,39 +62,37 @@ namespace Content.Client.Ghost SubscribeLocalEvent(OnGhostPlayerAttach); SubscribeLocalEvent(OnGhostPlayerDetach); - SubscribeLocalEvent(OnPlayerAttach); - SubscribeNetworkEvent(OnGhostWarpsResponse); SubscribeNetworkEvent(OnUpdateGhostRoleCount); - SubscribeLocalEvent(OnToggleLighting); - SubscribeLocalEvent(OnToggleFoV); + SubscribeLocalEvent(OnToggleLighting); + SubscribeLocalEvent(OnToggleFoV); SubscribeLocalEvent(OnToggleGhosts); } private void OnStartup(EntityUid uid, GhostComponent component, ComponentStartup args) { if (TryComp(uid, out SpriteComponent? sprite)) - sprite.Visible = GhostVisibility; + sprite.Visible = GhostVisibility || uid == _playerManager.LocalEntity; } - private void OnToggleLighting(EntityUid uid, GhostComponent component, ToggleLightingActionEvent args) + private void OnToggleLighting(EntityUid uid, EyeComponent component, ToggleLightingActionEvent args) { if (args.Handled) return; Popup.PopupEntity(Loc.GetString("ghost-gui-toggle-lighting-manager-popup"), args.Performer); - _lightManager.Enabled = !_lightManager.Enabled; + _contentEye.RequestToggleLight(uid, component); args.Handled = true; } - private void OnToggleFoV(EntityUid uid, GhostComponent component, ToggleFoVActionEvent args) + private void OnToggleFoV(EntityUid uid, EyeComponent component, ToggleFoVActionEvent args) { if (args.Handled) return; Popup.PopupEntity(Loc.GetString("ghost-gui-toggle-fov-popup"), args.Performer); - _contentEye.RequestToggleFov(uid); + _contentEye.RequestToggleFov(uid, component); args.Handled = true; } @@ -105,7 +103,7 @@ namespace Content.Client.Ghost Popup.PopupEntity(Loc.GetString("ghost-gui-toggle-ghost-visibility-popup"), args.Performer); - if (uid == _playerManager.LocalPlayer?.ControlledEntity) + if (uid == _playerManager.LocalEntity) ToggleGhostVisibility(); args.Handled = true; @@ -118,26 +116,16 @@ namespace Content.Client.Ghost _actions.RemoveAction(uid, component.ToggleGhostsActionEntity); _actions.RemoveAction(uid, component.ToggleGhostHearingActionEntity); - if (uid != _playerManager.LocalPlayer?.ControlledEntity) + if (uid != _playerManager.LocalEntity) return; - _lightManager.Enabled = true; - - if (component.IsAttached) - { - GhostVisibility = false; - } - + GhostVisibility = false; PlayerRemoved?.Invoke(component); } private void OnGhostPlayerAttach(EntityUid uid, GhostComponent component, LocalPlayerAttachedEvent localPlayerAttachedEvent) { - if (uid != _playerManager.LocalPlayer?.ControlledEntity) - return; - GhostVisibility = true; - component.IsAttached = true; PlayerAttached?.Invoke(component); } @@ -146,32 +134,16 @@ namespace Content.Client.Ghost if (TryComp(uid, out var sprite)) sprite.LayerSetColor(0, component.color); - if (uid != _playerManager.LocalPlayer?.ControlledEntity) + if (uid != _playerManager.LocalEntity) return; PlayerUpdated?.Invoke(component); } - private bool PlayerDetach(EntityUid uid) + private void OnGhostPlayerDetach(EntityUid uid, GhostComponent component, LocalPlayerDetachedEvent args) { - if (uid != _playerManager.LocalPlayer?.ControlledEntity) - return false; - GhostVisibility = false; PlayerDetached?.Invoke(); - return true; - } - - private void OnGhostPlayerDetach(EntityUid uid, GhostComponent component, LocalPlayerDetachedEvent args) - { - if (PlayerDetach(uid)) - component.IsAttached = false; - } - - private void OnPlayerAttach(LocalPlayerAttachedEvent ev) - { - if (!HasComp(ev.Entity)) - PlayerDetach(ev.Entity); } private void OnGhostWarpsResponse(GhostWarpsResponseEvent msg) diff --git a/Content.Client/Movement/Systems/ContentEyeSystem.cs b/Content.Client/Movement/Systems/ContentEyeSystem.cs index 4056f5fd85..d8f73b0057 100644 --- a/Content.Client/Movement/Systems/ContentEyeSystem.cs +++ b/Content.Client/Movement/Systems/ContentEyeSystem.cs @@ -30,14 +30,18 @@ public sealed class ContentEyeSystem : SharedContentEyeSystem public void RequestToggleFov(EntityUid uid, EyeComponent? eye = null) { if (Resolve(uid, ref eye, false)) - RequestFov(!eye.DrawFov); + RequestEye(!eye.DrawFov, eye.DrawLight); } - public void RequestFov(bool value) + public void RequestToggleLight(EntityUid uid, EyeComponent? eye = null) { - RaisePredictiveEvent(new RequestFovEvent() - { - Fov = value, - }); + if (Resolve(uid, ref eye, false)) + RequestEye(eye.DrawFov, !eye.DrawLight); + } + + + public void RequestEye(bool drawFov, bool drawLight) + { + RaisePredictiveEvent(new RequestEyeEvent(drawFov, drawLight)); } } diff --git a/Content.Shared/Chemistry/Components/Solution.cs b/Content.Shared/Chemistry/Components/Solution.cs index d793d3f70c..ca597710d4 100644 --- a/Content.Shared/Chemistry/Components/Solution.cs +++ b/Content.Shared/Chemistry/Components/Solution.cs @@ -301,6 +301,18 @@ namespace Content.Shared.Chemistry.Components return total; } + public FixedPoint2 GetTotalPrototypeQuantity(string id) + { + var total = FixedPoint2.Zero; + foreach (var (reagent, quantity) in Contents) + { + if (id == reagent.Prototype) + total += quantity; + } + + return total; + } + public ReagentId? GetPrimaryReagentId() { if (Contents.Count == 0) diff --git a/Content.Shared/Ghost/GhostComponent.cs b/Content.Shared/Ghost/GhostComponent.cs index 9090af4dba..15d177f069 100644 --- a/Content.Shared/Ghost/GhostComponent.cs +++ b/Content.Shared/Ghost/GhostComponent.cs @@ -8,10 +8,6 @@ namespace Content.Shared.Ghost; [AutoGenerateComponentState(true)] public sealed partial class GhostComponent : Component { - // I have no idea what this means I just wanted to kill comp references. - [ViewVariables] - public bool IsAttached; - // Actions [DataField] public EntProtoId ToggleLightingAction = "ActionToggleLighting"; diff --git a/Content.Shared/Movement/Systems/SharedContentEyeSystem.cs b/Content.Shared/Movement/Systems/SharedContentEyeSystem.cs index 4b81619fd0..d5dcaf0cbf 100644 --- a/Content.Shared/Movement/Systems/SharedContentEyeSystem.cs +++ b/Content.Shared/Movement/Systems/SharedContentEyeSystem.cs @@ -28,7 +28,7 @@ public abstract class SharedContentEyeSystem : EntitySystem base.Initialize(); SubscribeLocalEvent(OnContentEyeStartup); SubscribeAllEvent(OnContentZoomRequest); - SubscribeAllEvent(OnRequestFov); + SubscribeAllEvent(OnRequestEye); CommandBinds.Builder .Bind(ContentKeyFunctions.ZoomIn, InputCmdHandler.FromDelegate(ZoomIn, handle:false)) @@ -89,7 +89,7 @@ public abstract class SharedContentEyeSystem : EntitySystem SetZoom(args.SenderSession.AttachedEntity.Value, msg.TargetZoom, ignoreLimit, eye: content); } - private void OnRequestFov(RequestFovEvent msg, EntitySessionEventArgs args) + private void OnRequestEye(RequestEyeEvent msg, EntitySessionEventArgs args) { if (args.SenderSession.AttachedEntity is not { } player) return; @@ -99,7 +99,8 @@ public abstract class SharedContentEyeSystem : EntitySystem if (TryComp(player, out var eyeComp)) { - _eye.SetDrawFov(player, msg.Fov, eyeComp); + _eye.SetDrawFov(player, msg.DrawFov, eyeComp); + _eye.SetDrawLight((player, eyeComp), msg.DrawLight); } } @@ -141,8 +142,15 @@ public abstract class SharedContentEyeSystem : EntitySystem /// Sendable from client to server to request changing fov. /// [Serializable, NetSerializable] - public sealed class RequestFovEvent : EntityEventArgs + public sealed class RequestEyeEvent : EntityEventArgs { - public bool Fov; + public readonly bool DrawFov; + public readonly bool DrawLight; + + public RequestEyeEvent(bool drawFov, bool drawLight) + { + DrawFov = drawFov; + DrawLight = drawLight; + } } } -- 2.51.2