Generic clothing speed modifiers + hardsuit slowdown (#7094)
This commit is contained in:
36
Content.Shared/Clothing/ClothingSpeedModifierComponent.cs
Normal file
36
Content.Shared/Clothing/ClothingSpeedModifierComponent.cs
Normal file
@@ -0,0 +1,36 @@
|
||||
using Robust.Shared.GameStates;
|
||||
using Robust.Shared.Serialization;
|
||||
|
||||
namespace Content.Shared.Clothing;
|
||||
|
||||
[RegisterComponent, NetworkedComponent, Friend(typeof(ClothingSpeedModifierSystem))]
|
||||
public sealed class ClothingSpeedModifierComponent : Component
|
||||
{
|
||||
[DataField("walkModifier", required: true)] [ViewVariables(VVAccess.ReadWrite)]
|
||||
public float WalkModifier = 1.0f;
|
||||
|
||||
[DataField("sprintModifier", required: true)] [ViewVariables(VVAccess.ReadWrite)]
|
||||
public float SprintModifier = 1.0f;
|
||||
|
||||
/// <summary>
|
||||
/// Is this clothing item currently 'actively' slowing you down?
|
||||
/// e.g. magboots can be turned on and off.
|
||||
/// </summary>
|
||||
[DataField("enabled")] public bool Enabled = true;
|
||||
}
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
public sealed class ClothingSpeedModifierComponentState : ComponentState
|
||||
{
|
||||
public float WalkModifier;
|
||||
public float SprintModifier;
|
||||
|
||||
public bool Enabled;
|
||||
|
||||
public ClothingSpeedModifierComponentState(float walkModifier, float sprintModifier, bool enabled)
|
||||
{
|
||||
WalkModifier = walkModifier;
|
||||
SprintModifier = sprintModifier;
|
||||
Enabled = enabled;
|
||||
}
|
||||
}
|
||||
70
Content.Shared/Clothing/ClothingSpeedModifierSystem.cs
Normal file
70
Content.Shared/Clothing/ClothingSpeedModifierSystem.cs
Normal file
@@ -0,0 +1,70 @@
|
||||
using Content.Shared.Movement.EntitySystems;
|
||||
using Robust.Shared.Containers;
|
||||
using Robust.Shared.GameStates;
|
||||
|
||||
namespace Content.Shared.Clothing;
|
||||
|
||||
public sealed class ClothingSpeedModifierSystem : EntitySystem
|
||||
{
|
||||
[Dependency] private readonly MovementSpeedModifierSystem _movementSpeed = default!;
|
||||
[Dependency] private readonly SharedContainerSystem _container = default!;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
SubscribeLocalEvent<ClothingSpeedModifierComponent, ComponentGetState>(OnGetState);
|
||||
SubscribeLocalEvent<ClothingSpeedModifierComponent, ComponentHandleState>(OnHandleState);
|
||||
SubscribeLocalEvent<ClothingSpeedModifierComponent, RefreshMovementSpeedModifiersEvent>(OnRefreshMoveSpeed);
|
||||
}
|
||||
|
||||
// Public API
|
||||
|
||||
public void SetClothingSpeedModifierEnabled(EntityUid uid, bool enabled, ClothingSpeedModifierComponent? component = null)
|
||||
{
|
||||
if (!Resolve(uid, ref component, false))
|
||||
return;
|
||||
|
||||
if (component.Enabled != enabled)
|
||||
{
|
||||
component.Enabled = enabled;
|
||||
Dirty(component);
|
||||
|
||||
// inventory system will automatically hook into the event raised by this and update accordingly
|
||||
if (_container.TryGetContainingContainer(uid, out var container))
|
||||
{
|
||||
_movementSpeed.RefreshMovementSpeedModifiers(container.Owner);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Event handlers
|
||||
|
||||
private void OnGetState(EntityUid uid, ClothingSpeedModifierComponent component, ref ComponentGetState args)
|
||||
{
|
||||
args.State = new ClothingSpeedModifierComponentState(component.WalkModifier, component.SprintModifier, component.Enabled);
|
||||
}
|
||||
|
||||
private void OnHandleState(EntityUid uid, ClothingSpeedModifierComponent component, ref ComponentHandleState args)
|
||||
{
|
||||
if (args.Current is ClothingSpeedModifierComponentState state)
|
||||
{
|
||||
component.WalkModifier = state.WalkModifier;
|
||||
component.SprintModifier = state.SprintModifier;
|
||||
component.Enabled = state.Enabled;
|
||||
|
||||
if (_container.TryGetContainingContainer(uid, out var container))
|
||||
{
|
||||
_movementSpeed.RefreshMovementSpeedModifiers(container.Owner);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void OnRefreshMoveSpeed(EntityUid uid, ClothingSpeedModifierComponent component, RefreshMovementSpeedModifiersEvent args)
|
||||
{
|
||||
if (!component.Enabled)
|
||||
return;
|
||||
|
||||
args.ModifySpeed(component.WalkModifier, component.SprintModifier);
|
||||
}
|
||||
}
|
||||
@@ -18,22 +18,8 @@ namespace Content.Shared.Clothing
|
||||
protected void OnChanged()
|
||||
{
|
||||
EntitySystem.Get<SharedActionsSystem>().SetToggled(ToggleAction, On);
|
||||
|
||||
// inventory system will automatically hook into the event raised by this and update accordingly
|
||||
if (Owner.TryGetContainer(out var container))
|
||||
{
|
||||
EntitySystem.Get<MovementSpeedModifierSystem>().RefreshMovementSpeedModifiers(container.Owner);
|
||||
}
|
||||
EntitySystem.Get<ClothingSpeedModifierSystem>().SetClothingSpeedModifierEnabled(Owner, On);
|
||||
}
|
||||
[DataField("walkMoveCoeffecient", required: true)]
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
public float WalkMoveCoeffecient = 0.85f;
|
||||
|
||||
[DataField("sprintMoveCoeffecient", required: true)]
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
public float SprintMoveCoeffecient = 0.65f;
|
||||
public float WalkSpeedModifier => On ? WalkMoveCoeffecient : 1;
|
||||
public float SprintSpeedModifier => On ? SprintMoveCoeffecient : 1;
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
public sealed class MagbootsComponentState : ComponentState
|
||||
|
||||
Reference in New Issue
Block a user