Magboots ECS and Cleanup (#9245)
Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com>
This commit is contained in:
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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 override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
SubscribeLocalEvent<MagbootsComponent, ComponentHandleState>(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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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<InventorySystem>()
|
||||
.TryGetSlotEntity(container.Owner, "shoes", out var entityUid) && entityUid == Owner)
|
||||
{
|
||||
EntitySystem.Get<MagbootsSystem>().UpdateMagbootEffects(container.Owner, Owner, true, this);
|
||||
}
|
||||
|
||||
if (_entMan.TryGetComponent<SharedItemComponent>(Owner, out var item))
|
||||
item.EquippedPrefix = On ? "on" : null;
|
||||
if(_entMan.TryGetComponent<SpriteComponent>(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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,14 +1,22 @@
|
||||
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
|
||||
{
|
||||
[Dependency] private readonly AlertsSystem _alertsSystem = default!;
|
||||
[Dependency] private readonly InventorySystem _inventory = default!;
|
||||
[Dependency] private readonly SharedContainerSystem _sharedContainer = default!;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
@@ -16,9 +24,11 @@ namespace Content.Server.Clothing
|
||||
|
||||
SubscribeLocalEvent<MagbootsComponent, GotEquippedEvent>(OnGotEquipped);
|
||||
SubscribeLocalEvent<MagbootsComponent, GotUnequippedEvent>(OnGotUnequipped);
|
||||
SubscribeLocalEvent<MagbootsComponent, ToggleActionEvent>(OnToggleAction);
|
||||
SubscribeLocalEvent<MagbootsComponent, ComponentGetState>(OnGetState);
|
||||
}
|
||||
|
||||
public void UpdateMagbootEffects(EntityUid parent, EntityUid uid, bool state, MagbootsComponent? component)
|
||||
private void UpdateMagbootEffects(EntityUid parent, EntityUid uid, bool state, MagbootsComponent? component)
|
||||
{
|
||||
if (!Resolve(uid, ref component))
|
||||
return;
|
||||
@@ -39,6 +49,28 @@ namespace Content.Server.Clothing
|
||||
}
|
||||
}
|
||||
|
||||
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<SharedItemComponent>(component.Owner, out var item))
|
||||
item.EquippedPrefix = component.On ? "on" : null;
|
||||
|
||||
if (TryComp<SpriteComponent>(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")
|
||||
@@ -54,5 +86,9 @@ namespace Content.Server.Clothing
|
||||
UpdateMagbootEffects(args.Equipee, uid, true, component);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnGetState(EntityUid uid, MagbootsComponent component, ref ComponentGetState args)
|
||||
{
|
||||
args.State = new MagbootsComponentState(component.On);
|
||||
}
|
||||
}
|
||||
|
||||
26
Content.Shared/Clothing/MagbootsComponent.cs
Normal file
26
Content.Shared/Clothing/MagbootsComponent.cs
Normal file
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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<SharedActionsSystem>().SetToggled(ToggleAction, On);
|
||||
EntitySystem.Get<ClothingSpeedModifierSystem>().SetClothingSpeedModifierEnabled(Owner, On);
|
||||
}
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
public sealed class MagbootsComponentState : ComponentState
|
||||
{
|
||||
public bool On { get; }
|
||||
|
||||
public MagbootsComponentState(bool @on)
|
||||
{
|
||||
On = on;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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<SharedMagbootsComponent, GetVerbsEvent<ActivationVerb>>(AddToggleVerb);
|
||||
SubscribeLocalEvent<SharedMagbootsComponent, SlipAttemptEvent>(OnSlipAttempt);
|
||||
SubscribeLocalEvent<SharedMagbootsComponent, GetItemActionsEvent>(OnGetActions);
|
||||
SubscribeLocalEvent<SharedMagbootsComponent, ToggleActionEvent>(OnToggleAction);
|
||||
SubscribeLocalEvent<MagbootsComponent, GetVerbsEvent<ActivationVerb>>(AddToggleVerb);
|
||||
SubscribeLocalEvent<MagbootsComponent, SlipAttemptEvent>(OnSlipAttempt);
|
||||
SubscribeLocalEvent<MagbootsComponent, GetItemActionsEvent>(OnGetActions);
|
||||
}
|
||||
|
||||
private void AddToggleVerb(EntityUid uid, SharedMagbootsComponent component, GetVerbsEvent<ActivationVerb> 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<ActivationVerb> 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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -60,7 +60,7 @@ namespace Content.Shared.Movement.Components
|
||||
|
||||
if (invSys.TryGetSlotEntity(entity, "shoes", out var ent))
|
||||
{
|
||||
if (entityManager.TryGetComponent<SharedMagbootsComponent>(ent, out var boots) && boots.On)
|
||||
if (entityManager.TryGetComponent<MagbootsComponent>(ent, out var boots) && boots.On)
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user