Fix Whoopie Cushions from lagging the game. (#39194)

This commit is contained in:
Princess Cheeseballs
2025-08-08 15:11:13 -07:00
committed by GitHub
parent 2b8145ce87
commit ce7b7c1adf
5 changed files with 72 additions and 12 deletions

View File

@@ -30,10 +30,18 @@ public sealed class SlipperySystem : EntitySystem
[Dependency] private readonly SharedPhysicsSystem _physics = default!;
[Dependency] private readonly SpeedModifierContactsSystem _speedModifier = default!;
private EntityQuery<KnockedDownComponent> _knockedDownQuery;
private EntityQuery<PhysicsComponent> _physicsQuery;
private EntityQuery<SlidingComponent> _slidingQuery;
public override void Initialize()
{
base.Initialize();
_knockedDownQuery = GetEntityQuery<KnockedDownComponent>();
_physicsQuery = GetEntityQuery<PhysicsComponent>();
_slidingQuery = GetEntityQuery<SlidingComponent>();
SubscribeLocalEvent<SlipperyComponent, StepTriggerAttemptEvent>(HandleAttemptCollide);
SubscribeLocalEvent<SlipperyComponent, StepTriggeredOffEvent>(HandleStepTrigger);
SubscribeLocalEvent<NoSlipComponent, SlipAttemptEvent>(OnNoSlipAttempt);
@@ -92,7 +100,8 @@ public sealed class SlipperySystem : EntitySystem
public void TrySlip(EntityUid uid, SlipperyComponent component, EntityUid other, bool requiresContact = true)
{
if (HasComp<KnockedDownComponent>(other) && !component.SlipData.SuperSlippery)
var knockedDown = _knockedDownQuery.HasComp(other);
if (knockedDown && !component.SlipData.SuperSlippery)
return;
var attemptEv = new SlipAttemptEvent(uid);
@@ -111,7 +120,7 @@ public sealed class SlipperySystem : EntitySystem
var ev = new SlipEvent(other);
RaiseLocalEvent(uid, ref ev);
if (TryComp(other, out PhysicsComponent? physics) && !HasComp<SlidingComponent>(other))
if (_physicsQuery.TryComp(other, out var physics) && !_slidingQuery.HasComp(other))
{
_physics.SetLinearVelocity(other, physics.LinearVelocity * component.SlipData.LaunchForwardsMultiplier, body: physics);
@@ -120,16 +129,23 @@ public sealed class SlipperySystem : EntitySystem
}
// Preventing from playing the slip sound and stunning when you are already knocked down.
if (!HasComp<KnockedDownComponent>(other))
if (!knockedDown)
{
// Status effects should handle a TimeSpan of 0 properly...
_stun.TryUpdateStunDuration(other, component.SlipData.StunTime);
_stamina.TakeStaminaDamage(other, component.StaminaDamage); // Note that this can stamCrit
_movementMod.TryUpdateFrictionModDuration(
other,
component.FrictionStatusTime,
component.SlipData.SlipFriction,
component.SlipData.SlipFriction
);
// Don't make a new status effect entity if the entity wouldn't do anything
if (!MathHelper.CloseTo(component.SlipData.SlipFriction, 1f))
{
_movementMod.TryUpdateFrictionModDuration(
other,
component.FrictionStatusTime,
component.SlipData.SlipFriction
);
}
_stamina.TakeStaminaDamage(other, component.StaminaDamage); // Note that this can StamCrit
_audio.PlayPredicted(component.SlipSound, other, other);
}