4 using System.Collections.Generic;
9 internal static class HealingCooldown
11 private static readonly Dictionary<Client, DateTimeOffset> HealingCooldowns =
new();
14 private const float CooldownDuration = 0.4f;
16 public static bool IsOnCooldown(
Client client)
18 RemoveExpiredCooldowns();
19 return HealingCooldowns.ContainsKey(client);
22 public static void SetCooldown(
Client client)
24 RemoveExpiredCooldowns();
25 DateTimeOffset newCooldown = DateTimeOffset.UtcNow.AddSeconds(CooldownDuration);
26 HealingCooldowns[client] = newCooldown;
29 private static void RemoveExpiredCooldowns()
31 HashSet<Client>? expiredCooldowns =
null;
33 DateTimeOffset now = DateTimeOffset.UtcNow;
35 foreach (var (client, cooldown) in HealingCooldowns)
37 if (now < cooldown) {
continue; }
39 expiredCooldowns ??=
new HashSet<Client>();
40 expiredCooldowns.Add(client);
43 if (expiredCooldowns is
null) {
return; }
45 foreach (
Client expiredCooldown
in expiredCooldowns)
47 HealingCooldowns.Remove(expiredCooldown);