mirror of
https://github.com/WWhiteDreamProject/wwdpublic.git
synced 2026-04-17 21:48:58 +03:00
# Description Adds a number of new ways to juggle minds. The pAI adapter, craftable by hand, allows a pAI to act as a positronic brain. The machine-man interface allows positronic brains (or adaptered pAIs) to act as biological brains. It is a tier 2 research and exclusive to the exosuit fabricator. Additionally finagles some components so that biological brains in MMIa can be used to control IPCs. --- <details><summary><h1>Media</h1></summary> <p>      </p> </details> --- # Changelog 🆑 - add: Added machine-man interface - add: Added pAI adapter - tweak: Allowed MMIs to function as IPC brains (cherry picked from commit 2cae5a63824c1b260091f3f27b8df7d20d9bb100)
110 lines
3.8 KiB
C#
110 lines
3.8 KiB
C#
using Content.Server.Body.Components;
|
|
using Content.Server.Ghost.Components;
|
|
using Content.Shared.Body.Components;
|
|
using Content.Shared.Body.Events;
|
|
using Content.Shared.Mind;
|
|
using Content.Shared.Mind.Components;
|
|
using Content.Shared.Pointing;
|
|
|
|
// Shitmed Change
|
|
using Content.Shared._Shitmed.Body.Organ;
|
|
using Content.Shared.Body.Systems;
|
|
using Content.Shared.Silicons.Borgs.Components;
|
|
|
|
namespace Content.Server.Body.Systems
|
|
{
|
|
public sealed class BrainSystem : EntitySystem
|
|
{
|
|
[Dependency] private readonly SharedMindSystem _mindSystem = default!;
|
|
[Dependency] private readonly SharedBodySystem _bodySystem = default!; // Shitmed Change
|
|
public override void Initialize()
|
|
{
|
|
base.Initialize();
|
|
|
|
SubscribeLocalEvent<BrainComponent, OrganAddedToBodyEvent>(HandleAddition);
|
|
// Shitmed Change Start
|
|
SubscribeLocalEvent<BrainComponent, OrganRemovedFromBodyEvent>(HandleRemoval);
|
|
SubscribeLocalEvent<BrainComponent, PointAttemptEvent>(OnPointAttempt);
|
|
}
|
|
|
|
private void HandleRemoval(EntityUid uid, BrainComponent brain, ref OrganRemovedFromBodyEvent args)
|
|
{
|
|
if (TerminatingOrDeleted(uid) || TerminatingOrDeleted(args.OldBody))
|
|
return;
|
|
|
|
brain.Active = false;
|
|
if (!CheckOtherBrains(args.OldBody))
|
|
{
|
|
// Prevents revival, should kill the user within a given timespan too.
|
|
EnsureComp<DebrainedComponent>(args.OldBody);
|
|
HandleMind(uid, args.OldBody);
|
|
}
|
|
}
|
|
|
|
private void HandleAddition(EntityUid uid, BrainComponent brain, ref OrganAddedToBodyEvent args)
|
|
{
|
|
if (TerminatingOrDeleted(uid) || TerminatingOrDeleted(args.Body))
|
|
return;
|
|
|
|
if (!CheckOtherBrains(args.Body))
|
|
{
|
|
RemComp<DebrainedComponent>(args.Body);
|
|
HandleMind(args.Body, uid, brain);
|
|
}
|
|
}
|
|
|
|
|
|
private void HandleMind(EntityUid newEntity, EntityUid oldEntity, BrainComponent? brain = null)
|
|
{
|
|
if (TerminatingOrDeleted(newEntity) || TerminatingOrDeleted(oldEntity))
|
|
return;
|
|
|
|
EnsureComp<MindContainerComponent>(newEntity);
|
|
EnsureComp<MindContainerComponent>(oldEntity);
|
|
|
|
var ghostOnMove = EnsureComp<GhostOnMoveComponent>(newEntity);
|
|
if (HasComp<BodyComponent>(newEntity))
|
|
ghostOnMove.MustBeDead = true;
|
|
|
|
if (HasComp<BorgBrainComponent>(newEntity))
|
|
EntityManager.RemoveComponent<GhostOnMoveComponent>(newEntity);
|
|
|
|
if (!_mindSystem.TryGetMind(oldEntity, out var mindId, out var mind))
|
|
return;
|
|
|
|
_mindSystem.TransferTo(mindId, newEntity, mind: mind);
|
|
if (brain != null)
|
|
brain.Active = true;
|
|
}
|
|
|
|
private bool CheckOtherBrains(EntityUid entity)
|
|
{
|
|
var hasOtherBrains = false;
|
|
if (TryComp<BodyComponent>(entity, out var body))
|
|
{
|
|
if (TryComp<BrainComponent>(entity, out var bodyBrain))
|
|
hasOtherBrains = true;
|
|
else
|
|
{
|
|
foreach (var (organ, _) in _bodySystem.GetBodyOrgans(entity, body))
|
|
{
|
|
if (TryComp<BrainComponent>(organ, out var brain) && brain.Active)
|
|
{
|
|
hasOtherBrains = true;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
return hasOtherBrains;
|
|
}
|
|
|
|
// Shitmed Change End
|
|
private void OnPointAttempt(Entity<BrainComponent> ent, ref PointAttemptEvent args)
|
|
{
|
|
args.Cancel();
|
|
}
|
|
}
|
|
}
|