Skip to content

Commit

Permalink
Port fixes from EE (space-syndicate#875)
Browse files Browse the repository at this point in the history
  • Loading branch information
Roudenn authored and TokenStyle committed Oct 31, 2024
1 parent 1a43876 commit 39b21a0
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 19 deletions.
6 changes: 2 additions & 4 deletions Content.Server/Hands/Systems/HandsSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,8 @@ private void HandleBodyPartEnabled(EntityUid uid, HandsComponent component, ref

private void HandleBodyPartDisabled(EntityUid uid, HandsComponent component, ref BodyPartDisabledEvent args)
{
if(TerminatingOrDeleted(uid))
return;

if (args.Part.Comp is null
if (TerminatingOrDeleted(uid)
|| args.Part.Comp is null
|| args.Part.Comp.PartType != BodyPartType.Hand)
return;

Expand Down
9 changes: 7 additions & 2 deletions Content.Shared/Backmen/Surgery/SharedSurgerySystem.Steps.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
using System.Linq;
using Content.Shared.Backmen.Surgery.Steps;
using Content.Shared.Backmen.Surgery.Tools;
using Content.Shared.Containers.ItemSlots;

namespace Content.Shared.Backmen.Surgery;

Expand Down Expand Up @@ -275,11 +276,14 @@ private void OnCavityStep(Entity<SurgeryStepCavityEffectComponent> ent, ref Surg

private void OnCavityCheck(Entity<SurgeryStepCavityEffectComponent> ent, ref SurgeryStepCompleteCheckEvent args)
{
// Normally this check would simply be partComp.ItemInsertionSlot.HasItem, but as mentioned before,
// For whatever reason it's not instantiating the field on the clientside after the wizmerge.
if (!TryComp(args.Part, out BodyPartComponent? partComp)
|| !TryComp(args.Part, out ItemSlotsComponent? itemComp)
|| ent.Comp.Action == "Insert"
&& !partComp.ItemInsertionSlot.HasItem
&& !itemComp.Slots[partComp.ContainerName].HasItem
|| ent.Comp.Action == "Remove"
&& partComp.ItemInsertionSlot.HasItem)
&& itemComp.Slots[partComp.ContainerName].HasItem)
args.Cancelled = true;
}

Expand All @@ -299,6 +303,7 @@ private void OnAddPartStep(Entity<SurgeryAddPartStepComponent> ent, ref SurgeryS
: removedComp.Part.ToString().ToLower();
_body.TryCreatePartSlot(args.Part, slotName, partComp.PartType, out var _);
_body.AttachPart(args.Part, slotName, tool);
_body.ChangeSlotState((tool, partComp), false);
}
}
}
Expand Down
40 changes: 27 additions & 13 deletions Content.Shared/Body/Systems/SharedBodySystem.Parts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public partial class SharedBodySystem
[Dependency] private readonly SharedHandsSystem _handsSystem = default!;
[Dependency] private readonly RandomHelperSystem _randomHelper = default!;
[Dependency] private readonly InventorySystem _inventorySystem = default!;

private void InitializeParts()
{
// TODO: This doesn't handle comp removal on child ents.
Expand Down Expand Up @@ -169,19 +170,7 @@ protected virtual void RemovePart(

protected virtual void DropPart(Entity<BodyPartComponent> partEnt)
{
// We check for whether or not the arm, leg or head is being dropped, in which case
// If theres just one, that means we'll remove the container slots.
if (partEnt.Comp.Body is not null
&& TryGetPartSlotContainerName(partEnt.Comp.PartType, out var containerNames)
&& GetBodyPartCount(partEnt.Comp.Body.Value, partEnt.Comp.PartType) == 1)
{
foreach (var containerName in containerNames)
{
_inventorySystem.SetSlotStatus(partEnt.Comp.Body.Value, containerName, true);
var ev = new RefreshInventorySlotsEvent(containerName);
RaiseLocalEvent(partEnt.Comp.Body.Value, ev);
}
}
ChangeSlotState(partEnt, true);

// We then detach the part, which will kickstart EntRemovedFromContainer events.
if (TryComp(partEnt, out TransformComponent? transform) && _gameTiming.IsFirstTimePredicted)
Expand All @@ -194,6 +183,31 @@ protected virtual void DropPart(Entity<BodyPartComponent> partEnt)

}


/// <summary>
/// This function handles disabling or enabling equipment slots when an entity is
/// missing all of a given part type, or they get one added to them.
/// It is called right before dropping a part, or right after adding one.
/// </summary>
public void ChangeSlotState(Entity<BodyPartComponent> partEnt, bool disable)
{
if (partEnt.Comp.Body is not null)
Log.Debug($"Attempting to change slot state to {disable} for {partEnt.Comp.PartType}. Number of parts: {GetBodyPartCount(partEnt.Comp.Body.Value, partEnt.Comp.PartType)}");
if (partEnt.Comp.Body is not null
&& GetBodyPartCount(partEnt.Comp.Body.Value, partEnt.Comp.PartType) == 1
&& TryGetPartSlotContainerName(partEnt.Comp.PartType, out var containerNames))
{
Log.Debug($"Found container names {containerNames}, with a number of {containerNames.Count}");
foreach (var containerName in containerNames)
{
Log.Debug($"Setting slot state to {disable} for {containerName}");
_inventorySystem.SetSlotStatus(partEnt.Comp.Body.Value, containerName, disable);
var ev = new RefreshInventorySlotsEvent(containerName);
RaiseLocalEvent(partEnt.Comp.Body.Value, ev);
}
}
}

private void OnAmputateAttempt(Entity<BodyPartComponent> partEnt, ref AmputateAttemptEvent args)
{
DropPart(partEnt);
Expand Down

0 comments on commit 39b21a0

Please sign in to comment.