Files
tbd-station-14/Content.Server/Mind/TransferMindOnGibSystem.cs
slarticodefast 38232d2255 Predict healing and bloodstream (#38690)
* initial commit

* reapply 38126

* fix rootable

* someone missed an important minus sign here

* try this

* fix

* fix

* reenable crit hits

* cleanup

* fix status time dirtying

* fix

* camelCase
2025-07-02 19:20:31 -04:00

40 lines
1.2 KiB
C#

using System.Linq;
using Content.Shared.Body.Events;
using Content.Shared.Mind;
using Content.Shared.Mind.Components;
using Content.Shared.Tag;
using Robust.Shared.Random;
namespace Content.Server.Mind;
/// <summary>
/// This handles transfering a target's mind
/// to a different entity when they gib.
/// used for skeletons.
/// </summary>
public sealed class TransferMindOnGibSystem : EntitySystem
{
[Dependency] private readonly IRobustRandom _random = default!;
[Dependency] private readonly TagSystem _tag = default!;
[Dependency] private readonly SharedMindSystem _mindSystem = default!;
/// <inheritdoc/>
public override void Initialize()
{
SubscribeLocalEvent<TransferMindOnGibComponent, BeingGibbedEvent>(OnGib);
}
private void OnGib(EntityUid uid, TransferMindOnGibComponent component, BeingGibbedEvent args)
{
if (!_mindSystem.TryGetMind(uid, out var mindId, out var mind))
return;
var validParts = args.GibbedParts.Where(p => _tag.HasTag(p, component.TargetTag)).ToHashSet();
if (!validParts.Any())
return;
var ent = _random.Pick(validParts);
_mindSystem.TransferTo(mindId, ent, mind: mind);
}
}