Files

47 lines
1.5 KiB
C#
Raw Permalink Normal View History

2022-06-04 19:17:48 +12:00
using Content.Server.Body.Components;
using Content.Server.Ghost.Components;
using Content.Shared.Body.Events;
using Content.Shared.Mind;
using Content.Shared.Mind.Components;
2025-08-06 15:01:20 -04:00
using Content.Shared.Mobs.Components;
using Content.Shared.Pointing;
2025-08-06 15:01:20 -04:00
namespace Content.Server.Body.Systems;
public sealed class BrainSystem : EntitySystem
{
2025-08-06 15:01:20 -04:00
[Dependency] private readonly SharedMindSystem _mindSystem = default!;
2025-08-06 15:01:20 -04:00
public override void Initialize()
{
base.Initialize();
2025-08-06 15:01:20 -04:00
SubscribeLocalEvent<BrainComponent, OrganAddedToBodyEvent>((uid, _, args) => HandleMind(args.Body, uid));
SubscribeLocalEvent<BrainComponent, OrganRemovedFromBodyEvent>((uid, _, args) => HandleMind(uid, args.OldBody));
SubscribeLocalEvent<BrainComponent, PointAttemptEvent>(OnPointAttempt);
}
2025-08-06 15:01:20 -04:00
private void HandleMind(EntityUid newEntity, EntityUid oldEntity)
{
if (TerminatingOrDeleted(newEntity) || TerminatingOrDeleted(oldEntity))
return;
2023-10-09 00:49:20 -04:00
2025-08-06 15:01:20 -04:00
EnsureComp<MindContainerComponent>(newEntity);
EnsureComp<MindContainerComponent>(oldEntity);
2025-08-06 15:01:20 -04:00
var ghostOnMove = EnsureComp<GhostOnMoveComponent>(newEntity);
ghostOnMove.MustBeDead = HasComp<MobStateComponent>(newEntity); // Don't ghost living players out of their bodies.
2025-08-06 15:01:20 -04:00
if (!_mindSystem.TryGetMind(oldEntity, out var mindId, out var mind))
return;
2023-06-18 11:33:19 -07:00
2025-08-06 15:01:20 -04:00
_mindSystem.TransferTo(mindId, newEntity, mind: mind);
}
2025-08-06 15:01:20 -04:00
private void OnPointAttempt(Entity<BrainComponent> ent, ref PointAttemptEvent args)
{
args.Cancel();
}
}
2025-08-06 15:01:20 -04:00