Generic clothing speed modifiers + hardsuit slowdown (#7094)

This commit is contained in:
mirrorcult 2022-03-13 23:03:49 -07:00 committed by GitHub
parent 1652498830
commit 8005cf31bb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 136 additions and 34 deletions

View File

@ -5,16 +5,5 @@ namespace Content.Client.Clothing
{
public sealed class MagbootsSystem : SharedMagbootsSystem
{
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<MagbootsComponent, RefreshMovementSpeedModifiersEvent>(OnRefreshMovespeed);
}
private void OnRefreshMovespeed(EntityUid uid, MagbootsComponent component, RefreshMovementSpeedModifiersEvent args)
{
args.ModifySpeed(component.WalkSpeedModifier, component.SprintSpeedModifier);
}
}
}

View File

@ -21,7 +21,6 @@ namespace Content.Server.Clothing
SubscribeLocalEvent<MagbootsComponent, GetVerbsEvent<ActivationVerb>>(AddToggleVerb);
SubscribeLocalEvent<MagbootsComponent, SlipAttemptEvent>(OnSlipAttempt);
SubscribeLocalEvent<MagbootsComponent, RefreshMovementSpeedModifiersEvent>(OnRefreshMovespeed);
SubscribeLocalEvent<MagbootsComponent, GotEquippedEvent>(OnGotEquipped);
SubscribeLocalEvent<MagbootsComponent, GotUnequippedEvent>(OnGotUnequipped);
}
@ -63,11 +62,6 @@ namespace Content.Server.Clothing
}
}
private void OnRefreshMovespeed(EntityUid uid, MagbootsComponent component, RefreshMovementSpeedModifiersEvent args)
{
args.ModifySpeed(component.WalkSpeedModifier, component.SprintSpeedModifier);
}
private void AddToggleVerb(EntityUid uid, MagbootsComponent component, GetVerbsEvent<ActivationVerb> args)
{
if (!args.CanAccess || !args.CanInteract)

View 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;
}
}

View 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);
}
}

View File

@ -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

View File

@ -20,6 +20,9 @@
lowPressureMultiplier: 100
- type: TemperatureProtection
coefficient: 0.001 # yes it needs to be this low, fires are fucking deadly apparently!!!!
- type: ClothingSpeedModifier
walkModifier: 0.6
sprintModifier: 0.4
- type: Clothing
size: 50
- type: Armor

View File

@ -33,6 +33,9 @@
- type: PressureProtection
highPressureMultiplier: 0.5
lowPressureMultiplier: 100
- type: ClothingSpeedModifier
walkModifier: 0.8
sprintModifier: 0.8
- type: Armor
modifiers:
coefficients:
@ -55,6 +58,9 @@
- type: PressureProtection
highPressureMultiplier: 0.45
lowPressureMultiplier: 100
- type: ClothingSpeedModifier
walkModifier: 1.0
sprintModifier: 1.0
- type: Armor
modifiers:
coefficients:
@ -133,6 +139,9 @@
sprite: Clothing/OuterClothing/Hardsuits/eva.rsi
- type: Clothing
sprite: Clothing/OuterClothing/Hardsuits/eva.rsi
- type: ClothingSpeedModifier
walkModifier: 0.8
sprintModifier: 0.8
- type: PressureProtection
highPressureMultiplier: 1
lowPressureMultiplier: 100
@ -152,6 +161,9 @@
- type: PressureProtection
highPressureMultiplier: 1
lowPressureMultiplier: 100
- type: ClothingSpeedModifier
walkModifier: 0.8
sprintModifier: 0.8
- type: entity
parent: ClothingOuterHardsuitBase
@ -268,6 +280,9 @@
- type: PressureProtection
highPressureMultiplier: 0.45
lowPressureMultiplier: 100
- type: ClothingSpeedModifier
walkModifier: 1.0
sprintModifier: 1.0
- type: Armor
modifiers:
coefficients:
@ -290,6 +305,9 @@
- type: PressureProtection
highPressureMultiplier: 0.45
lowPressureMultiplier: 100
- type: ClothingSpeedModifier
walkModifier: 0.8
sprintModifier: 0.8
- type: Armor
modifiers:
coefficients:

View File

@ -17,6 +17,10 @@
description: action-decription-magboot-toggle
itemIconStyle: NoItem
event: !type:ToggleActionEvent
- type: ClothingSpeedModifier
walkModifier: 0.85
sprintModifier: 0.65
enabled: false
- type: entity
parent: ClothingShoesBootsMag
@ -30,5 +34,7 @@
- type: Clothing
sprite: Clothing/Shoes/Boots/magboots-advanced.rsi
- type: Magboots
walkMoveCoeffecient: 1
sprintMoveCoeffecient: 1
- type: ClothingSpeedModifier
walkModifier: 1
sprintModifier: 1
enabled: false