Skip to content

Commit

Permalink
MindSlave (SerbiaStrong-220#983)
Browse files Browse the repository at this point in the history
* basic implementation of mindslave

* mindslave implementation 2 (broken)

* mindslave implementation 3 (fixed)

* mindslave implementation 4

* Fix NT issue

* Added notification eui and minor fixes
  • Loading branch information
DexlerXD authored May 10, 2024
1 parent a9c8479 commit c6f3229
Show file tree
Hide file tree
Showing 35 changed files with 888 additions and 1 deletion.
3 changes: 3 additions & 0 deletions Content.Client/Antag/AntagStatusIconSystem.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Content.Shared.Antag;
using Content.Shared.Revolutionary.Components;
using Content.Shared.SS220.AdmemeEvents;
using Content.Shared.SS220.MindSlave;
using Content.Shared.StatusIcon;
using Content.Shared.StatusIcon.Components;
using Content.Shared.Zombies;
Expand All @@ -25,6 +26,8 @@ public override void Initialize()
SubscribeLocalEvent<HeadRevolutionaryComponent, GetStatusIconsEvent>(GetIcon);
SubscribeLocalEvent<InitialInfectedComponent, GetStatusIconsEvent>(GetIcon);
SubscribeLocalEvent<EventRoleComponent, GetStatusIconsEvent>(GetIcon); //SS220-admeme-ebents
SubscribeLocalEvent<MindSlaveComponent, GetStatusIconsEvent>(GetIcon); //SS220-mindslave
SubscribeLocalEvent<MindSlaveMasterComponent, GetStatusIconsEvent>(GetIcon); //SS220-mindslave
}

/// <summary>
Expand Down
34 changes: 34 additions & 0 deletions Content.Client/SS220/MindSlave/MindSlaveSystem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// © SS220, An EULA/CLA with a hosting restriction, full text: https://raw.githubusercontent.com/SerbiaStrong-220/space-station-14/master/CLA.txt

using Content.Shared.SS220.MindSlave;
using Content.Shared.StatusIcon.Components;

namespace Content.Client.SS220.MindSlave;

public sealed class MindSlaveSystem : EntitySystem
{
public override void Initialize()
{
base.Initialize();

SubscribeLocalEvent<MindSlaveComponent, CanDisplayStatusIconsEvent>(OnSlaveGetIcons);
SubscribeLocalEvent<MindSlaveMasterComponent, CanDisplayStatusIconsEvent>(OnMasterGetIcons);
}

private void OnSlaveGetIcons(Entity<MindSlaveComponent> entity, ref CanDisplayStatusIconsEvent args)
{
if (TryComp<MindSlaveMasterComponent>(args.User, out var masterComp) && masterComp.EnslavedEntities.Contains(entity))
return;

args.Cancelled = true;
}

private void OnMasterGetIcons(Entity<MindSlaveMasterComponent> entity, ref CanDisplayStatusIconsEvent args)
{
if (HasComp<MindSlaveComponent>(args.User) && entity.Comp.EnslavedEntities.Contains(args.User.Value))
return;

args.Cancelled = true;
}
}

48 changes: 48 additions & 0 deletions Content.Client/SS220/MindSlave/UI/MindSlaveNotificationEui.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// © SS220, An EULA/CLA with a hosting restriction, full text: https://raw.githubusercontent.com/SerbiaStrong-220/space-station-14/master/CLA.txt

using Content.Client.Eui;
using Content.Shared.Eui;
using Content.Shared.SS220.MindSlave;
using JetBrains.Annotations;
using Robust.Client.Graphics;

namespace Content.Client.SS220.MindSlave.UI;

//Stolen from DeathReminder
[UsedImplicitly]
public sealed class MindSlaveNotificationEui : BaseEui
{
private readonly MindSlaveNotificationWindow _window;

public MindSlaveNotificationEui()
{
_window = new MindSlaveNotificationWindow();

_window.AcceptButton.OnPressed += _ =>
{
_window.Close();
};
}

public override void HandleState(EuiStateBase state)
{
if (state is not MindSlaveNotificationEuiState newState)
return;

_window.TextLabel.Text = newState.IsEnslaved ?
Loc.GetString("mindslave-notification-window-text-enslaved", ("name", newState.MasterName)) :
Loc.GetString("mindslave-notification-window-text-freed");
}

public override void Opened()
{
IoCManager.Resolve<IClyde>().RequestWindowAttention();
_window.OpenCentered();
}

public override void Closed()
{
_window.Close();
}
}

