diff --git a/Content.IntegrationTests/Tests/Body/LegTest.cs b/Content.IntegrationTests/Tests/Body/LegTest.cs index 514b034c73..ec20602be0 100644 --- a/Content.IntegrationTests/Tests/Body/LegTest.cs +++ b/Content.IntegrationTests/Tests/Body/LegTest.cs @@ -43,7 +43,7 @@ namespace Content.IntegrationTests.Tests.Body foreach (var leg in legs) { - body.RemovePart(leg, false); + body.RemovePart(leg); } }); diff --git a/Content.IntegrationTests/Tests/Body/MechanismBehaviorEventsTest.cs b/Content.IntegrationTests/Tests/Body/MechanismBehaviorEventsTest.cs index c2f42ed4a1..9c28ff7666 100644 --- a/Content.IntegrationTests/Tests/Body/MechanismBehaviorEventsTest.cs +++ b/Content.IntegrationTests/Tests/Body/MechanismBehaviorEventsTest.cs @@ -180,7 +180,7 @@ namespace Content.IntegrationTests.Tests.Body component.ResetAll(); - body.RemovePart(centerPart, true); + body.RemovePart(centerPart); Assert.That(component.NoAdded); Assert.That(component.WasRemovedFromBody); diff --git a/Content.IntegrationTests/Tests/BuckleTest.cs b/Content.IntegrationTests/Tests/BuckleTest.cs index a580b91a9b..c0c4bdda78 100644 --- a/Content.IntegrationTests/Tests/BuckleTest.cs +++ b/Content.IntegrationTests/Tests/BuckleTest.cs @@ -244,7 +244,7 @@ namespace Content.IntegrationTests.Tests // Break our guy's kneecaps foreach (var leg in legs) { - body.RemovePart(leg, false); + body.RemovePart(leg); } }); diff --git a/Content.Server/GameObjects/Components/Body/BodyCommands.cs b/Content.Server/GameObjects/Components/Body/BodyCommands.cs index d8743f70b9..867ad77f9f 100644 --- a/Content.Server/GameObjects/Components/Body/BodyCommands.cs +++ b/Content.Server/GameObjects/Components/Body/BodyCommands.cs @@ -185,7 +185,7 @@ namespace Content.Server.GameObjects.Components.Body } else { - body.RemovePart(hand.Value, true); + body.RemovePart(hand.Value); } } } diff --git a/Content.Shared/GameObjects/Components/Body/IBody.cs b/Content.Shared/GameObjects/Components/Body/IBody.cs index 1d256f97e6..99f40dcd4e 100644 --- a/Content.Shared/GameObjects/Components/Body/IBody.cs +++ b/Content.Shared/GameObjects/Components/Body/IBody.cs @@ -61,18 +61,15 @@ namespace Content.Shared.GameObjects.Components.Body /// dropping other BodyParts if they /// were hanging off of it. /// - void RemovePart(IBodyPart part, bool drop); + void RemovePart(IBodyPart part); /// /// Removes the body part in slot from this body, /// if one exists. /// /// The slot to remove it from. - /// - /// Whether or not to drop the removed . - /// /// True if the part was removed, false otherwise. - bool RemovePart(string slot, bool drop); + bool RemovePart(string slot); /// /// Removes the body part from this body, if one exists. diff --git a/Content.Shared/GameObjects/Components/Body/Part/IBodyPart.cs b/Content.Shared/GameObjects/Components/Body/Part/IBodyPart.cs index 05a6d7f932..9940a8a0b6 100644 --- a/Content.Shared/GameObjects/Components/Body/Part/IBodyPart.cs +++ b/Content.Shared/GameObjects/Components/Body/Part/IBodyPart.cs @@ -9,7 +9,7 @@ namespace Content.Shared.GameObjects.Components.Body.Part { public interface IBodyPart : IComponent, IBodyPartContainer { - new IBody? Body { get; set; } + IBody? Body { get; set; } /// /// that this is considered @@ -46,8 +46,6 @@ namespace Content.Shared.GameObjects.Components.Body.Part public BodyPartSymmetry Symmetry { get; } - bool Drop(); - /// /// Checks if the given can be used on /// the current state of this . diff --git a/Content.Shared/GameObjects/Components/Body/Part/SharedBodyPartComponent.cs b/Content.Shared/GameObjects/Components/Body/Part/SharedBodyPartComponent.cs index 6a944780dd..f86ff22c3b 100644 --- a/Content.Shared/GameObjects/Components/Body/Part/SharedBodyPartComponent.cs +++ b/Content.Shared/GameObjects/Components/Body/Part/SharedBodyPartComponent.cs @@ -45,18 +45,12 @@ namespace Content.Shared.GameObjects.Components.Body.Part if (old != null) { - foreach (var mechanism in _mechanisms) - { - mechanism.RemovedFromBody(old); - } + RemovedFromBody(old); } if (value != null) { - foreach (var mechanism in _mechanisms) - { - mechanism.AddedToBody(); - } + AddedToBody(); } } } @@ -189,13 +183,6 @@ namespace Content.Shared.GameObjects.Components.Body.Part } } - public bool Drop() - { - Body = null; - Owner.Transform.AttachToGridOrMap(); - return true; - } - public bool SurgeryCheck(SurgeryType surgery) { return SurgeryDataComponent?.CheckSurgery(surgery) ?? false; @@ -301,6 +288,36 @@ namespace Content.Shared.GameObjects.Components.Body.Part mechanism.Owner.Delete(); return true; } + + private void AddedToBody() + { + Owner.Transform.AttachParent(Body!.Owner); + OnAddedToBody(); + + foreach (var mechanism in _mechanisms) + { + mechanism.AddedToBody(); + } + } + + private void RemovedFromBody(IBody old) + { + if (!Owner.Transform.Deleted) + { + Owner.Transform.AttachToGridOrMap(); + } + + OnRemovedFromBody(old); + + foreach (var mechanism in _mechanisms) + { + mechanism.RemovedFromBody(old); + } + } + + protected virtual void OnAddedToBody() { } + + protected virtual void OnRemovedFromBody(IBody old) { } } [Serializable, NetSerializable] diff --git a/Content.Shared/GameObjects/Components/Body/SharedBodyComponent.cs b/Content.Shared/GameObjects/Components/Body/SharedBodyComponent.cs index 59a20226d3..544d914c78 100644 --- a/Content.Shared/GameObjects/Components/Body/SharedBodyComponent.cs +++ b/Content.Shared/GameObjects/Components/Body/SharedBodyComponent.cs @@ -68,7 +68,6 @@ namespace Content.Shared.GameObjects.Components.Body protected virtual void OnAddPart(string slot, IBodyPart part) { - part.Owner.Transform.AttachParent(Owner); part.Body = this; var argsAdded = new BodyPartAddedEventArgs(part, slot); @@ -84,12 +83,6 @@ namespace Content.Shared.GameObjects.Components.Body protected virtual void OnRemovePart(string slot, IBodyPart part) { - // TODO BODY Move to Body part - if (!part.Owner.Transform.Deleted) - { - part.Owner.Transform.AttachToGridOrMap(); - } - part.Body = null; var args = new BodyPartRemovedEventArgs(part, slot); @@ -152,7 +145,7 @@ namespace Content.Shared.GameObjects.Components.Body return _parts.ContainsKey(slot); } - public void RemovePart(IBodyPart part, bool drop) + public void RemovePart(IBodyPart part) { DebugTools.AssertNotNull(part); @@ -163,11 +156,11 @@ namespace Content.Shared.GameObjects.Components.Body return; } - RemovePart(slotName, drop); + RemovePart(slotName); } // TODO BODY invert this behavior with the one above - public bool RemovePart(string slot, bool drop) + public bool RemovePart(string slot) { DebugTools.AssertNotNull(slot); @@ -176,11 +169,6 @@ namespace Content.Shared.GameObjects.Components.Body return false; } - if (drop) - { - part.Drop(); - } - OnRemovePart(slot, part); if (TryGetSlotConnections(slot, out var connections)) @@ -189,7 +177,7 @@ namespace Content.Shared.GameObjects.Components.Body { if (TryGetPart(connectionName, out var result) && !ConnectedToCenter(result)) { - RemovePart(connectionName, drop); + RemovePart(connectionName); } } } @@ -209,7 +197,7 @@ namespace Content.Shared.GameObjects.Components.Body return false; } - if (RemovePart(pair.Key, false)) + if (RemovePart(pair.Key)) { slotName = pair.Key; return true; @@ -235,8 +223,6 @@ namespace Content.Shared.GameObjects.Components.Body return false; } - part.Drop(); - dropped = new List {part}; // Call disconnect on all limbs that were hanging off this limb. if (TryGetSlotConnections(slotName, out var connections)) @@ -246,7 +232,7 @@ namespace Content.Shared.GameObjects.Components.Body { if (TryGetPart(connectionName, out var result) && !ConnectedToCenter(result) && - RemovePart(connectionName, true)) + RemovePart(connectionName)) { dropped.Add(result); } @@ -694,7 +680,7 @@ namespace Content.Shared.GameObjects.Components.Body if (!newParts.TryGetValue(slot, out var newPart) || newPart != oldPart) { - RemovePart(oldPart, false); + RemovePart(oldPart); } } diff --git a/Content.Shared/GameObjects/Components/Body/Surgery/BiologicalSurgeryDataComponent.cs b/Content.Shared/GameObjects/Components/Body/Surgery/BiologicalSurgeryDataComponent.cs index c2799fca6c..a5e7bbdfda 100644 --- a/Content.Shared/GameObjects/Components/Body/Surgery/BiologicalSurgeryDataComponent.cs +++ b/Content.Shared/GameObjects/Components/Body/Surgery/BiologicalSurgeryDataComponent.cs @@ -260,7 +260,7 @@ namespace Content.Shared.GameObjects.Components.Body.Surgery performer.PopupMessage(Loc.GetString("Saw off the limb!")); // TODO BODY do_after: Delay - body.RemovePart(Parent, true); + body.RemovePart(Parent); } } }