Struct CooldownInstance
Immutable cooldown instance using StartTick + DurationTicks.
Remaining time is computed as DurationTicks - (currentTick - StartTick),
which is perfectly deterministic across client and server with zero float drift.
No per-tick mutation is needed — cooldowns auto-expire via integer comparison.
public readonly struct CooldownInstance
- Inherited Members
Remarks
This replaces the previous SubtractTick() model. Because the struct is immutable after construction, it is safe during reconcile replay — the Replicate loop does not need to tick cooldowns at all, eliminating the double-subtract risk entirely. Reconcile only needs to transmit (StartTick, DurationTicks) which never change.
Constructors
CooldownInstance(uint, float, float)
Initializes a cooldown starting at the given tick with a duration in seconds.
Duration is converted to ticks via ceil(duration / tickDelta).
public CooldownInstance(uint startTick, float durationSeconds, float tickDelta)
Parameters
startTickuintThe network tick at which the cooldown begins.
durationSecondsfloatCooldown duration in seconds.
tickDeltafloatFixed time step per tick.
CooldownInstance(uint, uint, float)
Initializes a cooldown from pre-computed tick values (deserialization / reconcile).
public CooldownInstance(uint startTick, uint durationTicks, float tickDelta)
Parameters
startTickuintThe tick at which the cooldown began.
durationTicksuintTotal duration in ticks.
tickDeltafloatFixed time step per tick (for UI conversion).
Properties
DurationTicks
The cooldown duration in ticks. Immutable after construction.
public uint DurationTicks { get; }
Property Value
StartTick
The network tick at which this cooldown was started.
public uint StartTick { get; }
Property Value
TotalTime
The total cooldown duration in seconds, for UI display.
public float TotalTime { get; }
Property Value
Methods
FromRemainingSeconds(uint, float, float, float)
Creates a cooldown from total and remaining durations in seconds.
Computes StartTick backwards from currentTick
so that RemainingTicks(currentTick) equals the expected remaining value.
Used when restoring cooldown state from database or network payloads that store
seconds rather than ticks.
public static CooldownInstance FromRemainingSeconds(uint currentTick, float totalDurationSeconds, float remainingDurationSeconds, float tickDelta)
Parameters
currentTickuintThe current network tick.
totalDurationSecondsfloatTotal cooldown duration in seconds.
remainingDurationSecondsfloatRemaining cooldown duration in seconds.
tickDeltafloatFixed time step per tick.
Returns
- CooldownInstance
A cooldown instance with StartTick derived so remaining time is correct.
IsOnCooldown(uint)
Whether the cooldown is still active at the given tick.
public bool IsOnCooldown(uint currentTick)
Parameters
currentTickuintThe current network tick.
Returns
- bool
True if the cooldown has not yet expired.
RemainingTicks(uint)
Computes remaining ticks for the given current tick. Returns 0 if the cooldown has expired.
public uint RemainingTicks(uint currentTick)
Parameters
currentTickuintThe current network tick.
Returns
- uint
Remaining cooldown in ticks, clamped to zero.
RemainingTime(uint)
Computes remaining time in seconds for the given current tick. Returns 0 if the cooldown has expired.
public float RemainingTime(uint currentTick)
Parameters
currentTickuintThe current network tick.
Returns
- float
Remaining cooldown time in seconds, clamped to zero.