Fix magboots not needing a grid to work (#29034)

* Fix magboots not needing a grid to work

* ok fix it for realsies
This commit is contained in:
Nemanja
2024-06-15 23:38:17 -04:00
committed by GitHub
parent a341c3a1e9
commit 3644602fb8
3 changed files with 39 additions and 4 deletions

View File

@@ -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;
}

View File

@@ -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!;
@@ -147,6 +148,10 @@ public sealed class SharedMagbootsSystem : EntitySystem
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;
}

View File

@@ -17,6 +17,8 @@ namespace Content.Shared.Gravity
[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);
@@ -36,15 +38,35 @@ namespace Content.Shared.Gravity
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();
@@ -54,6 +76,8 @@ namespace Content.Shared.Gravity
SubscribeLocalEvent<GravityChangedEvent>(OnGravityChange);
SubscribeLocalEvent<GravityComponent, ComponentGetState>(OnGetState);
SubscribeLocalEvent<GravityComponent, ComponentHandleState>(OnHandleState);
_gravityQuery = GetEntityQuery<GravityComponent>();
}
public override void Update(float frameTime)