mirror of
https://github.com/DeltaV-Station/Delta-v.git
synced 2026-09-30 16:17:27 +00:00
62 lines
2.2 KiB
C#
62 lines
2.2 KiB
C#
using Content.Shared._DV.Traits.Assorted;
|
|
using Content.Shared.Body.Components;
|
|
using Content.Shared.Ghost;
|
|
using Content.Shared.Mind;
|
|
using Content.Shared.Mind.Components;
|
|
using Content.Shared.Mobs.Components;
|
|
using Content.Shared.Pointing;
|
|
|
|
namespace Content.Shared.Body.Systems;
|
|
|
|
public sealed class BrainSystem : EntitySystem
|
|
{
|
|
[Dependency] private readonly SharedMindSystem _mindSystem = default!;
|
|
|
|
public override void Initialize()
|
|
{
|
|
base.Initialize();
|
|
|
|
SubscribeLocalEvent<BrainComponent, OrganGotInsertedEvent>((uid, _, args) => HandleMind(args.Target, uid));
|
|
SubscribeLocalEvent<BrainComponent, OrganGotRemovedEvent>((uid, _, args) => HandleMind(uid, args.Target));
|
|
SubscribeLocalEvent<BrainComponent, PointAttemptEvent>(OnPointAttempt);
|
|
SubscribeLocalEvent<BrainComponent, BodyRelayedEvent<MakeBrainUnborgableEvent>>(OnMakeUnborgable); // Delta V - Expanded for Delta V MMI Trait
|
|
}
|
|
|
|
private void HandleMind(EntityUid newEntity, EntityUid oldEntity)
|
|
{
|
|
if (TerminatingOrDeleted(newEntity) || TerminatingOrDeleted(oldEntity))
|
|
return;
|
|
|
|
EnsureComp<MindContainerComponent>(newEntity);
|
|
EnsureComp<MindContainerComponent>(oldEntity);
|
|
|
|
var ghostOnMove = EnsureComp<GhostOnMoveComponent>(newEntity);
|
|
ghostOnMove.MustBeDead = HasComp<MobStateComponent>(newEntity); // Don't ghost living players out of their bodies.
|
|
|
|
if (!_mindSystem.TryGetMind(oldEntity, out var mindId, out var mind))
|
|
return;
|
|
|
|
_mindSystem.TransferTo(mindId, newEntity, mind: mind);
|
|
}
|
|
|
|
private void OnPointAttempt(Entity<BrainComponent> ent, ref PointAttemptEvent args)
|
|
{
|
|
args.Cancel();
|
|
}
|
|
|
|
// Delta V - Begin Unborgable
|
|
private void OnMakeUnborgable(Entity<BrainComponent> ent, ref BodyRelayedEvent<MakeBrainUnborgableEvent> args)
|
|
{
|
|
EnsureComp<MindContainerComponent>(ent);
|
|
EnsureComp<UnborgableComponent>(ent);
|
|
}
|
|
// Delta V - End Unborgable
|
|
}
|
|
|
|
/// <summary>
|
|
/// Delta V - Unborgable Trait Applier
|
|
/// Raised on organ entity, when it is inserted into a body
|
|
/// </summary>
|
|
[ByRefEvent]
|
|
public readonly record struct MakeBrainUnborgableEvent();
|