Spacelube slide (#24801)

* Space lube now makes you slide

* review

* oh lord he slippin

---------

Co-authored-by: metalgearsloth <comedian_vs_clown@hotmail.com>
This commit is contained in:
Arendian
2024-02-01 11:39:10 +01:00
committed by GitHub
parent c4f275bc53
commit 4f3b8d740c
7 changed files with 112 additions and 9 deletions

View File

@@ -0,0 +1,22 @@
using Robust.Shared.GameStates;
namespace Content.Shared.Slippery;
/// <summary>
/// Applies continuous movement to the attached entity when colliding with super slipper entities.
/// </summary>
[RegisterComponent, NetworkedComponent, AutoGenerateComponentState]
public sealed partial class SlidingComponent : Component
{
/// <summary>
/// A list of SuperSlippery entities the entity with this component is colliding with.
/// </summary>
[DataField, AutoNetworkedField]
public HashSet<EntityUid> CollidingEntities = new ();
/// <summary>
/// The friction modifier that will be applied to any friction calculations.
/// </summary>
[DataField, AutoNetworkedField]
public float FrictionModifier;
}

View File

@@ -0,0 +1,63 @@
using Content.Shared.Movement.Events;
using Content.Shared.Standing;
using Content.Shared.Stunnable;
using Robust.Shared.Physics.Events;
namespace Content.Shared.Slippery;
public sealed class SlidingSystem : EntitySystem
{
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<SlidingComponent, TileFrictionEvent>(OnSlideAttempt);
SubscribeLocalEvent<SlidingComponent, StoodEvent>(OnStand);
SubscribeLocalEvent<SlidingComponent, StartCollideEvent>(OnStartCollide);
SubscribeLocalEvent<SlidingComponent, EndCollideEvent>(OnEndCollide);
}
/// <summary>
/// Modify the friction by the frictionModifier stored on the component.
/// </summary>
private void OnSlideAttempt(EntityUid uid, SlidingComponent component, ref TileFrictionEvent args)
{
args.Modifier = component.FrictionModifier;
}
/// <summary>
/// Remove the component when the entity stands up again.
/// </summary>
private void OnStand(EntityUid uid, SlidingComponent component, ref StoodEvent args)
{
RemComp<SlidingComponent>(uid);
}
/// <summary>
/// Sets friction to 0 if colliding with a SuperSlippery Entity.
/// </summary>
private void OnStartCollide(EntityUid uid, SlidingComponent component, ref StartCollideEvent args)
{
if (!TryComp<SlipperyComponent>(args.OtherEntity, out var slippery) || !slippery.SuperSlippery)
return;
component.CollidingEntities.Add(args.OtherEntity);
component.FrictionModifier = 0;
Dirty(uid, component);
}
/// <summary>
/// Set friction to normal when ending collision with a SuperSlippery entity.
/// </summary>
private void OnEndCollide(EntityUid uid, SlidingComponent component, ref EndCollideEvent args)
{
if (!component.CollidingEntities.Remove(args.OtherEntity))
return;
if (component.CollidingEntities.Count == 0)
component.FrictionModifier = SharedStunSystem.KnockDownModifier;
Dirty(uid, component);
}
}

View File

@@ -23,7 +23,6 @@ namespace Content.Shared.Slippery
/// <summary>
/// How many seconds the mob will be paralyzed for.
/// </summary>
[ViewVariables(VVAccess.ReadWrite)]
[DataField, AutoNetworkedField]
[Access(Other = AccessPermissions.ReadWrite)]
public float ParalyzeTime = 3f;
@@ -31,9 +30,16 @@ namespace Content.Shared.Slippery
/// <summary>
/// The entity's speed will be multiplied by this to slip it forwards.
/// </summary>
[ViewVariables(VVAccess.ReadWrite)]
[DataField, AutoNetworkedField]
[Access(Other = AccessPermissions.ReadWrite)]
public float LaunchForwardsMultiplier = 1f;
/// <summary>
/// If this is true, any slipping entity loses its friction until
/// it's not colliding with any SuperSlippery entities anymore.
/// </summary>
[DataField, AutoNetworkedField]
[Access(Other = AccessPermissions.ReadWrite)]
public bool SuperSlippery;
}
}

View File

@@ -5,7 +5,6 @@ using Content.Shared.StatusEffect;
using Content.Shared.StepTrigger.Systems;
using Content.Shared.Stunnable;
using JetBrains.Annotations;
using Robust.Shared.Audio;
using Robust.Shared.Audio.Systems;
using Robust.Shared.Containers;
using Robust.Shared.Physics.Components;
@@ -60,7 +59,7 @@ public sealed class SlipperySystem : EntitySystem
private void TrySlip(EntityUid uid, SlipperyComponent component, EntityUid other)
{
if (HasComp<KnockedDownComponent>(other))
if (HasComp<KnockedDownComponent>(other) && !component.SuperSlippery)
return;
var attemptEv = new SlipAttemptEvent();
@@ -71,9 +70,14 @@ public sealed class SlipperySystem : EntitySystem
var ev = new SlipEvent(other);
RaiseLocalEvent(uid, ref ev);
if (TryComp(other, out PhysicsComponent? physics))
if (TryComp(other, out PhysicsComponent? physics) && !HasComp<SlidingComponent>(other))
{
_physics.SetLinearVelocity(other, physics.LinearVelocity * component.LaunchForwardsMultiplier, body: physics);
if (component.SuperSlippery)
EnsureComp<SlidingComponent>(other);
}
var playSound = !_statusEffects.HasStatusEffect(other, "KnockedDown");
_stun.TryParalyze(other, TimeSpan.FromSeconds(component.ParalyzeTime), true);