Skip to content

Commit

Permalink
feat(traits): add new trait Slow and Steady
Browse files Browse the repository at this point in the history
Also fixes a bug with Sluggish and Snail-Paced not applying
their speed modifiers until an entity gets their movement
speed adjusted.
  • Loading branch information
angelofallars committed Aug 8, 2024
1 parent ba9a937 commit aa28b49
Show file tree
Hide file tree
Showing 11 changed files with 129 additions and 26 deletions.
2 changes: 1 addition & 1 deletion Content.Server/Standing/LayingDownSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ private void OnRefreshMovementSpeed(EntityUid uid, LayingDownComponent component
if (TryComp<StandingStateComponent>(uid, out var standingState) && standingState.Standing)
return;

args.ModifySpeed(component.DownedSpeedMultiplier, component.DownedSpeedMultiplier);
args.ModifySpeed(component.DownedSpeedMultiplier, component.DownedSpeedMultiplier, bypassImmunity: true);
}

private void OnParentChanged(EntityUid uid, LayingDownComponent component, EntParentChangedMessage args)
Expand Down
19 changes: 0 additions & 19 deletions Content.Server/Traits/Assorted/TraitSpeedModifierSystem.cs

This file was deleted.

23 changes: 21 additions & 2 deletions Content.Shared/Movement/Systems/MovementSpeedModifierSystem.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Content.Shared.Inventory;
using Content.Shared.Movement.Components;
using Content.Shared.Traits.Assorted.Components;
using Robust.Shared.Timing;

namespace Content.Shared.Movement.Systems
Expand All @@ -16,7 +17,11 @@ public void RefreshMovementSpeedModifiers(EntityUid uid, MovementSpeedModifierCo
if (_timing.ApplyingState)
return;

var ev = new RefreshMovementSpeedModifiersEvent();
var isImmune = false;
if (HasComp<SpeedModifierImmunityComponent>(uid))
isImmune = true;

var ev = new RefreshMovementSpeedModifiersEvent(isImmune);
RaiseLocalEvent(uid, ev);

if (MathHelper.CloseTo(ev.WalkSpeedModifier, move.WalkSpeedModifier) &&
Expand Down Expand Up @@ -64,10 +69,24 @@ public sealed class RefreshMovementSpeedModifiersEvent : EntityEventArgs, IInven
public float WalkSpeedModifier { get; private set; } = 1.0f;
public float SprintSpeedModifier { get; private set; } = 1.0f;

public void ModifySpeed(float walk, float sprint)
/// <summary>
/// Whether this entity is immune to most movement speed modifiers.
/// Bypassable by setting bypassImmunity to true.
/// </summary
private bool IsImmune = false;

public void ModifySpeed(float walk, float sprint, bool bypassImmunity = false)
{
if (IsImmune && !bypassImmunity)
return;

WalkSpeedModifier *= walk;
SprintSpeedModifier *= sprint;
}

public RefreshMovementSpeedModifiersEvent(bool isImmune = false)
{
IsImmune = isImmune;
}
}
}
11 changes: 11 additions & 0 deletions Content.Shared/Traits/Assorted/Components/SlipImmunityComponent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using Robust.Shared.GameStates;

namespace Content.Shared.Traits.Assorted.Components;

