* Movement acceleration

* tweaks

* Weightless refactor coz fuck it

* CCVars

* weightless movement tweaks

* Some cleanup while I'm here

* dorkpacks

* thanks fork

* fixes

* zoomies

* toggles

* hmm

* yamls

* b

* so true

* Effects refactor

* namespace

* review
This commit is contained in:
metalgearsloth
2022-06-24 17:44:30 +10:00
committed by GitHub
parent 271d34f005
commit 2b6c352aff
107 changed files with 1197 additions and 206 deletions

View File

@@ -0,0 +1,72 @@
using Content.Shared.Movement.Components;
using Robust.Shared.Physics.Dynamics;
namespace Content.Shared.Movement.Systems;
public sealed class SlowContactsSystem : EntitySystem
{
[Dependency] private readonly SharedPhysicsSystem _physics = default!;
[Dependency] private readonly MovementSpeedModifierSystem _speedModifierSystem = default!;
private readonly Dictionary<EntityUid, int> _statusCapableInContact = new();
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<SlowContactsComponent, StartCollideEvent>(OnEntityEnter);
SubscribeLocalEvent<SlowContactsComponent, EndCollideEvent>(OnEntityExit);
SubscribeLocalEvent<SlowsOnContactComponent, RefreshMovementSpeedModifiersEvent>(MovementSpeedCheck);
}
private void MovementSpeedCheck(EntityUid uid, SlowsOnContactComponent component, RefreshMovementSpeedModifiersEvent args)
{
if (!_statusCapableInContact.ContainsKey(uid) || _statusCapableInContact[uid] <= 0)
return;
if (!EntityManager.TryGetComponent<PhysicsComponent>(uid, out var physicsComponent))
return;
var walkSpeed = 1.0f;
var sprintSpeed = 1.0f;
foreach (var colliding in _physics.GetCollidingEntities(physicsComponent))
{
var ent = colliding.Owner;
if (!EntityManager.TryGetComponent<SlowContactsComponent>(ent, out var slowContactsComponent))
continue;
walkSpeed = Math.Min(walkSpeed, slowContactsComponent.WalkSpeedModifier);
sprintSpeed = Math.Min(sprintSpeed, slowContactsComponent.SprintSpeedModifier);
}
args.ModifySpeed(walkSpeed, sprintSpeed);
}
private void OnEntityExit(EntityUid uid, SlowContactsComponent component, EndCollideEvent args)
{
var otherUid = args.OtherFixture.Body.Owner;
if (!EntityManager.HasComponent<MovementSpeedModifierComponent>(otherUid)
|| !EntityManager.HasComponent<SlowsOnContactComponent>(otherUid))
return;
if (!_statusCapableInContact.ContainsKey(otherUid))
Logger.ErrorS("slowscontacts", $"The entity {otherUid} left a body ({uid}) it was never in.");
_statusCapableInContact[otherUid]--;
if (_statusCapableInContact[otherUid] == 0)
EntityManager.RemoveComponentDeferred<SlowsOnContactComponent>(otherUid);
_speedModifierSystem.RefreshMovementSpeedModifiers(otherUid);
}
private void OnEntityEnter(EntityUid uid, SlowContactsComponent component, StartCollideEvent args)
{
var otherUid = args.OtherFixture.Body.Owner;
if (!EntityManager.HasComponent<MovementSpeedModifierComponent>(otherUid))
return;
if (!_statusCapableInContact.ContainsKey(otherUid))
_statusCapableInContact[otherUid] = 0;
_statusCapableInContact[otherUid]++;
EnsureComp<SlowsOnContactComponent>(otherUid);
_speedModifierSystem.RefreshMovementSpeedModifiers(otherUid);
}
}