2022-01-05 17:53:08 +13:00
|
|
|
using Content.Shared.Actions.Components;
|
|
|
|
|
using Content.Shared.Hands;
|
2021-02-11 01:13:03 -08:00
|
|
|
using Robust.Shared.GameObjects;
|
2022-01-05 17:53:08 +13:00
|
|
|
using System;
|
2020-12-13 14:28:20 -08:00
|
|
|
|
2021-06-09 22:19:39 +02:00
|
|
|
namespace Content.Shared.Actions
|
2020-12-13 14:28:20 -08:00
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Evicts action states with expired cooldowns.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public class SharedActionSystem : EntitySystem
|
|
|
|
|
{
|
|
|
|
|
private const float CooldownCheckIntervalSeconds = 10;
|
|
|
|
|
private float _timeSinceCooldownCheck;
|
|
|
|
|
|
2021-12-30 03:12:04 +01:00
|
|
|
public override void Initialize()
|
|
|
|
|
{
|
|
|
|
|
base.Initialize();
|
|
|
|
|
|
|
|
|
|
UpdatesOutsidePrediction = true;
|
2022-01-05 17:53:08 +13:00
|
|
|
SubscribeLocalEvent<ItemActionsComponent, UnequippedHandEvent>(OnHandUnequipped);
|
|
|
|
|
SubscribeLocalEvent<ItemActionsComponent, EquippedHandEvent>(OnHandEquipped);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnHandEquipped(EntityUid uid, ItemActionsComponent component, EquippedHandEvent args)
|
|
|
|
|
{
|
|
|
|
|
component.EquippedHand(args.User, args.Hand);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnHandUnequipped(EntityUid uid, ItemActionsComponent component, UnequippedHandEvent args)
|
|
|
|
|
{
|
|
|
|
|
component.UnequippedHand();
|
2021-12-30 03:12:04 +01:00
|
|
|
}
|
2020-12-13 14:28:20 -08:00
|
|
|
|
|
|
|
|
public override void Update(float frameTime)
|
|
|
|
|
{
|
|
|
|
|
base.Update(frameTime);
|
|
|
|
|
|
|
|
|
|
_timeSinceCooldownCheck += frameTime;
|
|
|
|
|
if (_timeSinceCooldownCheck < CooldownCheckIntervalSeconds) return;
|
|
|
|
|
|
2021-09-28 13:35:29 +02:00
|
|
|
foreach (var comp in EntityManager.EntityQuery<SharedActionsComponent>(false))
|
2020-12-13 14:28:20 -08:00
|
|
|
{
|
|
|
|
|
comp.ExpireCooldowns();
|
|
|
|
|
}
|
|
|
|
|
_timeSinceCooldownCheck -= CooldownCheckIntervalSeconds;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|