* #1462 extracted MapGrid's HasGravity property to separate Content component * #1462 - PR suggestions * Merge to master Co-authored-by: metalgearsloth <comedian_vs_clown@hotmail.com>
59 lines
1.9 KiB
C#
59 lines
1.9 KiB
C#
#nullable enable
|
|
using Content.Shared.Gravity;
|
|
using Robust.Shared.GameObjects;
|
|
using Robust.Shared.IoC;
|
|
using Robust.Shared.Map;
|
|
using Robust.Shared.Physics;
|
|
|
|
namespace Content.Shared.Movement.Components
|
|
{
|
|
[RegisterComponent]
|
|
public sealed class MovementIgnoreGravityComponent : Component
|
|
{
|
|
public override string Name => "MovementIgnoreGravity";
|
|
}
|
|
|
|
public static class GravityExtensions
|
|
{
|
|
public static bool IsWeightless(this IEntity entity, PhysicsComponent? body = null, EntityCoordinates? coords = null, IMapManager? mapManager = null, IEntityManager? entityManager = null)
|
|
{
|
|
if (body == null)
|
|
entity.TryGetComponent(out body);
|
|
|
|
if (entity.HasComponent<MovementIgnoreGravityComponent>() ||
|
|
(body?.BodyType & (BodyType.Static | BodyType.Kinematic)) != 0) return false;
|
|
|
|
var transform = entity.Transform;
|
|
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);
|
|
var gridEntityId = grid.GridEntityId;
|
|
entityManager ??= IoCManager.Resolve<IEntityManager>();
|
|
var gridEntity = entityManager.GetEntity(gridEntityId);
|
|
|
|
if (!gridEntity.GetComponent<GravityComponent>().Enabled)
|
|
{
|
|
return true;
|
|
}
|
|
|
|
coords ??= transform.Coordinates;
|
|
|
|
if (!coords.Value.IsValid(entity.EntityManager))
|
|
{
|
|
return true;
|
|
}
|
|
|
|
var tile = grid.GetTileRef(coords.Value).Tile;
|
|
return tile.IsEmpty;
|
|
}
|
|
}
|
|
}
|