SkatesSystem.cs 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. using Content.Shared.Inventory.Events;
  2. using Content.Shared.Movement.Systems;
  3. using Content.Shared.Damage.Systems;
  4. using Content.Shared.Movement.Components;
  5. namespace Content.Shared.Clothing;
  6. /// <summary>
  7. /// Changes the friction and acceleration of the wearer and also the damage on impact variables of thew wearer when hitting a static object.
  8. /// </summary>
  9. public sealed class SkatesSystem : EntitySystem
  10. {
  11. [Dependency] private readonly MovementSpeedModifierSystem _move = default!;
  12. [Dependency] private readonly DamageOnHighSpeedImpactSystem _impact = default!;
  13. public override void Initialize()
  14. {
  15. base.Initialize();
  16. SubscribeLocalEvent<SkatesComponent, ClothingGotEquippedEvent>(OnGotEquipped);
  17. SubscribeLocalEvent<SkatesComponent, ClothingGotUnequippedEvent>(OnGotUnequipped);
  18. }
  19. /// <summary>
  20. /// When item is unequipped from the shoe slot, friction, aceleration and collide on impact return to default settings.
  21. /// </summary>
  22. public void OnGotUnequipped(EntityUid uid, SkatesComponent component, ClothingGotUnequippedEvent args)
  23. {
  24. if (!TryComp(args.Wearer, out MovementSpeedModifierComponent? speedModifier))
  25. return;
  26. _move.ChangeFriction(args.Wearer, MovementSpeedModifierComponent.DefaultFriction, MovementSpeedModifierComponent.DefaultFrictionNoInput, MovementSpeedModifierComponent.DefaultAcceleration, speedModifier);
  27. _impact.ChangeCollide(args.Wearer, component.DefaultMinimumSpeed, component.DefaultStunSeconds, component.DefaultDamageCooldown, component.DefaultSpeedDamage);
  28. }
  29. /// <summary>
  30. /// When item is equipped into the shoe slot, friction, acceleration and collide on impact are adjusted.
  31. /// </summary>
  32. private void OnGotEquipped(EntityUid uid, SkatesComponent component, ClothingGotEquippedEvent args)
  33. {
  34. _move.ChangeFriction(args.Wearer, component.Friction, component.FrictionNoInput, component.Acceleration);
  35. _impact.ChangeCollide(args.Wearer, component.MinimumSpeed, component.StunSeconds, component.DamageCooldown, component.SpeedDamage);
  36. }
  37. }