Table of Contents

Struct CooldownInstance

Namespace
FishMMO.Shared
Assembly
FishMMO.Shared.dll

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

startTick uint

The network tick at which the cooldown begins.

durationSeconds float

Cooldown duration in seconds.

tickDelta float

Fixed 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

startTick uint

The tick at which the cooldown began.

durationTicks uint

Total duration in ticks.

tickDelta float

Fixed time step per tick (for UI conversion).

Properties

DurationTicks

The cooldown duration in ticks. Immutable after construction.

public uint DurationTicks { get; }

Property Value

uint

StartTick

The network tick at which this cooldown was started.

public uint StartTick { get; }

Property Value

uint

TotalTime

The total cooldown duration in seconds, for UI display.

public float TotalTime { get; }

Property Value

float

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

currentTick uint

The current network tick.

totalDurationSeconds float

Total cooldown duration in seconds.

remainingDurationSeconds float

Remaining cooldown duration in seconds.

tickDelta float

Fixed 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

currentTick uint

The 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

currentTick uint

The 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

currentTick uint

The current network tick.

Returns

float

Remaining cooldown time in seconds, clamped to zero.