Files
tbd-station-14/Content.Shared/Movement/Components/MovementIgnoreGravityComponent.cs
Moony 130302a262 Adds twenty-one new smites, moves the explosion smite to the verb category. (#8456)
* Adds seven new smites, moves the explosion smite to the verb category.

* adds even more smites.

* Even more smites, some messages for specific smites.

* Adds even more smites.

* Removes some junk, adds a smite that angers the pointing arrows.

* get rid of dumb component.

* Remove mistake from verb menu presentation.

* How did that happen?

* whoops

* c

* e

* fuck

* Loading...

* removes the BoM go away

* adds the funny kill sign. Fixes ghost smite.

* Move systems around.

* Adjust organ vomit.

* Adds a smite that turns people into an instrument, and one that removes their gravity.

* oops

* typo

Co-authored-by: Veritius <veritiusgaming@gmail.com>
2022-05-27 00:41:18 -07:00

81 lines
2.7 KiB
C#

using Content.Shared.Clothing;
using Content.Shared.Gravity;
using Content.Shared.Inventory;
using Robust.Shared.GameStates;
using Robust.Shared.Map;
using Robust.Shared.Physics;
using Robust.Shared.Serialization;
namespace Content.Shared.Movement.Components
{
[RegisterComponent, NetworkedComponent]
public sealed class MovementIgnoreGravityComponent : Component
{
/// <summary>
/// Whether or not gravity is on or off for this object.
/// </summary>
[DataField("gravityState")] public bool Weightless = false;
}
[NetSerializable, Serializable]
public sealed class MovementIgnoreGravityComponentState : ComponentState
{
public bool Weightless;
public MovementIgnoreGravityComponentState(MovementIgnoreGravityComponent component)
{
Weightless = component.Weightless;
}
}
public static class GravityExtensions
{
public static bool IsWeightless(this EntityUid entity, PhysicsComponent? body = null, EntityCoordinates? coords = null, IMapManager? mapManager = null, IEntityManager? entityManager = null)
{
entityManager ??= IoCManager.Resolve<IEntityManager>();
if (body == null)
entityManager.TryGetComponent(entity, out body);
if (entityManager.TryGetComponent<MovementIgnoreGravityComponent>(entity, out var ignoreGravityComponent) ||
(body?.BodyType & (BodyType.Static | BodyType.Kinematic)) != 0) return ignoreGravityComponent.Weightless;
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);
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;
}
if (!entityManager.GetComponent<GravityComponent>(grid.GridEntityId).Enabled)
{
return true;
}
coords ??= transform.Coordinates;
if (!coords.Value.IsValid(entityManager))
{
return true;
}
var tile = grid.GetTileRef(coords.Value).Tile;
return tile.IsEmpty;
}
}
}