2022-05-18 06:07:35 +02:00
|
|
|
using Content.Shared.Sound;
|
|
|
|
|
using Content.Shared.StepTrigger;
|
2021-07-12 01:32:10 -07:00
|
|
|
using Robust.Shared.GameStates;
|
2020-07-23 01:40:31 +02:00
|
|
|
using Robust.Shared.Serialization;
|
|
|
|
|
|
2021-06-09 22:19:39 +02:00
|
|
|
namespace Content.Shared.Slippery
|
2020-07-23 01:40:31 +02:00
|
|
|
{
|
2022-05-18 06:07:35 +02:00
|
|
|
/// <summary>
|
|
|
|
|
/// Causes somebody to slip when they walk over this entity.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <remarks>
|
|
|
|
|
/// Requires <see cref="StepTriggerComponent"/>, see that component for some additional properties.
|
|
|
|
|
/// </remarks>
|
2021-03-15 19:01:15 +01:00
|
|
|
[RegisterComponent]
|
2022-05-18 06:07:35 +02:00
|
|
|
[NetworkedComponent]
|
2021-07-21 22:13:58 +10:00
|
|
|
public sealed class SlipperyComponent : Component
|
2020-07-23 01:40:31 +02:00
|
|
|
{
|
2022-05-06 00:36:03 -04:00
|
|
|
private float _paralyzeTime = 3f;
|
2021-03-15 19:01:15 +01:00
|
|
|
private float _launchForwardsMultiplier = 1f;
|
2021-07-10 17:35:33 +02:00
|
|
|
private SoundSpecifier _slipSound = new SoundPathSpecifier("/Audio/Effects/slip.ogg");
|
2020-07-23 01:40:31 +02:00
|
|
|
|
2021-03-15 19:01:15 +01:00
|
|
|
/// <summary>
|
|
|
|
|
/// Path to the sound to be played when a mob slips.
|
|
|
|
|
/// </summary>
|
|
|
|
|
[ViewVariables]
|
|
|
|
|
[DataField("slipSound")]
|
2021-07-10 17:35:33 +02:00
|
|
|
public SoundSpecifier SlipSound
|
2021-03-15 19:01:15 +01:00
|
|
|
{
|
|
|
|
|
get => _slipSound;
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (value == _slipSound)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
_slipSound = value;
|
|
|
|
|
Dirty();
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-07-23 01:40:31 +02:00
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// How many seconds the mob will be paralyzed for.
|
|
|
|
|
/// </summary>
|
|
|
|
|
[ViewVariables(VVAccess.ReadWrite)]
|
2021-03-05 01:08:38 +01:00
|
|
|
[DataField("paralyzeTime")]
|
2021-03-08 05:00:50 +01:00
|
|
|
public float ParalyzeTime
|
|
|
|
|
{
|
|
|
|
|
get => _paralyzeTime;
|
|
|
|
|
set
|
|
|
|
|
{
|
2021-09-29 20:07:01 +10:00
|
|
|
if (MathHelper.CloseToPercent(_paralyzeTime, value)) return;
|
2021-03-08 05:00:50 +01:00
|
|
|
|
|
|
|
|
_paralyzeTime = value;
|
|
|
|
|
Dirty();
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-07-23 01:40:31 +02:00
|
|
|
|
2020-09-21 17:51:07 +02:00
|
|
|
/// <summary>
|
|
|
|
|
/// The entity's speed will be multiplied by this to slip it forwards.
|
|
|
|
|
/// </summary>
|
|
|
|
|
[ViewVariables(VVAccess.ReadWrite)]
|
2021-03-05 01:08:38 +01:00
|
|
|
[DataField("launchForwardsMultiplier")]
|
2021-03-08 05:00:50 +01:00
|
|
|
public float LaunchForwardsMultiplier
|
|
|
|
|
{
|
|
|
|
|
get => _launchForwardsMultiplier;
|
|
|
|
|
set
|
|
|
|
|
{
|
2021-09-29 20:07:01 +10:00
|
|
|
if (MathHelper.CloseToPercent(_launchForwardsMultiplier, value)) return;
|
2021-03-08 05:00:50 +01:00
|
|
|
|
|
|
|
|
_launchForwardsMultiplier = value;
|
|
|
|
|
Dirty();
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-07-23 01:40:31 +02:00
|
|
|
|
2021-11-30 15:20:38 +01:00
|
|
|
public override ComponentState GetComponentState()
|
2021-03-15 19:01:15 +01:00
|
|
|
{
|
2022-05-18 06:07:35 +02:00
|
|
|
return new SlipperyComponentState(ParalyzeTime, LaunchForwardsMultiplier, SlipSound.GetSound());
|
2021-03-15 19:01:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void HandleComponentState(ComponentState? curState, ComponentState? nextState)
|
|
|
|
|
{
|
|
|
|
|
if (curState is not SlipperyComponentState state) return;
|
|
|
|
|
|
|
|
|
|
_paralyzeTime = state.ParalyzeTime;
|
|
|
|
|
_launchForwardsMultiplier = state.LaunchForwardsMultiplier;
|
2021-07-10 17:35:33 +02:00
|
|
|
_slipSound = new SoundPathSpecifier(state.SlipSound);
|
2020-07-23 01:40:31 +02:00
|
|
|
}
|
|
|
|
|
}
|
2020-09-21 17:51:07 +02:00
|
|
|
|
|
|
|
|
[Serializable, NetSerializable]
|
2022-02-16 00:23:23 -07:00
|
|
|
public sealed class SlipperyComponentState : ComponentState
|
2020-09-21 17:51:07 +02:00
|
|
|
{
|
|
|
|
|
public float ParalyzeTime { get; }
|
|
|
|
|
public float LaunchForwardsMultiplier { get; }
|
2021-03-15 19:01:15 +01:00
|
|
|
public string SlipSound { get; }
|
2020-09-21 17:51:07 +02:00
|
|
|
|
2022-05-18 06:07:35 +02:00
|
|
|
public SlipperyComponentState(float paralyzeTime, float launchForwardsMultiplier, string slipSound)
|
2020-09-21 17:51:07 +02:00
|
|
|
{
|
|
|
|
|
ParalyzeTime = paralyzeTime;
|
|
|
|
|
LaunchForwardsMultiplier = launchForwardsMultiplier;
|
2021-03-15 19:01:15 +01:00
|
|
|
SlipSound = slipSound;
|
2020-09-21 17:51:07 +02:00
|
|
|
}
|
|
|
|
|
}
|
2020-07-23 01:40:31 +02:00
|
|
|
}
|