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

@@ -1,4 +1,5 @@
#nullable enable
using System;
using System.Collections.Generic;
using System.Linq;
using Content.Server.GameObjects.Components.Mobs;
@@ -6,12 +7,10 @@ using Content.Server.GameObjects.EntitySystems;
using Content.Server.Mobs;
using Content.Server.Mobs.Roles;
using Content.Server.Mobs.Roles.Suspicion;
using Content.Shared.GameObjects.Components.Damage;
using Content.Shared.GameObjects.Components.Mobs.State;
using Content.Shared.GameObjects.Components.Suspicion;
using Content.Shared.GameObjects.EntitySystems;
using Robust.Server.GameObjects;
using Robust.Server.Interfaces.GameObjects;
using Robust.Shared.GameObjects;
using Robust.Shared.GameObjects.Systems;
using Robust.Shared.Interfaces.GameObjects;
@@ -25,6 +24,7 @@ namespace Content.Server.GameObjects.Components.Suspicion
public class SuspicionRoleComponent : SharedSuspicionRoleComponent, IExamine
{
private Role? _role;
[ViewVariables]
private readonly HashSet<SuspicionRoleComponent> _allies = new();
[ViewVariables]
@@ -67,16 +67,12 @@ namespace Content.Server.GameObjects.Components.Suspicion
public bool IsInnocent()
{
return Owner.TryGetComponent(out MindComponent? mind) &&
mind.HasMind &&
mind.Mind!.HasRole<SuspicionInnocentRole>();
return !IsTraitor();
}
public bool IsTraitor()
{
return Owner.TryGetComponent(out MindComponent? mind) &&
mind.HasMind &&
mind.Mind!.HasRole<SuspicionTraitorRole>();
return Role?.Antagonist ?? false;
}
public void SyncRoles()
@@ -98,36 +94,13 @@ namespace Content.Server.GameObjects.Components.Suspicion
}
_allies.Add(ally);
if (KnowsAllies && Owner.TryGetComponent(out IActorComponent? actor))
{
var channel = actor.playerSession.ConnectedClient;
DebugTools.AssertNotNull(channel);
var message = new SuspicionAllyAddedMessage(ally.Owner.Uid);
SendNetworkMessage(message, channel);
}
}
public bool RemoveAlly(SuspicionRoleComponent ally)
{
if (ally == this)
{
return false;
}
if (_allies.Remove(ally))
{
if (KnowsAllies && Owner.TryGetComponent(out IActorComponent? actor))
{
var channel = actor.playerSession.ConnectedClient;
DebugTools.AssertNotNull(channel);
var message = new SuspicionAllyRemovedMessage(ally.Owner.Uid);
SendNetworkMessage(message, channel);
}
Dirty();
return true;
}
@@ -139,46 +112,16 @@ namespace Content.Server.GameObjects.Components.Suspicion
{
_allies.Clear();
foreach (var ally in allies)
{
if (ally == this)
{
continue;
}
_allies.UnionWith(allies.Where(a => a != this));
_allies.Add(ally);
}
if (!KnowsAllies ||
!Owner.TryGetComponent(out IActorComponent? actor))
{
return;
}
var channel = actor.playerSession.ConnectedClient;
DebugTools.AssertNotNull(channel);
var message = new SuspicionAlliesMessage(_allies.Select(role => role.Owner.Uid));
SendNetworkMessage(message, channel);
Dirty();
}
public void ClearAllies()
{
_allies.Clear();
if (!KnowsAllies ||
!Owner.TryGetComponent(out IActorComponent? actor))
{
return;
}
var channel = actor.playerSession.ConnectedClient;
DebugTools.AssertNotNull(channel);
var message = new SuspicionAlliesClearedMessage();
SendNetworkMessage(message, channel);
Dirty();
}
void IExamine.Examine(FormattedMessage message, bool inDetailsRange)
@@ -199,39 +142,28 @@ namespace Content.Server.GameObjects.Components.Suspicion
message.AddMarkup(tooltip);
}
public override void OnRemove()
{
Role = null;
base.OnRemove();
}
public override ComponentState GetComponentState()
{
return Role == null
? new SuspicionRoleComponentState(null, null)
: new SuspicionRoleComponentState(Role?.Name, Role?.Antagonist);
? new SuspicionRoleComponentState(null, null, Array.Empty<(string, EntityUid)>())
: new SuspicionRoleComponentState(Role?.Name, Role?.Antagonist,
_allies.Select(a => (a.Role!.Mind.CharacterName, a.Owner.Uid)).ToArray());
}
public override void HandleMessage(ComponentMessage message, IComponent? component)
{
base.HandleMessage(message, component);
if (message is not RoleMessage msg ||
msg.Role is not SuspicionRole role)
{
return;
}
switch (message)
{
case PlayerAttachedMsg _:
case PlayerDetachedMsg _:
case PlayerAttachedMsg:
case PlayerDetachedMsg:
SyncRoles();
break;
case RoleAddedMessage _:
case RoleAddedMessage {Role: SuspicionRole role}:
Role = role;
break;
case RoleRemovedMessage _:
case RoleRemovedMessage {Role: SuspicionRole}:
Role = null;
break;
}