Files
crystall-punk-14/Content.Server/GameObjects/Components/Suspicion/SuspicionRoleComponent.cs

240 lines
6.7 KiB
C#
Raw Normal View History

#nullable enable
using System.Collections.Generic;
using System.Linq;
using Content.Server.GameObjects.Components.Mobs;
using Content.Server.GameObjects.EntitySystems;
using Content.Server.Mobs;
using Content.Server.Mobs.Roles;
using Content.Server.Mobs.Roles.Suspicion;
Bodysystem and damagesystem rework (#1544) * Things and stuff with grids, unfinished w/ code debug changes. * Updated submodule and also lost some progress cause I fucked it up xd * First unfinished draft of the BodySystem. Doesn't compile. * More changes to make it compile, but still just a framework. Doesn't do anything at the moment. * Many cleanup changes. * Revert "Merge branch 'master' of https://github.com/GlassEclipse/space-station-14 into body_system" This reverts commit ddd4aebbc76cf2a0b7b102f72b93d55a0816c88c, reversing changes made to 12d0dd752706bdda8879393bd8191a1199a0c978. * Commit human.yml * Updated a lot of things to be more classy, more progress overall, etc. etc. * Latest update with many changes * Minor changes * Fixed Travis build bug * Adds first draft of Body Scanner console, apparently I also forgot to tie Mechanisms into body parts so now a heart just sits in the Torso like a good boy :) * Commit rest of stuff * Latest changes * Latest changes again * 14 naked cowboys * Yay! * Latest changes (probably doesnt compile) * Surgery!!!!!!!!!~1116y * Cleaned some stuff up * More cleanup * Refactoring of code. Basic surgery path now done. * Removed readme, has been added to HackMD * Fixes typo (and thus test errors) * WIP changes, committing so I can pull latest master changes * Still working on that god awful merge * Latest changes * Latest changes!! * Beginning of refactor to BoundUserInterface * Surgery! * Latest changes - fixes pr change requests and random fixes * oops * Fixes bodypart recursion * Beginning of work on revamping the damage system. * More latest changes * Latest changes * Finished merge * Commit before removing old healthcode * Almost done with removing speciescomponent... * It compiles!!! * yahoo more work * Fixes to make it work * Merge conflict fixes * Deleting species visualizer was a mistake * IDE warnings are VERBOTEN * makes the server not kill itself on startup, some cleanup (#1) * Namespaces, comments and exception fixes * Fix conveyor and conveyor switch serialization SS14 in reactive when * Move damage, acts and body to shared Damage cleanup Comment cleanup * Rename SpeciesComponent to RotationComponent and cleanup Damage cleanup Comment cleanup * Fix nullable warnings * Address old reviews Fix off welder suicide damage type, deathmatch and suspicion * Fix new test fail with units being able to accept items when unpowered * Remove RotationComponent, change references to IBodyManagerComponent * Add a bloodstream to humans * More cleanups * Add body conduits, connections, connectors substances and valves * Revert "Add body conduits, connections, connectors substances and valves" This reverts commit 9ab0b50e6b15fe98852d7b0836c0cdbf4bd76d20. * Implement the heart mechanism behavior with the circulatory network * Added network property to mechanism behaviors * Changed human organ sprites and added missing ones * Fix tests * Add individual body part sprite rendering * Fix error where dropped mechanisms are not initialized * Implement client/server body damage * Make DamageContainer take care of raising events * Reimplement medical scanner with the new body system * Improve the medical scanner ui * Merge conflict fixes * Fix crash when colliding with something * Fix microwave suicides and eyes sprite rendering * Fix nullable reference error * Fix up surgery client side * Fix missing using from merge conflict * Add breathing *inhale * Merge conflict fixes * Fix accumulatedframetime being reset to 0 instead of decreased by the threshold https://github.com/space-wizards/space-station-14/pull/1617 * Use and add to the new AtmosHelpers * Fix feet * Add proper coloring to dropped body parts * Fix Urist's lungs being too strong * Merge conflict fixes * Merge conflict fixes * Merge conflict fixes Co-authored-by: GlassEclipse <tsymall5@gmail.com> Co-authored-by: Pieter-Jan Briers <pieterjan.briers+git@gmail.com> Co-authored-by: AJCM-git <60196617+AJCM-git@users.noreply.github.com>
2020-08-17 01:42:42 +02:00
using Content.Shared.GameObjects.Components.Damage;
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;
using Robust.Shared.Localization;
using Robust.Shared.Utility;
using Robust.Shared.ViewVariables;
namespace Content.Server.GameObjects.Components.Suspicion
{
[RegisterComponent]
public class SuspicionRoleComponent : SharedSuspicionRoleComponent, IExamine
{
private Role? _role;
private readonly HashSet<SuspicionRoleComponent> _allies = new HashSet<SuspicionRoleComponent>();
[ViewVariables]
public Role? Role
{
get => _role;
set
{
if (_role == value)
{
return;
}
_role = value;
Dirty();
var suspicionRoleSystem = EntitySystem.Get<SuspicionRoleSystem>();
if (value == null || !value.Antagonist)
{
ClearAllies();
suspicionRoleSystem.RemoveTraitor(this);
}
else if (value.Antagonist)
{
SetAllies(suspicionRoleSystem.Traitors);
suspicionRoleSystem.AddTraitor(this);
}
}
}
[ViewVariables] public bool KnowsAllies => IsTraitor();
public bool IsDead()
{
return Owner.TryGetComponent(out IDamageableComponent? damageable) &&
damageable.CurrentState == DamageState.Dead;
}
public bool IsInnocent()
{
return Owner.TryGetComponent(out MindComponent? mind) &&
mind.HasMind &&
mind.Mind!.HasRole<SuspicionInnocentRole>();
}
public bool IsTraitor()
{
return Owner.TryGetComponent(out MindComponent? mind) &&
mind.HasMind &&
mind.Mind!.HasRole<SuspicionTraitorRole>();
}
public void SyncRoles()
{
if (!Owner.TryGetComponent(out MindComponent? mind) ||
!mind.HasMind)
{
return;
}
Role = mind.Mind!.AllRoles.First(role => role is SuspicionRole);
}
public void AddAlly(SuspicionRoleComponent ally)
{
if (ally == this)
{
return;
}
_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);
}
return true;
}
return false;
}
public void SetAllies(IEnumerable<SuspicionRoleComponent> allies)
{
_allies.Clear();
foreach (var ally in allies)
{
if (ally == this)
{
continue;
}
_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);
}
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);
}
void IExamine.Examine(FormattedMessage message, bool inDetailsRange)
{
if (!IsDead())
{
return;
}
var traitor = IsTraitor();
var color = traitor ? "red" : "green";
var role = traitor ? "traitor" : "innocent";
var article = traitor ? "a" : "an";
var tooltip = Loc.GetString("They were {0} [color={1}]{2}[/color]!", Loc.GetString(article), color,
Loc.GetString(role));
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);
}
public override void HandleMessage(ComponentMessage message, IComponent? component)
{
base.HandleMessage(message, component);
if (!(message is RoleMessage msg) ||
!(msg.Role is SuspicionRole role))
{
return;
}
switch (message)
{
case PlayerAttachedMsg _:
case PlayerDetachedMsg _:
SyncRoles();
break;
case RoleAddedMessage _:
Role = role;
break;
case RoleRemovedMessage _:
Role = null;
break;
}
}
}
}