extends RefCounted const MIN_SECONDS := 5 const BASE_SECONDS := 30 # Cumulative P(cooldown <= seconds); interpolate exponentially between anchors. const SECONDS := [5, 10, 15, 20, 25, 30] const CHANCES := [0.0002, 0.0015, 0.01, 0.05, 0.25, 1.0] static func cumulative_chance(seconds: int) -> float: if seconds < MIN_SECONDS: return 0.0 if seconds >= BASE_SECONDS: return 1.0 for index in SECONDS.size() - 1: if seconds <= SECONDS[index + 1]: var progress := float(seconds - SECONDS[index]) / float(SECONDS[index + 1] - SECONDS[index]) return exp(lerpf(log(CHANCES[index]), log(CHANCES[index + 1]), progress)) return 1.0 static func from_roll(roll: float) -> int: for seconds in range(MIN_SECONDS, BASE_SECONDS): if roll < cumulative_chance(seconds): return seconds return BASE_SECONDS static func roll_seconds() -> int: return from_roll(randf())