Fix ghost FOV bug (#21614)
This commit is contained in:
@@ -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<GhostComponent, SpriteComponent>();
|
||||
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, LocalPlayerDetachedEvent>(OnGhostPlayerDetach);
|
||||
|
||||
SubscribeLocalEvent<LocalPlayerAttachedEvent>(OnPlayerAttach);
|
||||
|
||||
SubscribeNetworkEvent<GhostWarpsResponseEvent>(OnGhostWarpsResponse);
|
||||
SubscribeNetworkEvent<GhostUpdateGhostRoleCountEvent>(OnUpdateGhostRoleCount);
|
||||
|
||||
SubscribeLocalEvent<GhostComponent, ToggleLightingActionEvent>(OnToggleLighting);
|
||||
SubscribeLocalEvent<GhostComponent, ToggleFoVActionEvent>(OnToggleFoV);
|
||||
SubscribeLocalEvent<EyeComponent, ToggleLightingActionEvent>(OnToggleLighting);
|
||||
SubscribeLocalEvent<EyeComponent, ToggleFoVActionEvent>(OnToggleFoV);
|
||||
SubscribeLocalEvent<GhostComponent, ToggleGhostsActionEvent>(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;
|
||||
}
|
||||
|
||||
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<SpriteComponent>(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)
|
||||
{
|
||||
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<GhostComponent>(ev.Entity))
|
||||
PlayerDetach(ev.Entity);
|
||||
GhostVisibility = false;
|
||||
PlayerDetached?.Invoke();
|
||||
}
|
||||
|
||||
private void OnGhostWarpsResponse(GhostWarpsResponseEvent msg)
|
||||
|
||||
@@ -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()
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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";
|
||||
|
||||
@@ -28,7 +28,7 @@ public abstract class SharedContentEyeSystem : EntitySystem
|
||||
base.Initialize();
|
||||
SubscribeLocalEvent<ContentEyeComponent, ComponentStartup>(OnContentEyeStartup);
|
||||
SubscribeAllEvent<RequestTargetZoomEvent>(OnContentZoomRequest);
|
||||
SubscribeAllEvent<RequestFovEvent>(OnRequestFov);
|
||||
SubscribeAllEvent<RequestEyeEvent>(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<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.
|
||||
/// </summary>
|
||||
[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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user