Files
OldThink/Content.Server/Body/Systems/BrainSystem.cs

57 lines
2.3 KiB
C#
Raw Normal View History

2022-06-04 19:17:48 +12:00
using Content.Server.Body.Components;
using Content.Server.Ghost.Components;
2023-03-26 11:31:13 -07:00
using Content.Server.Mind;
using Content.Server.Mind.Components;
2022-01-04 02:17:39 -07:00
using Content.Shared.Body.Components;
using Content.Shared.Body.Events;
using Content.Shared.Body.Organ;
using Content.Shared.Movement.Components;
namespace Content.Server.Body.Systems
{
public sealed class BrainSystem : EntitySystem
{
2023-03-26 11:31:13 -07:00
[Dependency] private readonly MindSystem _mindSystem = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<BrainComponent, AddedToBodyEvent>((uid, _, args) => HandleMind(args.Body, uid));
SubscribeLocalEvent<BrainComponent, AddedToPartEvent>((uid, _, args) => HandleMind(args.Part, uid));
SubscribeLocalEvent<BrainComponent, AddedToPartInBodyEvent>((uid, _, args) => HandleMind(args.Body, uid));
SubscribeLocalEvent<BrainComponent, RemovedFromBodyEvent>(OnRemovedFromBody);
SubscribeLocalEvent<BrainComponent, RemovedFromPartEvent>((uid, _, args) => HandleMind(uid, args.Old));
SubscribeLocalEvent<BrainComponent, RemovedFromPartInBodyEvent>((uid, _, args) => HandleMind(args.OldBody, uid));
}
private void OnRemovedFromBody(EntityUid uid, BrainComponent component, RemovedFromBodyEvent args)
{
// This one needs to be special, okay?
if (!EntityManager.TryGetComponent(uid, out OrganComponent? organ) ||
organ.ParentSlot is not {Parent: var parent})
return;
HandleMind(parent, args.Old);
}
private void HandleMind(EntityUid newEntity, EntityUid oldEntity)
{
2023-03-26 11:31:13 -07:00
EntityManager.EnsureComponent<MindContainerComponent>(newEntity);
var oldMind = EntityManager.EnsureComponent<MindContainerComponent>(oldEntity);
2022-01-04 02:17:39 -07:00
EnsureComp<GhostOnMoveComponent>(newEntity);
if (HasComp<BodyComponent>(newEntity))
Comp<GhostOnMoveComponent>(newEntity).MustBeDead = true;
// TODO: This is an awful solution.
EnsureComp<InputMoverComponent>(newEntity);
2023-03-26 11:31:13 -07:00
if (!_mindSystem.TryGetMind(oldEntity, out var mind, oldMind))
return;
_mindSystem.TransferTo(mind, newEntity);
}
}
}