* Implements mobility impairment * Implements mobility impairment * Implements mobility impairment * Removed white cane related stuff (impaired cane replacement and removed mobility aid component) * fix development.toml * Implements slower standing * Prevent speed stacking by checking if the entity is already holding a mobility aid * Move all speed handling into ImpairedMobilitySystem, added comments, made it so wielding a mobility aid doesn't grant the recovery benefit * Move all speed handling into ImpairedMobilitySystem, added comments, made it so wielding a mobility aid doesn't grant the recovery benefit * remove unused file * Shorten description * Apply suggestions Co-authored-by: Princess Cheeseballs <66055347+Princess-Cheeseballs@users.noreply.github.com> * Suggestion cleanup * formatting fix and removed extra datafield stuff * added comment, fixed slashes, yadda yadda * summary comments * removed a word * Add trait to clone whitelist * Fix clone.yml * my own review --------- Co-authored-by: Princess Cheeseballs <66055347+Princess-Cheeseballs@users.noreply.github.com> Co-authored-by: ScarKy0 <scarky0@onet.eu>
71 lines
2.5 KiB
C#
71 lines
2.5 KiB
C#
using Content.Shared.Movement.Systems;
|
|
using Content.Shared.Stunnable;
|
|
using Content.Shared.Hands.EntitySystems;
|
|
using Content.Shared.Hands.Components;
|
|
using Content.Shared.Wieldable.Components;
|
|
|
|
namespace Content.Shared.Traits.Assorted;
|
|
|
|
/// <summary>
|
|
/// Handles <see cref="ImpairedMobilityComponent"/>
|
|
/// </summary>
|
|
public sealed class ImpairedMobilitySystem : EntitySystem
|
|
{
|
|
[Dependency] private readonly SharedHandsSystem _hands = default!;
|
|
[Dependency] private readonly MovementSpeedModifierSystem _speedModifier = default!;
|
|
public override void Initialize()
|
|
{
|
|
SubscribeLocalEvent<ImpairedMobilityComponent, ComponentInit>(OnInit);
|
|
SubscribeLocalEvent<ImpairedMobilityComponent, ComponentShutdown>(OnShutdown);
|
|
SubscribeLocalEvent<ImpairedMobilityComponent, RefreshMovementSpeedModifiersEvent>(OnRefreshMovementSpeed);
|
|
SubscribeLocalEvent<ImpairedMobilityComponent, GetStandUpTimeEvent>(OnGetStandUpTime);
|
|
}
|
|
|
|
private void OnInit(Entity<ImpairedMobilityComponent> ent, ref ComponentInit args)
|
|
{
|
|
_speedModifier.RefreshMovementSpeedModifiers(ent);
|
|
}
|
|
|
|
private void OnShutdown(Entity<ImpairedMobilityComponent> ent, ref ComponentShutdown args)
|
|
{
|
|
_speedModifier.RefreshMovementSpeedModifiers(ent);
|
|
}
|
|
|
|
// Handles movement speed for entities with impaired mobility.
|
|
// Applies a speed penalty, but counteracts it if the entity is holding a non-wielded mobility aid.
|
|
private void OnRefreshMovementSpeed(Entity<ImpairedMobilityComponent> ent, ref RefreshMovementSpeedModifiersEvent args)
|
|
{
|
|
if (HasMobilityAid(ent.Owner))
|
|
return;
|
|
|
|
args.ModifySpeed(ent.Comp.SpeedModifier);
|
|
}
|
|
|
|
// Increases the time it takes for entities to stand up from being knocked down.
|
|
private void OnGetStandUpTime(Entity<ImpairedMobilityComponent> ent, ref GetStandUpTimeEvent args)
|
|
{
|
|
args.DoAfterTime *= ent.Comp.StandUpTimeModifier;
|
|
}
|
|
|
|
// Checks if the entity is holding any non-wielded mobility aids.
|
|
private bool HasMobilityAid(Entity<HandsComponent?> entity)
|
|
{
|
|
if (!Resolve(entity, ref entity.Comp, false))
|
|
return false;
|
|
|
|
foreach (var held in _hands.EnumerateHeld(entity))
|
|
{
|
|
if (!HasComp<MobilityAidComponent>(held))
|
|
continue;
|
|
|
|
// Makes sure it's not wielded yet
|
|
if (TryComp<WieldableComponent>(held, out var wieldable) && wieldable.Wielded)
|
|
continue;
|
|
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
}
|