diff --git a/Content.Server/Hands/Components/HandsComponent.cs b/Content.Server/Hands/Components/HandsComponent.cs index 8ad2ed31cc..4e06a6b67f 100644 --- a/Content.Server/Hands/Components/HandsComponent.cs +++ b/Content.Server/Hands/Components/HandsComponent.cs @@ -1,42 +1,9 @@ -using Content.Shared.Body.Part; using Content.Shared.Hands.Components; -using Content.Shared.Hands.EntitySystems; -namespace Content.Server.Hands.Components +namespace Content.Server.Hands.Components; + +[RegisterComponent] +[ComponentReference(typeof(SharedHandsComponent))] +public sealed class HandsComponent : SharedHandsComponent { - [RegisterComponent] - [ComponentReference(typeof(SharedHandsComponent))] -#pragma warning disable 618 - public sealed class HandsComponent : SharedHandsComponent, IBodyPartAdded, IBodyPartRemoved -#pragma warning restore 618 - { - [Dependency] private readonly IEntitySystemManager _entitySystemManager = default!; - - void IBodyPartAdded.BodyPartAdded(BodyPartAddedEventArgs args) - { - if (args.Part.PartType != BodyPartType.Hand) - return; - - // If this annoys you, which it should. - // Ping Smugleaf. - var location = args.Part.Symmetry switch - { - BodyPartSymmetry.None => HandLocation.Middle, - BodyPartSymmetry.Left => HandLocation.Left, - BodyPartSymmetry.Right => HandLocation.Right, - _ => throw new ArgumentOutOfRangeException() - }; - - _entitySystemManager.GetEntitySystem().AddHand(Owner, args.Slot, location); - } - - void IBodyPartRemoved.BodyPartRemoved(BodyPartRemovedEventArgs args) - { - if (args.Part.PartType != BodyPartType.Hand) - return; - - _entitySystemManager.GetEntitySystem().RemoveHand(Owner, args.Slot); - } - } } - diff --git a/Content.Server/Hands/Systems/HandsSystem.cs b/Content.Server/Hands/Systems/HandsSystem.cs index 8c11eb4862..afa6192b27 100644 --- a/Content.Server/Hands/Systems/HandsSystem.cs +++ b/Content.Server/Hands/Systems/HandsSystem.cs @@ -1,29 +1,22 @@ - -using System.Linq; -using Content.Server.CombatMode; using Content.Server.Hands.Components; using Content.Server.Popups; using Content.Server.Pulling; using Content.Server.Stack; using Content.Server.Storage.Components; using Content.Server.Storage.EntitySystems; -using Content.Server.Strip; using Content.Server.Stunnable; using Content.Shared.ActionBlocker; +using Content.Shared.Body.Part; using Content.Shared.CombatMode; using Content.Shared.Hands; using Content.Shared.Hands.Components; using Content.Shared.Hands.EntitySystems; -using Content.Shared.IdentityManagement; using Content.Shared.Input; using Content.Shared.Inventory; using Content.Shared.Physics.Pull; -using Content.Shared.Popups; using Content.Shared.Pulling.Components; -using Content.Shared.Stunnable; using Content.Shared.Throwing; using JetBrains.Annotations; -using Robust.Server.GameObjects; using Robust.Server.Player; using Robust.Shared.Containers; using Robust.Shared.GameStates; @@ -42,7 +35,6 @@ namespace Content.Server.Hands.Systems [Dependency] private readonly StackSystem _stackSystem = default!; [Dependency] private readonly HandVirtualItemSystem _virtualItemSystem = default!; [Dependency] private readonly ActionBlockerSystem _actionBlockerSystem = default!; - [Dependency] private readonly StrippableSystem _strippableSystem = default!; [Dependency] private readonly SharedHandVirtualItemSystem _virtualSystem = default!; [Dependency] private readonly PopupSystem _popupSystem = default!; [Dependency] private readonly SharedHandsSystem _handsSystem = default!; @@ -61,6 +53,9 @@ namespace Content.Server.Hands.Systems SubscribeLocalEvent(HandleEntityRemoved); + SubscribeLocalEvent(HandleBodyPartAdded); + SubscribeLocalEvent(HandleBodyPartRemoved); + SubscribeLocalEvent(GetComponentState); CommandBinds.Builder @@ -97,7 +92,6 @@ namespace Content.Server.Hands.Systems args.Handled = true; // no shove/stun. } - #region EntityInsertRemove public override void PickupAnimation(EntityUid item, EntityCoordinates initialPosition, Vector2 finalPosition, EntityUid? exclude) { @@ -117,7 +111,32 @@ namespace Content.Server.Hands.Systems if (!Deleted(args.Entity) && TryComp(args.Entity, out HandVirtualItemComponent? @virtual)) _virtualSystem.Delete(@virtual, uid); } - #endregion + + private void HandleBodyPartAdded(EntityUid uid, HandsComponent component, ref BodyPartAddedEvent args) + { + if (args.Part.PartType != BodyPartType.Hand) + return; + + // If this annoys you, which it should. + // Ping Smugleaf. + var location = args.Part.Symmetry switch + { + BodyPartSymmetry.None => HandLocation.Middle, + BodyPartSymmetry.Left => HandLocation.Left, + BodyPartSymmetry.Right => HandLocation.Right, + _ => throw new ArgumentOutOfRangeException(nameof(args.Part.Symmetry)) + }; + + AddHand(uid, args.Slot, location); + } + + private void HandleBodyPartRemoved(EntityUid uid, HandsComponent component, ref BodyPartRemovedEvent args) + { + if (args.Part.PartType != BodyPartType.Hand) + return; + + RemoveHand(uid, args.Slot); + } #region pulling private void HandlePullStarted(EntityUid uid, HandsComponent component, PullStartedMessage args) diff --git a/Content.Shared/Body/Part/BodyPartEvents.cs b/Content.Shared/Body/Part/BodyPartEvents.cs new file mode 100644 index 0000000000..4dbc543fc8 --- /dev/null +++ b/Content.Shared/Body/Part/BodyPartEvents.cs @@ -0,0 +1,7 @@ +namespace Content.Shared.Body.Part; + +[ByRefEvent] +public readonly record struct BodyPartAddedEvent(string Slot, BodyPartComponent Part); + +[ByRefEvent] +public readonly record struct BodyPartRemovedEvent(string Slot, BodyPartComponent Part); diff --git a/Content.Shared/Body/Part/IBodyPartAdded.cs b/Content.Shared/Body/Part/IBodyPartAdded.cs deleted file mode 100644 index a2219905f9..0000000000 --- a/Content.Shared/Body/Part/IBodyPartAdded.cs +++ /dev/null @@ -1,37 +0,0 @@ -using Content.Shared.Body.Components; - -namespace Content.Shared.Body.Part -{ - /// - /// This interface gives components behavior when a body part - /// is added to their owning entity. - /// - public interface IBodyPartAdded : IComponent - { - /// - /// Called when a is added to the - /// entity owning this component. - /// - /// Information about the part that was added. - void BodyPartAdded(BodyPartAddedEventArgs args); - } - - public sealed class BodyPartAddedEventArgs : EventArgs - { - public BodyPartAddedEventArgs(string slot, BodyPartComponent part) - { - Slot = slot; - Part = part; - } - - /// - /// The slot that was added to. - /// - public string Slot { get; } - - /// - /// The part that was added. - /// - public BodyPartComponent Part { get; } - } -} diff --git a/Content.Shared/Body/Part/IBodyPartRemoved.cs b/Content.Shared/Body/Part/IBodyPartRemoved.cs deleted file mode 100644 index 0a88f35f03..0000000000 --- a/Content.Shared/Body/Part/IBodyPartRemoved.cs +++ /dev/null @@ -1,37 +0,0 @@ -using Content.Shared.Body.Components; - -namespace Content.Shared.Body.Part -{ - /// - /// This interface gives components behavior when a body part - /// is removed from their owning entity. - /// - public interface IBodyPartRemoved - { - /// - /// Called when a is removed from the - /// entity owning this component. - /// - /// Information about the part that was removed. - void BodyPartRemoved(BodyPartRemovedEventArgs args); - } - - public sealed class BodyPartRemovedEventArgs : EventArgs - { - public BodyPartRemovedEventArgs(string slot, BodyPartComponent part) - { - Slot = slot; - Part = part; - } - - /// - /// The slot that was removed from. - /// - public string Slot { get; } - - /// - /// The part that was removed. - /// - public BodyPartComponent Part { get; } - } -} diff --git a/Content.Shared/Body/Systems/SharedBodySystem.Parts.cs b/Content.Shared/Body/Systems/SharedBodySystem.Parts.cs index f92e3c1a5c..2f1a7fec46 100644 --- a/Content.Shared/Body/Systems/SharedBodySystem.Parts.cs +++ b/Content.Shared/Body/Systems/SharedBodySystem.Parts.cs @@ -211,14 +211,11 @@ public partial class SharedBodySystem if (part.Body is { } newBody) { - var argsAdded = new BodyPartAddedEventArgs(slot.Id, part); + var partAddedEvent = new BodyPartAddedEvent(slot.Id, part); + RaiseLocalEvent(newBody, ref partAddedEvent); // TODO: Body refactor. Somebody is doing it // EntitySystem.Get().BodyPartAdded(Owner, argsAdded); - foreach (var component in AllComps(newBody).ToArray()) - { - component.BodyPartAdded(argsAdded); - } foreach (var organ in GetPartOrgans(partId, part)) { @@ -238,7 +235,7 @@ public partial class SharedBodySystem part.ParentSlot is not { } slot) return false; - var oldBody = part.Body; + var oldBodyNullable = part.Body; slot.Child = null; part.ParentSlot = null; @@ -252,18 +249,15 @@ public partial class SharedBodySystem part.Owner.RandomOffset(0.25f); - if (oldBody != null) + if (oldBodyNullable is { } oldBody) { - var args = new BodyPartRemovedEventArgs(slot.Id, part); - foreach (var component in AllComps(oldBody.Value)) - { - component.BodyPartRemoved(args); - } + var args = new BodyPartRemovedEvent(slot.Id, part); + RaiseLocalEvent(oldBody, ref args); if (part.PartType == BodyPartType.Leg && !GetBodyChildrenOfType(oldBody, BodyPartType.Leg).Any()) { - Standing.Down(oldBody.Value); + Standing.Down(oldBody); } if (part.IsVital && !GetBodyChildrenOfType(oldBody, part.PartType).Any()) @@ -278,7 +272,7 @@ public partial class SharedBodySystem if (organSlot.Child is not { } child) continue; - RaiseLocalEvent(child, new RemovedFromBodyEvent(oldBody.Value), true); + RaiseLocalEvent(child, new RemovedFromBodyEvent(oldBody), true); } }