STLaySystem.Laid.cs 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. using Content.Shared.Movement.Events;
  2. using Content.Shared.Movement.Systems;
  3. using Content.Shared.Standing;
  4. namespace Content.Server._Stalker.Lay;
  5. public sealed partial class STLaySystem
  6. {
  7. [Dependency] private readonly StandingStateSystem _standingState = default!;
  8. [Dependency] private readonly MovementSpeedModifierSystem _movementSpeedModifier = default!;
  9. private void InitializeLaid()
  10. {
  11. SubscribeLocalEvent<STLaidComponent, ComponentInit>(OnLaidInit);
  12. SubscribeLocalEvent<STLaidComponent, ComponentShutdown>(OnLaidShutdown);
  13. SubscribeLocalEvent<STLaidComponent, StandAttemptEvent>(OnLaidStandAttempt);
  14. SubscribeLocalEvent<STLaidComponent, TileFrictionEvent>(OnLaidTileFriction);
  15. SubscribeLocalEvent<STLaidComponent, RefreshMovementSpeedModifiersEvent>(OnRefreshMovementSpeedModifiers);
  16. }
  17. private void OnLaidInit(Entity<STLaidComponent> laid, ref ComponentInit args)
  18. {
  19. _standingState.Down(laid, dropHeldItems: false, fixtureAttempt: false);
  20. _movementSpeedModifier.RefreshMovementSpeedModifiers(laid);
  21. }
  22. private void OnLaidShutdown(Entity<STLaidComponent> laid, ref ComponentShutdown args)
  23. {
  24. laid.Comp.Standing = true;
  25. _standingState.Stand(laid);
  26. laid.Comp.Standing = true;
  27. _movementSpeedModifier.RefreshMovementSpeedModifiers(laid);
  28. }
  29. private void OnLaidStandAttempt(Entity<STLaidComponent> laid, ref StandAttemptEvent args)
  30. {
  31. var standing = laid.Comp.Standing;
  32. laid.Comp.Standing = false;
  33. if (args.Cancelled)
  34. return;
  35. if (standing)
  36. return;
  37. args.Cancel();
  38. }
  39. private void OnLaidTileFriction(Entity<STLaidComponent> laid, ref TileFrictionEvent args)
  40. {
  41. args.Modifier *= laid.Comp.TileFrictionModifier;
  42. }
  43. private void OnRefreshMovementSpeedModifiers(Entity<STLaidComponent> laid, ref RefreshMovementSpeedModifiersEvent args)
  44. {
  45. if (laid.Comp.Standing)
  46. return;
  47. args.ModifySpeed(laid.Comp.MovementSpeedModifier, laid.Comp.MovementSpeedModifier);
  48. }
  49. }