2020-08-27 16:39:29 +02:00
|
|
|
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;
|
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
|
|
|
|
2021-06-09 22:19:39 +02:00
|
|
|
namespace Content.Server.Suspicion
|
2020-08-16 18:41:16 +02:00
|
|
|
{
|
|
|
|
|
[RegisterComponent]
|
2022-04-08 17:17:25 -04:00
|
|
|
public sealed class SuspicionRoleComponent : SharedSuspicionRoleComponent
|
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-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
|
|
|
}
|
|
|
|
|
}
|