Fix ghost FOV bug (#21614)

This commit is contained in:
Leon Friedrich
2023-11-13 05:36:00 +11:00
committed by GitHub
parent b9b706bda9
commit c9e2a91f13
5 changed files with 50 additions and 58 deletions

View File

@@ -14,8 +14,8 @@ namespace Content.Client.Ghost
[Dependency] private readonly IClientConsoleHost _console = default!; [Dependency] private readonly IClientConsoleHost _console = default!;
[Dependency] private readonly IPlayerManager _playerManager = default!; [Dependency] private readonly IPlayerManager _playerManager = default!;
[Dependency] private readonly SharedActionsSystem _actions = default!; [Dependency] private readonly SharedActionsSystem _actions = default!;
[Dependency] private readonly ILightManager _lightManager = default!;
[Dependency] private readonly ContentEyeSystem _contentEye = default!; [Dependency] private readonly ContentEyeSystem _contentEye = default!;
[Dependency] private readonly EyeSystem _eye = default!;
public int AvailableGhostRoleCount { get; private set; } public int AvailableGhostRoleCount { get; private set; }
@@ -36,7 +36,7 @@ namespace Content.Client.Ghost
var query = AllEntityQuery<GhostComponent, SpriteComponent>(); var query = AllEntityQuery<GhostComponent, SpriteComponent>();
while (query.MoveNext(out var uid, out _, out var sprite)) 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<GhostComponent, LocalPlayerAttachedEvent>(OnGhostPlayerAttach); SubscribeLocalEvent<GhostComponent, LocalPlayerAttachedEvent>(OnGhostPlayerAttach);
SubscribeLocalEvent<GhostComponent, LocalPlayerDetachedEvent>(OnGhostPlayerDetach); SubscribeLocalEvent<GhostComponent, LocalPlayerDetachedEvent>(OnGhostPlayerDetach);
SubscribeLocalEvent<LocalPlayerAttachedEvent>(OnPlayerAttach);
SubscribeNetworkEvent<GhostWarpsResponseEvent>(OnGhostWarpsResponse); SubscribeNetworkEvent<GhostWarpsResponseEvent>(OnGhostWarpsResponse);
SubscribeNetworkEvent<GhostUpdateGhostRoleCountEvent>(OnUpdateGhostRoleCount); SubscribeNetworkEvent<GhostUpdateGhostRoleCountEvent>(OnUpdateGhostRoleCount);
SubscribeLocalEvent<GhostComponent, ToggleLightingActionEvent>(OnToggleLighting); SubscribeLocalEvent<EyeComponent, ToggleLightingActionEvent>(OnToggleLighting);
SubscribeLocalEvent<GhostComponent, ToggleFoVActionEvent>(OnToggleFoV); SubscribeLocalEvent<EyeComponent, ToggleFoVActionEvent>(OnToggleFoV);
SubscribeLocalEvent<GhostComponent, ToggleGhostsActionEvent>(OnToggleGhosts); SubscribeLocalEvent<GhostComponent, ToggleGhostsActionEvent>(OnToggleGhosts);
} }
private void OnStartup(EntityUid uid, GhostComponent component, ComponentStartup args) private void OnStartup(EntityUid uid, GhostComponent component, ComponentStartup args)
{ {
if (TryComp(uid, out SpriteComponent? sprite)) 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) if (args.Handled)
return; return;
Popup.PopupEntity(Loc.GetString("ghost-gui-toggle-lighting-manager-popup"), args.Performer); Popup.PopupEntity(Loc.GetString("ghost-gui-toggle-lighting-manager-popup"), args.Performer);
_lightManager.Enabled = !_lightManager.Enabled; _contentEye.RequestToggleLight(uid, component);
args.Handled = true; args.Handled = true;
} }
private void OnToggleFoV(EntityUid uid, GhostComponent component, ToggleFoVActionEvent args) private void OnToggleFoV(EntityUid uid, EyeComponent component, ToggleFoVActionEvent args)
{ {
if (args.Handled) if (args.Handled)
return; return;
Popup.PopupEntity(Loc.GetString("ghost-gui-toggle-fov-popup"), args.Performer); Popup.PopupEntity(Loc.GetString("ghost-gui-toggle-fov-popup"), args.Performer);
_contentEye.RequestToggleFov(uid); _contentEye.RequestToggleFov(uid, component);
args.Handled = true; args.Handled = true;
} }
@@ -105,7 +103,7 @@ namespace Content.Client.Ghost
Popup.PopupEntity(Loc.GetString("ghost-gui-toggle-ghost-visibility-popup"), args.Performer); Popup.PopupEntity(Loc.GetString("ghost-gui-toggle-ghost-visibility-popup"), args.Performer);
if (uid == _playerManager.LocalPlayer?.ControlledEntity) if (uid == _playerManager.LocalEntity)
ToggleGhostVisibility(); ToggleGhostVisibility();
args.Handled = true; args.Handled = true;
@@ -118,26 +116,16 @@ namespace Content.Client.Ghost
_actions.RemoveAction(uid, component.ToggleGhostsActionEntity); _actions.RemoveAction(uid, component.ToggleGhostsActionEntity);
_actions.RemoveAction(uid, component.ToggleGhostHearingActionEntity); _actions.RemoveAction(uid, component.ToggleGhostHearingActionEntity);
if (uid != _playerManager.LocalPlayer?.ControlledEntity) if (uid != _playerManager.LocalEntity)
return; return;
_lightManager.Enabled = true;
if (component.IsAttached)
{
GhostVisibility = false; GhostVisibility = false;
}
PlayerRemoved?.Invoke(component); PlayerRemoved?.Invoke(component);
} }
private void OnGhostPlayerAttach(EntityUid uid, GhostComponent component, LocalPlayerAttachedEvent localPlayerAttachedEvent) private void OnGhostPlayerAttach(EntityUid uid, GhostComponent component, LocalPlayerAttachedEvent localPlayerAttachedEvent)
{ {
if (uid != _playerManager.LocalPlayer?.ControlledEntity)
return;
GhostVisibility = true; GhostVisibility = true;
component.IsAttached = true;
PlayerAttached?.Invoke(component); PlayerAttached?.Invoke(component);
} }
@@ -146,32 +134,16 @@ namespace Content.Client.Ghost
if (TryComp<SpriteComponent>(uid, out var sprite)) if (TryComp<SpriteComponent>(uid, out var sprite))
sprite.LayerSetColor(0, component.color); sprite.LayerSetColor(0, component.color);
if (uid != _playerManager.LocalPlayer?.ControlledEntity) if (uid != _playerManager.LocalEntity)
return; return;
PlayerUpdated?.Invoke(component); PlayerUpdated?.Invoke(component);
} }
private bool PlayerDetach(EntityUid uid)
{
if (uid != _playerManager.LocalPlayer?.ControlledEntity)
return false;
GhostVisibility = false;
PlayerDetached?.Invoke();
return true;
}
private void OnGhostPlayerDetach(EntityUid uid, GhostComponent component, LocalPlayerDetachedEvent args) private void OnGhostPlayerDetach(EntityUid uid, GhostComponent component, LocalPlayerDetachedEvent args)
{ {
if (PlayerDetach(uid)) GhostVisibility = false;
component.IsAttached = false; PlayerDetached?.Invoke();
}
private void OnPlayerAttach(LocalPlayerAttachedEvent ev)
{
if (!HasComp<GhostComponent>(ev.Entity))
PlayerDetach(ev.Entity);
} }
private void OnGhostWarpsResponse(GhostWarpsResponseEvent msg) private void OnGhostWarpsResponse(GhostWarpsResponseEvent msg)

