CooldownInstance - jimdroberts/FishMMO GitHub Wiki
Represents a single cooldown instance for an ability. Tracks total and remaining cooldown time, and provides methods to modify and query cooldown state for ability management in FishMMO.
-
private float totalTime
The total cooldown time.
-
private float remainingTime
The remaining cooldown time.
-
public float TotalTime { get; }
Gets the total cooldown time.
-
public float RemainingTime { get; }
Gets the remaining cooldown time.
-
public bool IsOnCooldown { get; }
Gets whether the cooldown is still active.
-
public CooldownInstance(float remainingTime)
Initializes a new cooldown instance with the same total and remaining time. remainingTime: float - The cooldown time.
-
public CooldownInstance(float totalTime, float remainingTime)
Initializes a new cooldown instance with specified total and remaining time. totalTime: float - Total cooldown time. remainingTime: float - Remaining cooldown time.
-
public void SubtractTime(float time)
Subtracts time from the remaining cooldown. time: float - Time to subtract.
-
public void AddTime(float time)
Adds time to the remaining cooldown. time: float - Time to add.
- Create a
CooldownInstance
for each ability that requires cooldown tracking. - Use the constructor to set the initial total and remaining cooldown time.
- Call
SubtractTime
orAddTime
to update the cooldown as time passes or effects are applied. - Check
IsOnCooldown
to determine if the ability is still cooling down.
// Example 1: Creating and updating a cooldown instance
var cooldown = new CooldownInstance(5.0f); // 5 seconds cooldown
cooldown.SubtractTime(Time.deltaTime);
if (!cooldown.IsOnCooldown)
{
// Ability is ready to use again
}
// Example 2: Creating a cooldown with custom total and remaining time
var cooldown = new CooldownInstance(10.0f, 3.0f); // 10 seconds total, 3 seconds remaining
- Always use
SubtractTime
in your update loop to decrement cooldowns over time. - Use
AddTime
to extend cooldowns for debuffs or penalties. - Check
IsOnCooldown
before allowing ability use to enforce cooldown rules. - Store cooldown instances in a controller or dictionary keyed by ability ID for efficient management.