2022-06-04 19:17:48 +12:00
|
|
|
using Content.Server.Body.Components;
|
2021-11-12 23:47:50 -07:00
|
|
|
using Content.Server.Ghost.Components;
|
2022-01-04 02:17:39 -07:00
|
|
|
using Content.Shared.Body.Components;
|
2021-11-12 23:47:50 -07:00
|
|
|
using Content.Shared.Body.Events;
|
2023-08-30 21:46:11 -07:00
|
|
|
using Content.Shared.Mind;
|
|
|
|
|
using Content.Shared.Mind.Components;
|
2024-02-03 03:09:20 -05:00
|
|
|
using Content.Shared.Pointing;
|
2021-11-12 23:47:50 -07:00
|
|
|
|
|
|
|
|
namespace Content.Server.Body.Systems
|
|
|
|
|
{
|
2022-02-16 00:23:23 -07:00
|
|
|
public sealed class BrainSystem : EntitySystem
|
2021-11-12 23:47:50 -07:00
|
|
|
{
|
2023-08-30 21:46:11 -07:00
|
|
|
[Dependency] private readonly SharedMindSystem _mindSystem = default!;
|
2023-04-29 18:35:28 +12:00
|
|
|
|
2021-11-12 23:47:50 -07:00
|
|
|
public override void Initialize()
|
|
|
|
|
{
|
|
|
|
|
base.Initialize();
|
|
|
|
|
|
2024-03-28 01:48:37 +01:00
|
|
|
SubscribeLocalEvent<BrainComponent, OrganAddedToBodyEvent>((uid, _, args) => HandleMind(args.Body, uid));
|
|
|
|
|
SubscribeLocalEvent<BrainComponent, OrganRemovedFromBodyEvent>((uid, _, args) => HandleMind(uid, args.OldBody));
|
2024-02-03 03:09:20 -05:00
|
|
|
SubscribeLocalEvent<BrainComponent, PointAttemptEvent>(OnPointAttempt);
|
2021-11-12 23:47:50 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void HandleMind(EntityUid newEntity, EntityUid oldEntity)
|
|
|
|
|
{
|
2023-10-09 00:49:20 -04:00
|
|
|
if (TerminatingOrDeleted(newEntity) || TerminatingOrDeleted(oldEntity))
|
|
|
|
|
return;
|
|
|
|
|
|
2023-08-12 17:39:58 -04:00
|
|
|
EnsureComp<MindContainerComponent>(newEntity);
|
2023-09-21 00:23:02 -07:00
|
|
|
EnsureComp<MindContainerComponent>(oldEntity);
|
2021-11-12 23:47:50 -07:00
|
|
|
|
2023-08-12 17:39:58 -04:00
|
|
|
var ghostOnMove = EnsureComp<GhostOnMoveComponent>(newEntity);
|
2022-01-04 02:17:39 -07:00
|
|
|
if (HasComp<BodyComponent>(newEntity))
|
2023-08-12 17:39:58 -04:00
|
|
|
ghostOnMove.MustBeDead = true;
|
2021-11-12 23:47:50 -07:00
|
|
|
|
2023-08-28 16:53:24 -07:00
|
|
|
if (!_mindSystem.TryGetMind(oldEntity, out var mindId, out var mind))
|
2023-06-18 11:33:19 -07:00
|
|
|
return;
|
|
|
|
|
|
2023-08-28 16:53:24 -07:00
|
|
|
_mindSystem.TransferTo(mindId, newEntity, mind: mind);
|
2021-11-12 23:47:50 -07:00
|
|
|
}
|
2024-02-03 03:09:20 -05:00
|
|
|
|
2024-03-28 01:48:37 +01:00
|
|
|
private void OnPointAttempt(Entity<BrainComponent> ent, ref PointAttemptEvent args)
|
2024-02-03 03:09:20 -05:00
|
|
|
{
|
|
|
|
|
args.Cancel();
|
|
|
|
|
}
|
2021-11-12 23:47:50 -07:00
|
|
|
}
|
|
|
|
|
}
|