2021-01-04 09:17:44 +01:00
|
|
|
using System;
|
2020-08-27 16:39:29 +02:00
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
2021-12-21 21:23:29 +01:00
|
|
|
using Content.Server.GameTicking.Rules;
|
2021-06-09 22:19:39 +02:00
|
|
|
using Content.Server.Mind.Components;
|
|
|
|
|
using Content.Server.Roles;
|
|
|
|
|
using Content.Server.Suspicion.Roles;
|
|
|
|
|
using Content.Shared.Examine;
|
2021-11-08 15:11:58 +01:00
|
|
|
using Content.Shared.MobState.Components;
|
2021-06-09 22:19:39 +02:00
|
|
|
using Content.Shared.Suspicion;
|
2020-08-16 18:41:16 +02:00
|
|
|
using Robust.Shared.GameObjects;
|
2021-12-03 14:17:01 +01:00
|
|
|
using Robust.Shared.IoC;
|
2020-08-16 18:41:16 +02:00
|
|
|
using Robust.Shared.Localization;
|
|
|
|
|
using Robust.Shared.Utility;
|
2020-08-27 16:39:29 +02:00
|
|
|
using Robust.Shared.ViewVariables;
|
2020-08-16 18:41:16 +02:00
|
|
|
|
2021-06-09 22:19:39 +02:00
|
|
|
namespace Content.Server.Suspicion
|
2020-08-16 18:41:16 +02:00
|
|
|
{
|
|
|
|
|
[RegisterComponent]
|
2021-10-27 18:10:40 +02:00
|
|
|
#pragma warning disable 618
|
2022-02-16 00:23:23 -07:00
|
|
|
public sealed class SuspicionRoleComponent : SharedSuspicionRoleComponent, IExamine
|
2021-10-27 18:10:40 +02:00
|
|
|
#pragma warning restore 618
|
2020-08-16 18:41:16 +02:00
|
|
|
{
|
2021-12-08 17:32:32 +01:00
|
|
|
[Dependency] private readonly IEntityManager _entMan = default!;
|
|
|
|
|
|
2020-08-27 16:39:29 +02:00
|
|
|
private Role? _role;
|
2021-01-04 09:17:44 +01:00
|
|
|
[ViewVariables]
|
2020-11-27 11:00:49 +01:00
|
|
|
private readonly HashSet<SuspicionRoleComponent> _allies = new();
|
2020-08-27 16:39:29 +02:00
|
|
|
|
|
|
|
|
[ViewVariables]
|
|
|
|
|
public Role? Role
|
|
|
|
|
{
|
|
|
|
|
get => _role;
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (_role == value)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_role = value;
|
|
|
|
|
|
|
|
|
|
Dirty();
|
|
|
|
|
|
2021-12-21 21:23:29 +01:00
|
|
|
var sus = EntitySystem.Get<SuspicionRuleSystem>();
|
2020-08-27 16:39:29 +02:00
|
|
|
|
|
|
|
|
if (value == null || !value.Antagonist)
|
|
|
|
|
{
|
|
|
|
|
ClearAllies();
|
2021-12-21 21:23:29 +01:00
|
|
|
sus.RemoveTraitor(this);
|
2020-08-27 16:39:29 +02:00
|
|
|
}
|
|
|
|
|
else if (value.Antagonist)
|
|
|
|
|
{
|
2021-12-21 21:23:29 +01:00
|
|
|
SetAllies(sus.Traitors);
|
|
|
|
|
sus.AddTraitor(this);
|
2020-08-27 16:39:29 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[ViewVariables] public bool KnowsAllies => IsTraitor();
|
2020-08-16 18:41:16 +02:00
|
|
|
|
|
|
|
|
public bool IsDead()
|
|
|
|
|
{
|
2021-12-08 17:32:32 +01:00
|
|
|
return _entMan.TryGetComponent(Owner, out MobStateComponent? state) &&
|
2020-12-07 14:52:55 +01:00
|
|
|
state.IsDead();
|
2020-08-16 18:41:16 +02:00
|
|
|
}
|
|
|
|
|
|
2020-08-27 16:39:29 +02:00
|
|
|
public bool IsInnocent()
|
|
|
|
|
{
|
2021-01-04 09:17:44 +01:00
|
|
|
return !IsTraitor();
|
2020-08-27 16:39:29 +02:00
|
|
|
}
|
|
|
|
|
|
2020-08-16 18:41:16 +02:00
|
|
|
public bool IsTraitor()
|
|
|
|
|
{
|
2021-01-04 09:17:44 +01:00
|
|
|
return Role?.Antagonist ?? false;
|
2020-08-16 18:41:16 +02:00
|
|
|
}
|
|
|
|
|
|
2020-08-27 16:39:29 +02:00
|
|
|
public void SyncRoles()
|
|
|
|
|
{
|
2021-12-08 17:32:32 +01:00
|
|
|
if (!_entMan.TryGetComponent(Owner, out MindComponent? mind) ||
|
2020-08-27 16:39:29 +02:00
|
|
|
!mind.HasMind)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Role = mind.Mind!.AllRoles.First(role => role is SuspicionRole);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void AddAlly(SuspicionRoleComponent ally)
|
|
|
|
|
{
|
|
|
|
|
if (ally == this)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_allies.Add(ally);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool RemoveAlly(SuspicionRoleComponent ally)
|
|
|
|
|
{
|
|
|
|
|
if (_allies.Remove(ally))
|
|
|
|
|
{
|
2021-01-04 09:17:44 +01:00
|
|
|
Dirty();
|
2020-08-27 16:39:29 +02:00
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void SetAllies(IEnumerable<SuspicionRoleComponent> allies)
|
|
|
|
|
{
|
|
|
|
|
_allies.Clear();
|
|
|
|
|
|
2021-01-04 09:17:44 +01:00
|
|
|
_allies.UnionWith(allies.Where(a => a != this));
|
2020-08-27 16:39:29 +02:00
|
|
|
|
2021-01-04 09:17:44 +01:00
|
|
|
Dirty();
|
2020-08-27 16:39:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void ClearAllies()
|
|
|
|
|
{
|
|
|
|
|
_allies.Clear();
|
|
|
|
|
|
2021-01-04 09:17:44 +01:00
|
|
|
Dirty();
|
2020-08-27 16:39:29 +02:00
|
|
|
}
|
|
|
|
|
|
2021-12-20 12:42:42 +01:00
|
|
|
void IExamine.Examine(FormattedMessage message, bool inDetailsRange)
|
2020-08-16 18:41:16 +02:00
|
|
|
{
|
|
|
|
|
if (!IsDead())
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-13 14:23:52 +02:00
|
|
|
var traitor = IsTraitor();
|
|
|
|
|
var color = traitor ? "red" : "green";
|
2021-06-21 02:13:54 +02:00
|
|
|
var role = traitor ? "suspicion-role-component-role-traitor" : "suspicion-role-component-role-innocent";
|
|
|
|
|
var article = traitor ? "generic-article-a" : "generic-article-an";
|
2020-09-13 14:23:52 +02:00
|
|
|
|
2021-06-21 02:13:54 +02:00
|
|
|
var tooltip = Loc.GetString("suspicion-role-component-on-examine-tooltip",
|
|
|
|
|
("article", Loc.GetString(article)),
|
|
|
|
|
("colorName", color),
|
|
|
|
|
("role",Loc.GetString(role)));
|
2020-08-16 18:41:16 +02:00
|
|
|
|
|
|
|
|
message.AddMarkup(tooltip);
|
|
|
|
|
}
|
2020-08-27 16:39:29 +02:00
|
|
|
|
2021-11-30 15:20:38 +01:00
|
|
|
public override ComponentState GetComponentState()
|
2020-08-27 16:39:29 +02:00
|
|
|
{
|
2021-03-16 15:50:20 +01:00
|
|
|
if (Role == null)
|
|
|
|
|
{
|
|
|
|
|
return new SuspicionRoleComponentState(null, null, Array.Empty<(string, EntityUid)>());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var allies = new List<(string name, EntityUid)>();
|
|
|
|
|
|
|
|
|
|
foreach (var role in _allies)
|
|
|
|
|
{
|
|
|
|
|
if (role.Role?.Mind.CharacterName == null)
|
|
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-09 20:10:36 -08:00
|
|
|
allies.Add((role.Role!.Mind.CharacterName, role.Owner));
|
2021-03-16 15:50:20 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return new SuspicionRoleComponentState(Role?.Name, Role?.Antagonist, allies.ToArray());
|
2020-08-27 16:39:29 +02:00
|
|
|
}
|
2020-08-16 18:41:16 +02:00
|
|
|
}
|
|
|
|
|
}
|