Roller Skates fixes (#21542)
This commit is contained in:
@@ -1,9 +1,67 @@
|
||||
using Robust.Shared.GameStates;
|
||||
using Content.Shared.Clothing.EntitySystems;
|
||||
|
||||
namespace Content.Shared.Clothing;
|
||||
|
||||
[RegisterComponent]
|
||||
[NetworkedComponent]
|
||||
[Access(typeof(SkatesSystem))]
|
||||
public sealed partial class SkatesComponent : Component
|
||||
{
|
||||
/// <summary>
|
||||
/// the levels of friction the wearer is subected to, higher the number the more friction.
|
||||
/// </summary>
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
public float Friction = 5;
|
||||
|
||||
/// <summary>
|
||||
/// Determines the turning ability of the wearer, Higher the number the less control of their turning ability.
|
||||
/// </summary>
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
public float? FrictionNoInput = 5f;
|
||||
|
||||
/// <summary>
|
||||
/// Sets the speed in which the wearer accelerates to full speed, higher the number the quicker the acceleration.
|
||||
/// </summary>
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
public float Acceleration = 10f;
|
||||
|
||||
/// <summary>
|
||||
/// The minimum speed the wearer needs to be traveling to take damage from collision.
|
||||
/// </summary>
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
public float MinimumSpeed = 4f;
|
||||
|
||||
/// <summary>
|
||||
/// The length of time the wearer is stunned for on collision.
|
||||
/// </summary>
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
public float StunSeconds = 1f;
|
||||
|
||||
/// <summary>
|
||||
/// The time duration before another collision can take place.
|
||||
/// </summary>
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
public float DamageCooldown = 2f;
|
||||
|
||||
/// <summary>
|
||||
/// The damage per increment of speed on collision.
|
||||
/// </summary>
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
public float SpeedDamage = 0.5f;
|
||||
|
||||
/// <summary>
|
||||
/// Defaults for MinimumSpeed, StunSeconds, DamageCooldown and SpeedDamage.
|
||||
/// </summary>
|
||||
[ViewVariables]
|
||||
public float DefaultMinimumSpeed = 20f;
|
||||
|
||||
[ViewVariables]
|
||||
public float DefaultStunSeconds = 1f;
|
||||
|
||||
[ViewVariables]
|
||||
public float DefaultDamageCooldown = 2f;
|
||||
|
||||
[ViewVariables]
|
||||
public float DefaultSpeedDamage = 0.5f;
|
||||
}
|
||||
|
||||
50
Content.Shared/Clothing/EntitySystems/SkatesSystem.cs
Normal file
50
Content.Shared/Clothing/EntitySystems/SkatesSystem.cs
Normal file
@@ -0,0 +1,50 @@
|
||||
using Content.Shared.Inventory.Events;
|
||||
using Content.Shared.Movement.Systems;
|
||||
using Content.Shared.Damage.Systems;
|
||||
using Content.Shared.Movement.Components;
|
||||
|
||||
namespace Content.Shared.Clothing;
|
||||
|
||||
/// <summary>
|
||||
/// Changes the friction and acceleration of the wearer and also the damage on impact variables of thew wearer when hitting a static object.
|
||||
/// </summary>
|
||||
public sealed class SkatesSystem : EntitySystem
|
||||
{
|
||||
[Dependency] private readonly MovementSpeedModifierSystem _move = default!;
|
||||
[Dependency] private readonly DamageOnHighSpeedImpactSystem _impact = default!;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
SubscribeLocalEvent<SkatesComponent, GotEquippedEvent>(OnGotEquipped);
|
||||
SubscribeLocalEvent<SkatesComponent, GotUnequippedEvent>(OnGotUnequipped);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// When item is unequipped from the shoe slot, friction, aceleration and collide on impact return to default settings.
|
||||
/// </summary>
|
||||
public void OnGotUnequipped(EntityUid uid, SkatesComponent component, GotUnequippedEvent args)
|
||||
{
|
||||
if (!TryComp(args.Equipee, out MovementSpeedModifierComponent? speedModifier))
|
||||
return;
|
||||
|
||||
if (args.Slot == "shoes")
|
||||
{
|
||||
_move.ChangeFriction(args.Equipee, MovementSpeedModifierComponent.DefaultFriction, MovementSpeedModifierComponent.DefaultFrictionNoInput, MovementSpeedModifierComponent.DefaultAcceleration, speedModifier);
|
||||
_impact.ChangeCollide(args.Equipee, component.DefaultMinimumSpeed, component.DefaultStunSeconds, component.DefaultDamageCooldown, component.DefaultSpeedDamage);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// When item is equipped into the shoe slot, friction, acceleration and collide on impact are adjusted.
|
||||
/// </summary>
|
||||
private void OnGotEquipped(EntityUid uid, SkatesComponent component, GotEquippedEvent args)
|
||||
{
|
||||
if (args.Slot == "shoes")
|
||||
{
|
||||
_move.ChangeFriction(args.Equipee, component.Friction, component.FrictionNoInput, component.Acceleration);
|
||||
_impact.ChangeCollide(args.Equipee, component.MinimumSpeed, component.StunSeconds, component.DamageCooldown, component.SpeedDamage);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user