Mirror speed penalty for worn duffels and hardsuits when in-hand (#22168)

* Add speed penalty for holding hardsuits and duffels

* just inherit from ClothingSpeedModifier

* comment godo
This commit is contained in:
Nemanja
2023-12-06 22:41:29 -05:00
committed by GitHub
parent 6509681f00
commit fb10dff335
11 changed files with 150 additions and 0 deletions

View File

@@ -0,0 +1,34 @@
using Content.Shared.Clothing;
using Robust.Shared.GameStates;
namespace Content.Shared.Item;
/// <summary>
/// This is used for items that change your speed when they are held.
/// </summary>
/// <remarks>
/// This is separate from <see cref="ClothingSpeedModifierComponent"/> because things like boots increase/decrease speed when worn, but
/// shouldn't do that when just held in hand.
/// </remarks>
[RegisterComponent, NetworkedComponent, AutoGenerateComponentState]
[Access(typeof(HeldSpeedModifierSystem))]
public sealed partial class HeldSpeedModifierComponent : Component
{
/// <summary>
/// A multiplier applied to the walk speed.
/// </summary>
[DataField] [ViewVariables(VVAccess.ReadWrite), AutoNetworkedField]
public float WalkModifier = 1.0f;
/// <summary>
/// A multiplier applied to the sprint speed.
/// </summary>
[DataField] [ViewVariables(VVAccess.ReadWrite), AutoNetworkedField]
public float SprintModifier = 1.0f;
/// <summary>
/// If true, values from <see cref="ClothingSpeedModifierComponent"/> will attempted to be used before the ones in this component.
/// </summary>
[DataField, ViewVariables(VVAccess.ReadWrite), AutoNetworkedField]
public bool MirrorClothingModifier = true;
}

View File

@@ -0,0 +1,44 @@
using Content.Shared.Clothing;
using Content.Shared.Hands;
using Content.Shared.Movement.Systems;
namespace Content.Shared.Item;
/// <summary>
/// This handles <see cref="HeldSpeedModifierComponent"/>
/// </summary>
public sealed class HeldSpeedModifierSystem : EntitySystem
{
[Dependency] private readonly MovementSpeedModifierSystem _movementSpeedModifier = default!;
/// <inheritdoc/>
public override void Initialize()
{
SubscribeLocalEvent<HeldSpeedModifierComponent, GotEquippedHandEvent>(OnGotEquippedHand);
SubscribeLocalEvent<HeldSpeedModifierComponent, GotUnequippedHandEvent>(OnGotUnequippedHand);
SubscribeLocalEvent<HeldSpeedModifierComponent, HeldRelayedEvent<RefreshMovementSpeedModifiersEvent>>(OnRefreshMovementSpeedModifiers);
}
private void OnGotEquippedHand(Entity<HeldSpeedModifierComponent> ent, ref GotEquippedHandEvent args)
{
_movementSpeedModifier.RefreshMovementSpeedModifiers(args.User);
}
private void OnGotUnequippedHand(Entity<HeldSpeedModifierComponent> ent, ref GotUnequippedHandEvent args)
{
_movementSpeedModifier.RefreshMovementSpeedModifiers(args.User);
}
private void OnRefreshMovementSpeedModifiers(EntityUid uid, HeldSpeedModifierComponent component, HeldRelayedEvent<RefreshMovementSpeedModifiersEvent> args)
{
var walkMod = component.WalkModifier;
var sprintMod = component.SprintModifier;
if (component.MirrorClothingModifier && TryComp<ClothingSpeedModifierComponent>(uid, out var clothingSpeedModifier))
{
walkMod = clothingSpeedModifier.WalkModifier;
sprintMod = clothingSpeedModifier.SprintModifier;
}
args.Args.ModifySpeed(walkMod, sprintMod);
}
}