using Content.Shared.Clothing.Components;
using Content.Shared.Gravity;
using Content.Shared.Inventory;
using Content.Shared.Standing;
namespace Content.Shared.Clothing.EntitySystems;
///
/// We check standing state on all clothing because we don't want you to have anti-gravity unless you're standing.
/// This is for balance reasons as it prevents you from wearing anti-grav clothing to cheese being stun cuffed, as
/// well as other worse things.
///
public sealed class AntiGravityClothingSystem : EntitySystem
{
[Dependency] private readonly StandingStateSystem _standing = default!;
[Dependency] private readonly SharedGravitySystem _gravity = default!;
///
public override void Initialize()
{
SubscribeLocalEvent>(OnIsWeightless);
SubscribeLocalEvent(OnEquipped);
SubscribeLocalEvent(OnUnequipped);
SubscribeLocalEvent>(OnDowned);
SubscribeLocalEvent>(OnStood);
}
private void OnIsWeightless(Entity ent, ref InventoryRelayedEvent args)
{
if (args.Args.Handled || _standing.IsDown(args.Owner))
return;
args.Args.Handled = true;
args.Args.IsWeightless = true;
}
private void OnEquipped(Entity entity, ref ClothingGotEquippedEvent args)
{
// This clothing item does nothing if we're not standing
if (_standing.IsDown(args.Wearer))
return;
_gravity.RefreshWeightless(args.Wearer, true);
}
private void OnUnequipped(Entity entity, ref ClothingGotUnequippedEvent args)
{
// This clothing item does nothing if we're not standing
if (_standing.IsDown(args.Wearer))
return;
_gravity.RefreshWeightless(args.Wearer, false);
}
private void OnDowned(Entity entity, ref InventoryRelayedEvent args)
{
_gravity.RefreshWeightless(args.Owner, false);
}
private void OnStood(Entity entity, ref InventoryRelayedEvent args)
{
_gravity.RefreshWeightless(args.Owner, true);
}
}