Files
tbd-station-14/Content.Shared/Clothing/MagbootsSystem.cs
B_Kirill fd40888b0e Cleanup warnings: CS0067, CS8509, CS8073 (#39770)
* Cleanup

* Bonus

---------

Co-authored-by: ElectroJr <leonsfriedrich@gmail.com>
2025-09-23 15:11:29 +12:00

80 lines
2.9 KiB
C#

using Content.Shared.Actions;
using Content.Shared.Alert;
using Content.Shared.Atmos.Components;
using Content.Shared.Clothing.EntitySystems;
using Content.Shared.Gravity;
using Content.Shared.Inventory;
using Content.Shared.Item;
using Content.Shared.Item.ItemToggle;
using Content.Shared.Item.ItemToggle.Components;
using Robust.Shared.Containers;
namespace Content.Shared.Clothing;
public sealed class SharedMagbootsSystem : EntitySystem
{
[Dependency] private readonly AlertsSystem _alerts = default!;
[Dependency] private readonly ItemToggleSystem _toggle = default!;
[Dependency] private readonly SharedContainerSystem _container = default!;
[Dependency] private readonly SharedGravitySystem _gravity = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<MagbootsComponent, ItemToggledEvent>(OnToggled);
SubscribeLocalEvent<MagbootsComponent, ClothingGotEquippedEvent>(OnGotEquipped);
SubscribeLocalEvent<MagbootsComponent, ClothingGotUnequippedEvent>(OnGotUnequipped);
SubscribeLocalEvent<MagbootsComponent, IsWeightlessEvent>(OnIsWeightless);
SubscribeLocalEvent<MagbootsComponent, InventoryRelayedEvent<IsWeightlessEvent>>(OnIsWeightless);
}
private void OnToggled(Entity<MagbootsComponent> ent, ref ItemToggledEvent args)
{
if (_container.TryGetContainingContainer((ent.Owner, null, null), out var container))
UpdateMagbootEffects(container.Owner, ent, args.Activated);
}
private void OnGotUnequipped(Entity<MagbootsComponent> ent, ref ClothingGotUnequippedEvent args)
{
UpdateMagbootEffects(args.Wearer, ent, false);
}
private void OnGotEquipped(Entity<MagbootsComponent> ent, ref ClothingGotEquippedEvent args)
{
UpdateMagbootEffects(args.Wearer, ent, _toggle.IsActivated(ent.Owner));
}
public void UpdateMagbootEffects(EntityUid user, Entity<MagbootsComponent> ent, bool state)
{
// TODO: public api for this and add access
if (TryComp<MovedByPressureComponent>(user, out var moved))
moved.Enabled = !state;
_gravity.RefreshWeightless(user);
if (state)
_alerts.ShowAlert(user, ent.Comp.MagbootsAlert);
else
_alerts.ClearAlert(user, ent.Comp.MagbootsAlert);
}
private void OnIsWeightless(Entity<MagbootsComponent> ent, ref IsWeightlessEvent args)
{
if (args.Handled || !_toggle.IsActivated(ent.Owner))
return;
// do not cancel weightlessness if the person is in off-grid.
if (ent.Comp.RequiresGrid && !_gravity.EntityOnGravitySupportingGridOrMap(ent.Owner))
return;
args.IsWeightless = false;
args.Handled = true;
}
private void OnIsWeightless(Entity<MagbootsComponent> ent, ref InventoryRelayedEvent<IsWeightlessEvent> args)
{
OnIsWeightless(ent, ref args.Args);
}
}