View File

@@ -30,14 +30,18 @@ public sealed class ContentEyeSystem : SharedContentEyeSystem
public void RequestToggleFov(EntityUid uid, EyeComponent? eye = null) public void RequestToggleFov(EntityUid uid, EyeComponent? eye = null)
{ {
if (Resolve(uid, ref eye, false)) 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() if (Resolve(uid, ref eye, false))
RequestEye(eye.DrawFov, !eye.DrawLight);
}
public void RequestEye(bool drawFov, bool drawLight)
{ {
Fov = value, RaisePredictiveEvent(new RequestEyeEvent(drawFov, drawLight));
});
} }
} }

View File

@@ -301,6 +301,18 @@ namespace Content.Shared.Chemistry.Components
return total; 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() public ReagentId? GetPrimaryReagentId()
{ {
if (Contents.Count == 0) if (Contents.Count == 0)

View File

@@ -8,10 +8,6 @@ namespace Content.Shared.Ghost;
[AutoGenerateComponentState(true)] [AutoGenerateComponentState(true)]
public sealed partial class GhostComponent : Component 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 // Actions
[DataField] [DataField]
public EntProtoId ToggleLightingAction = "ActionToggleLighting"; public EntProtoId ToggleLightingAction = "ActionToggleLighting";

View File

@@ -28,7 +28,7 @@ public abstract class SharedContentEyeSystem : EntitySystem
base.Initialize(); base.Initialize();
SubscribeLocalEvent<ContentEyeComponent, ComponentStartup>(OnContentEyeStartup); SubscribeLocalEvent<ContentEyeComponent, ComponentStartup>(OnContentEyeStartup);
SubscribeAllEvent<RequestTargetZoomEvent>(OnContentZoomRequest); SubscribeAllEvent<RequestTargetZoomEvent>(OnContentZoomRequest);
SubscribeAllEvent<RequestFovEvent>(OnRequestFov); SubscribeAllEvent<RequestEyeEvent>(OnRequestEye);
CommandBinds.Builder CommandBinds.Builder
.Bind(ContentKeyFunctions.ZoomIn, InputCmdHandler.FromDelegate(ZoomIn, handle:false)) .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); 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) if (args.SenderSession.AttachedEntity is not { } player)
return; return;
@@ -99,7 +99,8 @@ public abstract class SharedContentEyeSystem : EntitySystem
if (TryComp<EyeComponent>(player, out var eyeComp)) if (TryComp<EyeComponent>(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. /// Sendable from client to server to request changing fov.
/// </summary> /// </summary>
[Serializable, NetSerializable] [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;
}
} }
} }