MovementIgnoreGravitySystem.cs 1.2 KB

123456789101112131415161718192021222324252627282930313233
  1. using Content.Shared.Movement.Components;
  2. using Content.Shared.Movement.Events;
  3. using Robust.Shared.GameStates;
  4. namespace Content.Shared.Movement.Systems;
  5. public sealed class MovementIgnoreGravitySystem : EntitySystem
  6. {
  7. public override void Initialize()
  8. {
  9. SubscribeLocalEvent<MovementIgnoreGravityComponent, ComponentGetState>(GetState);
  10. SubscribeLocalEvent<MovementIgnoreGravityComponent, ComponentHandleState>(HandleState);
  11. SubscribeLocalEvent<MovementAlwaysTouchingComponent, CanWeightlessMoveEvent>(OnWeightless);
  12. }
  13. private void OnWeightless(EntityUid uid, MovementAlwaysTouchingComponent component, ref CanWeightlessMoveEvent args)
  14. {
  15. args.CanMove = true;
  16. }
  17. private void HandleState(EntityUid uid, MovementIgnoreGravityComponent component, ref ComponentHandleState args)
  18. {
  19. if (args.Next is null)
  20. return;
  21. component.Weightless = ((MovementIgnoreGravityComponentState) args.Next).Weightless;
  22. }
  23. private void GetState(EntityUid uid, MovementIgnoreGravityComponent component, ref ComponentGetState args)
  24. {
  25. args.State = new MovementIgnoreGravityComponentState(component);
  26. }
  27. }