2022-01-13 06:13:25 -08:00
|
|
|
using Content.Shared.Clothing;
|
2021-06-27 07:43:39 +02:00
|
|
|
using Content.Shared.Gravity;
|
2022-01-13 06:13:25 -08:00
|
|
|
using Content.Shared.Inventory;
|
2020-05-24 11:40:49 +02:00
|
|
|
using Robust.Shared.GameObjects;
|
2020-10-14 22:37:25 +02:00
|
|
|
using Robust.Shared.IoC;
|
2021-06-09 09:26:46 +10:00
|
|
|
using Robust.Shared.Map;
|
2021-02-11 01:13:03 -08:00
|
|
|
using Robust.Shared.Physics;
|
2020-05-24 11:40:49 +02:00
|
|
|
|
2021-06-09 22:19:39 +02:00
|
|
|
namespace Content.Shared.Movement.Components
|
2020-05-24 11:40:49 +02:00
|
|
|
{
|
|
|
|
|
[RegisterComponent]
|
|
|
|
|
public sealed class MovementIgnoreGravityComponent : Component
|
|
|
|
|
{
|
|
|
|
|
}
|
2020-10-14 22:37:25 +02:00
|
|
|
|
|
|
|
|
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)
|
2020-10-14 22:37:25 +02:00
|
|
|
{
|
2021-12-05 18:09:01 +01:00
|
|
|
entityManager ??= IoCManager.Resolve<IEntityManager>();
|
|
|
|
|
|
2021-06-09 09:26:46 +10:00
|
|
|
if (body == null)
|
2021-12-05 18:09:01 +01:00
|
|
|
entityManager.TryGetComponent(entity, out body);
|
2020-10-14 22:37:25 +02:00
|
|
|
|
2021-12-05 18:09:01 +01:00
|
|
|
if (entityManager.HasComponent<MovementIgnoreGravityComponent>(entity) ||
|
2021-06-09 09:26:46 +10:00
|
|
|
(body?.BodyType & (BodyType.Static | BodyType.Kinematic)) != 0) return false;
|
|
|
|
|
|
2021-12-05 18:09:01 +01:00
|
|
|
var transform = entityManager.GetComponent<TransformComponent>(entity);
|
2021-06-09 09:26:46 +10:00
|
|
|
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-06-09 09:26:46 +10:00
|
|
|
|
2021-12-05 18:09:01 +01:00
|
|
|
if (!entityManager.GetComponent<GravityComponent>(grid.GridEntityId).Enabled)
|
2021-06-09 09:26:46 +10:00
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
coords ??= transform.Coordinates;
|
|
|
|
|
|
2021-12-05 18:09:01 +01:00
|
|
|
if (!coords.Value.IsValid(entityManager))
|
2021-06-09 09:26:46 +10:00
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var tile = grid.GetTileRef(coords.Value).Tile;
|
|
|
|
|
return tile.IsEmpty;
|
2020-10-14 22:37:25 +02:00
|
|
|
}
|
|
|
|
|
}
|
2020-05-24 11:40:49 +02:00
|
|
|
}
|