54 changes: 54 additions & 0 deletions Content.Client/SS220/MindSlave/UI/MindSlaveNotificationWindow.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// © SS220, An EULA/CLA with a hosting restriction, full text: https://raw.githubusercontent.com/SerbiaStrong-220/space-station-14/master/CLA.txt

using Robust.Client.UserInterface;
using Robust.Client.UserInterface.Controls;
using Robust.Client.UserInterface.CustomControls;
using System.Numerics;

namespace Content.Client.SS220.MindSlave.UI;

//Stolen from DeathReminder
public sealed class MindSlaveNotificationWindow : DefaultWindow
{
public readonly Button AcceptButton;
public readonly Label TextLabel;

public MindSlaveNotificationWindow()
{
Title = Loc.GetString("mindslave-notification-window-title");

Contents.AddChild(new BoxContainer
{
Orientation = BoxContainer.LayoutOrientation.Vertical,
Children =
{
new BoxContainer
{
Orientation = BoxContainer.LayoutOrientation.Vertical,
Children =
{
(TextLabel = new Label()
{
}),
new BoxContainer
{
Orientation = BoxContainer.LayoutOrientation.Horizontal,
Align = BoxContainer.AlignMode.Center,
Children =
{
(AcceptButton = new Button
{
Text = Loc.GetString("mindslave-notification-window-accept"),
}),
(new Control()
{
MinSize = new Vector2(20, 0)
}),
}
},
}
},
}
});
}
}
29 changes: 29 additions & 0 deletions Content.Server/GameTicking/Rules/TraitorRuleSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
using System.Linq;
using System.Text;
using Content.Server.GameTicking.Components;
using Content.Server.SS220.MindSlave;

namespace Content.Server.GameTicking.Rules;

Expand All @@ -30,6 +31,7 @@ public sealed class TraitorRuleSystem : GameRuleSystem<TraitorRuleComponent>
[Dependency] private readonly SharedRoleSystem _roleSystem = default!;
[Dependency] private readonly SharedJobSystem _jobs = default!;
[Dependency] private readonly ObjectivesSystem _objectives = default!;
[Dependency] private readonly MindSlaveSystem _mindSlave = default!;

public const int MaxPicks = 20;

Expand Down Expand Up @@ -67,6 +69,24 @@ private void MakeCodewords(TraitorRuleComponent component)
}
}

//SS220-mindslave begin
public void AddToTraitorList(EntityUid mind, EntityUid gameRuleEntity, TraitorRuleComponent? component = null)
{
if (!Resolve(gameRuleEntity, ref component))
return;

component.TraitorMinds.Add(mind);
}

public void RemoveFromTraitorList(EntityUid mind, EntityUid gameRuleEntity, TraitorRuleComponent? component = null)
{
if (!Resolve(gameRuleEntity, ref component))
return;

component.TraitorMinds.Remove(mind);
}
//SS220-mindslave end

