Clean up a ton of bugs with suspicion.
This commit is contained in:
@@ -6,14 +6,11 @@ using Content.Shared.GameObjects.Components.Suspicion;
|
||||
using Robust.Client.GameObjects;
|
||||
using Robust.Client.Interfaces.Graphics.ClientEye;
|
||||
using Robust.Client.Interfaces.Graphics.Overlays;
|
||||
using Robust.Client.Interfaces.Input;
|
||||
using Robust.Client.Interfaces.ResourceManagement;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Interfaces.GameObjects;
|
||||
using Robust.Shared.Interfaces.Network;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Players;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.ViewVariables;
|
||||
|
||||
namespace Content.Client.GameObjects.Components.Suspicion
|
||||
{
|
||||
@@ -28,6 +25,7 @@ namespace Content.Client.GameObjects.Components.Suspicion
|
||||
private SuspicionGui? _gui;
|
||||
private string? _role;
|
||||
private bool? _antagonist;
|
||||
private bool _overlayActive;
|
||||
|
||||
public string? Role
|
||||
{
|
||||
@@ -67,37 +65,8 @@ namespace Content.Client.GameObjects.Components.Suspicion
|
||||
}
|
||||
}
|
||||
|
||||
public HashSet<EntityUid> Allies { get; } = new();
|
||||
|
||||
private bool AddAlly(EntityUid ally)
|
||||
{
|
||||
if (!Allies.Add(ally))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!_overlayManager.TryGetOverlay<TraitorOverlay>(nameof(TraitorOverlay), out var overlay))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return overlay.AddAlly(ally);
|
||||
}
|
||||
|
||||
private bool RemoveAlly(EntityUid ally)
|
||||
{
|
||||
if (!Allies.Remove(ally))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!_overlayManager.TryGetOverlay<TraitorOverlay>(nameof(TraitorOverlay), out var overlay))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return overlay.RemoveAlly(ally);
|
||||
}
|
||||
[ViewVariables]
|
||||
public List<(string name, EntityUid uid)> Allies { get; } = new();
|
||||
|
||||
private void AddTraitorOverlay()
|
||||
{
|
||||
@@ -106,12 +75,18 @@ namespace Content.Client.GameObjects.Components.Suspicion
|
||||
return;
|
||||
}
|
||||
|
||||
var overlay = new TraitorOverlay(Owner, Owner.EntityManager, _resourceCache, _eyeManager);
|
||||
_overlayActive = true;
|
||||
var overlay = new TraitorOverlay(Owner.EntityManager, _resourceCache, _eyeManager);
|
||||
_overlayManager.AddOverlay(overlay);
|
||||
}
|
||||
|
||||
private void RemoveTraitorOverlay()
|
||||
{
|
||||
if (!_overlayActive)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_overlayManager.RemoveOverlay(nameof(TraitorOverlay));
|
||||
}
|
||||
|
||||
@@ -126,6 +101,8 @@ namespace Content.Client.GameObjects.Components.Suspicion
|
||||
|
||||
Role = state.Role;
|
||||
Antagonist = state.Antagonist;
|
||||
Allies.Clear();
|
||||
Allies.AddRange(state.Allies);
|
||||
}
|
||||
|
||||
public override void HandleMessage(ComponentMessage message, IComponent? component)
|
||||
@@ -160,36 +137,6 @@ namespace Content.Client.GameObjects.Components.Suspicion
|
||||
}
|
||||
}
|
||||
|
||||
public override void HandleNetworkMessage(ComponentMessage message, INetChannel netChannel, ICommonSession? session = null)
|
||||
{
|
||||
base.HandleNetworkMessage(message, netChannel, session);
|
||||
|
||||
switch (message)
|
||||
{
|
||||
case SuspicionAlliesMessage msg:
|
||||
{
|
||||
Allies.Clear();
|
||||
|
||||
foreach (var uid in msg.Allies)
|
||||
{
|
||||
AddAlly(uid);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
case SuspicionAllyAddedMessage msg:
|
||||
{
|
||||
AddAlly(msg.Ally);
|
||||
break;
|
||||
}
|
||||
case SuspicionAllyRemovedMessage msg:
|
||||
{
|
||||
RemoveAlly(msg.Ally);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnRemove()
|
||||
{
|
||||
base.OnRemove();
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
using System.Collections.Generic;
|
||||
using Content.Shared.GameObjects.EntitySystems;
|
||||
using Content.Shared.GameObjects.EntitySystems;
|
||||
using Robust.Client.Graphics;
|
||||
using Robust.Client.Graphics.Drawing;
|
||||
using Robust.Client.Graphics.Overlays;
|
||||
using Robust.Client.Interfaces.Graphics.ClientEye;
|
||||
using Robust.Client.Interfaces.ResourceManagement;
|
||||
using Robust.Client.Player;
|
||||
using Robust.Client.ResourceManagement;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.GameObjects.Components;
|
||||
using Robust.Shared.Interfaces.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Localization;
|
||||
using Robust.Shared.Maths;
|
||||
|
||||
@@ -18,37 +18,25 @@ namespace Content.Client.GameObjects.Components.Suspicion
|
||||
{
|
||||
private readonly IEntityManager _entityManager;
|
||||
private readonly IEyeManager _eyeManager;
|
||||
private readonly IPlayerManager _playerManager;
|
||||
|
||||
public override OverlaySpace Space => OverlaySpace.ScreenSpace;
|
||||
private readonly Font _font;
|
||||
|
||||
private readonly IEntity _user;
|
||||
private readonly HashSet<EntityUid> _allies = new();
|
||||
private readonly string _traitorText = Loc.GetString("Traitor");
|
||||
|
||||
public TraitorOverlay(
|
||||
IEntity user,
|
||||
IEntityManager entityManager,
|
||||
IResourceCache resourceCache,
|
||||
IEyeManager eyeManager)
|
||||
: base(nameof(TraitorOverlay))
|
||||
{
|
||||
_playerManager = IoCManager.Resolve<IPlayerManager>();
|
||||
|
||||
_entityManager = entityManager;
|
||||
_eyeManager = eyeManager;
|
||||
|
||||
_font = new VectorFont(resourceCache.GetResource<FontResource>("/Fonts/NotoSans/NotoSans-Regular.ttf"), 10);
|
||||
|
||||
_user = user;
|
||||
}
|
||||
|
||||
public bool AddAlly(EntityUid ally)
|
||||
{
|
||||
return _allies.Add(ally);
|
||||
}
|
||||
|
||||
public bool RemoveAlly(EntityUid ally)
|
||||
{
|
||||
return _allies.Remove(ally);
|
||||
}
|
||||
|
||||
protected override void Draw(DrawingHandleBase handle, OverlaySpace currentSpace)
|
||||
@@ -65,7 +53,13 @@ namespace Content.Client.GameObjects.Components.Suspicion
|
||||
{
|
||||
var viewport = _eyeManager.GetWorldViewport();
|
||||
|
||||
foreach (var uid in _allies)
|
||||
var ent = _playerManager.LocalPlayer?.ControlledEntity;
|
||||
if (ent == null || ent.TryGetComponent(out SuspicionRoleComponent sus) != true)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (var (_, uid) in sus.Allies)
|
||||
{
|
||||
// Otherwise the entity can not exist yet
|
||||
if (!_entityManager.TryGetEntity(uid, out var ally))
|
||||
@@ -78,8 +72,8 @@ namespace Content.Client.GameObjects.Components.Suspicion
|
||||
return;
|
||||
}
|
||||
|
||||
if (!ExamineSystemShared.InRangeUnOccluded(_user.Transform.MapPosition, ally.Transform.MapPosition, 15,
|
||||
entity => entity == _user || entity == ally))
|
||||
if (!ExamineSystemShared.InRangeUnOccluded(ent.Transform.MapPosition, ally.Transform.MapPosition, 15,
|
||||
entity => entity == ent || entity == ally))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user