6
StarHorizon_Public/Content.Shared/_EE/Carrying/CarryingSlowdownSystem.cs
2025-11-15 12:24:44 +03:00

47 lines
1.9 KiB
C#

using Content.Shared.Movement.Systems;
using Robust.Shared.GameStates;
namespace Content.Shared.Carrying
{
public sealed class CarryingSlowdownSystem : EntitySystem
{
[Dependency] private readonly MovementSpeedModifierSystem _movementSpeed = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<CarryingSlowdownComponent, ComponentGetState>(OnGetState);
SubscribeLocalEvent<CarryingSlowdownComponent, ComponentHandleState>(OnHandleState);
SubscribeLocalEvent<CarryingSlowdownComponent, RefreshMovementSpeedModifiersEvent>(OnRefreshMoveSpeed);
}
public void SetModifier(EntityUid uid, float walkSpeedModifier, float sprintSpeedModifier, CarryingSlowdownComponent? component = null)
{
if (!Resolve(uid, ref component))
return;
component.WalkModifier = walkSpeedModifier;
component.SprintModifier = sprintSpeedModifier;
_movementSpeed.RefreshMovementSpeedModifiers(uid);
}
private void OnGetState(EntityUid uid, CarryingSlowdownComponent component, ref ComponentGetState args)
{
args.State = new CarryingSlowdownComponentState(component.WalkModifier, component.SprintModifier);
}
private void OnHandleState(EntityUid uid, CarryingSlowdownComponent component, ref ComponentHandleState args)
{
if (args.Current is not CarryingSlowdownComponentState state)
return;
component.WalkModifier = state.WalkModifier;
component.SprintModifier = state.SprintModifier;
_movementSpeed.RefreshMovementSpeedModifiers(uid);
}
private void OnRefreshMoveSpeed(EntityUid uid, CarryingSlowdownComponent component, RefreshMovementSpeedModifiersEvent args)
{
args.ModifySpeed(component.WalkModifier, component.SprintModifier);
}
}
}