2021-02-27 04:12:09 +01:00
|
|
|
using System;
|
2019-11-12 01:43:11 +01:00
|
|
|
using Robust.Shared.GameObjects;
|
2021-07-12 01:32:10 -07:00
|
|
|
using Robust.Shared.GameStates;
|
2021-02-18 09:09:07 +01:00
|
|
|
using Robust.Shared.Players;
|
2019-11-12 01:43:11 +01:00
|
|
|
using Robust.Shared.Serialization;
|
|
|
|
|
using Robust.Shared.ViewVariables;
|
|
|
|
|
|
2021-06-09 22:19:39 +02:00
|
|
|
namespace Content.Shared.Cooldown
|
2019-11-12 01:43:11 +01:00
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Stores a visual "cooldown" for items, that gets displayed in the hands GUI.
|
|
|
|
|
/// </summary>
|
|
|
|
|
[RegisterComponent]
|
2021-07-12 01:32:10 -07:00
|
|
|
[NetworkedComponent()]
|
2019-11-12 01:43:11 +01:00
|
|
|
public sealed class ItemCooldownComponent : Component
|
|
|
|
|
{
|
|
|
|
|
private TimeSpan? _cooldownEnd;
|
|
|
|
|
private TimeSpan? _cooldownStart;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// The time when this cooldown ends.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <remarks>
|
|
|
|
|
/// If null, no cooldown is displayed.
|
|
|
|
|
/// </remarks>
|
|
|
|
|
[ViewVariables]
|
|
|
|
|
public TimeSpan? CooldownEnd
|
|
|
|
|
{
|
|
|
|
|
get => _cooldownEnd;
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
_cooldownEnd = value;
|
|
|
|
|
Dirty();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// The time when this cooldown started.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <remarks>
|
|
|
|
|
/// If null, no cooldown is displayed.
|
|
|
|
|
/// </remarks>
|
|
|
|
|
[ViewVariables]
|
|
|
|
|
public TimeSpan? CooldownStart
|
|
|
|
|
{
|
|
|
|
|
get => _cooldownStart;
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
_cooldownStart = value;
|
|
|
|
|
Dirty();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-11-30 15:20:38 +01:00
|
|
|
public override ComponentState GetComponentState()
|
2019-11-12 01:43:11 +01:00
|
|
|
{
|
|
|
|
|
return new ItemCooldownComponentState
|
|
|
|
|
{
|
|
|
|
|
CooldownEnd = CooldownEnd,
|
|
|
|
|
CooldownStart = CooldownStart
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2021-02-27 04:12:09 +01:00
|
|
|
public override void HandleComponentState(ComponentState? curState, ComponentState? nextState)
|
2019-11-12 01:43:11 +01:00
|
|
|
{
|
2020-11-26 14:33:31 +01:00
|
|
|
base.HandleComponentState(curState, nextState);
|
|
|
|
|
|
|
|
|
|
if (curState is not ItemCooldownComponentState cast)
|
2020-02-09 02:28:47 -08:00
|
|
|
return;
|
2019-11-12 01:43:11 +01:00
|
|
|
|
|
|
|
|
CooldownStart = cast.CooldownStart;
|
|
|
|
|
CooldownEnd = cast.CooldownEnd;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Serializable, NetSerializable]
|
|
|
|
|
private sealed class ItemCooldownComponentState : ComponentState
|
|
|
|
|
{
|
|
|
|
|
public TimeSpan? CooldownStart { get; set; }
|
|
|
|
|
public TimeSpan? CooldownEnd { get; set; }
|
|
|
|
|
|
2021-07-12 01:32:10 -07:00
|
|
|
public ItemCooldownComponentState() {
|
2019-11-12 01:43:11 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|