Files
crystall-punk-14/Content.Shared/Movement/Components/MovementIgnoreGravityComponent.cs

65 lines
2.1 KiB
C#
Raw Normal View History

2022-01-13 06:13:25 -08:00
using Content.Shared.Clothing;
using Content.Shared.Gravity;
2022-01-13 06:13:25 -08:00
using Content.Shared.Inventory;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Map;
using Robust.Shared.Physics;
2021-06-09 22:19:39 +02:00
namespace Content.Shared.Movement.Components
{
[RegisterComponent]
public sealed class MovementIgnoreGravityComponent : Component
{
}
public static class GravityExtensions
{
2021-12-04 12:59:44 +01:00
public static bool IsWeightless(this EntityUid entity, PhysicsComponent? body = null, EntityCoordinates? coords = null, IMapManager? mapManager = null, IEntityManager? entityManager = null)
{
2021-12-05 18:09:01 +01:00
entityManager ??= IoCManager.Resolve<IEntityManager>();
if (body == null)
2021-12-05 18:09:01 +01:00
entityManager.TryGetComponent(entity, out body);
2021-12-05 18:09:01 +01:00
if (entityManager.HasComponent<MovementIgnoreGravityComponent>(entity) ||
(body?.BodyType & (BodyType.Static | BodyType.Kinematic)) != 0) return false;
2021-12-05 18:09:01 +01:00
var transform = entityManager.GetComponent<TransformComponent>(entity);
var gridId = transform.GridID;
if (!gridId.IsValid())
{
// Not on a grid = no gravity for now.
// In the future, may want to allow maps to override to always have gravity instead.
return true;
}
mapManager ??= IoCManager.Resolve<IMapManager>();
var grid = mapManager.GetGrid(gridId);
2022-01-13 06:13:25 -08:00
var invSys = EntitySystem.Get<InventorySystem>();
if (invSys.TryGetSlotEntity(entity, "shoes", out var ent))
{
if (entityManager.TryGetComponent<SharedMagbootsComponent>(ent, out var boots) && boots.On)
return false;
}
2021-12-05 18:09:01 +01:00
if (!entityManager.GetComponent<GravityComponent>(grid.GridEntityId).Enabled)
{
return true;
}
coords ??= transform.Coordinates;
2021-12-05 18:09:01 +01:00
if (!coords.Value.IsValid(entityManager))
{
return true;
}
var tile = grid.GetTileRef(coords.Value).Tile;
return tile.IsEmpty;
}
}
}