diff --git a/Content.Client/Clothing/MagbootsComponent.cs b/Content.Client/Clothing/MagbootsComponent.cs deleted file mode 100644 index 26e26bd908..0000000000 --- a/Content.Client/Clothing/MagbootsComponent.cs +++ /dev/null @@ -1,21 +0,0 @@ -using Content.Shared.Clothing; -using Robust.Shared.GameObjects; - -namespace Content.Client.Clothing -{ - [RegisterComponent] - [ComponentReference(typeof(SharedMagbootsComponent))] - public sealed class MagbootsComponent : SharedMagbootsComponent - { - public override bool On { get; set; } - - public override void HandleComponentState(ComponentState? curState, ComponentState? nextState) - { - if (curState is not MagbootsComponentState compState) - return; - - On = compState.On; - OnChanged(); - } - } -} diff --git a/Content.Client/Clothing/MagbootsSystem.cs b/Content.Client/Clothing/MagbootsSystem.cs index b832a3559b..d8b9119e09 100644 --- a/Content.Client/Clothing/MagbootsSystem.cs +++ b/Content.Client/Clothing/MagbootsSystem.cs @@ -1,8 +1,27 @@ -using Content.Shared.Clothing; +using Content.Shared.Clothing; +using Robust.Shared.GameStates; +using static Content.Shared.Clothing.MagbootsComponent; -namespace Content.Client.Clothing +namespace Content.Client.Clothing; + +public sealed class MagbootsSystem : SharedMagbootsSystem { - public sealed class MagbootsSystem : SharedMagbootsSystem + public override void Initialize() { + base.Initialize(); + + SubscribeLocalEvent(OnHandleState); + } + + private void OnHandleState(EntityUid uid, MagbootsComponent component, ref ComponentHandleState args) + { + if (args.Current is not MagbootsComponentState componentState) + return; + + if (component.On == componentState.On) return; + + component.On = componentState.On; + OnChanged(component); } } + diff --git a/Content.Server/Clothing/Components/MagbootsComponent.cs b/Content.Server/Clothing/Components/MagbootsComponent.cs deleted file mode 100644 index b27079fa3f..0000000000 --- a/Content.Server/Clothing/Components/MagbootsComponent.cs +++ /dev/null @@ -1,52 +0,0 @@ -using Content.Shared.Clothing; -using Content.Shared.Interaction; -using Content.Shared.Inventory; -using Content.Shared.Item; -using Robust.Server.GameObjects; -using Robust.Shared.Containers; - -namespace Content.Server.Clothing.Components -{ - [RegisterComponent] - [ComponentReference(typeof(IActivate))] - [ComponentReference(typeof(SharedMagbootsComponent))] - public sealed class MagbootsComponent : SharedMagbootsComponent, IActivate - { - [Dependency] private readonly IEntityManager _entMan = default!; - - private bool _on; - - [ViewVariables] - public override bool On - { - get => _on; - set - { - _on = value; - - if (Owner.TryGetContainer(out var container) && EntitySystem.Get() - .TryGetSlotEntity(container.Owner, "shoes", out var entityUid) && entityUid == Owner) - { - EntitySystem.Get().UpdateMagbootEffects(container.Owner, Owner, true, this); - } - - if (_entMan.TryGetComponent(Owner, out var item)) - item.EquippedPrefix = On ? "on" : null; - if(_entMan.TryGetComponent(Owner, out var sprite)) - sprite.LayerSetState(0, On ? "icon-on" : "icon"); - OnChanged(); - Dirty(); - } - } - - void IActivate.Activate(ActivateEventArgs eventArgs) - { - On = !On; - } - - public override ComponentState GetComponentState() - { - return new MagbootsComponentState(On); - } - } -} diff --git a/Content.Server/Clothing/MagbootsSystem.cs b/Content.Server/Clothing/MagbootsSystem.cs index 4c3b5673bd..e3684f6572 100644 --- a/Content.Server/Clothing/MagbootsSystem.cs +++ b/Content.Server/Clothing/MagbootsSystem.cs @@ -1,58 +1,94 @@ using Content.Server.Atmos.Components; -using Content.Server.Clothing.Components; using Content.Shared.Alert; using Content.Shared.Clothing; +using Content.Shared.Inventory; using Content.Shared.Inventory.Events; +using Content.Shared.Item; +using Content.Shared.Toggleable; +using Robust.Server.GameObjects; +using Robust.Shared.Containers; +using Robust.Shared.GameStates; +using static Content.Shared.Clothing.MagbootsComponent; -namespace Content.Server.Clothing +namespace Content.Server.Clothing; + +public sealed class MagbootsSystem : SharedMagbootsSystem { - public sealed class MagbootsSystem : SharedMagbootsSystem + [Dependency] private readonly AlertsSystem _alertsSystem = default!; + [Dependency] private readonly InventorySystem _inventory = default!; + [Dependency] private readonly SharedContainerSystem _sharedContainer = default!; + + public override void Initialize() { - [Dependency] private readonly AlertsSystem _alertsSystem = default!; + base.Initialize(); - public override void Initialize() + SubscribeLocalEvent(OnGotEquipped); + SubscribeLocalEvent(OnGotUnequipped); + SubscribeLocalEvent(OnToggleAction); + SubscribeLocalEvent(OnGetState); + } + + private void UpdateMagbootEffects(EntityUid parent, EntityUid uid, bool state, MagbootsComponent? component) + { + if (!Resolve(uid, ref component)) + return; + state = state && component.On; + + if (TryComp(parent, out MovedByPressureComponent? movedByPressure)) { - base.Initialize(); - - SubscribeLocalEvent(OnGotEquipped); - SubscribeLocalEvent(OnGotUnequipped); + movedByPressure.Enabled = !state; } - public void UpdateMagbootEffects(EntityUid parent, EntityUid uid, bool state, MagbootsComponent? component) + if (state) { - if (!Resolve(uid, ref component)) - return; - state = state && component.On; - - if (TryComp(parent, out MovedByPressureComponent? movedByPressure)) - { - movedByPressure.Enabled = !state; - } - - if (state) - { - _alertsSystem.ShowAlert(parent, AlertType.Magboots); - } - else - { - _alertsSystem.ClearAlert(parent, AlertType.Magboots); - } + _alertsSystem.ShowAlert(parent, AlertType.Magboots); } - - private void OnGotUnequipped(EntityUid uid, MagbootsComponent component, GotUnequippedEvent args) + else { - if (args.Slot == "shoes") - { - UpdateMagbootEffects(args.Equipee, uid, false, component); - } - } - - private void OnGotEquipped(EntityUid uid, MagbootsComponent component, GotEquippedEvent args) - { - if (args.Slot == "shoes") - { - UpdateMagbootEffects(args.Equipee, uid, true, component); - } + _alertsSystem.ClearAlert(parent, AlertType.Magboots); } } + + private void OnToggleAction(EntityUid uid, MagbootsComponent component, ToggleActionEvent args) + { + if (args.Handled) + return; + + args.Handled = true; + component.On = !component.On; + + if (_sharedContainer.TryGetContainingContainer(uid, out var container) && + _inventory.TryGetSlotEntity(container.Owner, "shoes", out var entityUid) && entityUid == component.Owner) + UpdateMagbootEffects(container.Owner, component.Owner, true, component); + + if (TryComp(component.Owner, out var item)) + item.EquippedPrefix = component.On ? "on" : null; + + if (TryComp(component.Owner, out var sprite)) + sprite.LayerSetState(0, component.On ? "icon-on" : "icon"); + + OnChanged(component); + Dirty(component); + } + + private void OnGotUnequipped(EntityUid uid, MagbootsComponent component, GotUnequippedEvent args) + { + if (args.Slot == "shoes") + { + UpdateMagbootEffects(args.Equipee, uid, false, component); + } + } + + private void OnGotEquipped(EntityUid uid, MagbootsComponent component, GotEquippedEvent args) + { + if (args.Slot == "shoes") + { + UpdateMagbootEffects(args.Equipee, uid, true, component); + } + } + + private void OnGetState(EntityUid uid, MagbootsComponent component, ref ComponentGetState args) + { + args.State = new MagbootsComponentState(component.On); + } } diff --git a/Content.Shared/Clothing/MagbootsComponent.cs b/Content.Shared/Clothing/MagbootsComponent.cs new file mode 100644 index 0000000000..744cf964f5 --- /dev/null +++ b/Content.Shared/Clothing/MagbootsComponent.cs @@ -0,0 +1,26 @@ +using Content.Shared.Actions.ActionTypes; +using Robust.Shared.GameStates; +using Robust.Shared.Serialization; + +namespace Content.Shared.Clothing; + +[RegisterComponent, NetworkedComponent()] +public sealed class MagbootsComponent : Component +{ + [DataField("toggleAction", required: true)] + public InstantAction ToggleAction = new(); + + [ViewVariables] + public bool On; + + [Serializable, NetSerializable] + public sealed class MagbootsComponentState : ComponentState + { + public bool On { get; } + + public MagbootsComponentState(bool @on) + { + On = on; + } + } +} diff --git a/Content.Shared/Clothing/SharedMagbootsComponent.cs b/Content.Shared/Clothing/SharedMagbootsComponent.cs deleted file mode 100644 index 189d35234e..0000000000 --- a/Content.Shared/Clothing/SharedMagbootsComponent.cs +++ /dev/null @@ -1,33 +0,0 @@ -using Content.Shared.Actions; -using Content.Shared.Actions.ActionTypes; -using Robust.Shared.GameStates; -using Robust.Shared.Serialization; - -namespace Content.Shared.Clothing -{ - [NetworkedComponent()] - public abstract class SharedMagbootsComponent : Component - { - [DataField("toggleAction", required: true)] - public InstantAction ToggleAction = new(); - - public abstract bool On { get; set; } - - protected void OnChanged() - { - EntitySystem.Get().SetToggled(ToggleAction, On); - EntitySystem.Get().SetClothingSpeedModifierEnabled(Owner, On); - } - - [Serializable, NetSerializable] - public sealed class MagbootsComponentState : ComponentState - { - public bool On { get; } - - public MagbootsComponentState(bool @on) - { - On = on; - } - } - } -} diff --git a/Content.Shared/Clothing/SharedMagbootsSystem.cs b/Content.Shared/Clothing/SharedMagbootsSystem.cs index 75e8f2a8ca..81ec3e7d3d 100644 --- a/Content.Shared/Clothing/SharedMagbootsSystem.cs +++ b/Content.Shared/Clothing/SharedMagbootsSystem.cs @@ -7,17 +7,25 @@ namespace Content.Shared.Clothing; public abstract class SharedMagbootsSystem : EntitySystem { + [Dependency] private readonly SharedActionsSystem _sharedActions = default!; + [Dependency] private readonly ClothingSpeedModifierSystem _clothingSpeedModifier = default!; + public override void Initialize() { base.Initialize(); - SubscribeLocalEvent>(AddToggleVerb); - SubscribeLocalEvent(OnSlipAttempt); - SubscribeLocalEvent(OnGetActions); - SubscribeLocalEvent(OnToggleAction); + SubscribeLocalEvent>(AddToggleVerb); + SubscribeLocalEvent(OnSlipAttempt); + SubscribeLocalEvent(OnGetActions); } - private void AddToggleVerb(EntityUid uid, SharedMagbootsComponent component, GetVerbsEvent args) + protected void OnChanged(MagbootsComponent component) + { + _sharedActions.SetToggled(component.ToggleAction, component.On); + _clothingSpeedModifier.SetClothingSpeedModifierEnabled(component.Owner, component.On); + } + + private void AddToggleVerb(EntityUid uid, MagbootsComponent component, GetVerbsEvent args) { if (!args.CanAccess || !args.CanInteract) return; @@ -29,24 +37,14 @@ public abstract class SharedMagbootsSystem : EntitySystem args.Verbs.Add(verb); } - private void OnSlipAttempt(EntityUid uid, SharedMagbootsComponent component, SlipAttemptEvent args) + private void OnSlipAttempt(EntityUid uid, MagbootsComponent component, SlipAttemptEvent args) { if (component.On) args.Cancel(); } - private void OnGetActions(EntityUid uid, SharedMagbootsComponent component, GetItemActionsEvent args) + private void OnGetActions(EntityUid uid, MagbootsComponent component, GetItemActionsEvent args) { args.Actions.Add(component.ToggleAction); } - - private void OnToggleAction(EntityUid uid, SharedMagbootsComponent component, ToggleActionEvent args) - { - if (args.Handled) - return; - - component.On = !component.On; - - args.Handled = true; - } } diff --git a/Content.Shared/Movement/Components/MovementIgnoreGravityComponent.cs b/Content.Shared/Movement/Components/MovementIgnoreGravityComponent.cs index 53d68ed25c..2015c5f386 100644 --- a/Content.Shared/Movement/Components/MovementIgnoreGravityComponent.cs +++ b/Content.Shared/Movement/Components/MovementIgnoreGravityComponent.cs @@ -60,7 +60,7 @@ namespace Content.Shared.Movement.Components if (invSys.TryGetSlotEntity(entity, "shoes", out var ent)) { - if (entityManager.TryGetComponent(ent, out var boots) && boots.On) + if (entityManager.TryGetComponent(ent, out var boots) && boots.On) return false; }