Clean up a ton of bugs with suspicion.

This commit is contained in:
Pieter-Jan Briers
2021-01-04 09:17:44 +01:00
parent 9c2aaef73a
commit c1f53a4303
5 changed files with 47 additions and 222 deletions

View File

@@ -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();