- add: Crawl

This commit is contained in:
2024-02-24 21:20:43 +03:00
parent e15ae4ced8
commit b63a46e032
7 changed files with 152 additions and 0 deletions

View File

@@ -0,0 +1,10 @@
using Robust.Shared.GameStates;
namespace Content.Shared._Amour.Crawl;
[RegisterComponent, NetworkedComponent]
public sealed partial class CrawlComponent : Component
{
public float SprintSpeedModifier { get; set; } = 0.4f;
public float WalkSpeedModifier { get; set; } = 0.4f;
}

View File

@@ -0,0 +1,7 @@
namespace Content.Shared._Amour.Crawl;
[RegisterComponent]
public sealed partial class CrawlableComponent : Component
{
}

View File

@@ -0,0 +1,70 @@
using Content.Shared.Buckle;
using Content.Shared.Movement.Systems;
using Content.Shared.Standing;
using Content.Shared.StatusEffect;
namespace Content.Shared._Amour.Crawl;
public abstract class SharedCrawlSystem : EntitySystem
{
[Dependency] private readonly StatusEffectsSystem _statusEffectsSystem = default!;
[Dependency] private readonly MovementSpeedModifierSystem _speed = default!;
[Dependency] private readonly StandingStateSystem _standingStateSystem = default!;
[Dependency] private readonly SharedBuckleSystem _buckle = default!;
public override void Initialize()
{
SubscribeLocalEvent<CrawlComponent, ComponentInit>(OnInit);
SubscribeLocalEvent<CrawlComponent, ComponentShutdown>(OnShutdown);
SubscribeLocalEvent<CrawlableComponent, ComponentShutdown>(OnCrawlShutdown);
SubscribeLocalEvent<CrawlComponent, StoodEvent>(OnStood);
SubscribeLocalEvent<CrawlComponent, RefreshMovementSpeedModifiersEvent>(OnRefresh);
}
private void OnRefresh(EntityUid uid, CrawlComponent component, RefreshMovementSpeedModifiersEvent args)
{
args.ModifySpeed(component.WalkSpeedModifier, component.SprintSpeedModifier);
}
private void OnInit(EntityUid uid, CrawlComponent component, ComponentInit args)
{
if (_buckle.TryUnbuckle(uid, uid) || !_standingStateSystem.Down(uid, true, false))
{
DisableCrawl(uid);
return;
}
_speed.RefreshMovementSpeedModifiers(uid);
}
private void OnCrawlShutdown(EntityUid uid, CrawlableComponent component, ComponentShutdown args)
{
DisableCrawl(uid);
}
private void OnStood(EntityUid uid, CrawlComponent component, StoodEvent args)
{
if (component.LifeStage == ComponentLifeStage.Stopping)
return;
DisableCrawl(uid);
}
private void OnShutdown(EntityUid uid, CrawlComponent component, ComponentShutdown args)
{
_standingStateSystem.Stand(uid);
component.SprintSpeedModifier = 1f;
component.WalkSpeedModifier = 1f;
_speed.RefreshMovementSpeedModifiers(uid);
}
public void EnableCrawl(EntityUid uid)
{
EnsureComp<CrawlComponent>(uid);
}
public void DisableCrawl(EntityUid uid)
{
RemComp<CrawlComponent>(uid);
}
}