Files
wwdpublic/Content.Shared/_Shitmed/BodyEffects/Subsystems/GenerateChildPartSystem.cs
gluesniffler 2a33691a1c Ports Shitmed Updates From Goob (#1387)
Lots of stuff. Also moved everything I could to the _Shitmed namespace
as I do in Goob. Will make future ports way faster

# Changelog
🆑 Mocho
- add: Added some fun organs and other thingies, check out the Goob PRs
if you want more details.
- fix: Fixed tons of issues with shitmed. Too many for the changelog in
fact.

(cherry picked from commit 3c9db94102cb25b28a83d51ac8d659fa31fe7d12)
2025-01-13 23:01:51 +03:00

68 lines
2.4 KiB
C#

using Content.Shared.Body.Part;
using Content.Shared.Body.Systems;
using Content.Shared._Shitmed.Body.Events;
using Robust.Shared.Map;
using Robust.Shared.Timing;
using Robust.Shared.Network;
using System.Numerics;
namespace Content.Shared._Shitmed.BodyEffects.Subsystems;
public sealed class GenerateChildPartSystem : EntitySystem
{
[Dependency] private readonly SharedBodySystem _bodySystem = default!;
[Dependency] private readonly IGameTiming _timing = default!;
[Dependency] private readonly INetManager _net = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<GenerateChildPartComponent, BodyPartComponentsModifyEvent>(OnPartComponentsModify);
}
private void OnPartComponentsModify(EntityUid uid, GenerateChildPartComponent component, ref BodyPartComponentsModifyEvent args)
{
if (args.Add)
CreatePart(uid, component);
//else
//DeletePart(uid, component);
}
private void CreatePart(EntityUid uid, GenerateChildPartComponent component)
{
if (!TryComp(uid, out BodyPartComponent? partComp)
|| partComp.Body is null
|| component.Active)
return;
// I pinky swear to also move this to the server side properly next update :)
if (_net.IsServer)
{
var childPart = Spawn(component.Id, new EntityCoordinates(partComp.Body.Value, Vector2.Zero));
if (!TryComp(childPart, out BodyPartComponent? childPartComp))
return;
var slotName = _bodySystem.GetSlotFromBodyPart(childPartComp);
_bodySystem.TryCreatePartSlot(uid, slotName, childPartComp.PartType, out var _);
_bodySystem.AttachPart(uid, slotName, childPart, partComp, childPartComp);
component.ChildPart = childPart;
component.Active = true;
Dirty(childPart, childPartComp);
}
}
// Still unusued, gotta figure out what I want to do with this function outside of fuckery with mantis blades.
private void DeletePart(EntityUid uid, GenerateChildPartComponent component)
{
if (!TryComp(uid, out BodyPartComponent? partComp))
return;
_bodySystem.DropSlotContents((uid, partComp));
var ev = new BodyPartDroppedEvent((uid, partComp));
RaiseLocalEvent(uid, ref ev);
QueueDel(uid);
}
}