Files
space-station-14/Content.Server/Body/Systems/BodySystem.cs
pathetic meowmeow fb133494cc Decouple gibbing from the body system (#42405)
* Decouple gibbing from the body system

* allow gibs that don't drop giblets

* pass through user

* prediction gon

* comment

* destructible

* playpvs

* very very very very very very very minor cleanup

---------

Co-authored-by: Princess Cheeseballs <66055347+Pronana@users.noreply.github.com>
2026-01-14 05:57:08 +00:00

96 lines
3.1 KiB
C#

using System.Numerics;
using Content.Server.Ghost;
using Content.Server.Humanoid;
using Content.Shared.Body.Components;
using Content.Shared.Body.Events;
using Content.Shared.Body.Part;
using Content.Shared.Body.Systems;
using Content.Shared.Damage.Components;
using Content.Shared.Humanoid;
using Content.Shared.Mind;
using Content.Shared.Mobs.Systems;
using Content.Shared.Movement.Events;
using Content.Shared.Movement.Systems;
using Robust.Shared.Audio;
using Robust.Shared.Timing;
namespace Content.Server.Body.Systems;
public sealed class BodySystem : SharedBodySystem
{
[Dependency] private readonly GhostSystem _ghostSystem = default!;
[Dependency] private readonly IGameTiming _gameTiming = default!;
[Dependency] private readonly HumanoidAppearanceSystem _humanoidSystem = default!;
[Dependency] private readonly MobStateSystem _mobState = default!;
[Dependency] private readonly SharedMindSystem _mindSystem = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<BodyComponent, MoveInputEvent>(OnRelayMoveInput);
SubscribeLocalEvent<BodyComponent, ApplyMetabolicMultiplierEvent>(OnApplyMetabolicMultiplier);
}
private void OnRelayMoveInput(Entity<BodyComponent> ent, ref MoveInputEvent args)
{
// If they haven't actually moved then ignore it.
if ((args.Entity.Comp.HeldMoveButtons &
(MoveButtons.Down | MoveButtons.Left | MoveButtons.Up | MoveButtons.Right)) == 0x0)
{
return;
}
if (_mobState.IsDead(ent) && _mindSystem.TryGetMind(ent, out var mindId, out var mind))
{
mind.TimeOfDeath ??= _gameTiming.RealTime;
_ghostSystem.OnGhostAttempt(mindId, canReturnGlobal: true, mind: mind);
}
}
private void OnApplyMetabolicMultiplier(
Entity<BodyComponent> ent,
ref ApplyMetabolicMultiplierEvent args)
{
foreach (var organ in GetBodyOrgans(ent, ent))
{
RaiseLocalEvent(organ.Id, ref args);
}
}
protected override void AddPart(
Entity<BodyComponent?> bodyEnt,
Entity<BodyPartComponent> partEnt,
string slotId)
{
// TODO: Predict this probably.
base.AddPart(bodyEnt, partEnt, slotId);
var layer = partEnt.Comp.ToHumanoidLayers();
if (layer != null)
{
var layers = HumanoidVisualLayersExtension.Sublayers(layer.Value);
_humanoidSystem.SetLayersVisibility(bodyEnt.Owner, layers, visible: true);
}
}
protected override void RemovePart(
Entity<BodyComponent?> bodyEnt,
Entity<BodyPartComponent> partEnt,
string slotId)
{
base.RemovePart(bodyEnt, partEnt, slotId);
if (!TryComp<HumanoidAppearanceComponent>(bodyEnt, out var humanoid))
return;
var layer = partEnt.Comp.ToHumanoidLayers();
if (layer is null)
return;
var layers = HumanoidVisualLayersExtension.Sublayers(layer.Value);
_humanoidSystem.SetLayersVisibility((bodyEnt, humanoid), layers, visible: false);
}
}