/// <summary>
/// This is used for traits that make an entity immune to slips
/// </summary>
[RegisterComponent, NetworkedComponent]
public sealed partial class SlipImmunityComponent : Component
{
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using Robust.Shared.GameStates;

namespace Content.Shared.Traits.Assorted.Components;

/// <summary>
/// This is used to make an entity's movement speed constant and
/// never affected by almost all movement speed modifiers.
/// </summary>
[RegisterComponent, NetworkedComponent]
public sealed partial class SpeedModifierImmunityComponent : Component
{
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
namespace Content.Server.Traits.Assorted;
using Robust.Shared.GameStates;

namespace Content.Shared.Traits.Assorted.Components;

/// <summary>
/// This component is used for traits that modify movement speed.
/// </summary>
[RegisterComponent]
[RegisterComponent, NetworkedComponent, AutoGenerateComponentState]
public sealed partial class TraitSpeedModifierComponent : Component
{
[DataField(required: true)]
[DataField, AutoNetworkedField]
public float WalkModifier = 1.0f;

[DataField(required: true)]
[DataField, AutoNetworkedField]
public float SprintModifier = 1.0f;
}
19 changes: 19 additions & 0 deletions Content.Shared/Traits/Assorted/Systems/SlipImmunitySystem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using Content.Shared.Slippery;
using Content.Shared.Traits.Assorted.Components;

namespace Content.Shared.Traits.Assorted.Systems;

public sealed class SlipImmunitySystem : EntitySystem
{
public override void Initialize()
{
base.Initialize();

SubscribeLocalEvent<SlipImmunityComponent, SlipAttemptEvent>(OnSlipAttempt);
}

private void OnSlipAttempt(EntityUid uid, SlipImmunityComponent component, ref SlipAttemptEvent args)
{
args.Cancel();
}
}
31 changes: 31 additions & 0 deletions Content.Shared/Traits/Assorted/Systems/TraitSpeedModifierSystem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using Content.Shared.Movement.Components;
using Content.Shared.Movement.Systems;
using Content.Shared.Traits.Assorted.Components;

namespace Content.Shared.Traits.Assorted.Systems;

public sealed class TraitSpeedModifierSystem : EntitySystem
{
[Dependency] private readonly MovementSpeedModifierSystem _movement = default!;

public override void Initialize()
{
base.Initialize();

SubscribeLocalEvent<TraitSpeedModifierComponent, ComponentStartup>(OnStartup);
SubscribeLocalEvent<TraitSpeedModifierComponent, RefreshMovementSpeedModifiersEvent>(OnRefreshMovementSpeed);
}

private void OnRefreshMovementSpeed(EntityUid uid, TraitSpeedModifierComponent component, RefreshMovementSpeedModifiersEvent args)
{
args.ModifySpeed(component.WalkModifier, component.SprintModifier, bypassImmunity: true);
}

private void OnStartup(EntityUid uid, TraitSpeedModifierComponent component, ComponentStartup args)
{
if (!TryComp<MovementSpeedModifierComponent>(uid, out var move))
return;

_movement.RefreshMovementSpeedModifiers(uid, move);
}
}
6 changes: 6 additions & 0 deletions Resources/Locale/en-US/traits/traits.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -122,3 +122,9 @@ trait-name-WeaponsGeneralist = Weapons Generalist
trait-description-WeaponsGeneralist =
You are a jack of all trades with melee weapons, enabling you to be versatile with your weapon arsenal.
Your melee damage bonus for all Brute damage types (Blunt, Slash, Piercing) becomes 25%.
trait-name-SlowAndSteady = Slow And Steady
trait-description-SlowAndSteady =
"Slow and steady wins the race."
Your movement speed is decreased by [color=yellow]25%[/color].
You gain [color=skyblue]slip immunity[/color], [color=skyblue]slow immunity[/color] (except lying down), and [color=skyblue]speed boost immunity[/color].
2 changes: 2 additions & 0 deletions Resources/Prototypes/Traits/disabilities.yml
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@
traits:
- ParkourTraining
- SnailPaced
- SlowAndSteady
components:
- type: TraitSpeedModifier
sprintModifier: 0.85
Expand All @@ -124,6 +125,7 @@
traits:
- ParkourTraining
- Sluggish
- SlowAndSteady
components:
- type: TraitSpeedModifier
sprintModifier: 0.7
Expand Down
20 changes: 20 additions & 0 deletions Resources/Prototypes/Traits/species.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,23 @@
traits:
- Swashbuckler
- Spearmaster

- type: trait
id: SlowAndSteady
category: Physical
points: -3
components:
- type: SpeedModifierImmunity
- type: TraitSpeedModifier
sprintModifier: 0.75
walkModifier: 0.75
- type: SlipImmunity
requirements:
- !type:CharacterSpeciesRequirement
species:
- Diona
- !type:CharacterTraitRequirement
inverted: true
traits:
- Sluggish
- SnailPaced

0 comments on commit aa28b49

Please sign in to comment.