public bool MakeTraitor(EntityUid traitor, TraitorRuleComponent component, bool giveUplink = true, bool giveObjectives = true)
{
//Grab the mind if it wasnt provided
Expand Down Expand Up @@ -134,6 +154,15 @@ public bool MakeTraitor(EntityUid traitor, TraitorRuleComponent component, bool
private void OnObjectivesTextGetInfo(EntityUid uid, TraitorRuleComponent comp, ref ObjectivesTextGetInfoEvent args)
{
args.Minds = _antag.GetAntagMindEntityUids(uid);

//SS220-mindslave begin
if (_mindSlave.EnslavedMinds.Count > 0)
{
foreach (var slave in _mindSlave.EnslavedMinds)
args.Minds.Add(slave.Key);
}
//SS220-mindslave end

args.AgentName = Loc.GetString("traitor-round-end-agent-name");
}

Expand Down
32 changes: 32 additions & 0 deletions Content.Server/Implants/ImplanterSystem.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
using System.Linq;
using Content.Server.Popups;
using Content.Server.SS220.MindSlave;
using Content.Shared.DoAfter;
using Content.Shared.IdentityManagement;
using Content.Shared.Implants;
using Content.Shared.Implants.Components;
using Content.Shared.Interaction;
using Content.Shared.Mindshield.Components;
using Content.Shared.Popups;
using Robust.Shared.Containers;
using Robust.Shared.Prototypes;

namespace Content.Server.Implants;

Expand All @@ -15,6 +18,12 @@ public sealed partial class ImplanterSystem : SharedImplanterSystem
[Dependency] private readonly PopupSystem _popup = default!;
[Dependency] private readonly SharedDoAfterSystem _doAfter = default!;
[Dependency] private readonly SharedContainerSystem _container = default!;
[Dependency] private readonly MindSlaveSystem _mindslave = default!;

//SS220-mindslave begin
[ValidatePrototypeId<EntityPrototype>]
private const string MindSlaveImplantProto = "MindSlaveImplant";
//SS220-mindslave end

public override void Initialize()
{
Expand All @@ -36,6 +45,29 @@ private void OnImplanterAfterInteract(EntityUid uid, ImplanterComponent componen
if (!CheckTarget(target, component.Whitelist, component.Blacklist))
return;

//SS220-mindslave begin
if (component.Implant == MindSlaveImplantProto)
{
if (args.User == target)
{
_popup.PopupEntity(Loc.GetString("mindslave-enslaving-yourself-attempt"), target, args.User);
return;
}

if (_mindslave.IsEnslaved(target))
{
_popup.PopupEntity(Loc.GetString("mindslave-target-already-enslaved"), target, args.User);
return;
}

if (HasComp<MindShieldComponent>(target))
{
_popup.PopupEntity(Loc.GetString("mindslave-target-mindshielded"), target, args.User);
return;
}
}
//SS220-mindslave end

//TODO: Rework when surgery is in for implant cases
if (component.CurrentMode == ImplanterToggleMode.Draw && !component.ImplantOnly)
{
Expand Down
16 changes: 16 additions & 0 deletions Content.Server/Mindshield/MindShieldSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Content.Server.Mind;
using Content.Server.Popups;
using Content.Server.Roles;
using Content.Server.SS220.MindSlave;
using Content.Shared.Database;
using Content.Shared.Implants;
using Content.Shared.Implants.Components;
Expand All @@ -21,10 +22,17 @@ public sealed class MindShieldSystem : EntitySystem
[Dependency] private readonly MindSystem _mindSystem = default!;
[Dependency] private readonly TagSystem _tag = default!;
[Dependency] private readonly PopupSystem _popupSystem = default!;
[Dependency] private readonly MindSlaveSystem _mindSlave = default!;
[Dependency] private readonly SharedSubdermalImplantSystem _sharedSubdermalImplant = default!;

[ValidatePrototypeId<TagPrototype>]
public const string MindShieldTag = "MindShield";

//SS220-mindslave begin
[ValidatePrototypeId<TagPrototype>]
public const string MindSlaveTag = "MindSlave";
//SS220-mindslave end

public override void Initialize()
{
base.Initialize();
Expand All @@ -41,6 +49,14 @@ public void ImplantCheck(EntityUid uid, SubdermalImplantComponent comp, ref Impl
EnsureComp<MindShieldComponent>(ev.Implanted.Value);
MindShieldRemovalCheck(ev.Implanted.Value, ev.Implant);
}

//SS220-mindslave begin
if (_tag.HasTag(ev.Implant, MindSlaveTag) && ev.Implanted != null && comp.user != null)
{
if (!_mindSlave.TryMakeSlave(ev.Implanted.Value, comp.user.Value))
_sharedSubdermalImplant.ForceRemove(ev.Implanted.Value, ev.Implant);
}
//SS220-mindslave end
}

/// <summary>
Expand Down
13 changes: 13 additions & 0 deletions Content.Server/Objectives/Systems/TargetObjectiveSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,19 @@ private void OnAfterAssign(EntityUid uid, TargetObjectiveComponent comp, ref Obj
_metaData.SetEntityName(uid, GetTitle(target.Value, comp.Title), args.Meta);
}

//SS220-mindslave begin
public void ResetEntityName(EntityUid uid, TargetObjectiveComponent? comp = null)
{
if (!Resolve(uid, ref comp))
return;

if (!GetTarget(uid, out var target, comp))
return;

_metaData.SetEntityName(uid, GetTitle(target.Value, comp.Title), MetaData(uid));
}
//SS220-mindslave end

/// <summary>
/// Sets the Target field for the title and other components to use.
/// </summary>
Expand Down
3 changes: 3 additions & 0 deletions Content.Server/Roles/RoleSystem.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Content.Shared.Roles;
using Content.Shared.SS220.MindSlave;

namespace Content.Server.Roles;

Expand All @@ -18,6 +19,8 @@ public override void Initialize()
SubscribeAntagEvents<TraitorRoleComponent>();
SubscribeAntagEvents<ZombieRoleComponent>();
SubscribeAntagEvents<ThiefRoleComponent>();
//SS220-mindslave
SubscribeAntagEvents<MindSlaveRoleComponent>();
}

public string? MindGetBriefing(EntityUid? mindId)
Expand Down
Loading

0 comments on commit c6f3229

Please sign in to comment.