Fix Whoopie Cushions from lagging the game. (#39194)
This commit is contained in:
committed by
GitHub
parent
2b8145ce87
commit
ce7b7c1adf
@@ -194,6 +194,16 @@ public sealed class MovementModStatusSystem : EntitySystem
|
||||
return TryUpdateMovementStatus(uid, status, speedModifier, speedModifier);
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="TryAddFrictionModDuration(EntityUid,TimeSpan,float,float)"/>
|
||||
public bool TryAddFrictionModDuration(
|
||||
EntityUid uid,
|
||||
TimeSpan duration,
|
||||
float friction
|
||||
)
|
||||
{
|
||||
return TryAddFrictionModDuration(uid, duration, friction, friction);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Apply friction modifier with provided duration,
|
||||
/// or incrementing duration of existing.
|
||||
@@ -214,6 +224,16 @@ public sealed class MovementModStatusSystem : EntitySystem
|
||||
&& TrySetFrictionStatus(status.Value, friction, acceleration, uid);
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="TryUpdateFrictionModDuration(EntityUid,TimeSpan,float,float)"/>
|
||||
public bool TryUpdateFrictionModDuration(
|
||||
EntityUid uid,
|
||||
TimeSpan duration,
|
||||
float friction
|
||||
)
|
||||
{
|
||||
return TryUpdateFrictionModDuration(uid,duration, friction, friction);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Apply friction modifier with provided duration,
|
||||
/// or update duration of existing if it is lesser than provided duration.
|
||||
|
||||
@@ -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
|
||||
|
||||
// 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,
|
||||
component.SlipData.SlipFriction
|
||||
);
|
||||
}
|
||||
|
||||
_stamina.TakeStaminaDamage(other, component.StaminaDamage); // Note that this can StamCrit
|
||||
|
||||
_audio.PlayPredicted(component.SlipSound, other, other);
|
||||
}
|
||||
|
||||
|
||||
@@ -22,6 +22,13 @@ public sealed partial class StatusEffectsSystem
|
||||
TimeSpan duration
|
||||
)
|
||||
{
|
||||
if (duration == TimeSpan.Zero)
|
||||
{
|
||||
statusEffect = null;
|
||||
return false;
|
||||
}
|
||||
|
||||
// We check to make sure time is greater than zero here because sometimes you want to use TryAddStatusEffect to remove duration instead...
|
||||
if (!TryGetStatusEffect(target, effectProto, out statusEffect))
|
||||
return TryAddStatusEffect(target, effectProto, out statusEffect, duration);
|
||||
|
||||
@@ -53,6 +60,12 @@ public sealed partial class StatusEffectsSystem
|
||||
TimeSpan? duration = null
|
||||
)
|
||||
{
|
||||
if (duration <= TimeSpan.Zero)
|
||||
{
|
||||
statusEffect = null;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!TryGetStatusEffect(target, effectProto, out statusEffect))
|
||||
return TryAddStatusEffect(target, effectProto, out statusEffect, duration);
|
||||
|
||||
@@ -83,6 +96,12 @@ public sealed partial class StatusEffectsSystem
|
||||
TimeSpan? duration = null
|
||||
)
|
||||
{
|
||||
if (duration <= TimeSpan.Zero)
|
||||
{
|
||||
statusEffect = null;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!TryGetStatusEffect(target, effectProto, out statusEffect))
|
||||
return TryAddStatusEffect(target, effectProto, out statusEffect, duration);
|
||||
|
||||
|
||||
@@ -202,6 +202,10 @@ public sealed partial class StatusEffectsSystem : EntitySystem
|
||||
)
|
||||
{
|
||||
statusEffect = null;
|
||||
|
||||
if (duration <= TimeSpan.Zero)
|
||||
return false;
|
||||
|
||||
if (!CanAddStatusEffect(target, effectProto))
|
||||
return false;
|
||||
|
||||
|
||||
@@ -911,6 +911,7 @@
|
||||
delay: 0.8
|
||||
- type: Slippery
|
||||
staminaDamage: 0
|
||||
frictionStatusTime: 0
|
||||
slipData:
|
||||
stunTime: 0
|
||||
knockdownTime: 0
|
||||
|
||||
Reference in New Issue
Block a user