2021-02-27 04:12:09 +01:00
|
|
|
using System;
|
2020-09-21 17:51:07 +02:00
|
|
|
using System.Collections.Generic;
|
2020-08-22 22:29:20 +02:00
|
|
|
using System.Linq;
|
2021-07-10 17:35:33 +02:00
|
|
|
using Content.Shared.Sound;
|
2020-07-23 01:40:31 +02:00
|
|
|
using Robust.Shared.GameObjects;
|
2021-07-12 01:32:10 -07:00
|
|
|
using Robust.Shared.GameStates;
|
2021-03-08 05:00:50 +01:00
|
|
|
using Robust.Shared.Maths;
|
2021-03-15 19:01:15 +01:00
|
|
|
using Robust.Shared.Players;
|
2020-07-23 01:40:31 +02:00
|
|
|
using Robust.Shared.Serialization;
|
2021-03-05 01:08:38 +01:00
|
|
|
using Robust.Shared.Serialization.Manager.Attributes;
|
2020-07-23 01:40:31 +02:00
|
|
|
using Robust.Shared.ViewVariables;
|
|
|
|
|
|
2021-06-09 22:19:39 +02:00
|
|
|
namespace Content.Shared.Slippery
|
2020-07-23 01:40:31 +02:00
|
|
|
{
|
2021-03-15 19:01:15 +01:00
|
|
|
[RegisterComponent]
|
2021-07-12 01:32:10 -07:00
|
|
|
[NetworkedComponent()]
|
2021-07-21 22:13:58 +10:00
|
|
|
public sealed class SlipperyComponent : Component
|
2020-07-23 01:40:31 +02:00
|
|
|
{
|
2021-12-07 09:18:07 +03:00
|
|
|
private float _paralyzeTime = 5f;
|
2021-03-15 19:01:15 +01:00
|
|
|
private float _intersectPercentage = 0.3f;
|
2022-01-08 15:46:38 -06:00
|
|
|
private float _requiredSlipSpeed = 3.5f;
|
2021-03-15 19:01:15 +01:00
|
|
|
private float _launchForwardsMultiplier = 1f;
|
|
|
|
|
private bool _slippery = true;
|
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>
|
|
|
|
|
/// List of entities that are currently colliding with the entity.
|
|
|
|
|
/// </summary>
|
2021-07-21 22:13:58 +10:00
|
|
|
public readonly HashSet<EntityUid> Colliding = new();
|
2021-03-08 05:00:50 +01:00
|
|
|
|
2020-07-23 01:40:31 +02:00
|
|
|
/// <summary>
|
2021-03-15 19:01:15 +01:00
|
|
|
/// The list of entities that have been slipped by this component, which shouldn't be slipped again.
|
2020-07-23 01:40:31 +02:00
|
|
|
/// </summary>
|
2021-07-21 22:13:58 +10:00
|
|
|
public readonly HashSet<EntityUid> Slipped = new();
|
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
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Percentage of shape intersection for a slip to occur.
|
|
|
|
|
/// </summary>
|
|
|
|
|
[ViewVariables(VVAccess.ReadWrite)]
|
2021-03-05 01:08:38 +01:00
|
|
|
[DataField("intersectPercentage")]
|
2021-03-08 05:00:50 +01:00
|
|
|
public float IntersectPercentage
|
|
|
|
|
{
|
|
|
|
|
get => _intersectPercentage;
|
|
|
|
|
set
|
|
|
|
|
{
|
2021-09-29 20:07:01 +10:00
|
|
|
if (MathHelper.CloseToPercent(_intersectPercentage, value)) return;
|
2021-03-08 05:00:50 +01:00
|
|
|
|
|
|
|
|
_intersectPercentage = value;
|
|
|
|
|
Dirty();
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-07-23 01:40:31 +02:00
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Entities will only be slipped if their speed exceeds this limit.
|
|
|
|
|
/// </summary>
|
|
|
|
|
[ViewVariables(VVAccess.ReadWrite)]
|
2021-03-05 01:08:38 +01:00
|
|
|
[DataField("requiredSlipSpeed")]
|
2021-03-08 05:00:50 +01:00
|
|
|
public float RequiredSlipSpeed
|
|
|
|
|
{
|
|
|
|
|
get => _requiredSlipSpeed;
|
|
|
|
|
set
|
|
|
|
|
{
|
2021-09-29 20:07:01 +10:00
|
|
|
if (MathHelper.CloseToPercent(_requiredSlipSpeed, value)) return;
|
2021-03-08 05:00:50 +01:00
|
|
|
|
|
|
|
|
_requiredSlipSpeed = value;
|
|
|
|
|
Dirty();
|
|
|
|
|
}
|
|
|
|
|
}
|
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
|
|
|
|
2020-08-29 13:13:22 +02:00
|
|
|
/// <summary>
|
|
|
|
|
/// Whether or not this component will try to slip entities.
|
|
|
|
|
/// </summary>
|
|
|
|
|
[ViewVariables(VVAccess.ReadWrite)]
|
2021-03-05 01:08:38 +01:00
|
|
|
[DataField("slippery")]
|
2021-03-08 05:00:50 +01:00
|
|
|
public bool Slippery
|
|
|
|
|
{
|
|
|
|
|
get => _slippery;
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (_slippery == value) return;
|
|
|
|
|
|
|
|
|
|
_slippery = value;
|
|
|
|
|
Dirty();
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-08-29 13:13:22 +02:00
|
|
|
|
2021-11-30 15:20:38 +01:00
|
|
|
public override ComponentState GetComponentState()
|
2021-03-15 19:01:15 +01:00
|
|
|
{
|
2021-07-25 14:12:00 +02:00
|
|
|
return new SlipperyComponentState(ParalyzeTime, IntersectPercentage, RequiredSlipSpeed, LaunchForwardsMultiplier, Slippery, SlipSound.GetSound(), Slipped.ToArray());
|
2021-03-15 19:01:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void HandleComponentState(ComponentState? curState, ComponentState? nextState)
|
|
|
|
|
{
|
|
|
|
|
if (curState is not SlipperyComponentState state) return;
|
|
|
|
|
|
|
|
|
|
_slippery = state.Slippery;
|
|
|
|
|
_intersectPercentage = state.IntersectPercentage;
|
|
|
|
|
_paralyzeTime = state.ParalyzeTime;
|
|
|
|
|
_requiredSlipSpeed = state.RequiredSlipSpeed;
|
|
|
|
|
_launchForwardsMultiplier = state.LaunchForwardsMultiplier;
|
2021-07-10 17:35:33 +02:00
|
|
|
_slipSound = new SoundPathSpecifier(state.SlipSound);
|
2021-07-21 22:13:58 +10:00
|
|
|
Slipped.Clear();
|
2021-03-15 19:01:15 +01:00
|
|
|
|
|
|
|
|
foreach (var slipped in state.Slipped)
|
|
|
|
|
{
|
2021-07-21 22:13:58 +10:00
|
|
|
Slipped.Add(slipped);
|
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 IntersectPercentage { get; }
|
|
|
|
|
public float RequiredSlipSpeed { get; }
|
|
|
|
|
public float LaunchForwardsMultiplier { get; }
|
|
|
|
|
public bool Slippery { get; }
|
2021-03-15 19:01:15 +01:00
|
|
|
public string SlipSound { get; }
|
|
|
|
|
public readonly EntityUid[] Slipped;
|
2020-09-21 17:51:07 +02:00
|
|
|
|
2021-07-12 01:32:10 -07:00
|
|
|
public SlipperyComponentState(float paralyzeTime, float intersectPercentage, float requiredSlipSpeed, float launchForwardsMultiplier, bool slippery, string slipSound, EntityUid[] slipped)
|
2020-09-21 17:51:07 +02:00
|
|
|
{
|
|
|
|
|
ParalyzeTime = paralyzeTime;
|
|
|
|
|
IntersectPercentage = intersectPercentage;
|
|
|
|
|
RequiredSlipSpeed = requiredSlipSpeed;
|
|
|
|
|
LaunchForwardsMultiplier = launchForwardsMultiplier;
|
|
|
|
|
Slippery = slippery;
|
2021-03-15 19:01:15 +01:00
|
|
|
SlipSound = slipSound;
|
|
|
|
|
Slipped = slipped;
|
2020-09-21 17:51:07 +02:00
|
|
|
}
|
|
|
|
|
}
|
2020-07-23 01:40:31 +02:00
|
|
|
}
|