Skip to content

Commit

Permalink
Fix magboots not needing a grid to work (space-wizards#29034)
Browse files Browse the repository at this point in the history
* Fix magboots not needing a grid to work

* ok fix it for realsies
  • Loading branch information
EmoGarbage404 authored Jun 16, 2024
1 parent a341c3a commit 3644602
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 4 deletions.
6 changes: 6 additions & 0 deletions Content.Shared/Clothing/MagbootsComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,10 @@ public sealed partial class MagbootsComponent : Component

[DataField]
public ProtoId<AlertPrototype> MagbootsAlert = "Magboots";

/// <summary>
/// If true, the user must be standing on a grid or planet map to experience the weightlessness-canceling effect
/// </summary>
[DataField]
public bool RequiresGrid = true;
}
5 changes: 5 additions & 0 deletions Content.Shared/Clothing/SharedMagbootsSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public sealed class SharedMagbootsSystem : EntitySystem
[Dependency] private readonly AlertsSystem _alerts = default!;
[Dependency] private readonly ClothingSpeedModifierSystem _clothingSpeedModifier = default!;
[Dependency] private readonly ClothingSystem _clothing = default!;
[Dependency] private readonly SharedGravitySystem _gravity = default!;
[Dependency] private readonly InventorySystem _inventory = default!;
[Dependency] private readonly SharedActionsSystem _sharedActions = default!;
[Dependency] private readonly SharedActionsSystem _actionContainer = default!;
Expand Down Expand Up @@ -147,6 +148,10 @@ private void OnIsWeightless(Entity<MagbootsComponent> ent, ref InventoryRelayedE
if (!ent.Comp.On)
return;

// do not cancel weightlessness if the person is in off-grid.
if (ent.Comp.RequiresGrid && !_gravity.EntityOnGravitySupportingGridOrMap(ent.Owner))
return;

args.Args.IsWeightless = false;
args.Args.Handled = true;
}
Expand Down
32 changes: 28 additions & 4 deletions Content.Shared/Gravity/SharedGravitySystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ public abstract partial class SharedGravitySystem : EntitySystem
[ValidatePrototypeId<AlertPrototype>]
public const string WeightlessAlert = "Weightless";

private EntityQuery<GravityComponent> _gravityQuery;

public bool IsWeightless(EntityUid uid, PhysicsComponent? body = null, TransformComponent? xform = null)
{
Resolve(uid, ref body, false);
Expand All @@ -36,15 +38,35 @@ public bool IsWeightless(EntityUid uid, PhysicsComponent? body = null, Transform
return true;

// If grid / map has gravity
if (TryComp<GravityComponent>(xform.GridUid, out var gravity) && gravity.Enabled ||
TryComp<GravityComponent>(xform.MapUid, out var mapGravity) && mapGravity.Enabled)
{
if (EntityGridOrMapHaveGravity((uid, xform)))
return false;
}

return true;
}

/// <summary>
/// Checks if a given entity is currently standing on a grid or map that supports having gravity at all.
/// </summary>
public bool EntityOnGravitySupportingGridOrMap(Entity<TransformComponent?> entity)
{
entity.Comp ??= Transform(entity);

return _gravityQuery.HasComp(entity.Comp.GridUid) ||
_gravityQuery.HasComp(entity.Comp.MapUid);
}


/// <summary>
/// Checks if a given entity is currently standing on a grid or map that has gravity of some kind.
/// </summary>
public bool EntityGridOrMapHaveGravity(Entity<TransformComponent?> entity)
{
entity.Comp ??= Transform(entity);

return _gravityQuery.TryComp(entity.Comp.GridUid, out var gravity) && gravity.Enabled ||
_gravityQuery.TryComp(entity.Comp.MapUid, out var mapGravity) && mapGravity.Enabled;
}

public override void Initialize()
{
base.Initialize();
Expand All @@ -54,6 +76,8 @@ public override void Initialize()
SubscribeLocalEvent<GravityChangedEvent>(OnGravityChange);
SubscribeLocalEvent<GravityComponent, ComponentGetState>(OnGetState);
SubscribeLocalEvent<GravityComponent, ComponentHandleState>(OnHandleState);

_gravityQuery = GetEntityQuery<GravityComponent>();
}

public override void Update(float frameTime)
Expand Down

0 comments on commit 3644602

Please sign in to comment.