using Content.Server.Body.Components; using Content.Server.Ghost; using Content.Server.Ghost.Components; using Content.Server.Mind.Components; using Content.Shared.Body.Events; using Content.Shared.Movement.Components; using Robust.Shared.GameObjects; namespace Content.Server.Body.Systems { public class BrainSystem : EntitySystem { public override void Initialize() { base.Initialize(); SubscribeLocalEvent((uid, component, args) => HandleMind(args.Body.OwnerUid, uid)); SubscribeLocalEvent((uid, component, args) => HandleMind(args.Part.OwnerUid, uid)); SubscribeLocalEvent((uid, component, args) => HandleMind(args.Body.OwnerUid, uid)); SubscribeLocalEvent(OnRemovedFromBody); SubscribeLocalEvent((uid, component, args) => HandleMind(uid, args.Old.OwnerUid)); SubscribeLocalEvent((uid, component, args) => HandleMind(args.OldBody.OwnerUid, uid)); } private void OnRemovedFromBody(EntityUid uid, BrainComponent component, RemovedFromBodyEvent args) { // This one needs to be special, okay? if (!EntityManager.TryGetComponent(uid, out MechanismComponent mech)) return; HandleMind(mech.Part!.OwnerUid, args.Old.OwnerUid); } private void HandleMind(EntityUid newEntity, EntityUid oldEntity) { EntityManager.EnsureComponent(newEntity); var oldMind = EntityManager.EnsureComponent(oldEntity); if (!EntityManager.HasComponent(newEntity)) EntityManager.AddComponent(newEntity); // TODO: This is an awful solution. if (!EntityManager.HasComponent(newEntity)) EntityManager.AddComponent(newEntity); oldMind.Mind?.TransferTo(EntityManager.GetEntity(newEntity)); } } }