Files
tbd-station-14/Content.Shared/Clothing/SharedMagbootsSystem.cs
2023-04-22 20:42:36 +10:00

92 lines
3.4 KiB
C#

using Content.Shared.Actions;
using Content.Shared.Clothing.EntitySystems;
using Content.Shared.Inventory;
using Content.Shared.Item;
using Content.Shared.Slippery;
using Content.Shared.Toggleable;
using Content.Shared.Verbs;
using Robust.Shared.Containers;
namespace Content.Shared.Clothing;
public abstract class SharedMagbootsSystem : EntitySystem
{
[Dependency] private readonly ClothingSpeedModifierSystem _clothingSpeedModifier = default!;
[Dependency] private readonly ClothingSystem _clothing = default!;
[Dependency] private readonly InventorySystem _inventory = default!;
[Dependency] private readonly SharedActionsSystem _sharedActions = default!;
[Dependency] private readonly SharedAppearanceSystem _appearance = default!;
[Dependency] private readonly SharedContainerSystem _sharedContainer = default!;
[Dependency] private readonly SharedItemSystem _item = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<MagbootsComponent, GetVerbsEvent<ActivationVerb>>(AddToggleVerb);
SubscribeLocalEvent<MagbootsComponent, InventoryRelayedEvent<SlipAttemptEvent>>(OnSlipAttempt);
SubscribeLocalEvent<MagbootsComponent, GetItemActionsEvent>(OnGetActions);
SubscribeLocalEvent<MagbootsComponent, ToggleActionEvent>(OnToggleAction);
}
private void OnToggleAction(EntityUid uid, MagbootsComponent component, ToggleActionEvent args)
{
if (args.Handled)
return;
args.Handled = true;
ToggleMagboots(uid, component);
}
private void ToggleMagboots(EntityUid uid, MagbootsComponent magboots)
{
magboots.On = !magboots.On;
if (_sharedContainer.TryGetContainingContainer(uid, out var container) &&
_inventory.TryGetSlotEntity(container.Owner, "shoes", out var entityUid) && entityUid == uid)
UpdateMagbootEffects(container.Owner, uid, true, magboots);
if (TryComp<ItemComponent>(uid, out var item))
{
_item.SetHeldPrefix(uid, magboots.On ? "on" : null, item);
_clothing.SetEquippedPrefix(uid, magboots.On ? "on" : null);
}
_appearance.SetData(uid, ToggleVisuals.Toggled, magboots.On);
OnChanged(uid, magboots);
Dirty(magboots);
}
protected virtual void UpdateMagbootEffects(EntityUid parent, EntityUid uid, bool state, MagbootsComponent? component) { }
protected void OnChanged(EntityUid uid, MagbootsComponent component)
{
_sharedActions.SetToggled(component.ToggleAction, component.On);
_clothingSpeedModifier.SetClothingSpeedModifierEnabled(uid, component.On);
}
private void AddToggleVerb(EntityUid uid, MagbootsComponent component, GetVerbsEvent<ActivationVerb> args)
{
if (!args.CanAccess || !args.CanInteract)
return;
ActivationVerb verb = new();
verb.Text = Loc.GetString("toggle-magboots-verb-get-data-text");
verb.Act = () => ToggleMagboots(uid, component);
// TODO VERB ICON add toggle icon? maybe a computer on/off symbol?
args.Verbs.Add(verb);
}
private void OnSlipAttempt(EntityUid uid, MagbootsComponent component, InventoryRelayedEvent<SlipAttemptEvent> args)
{
if (component.On)
args.Args.Cancel();
}
private void OnGetActions(EntityUid uid, MagbootsComponent component, GetItemActionsEvent args)
{
args.Actions.Add(component.ToggleAction);
}
}