/datum/spell_cooldown /// the world.time the spell will be available again var/recharge_time = 0 /// the amount of time that must pass before a spell can be used again var/recharge_duration = 10 SECONDS // default spell cooldown /// does it start off cooldown? var/starts_off_cooldown = TRUE /// holds a ref to the spell var/obj/effect/proc_holder/spell/spell_parent /datum/spell_cooldown/Destroy() spell_parent = null return ..() /datum/spell_cooldown/proc/cooldown_init(obj/effect/proc_holder/spell/new_spell) spell_parent = new_spell if(!starts_off_cooldown) start_recharge() /datum/spell_cooldown/proc/is_on_cooldown() return recharge_time > world.time /datum/spell_cooldown/proc/should_end_cooldown() return !is_on_cooldown() /datum/spell_cooldown/proc/end_recharge() return /datum/spell_cooldown/process() if(!spell_parent.action) stack_trace("[spell_parent.type] ended up with a null action") return PROCESS_KILL spell_parent.action.UpdateButtonIcon() if(should_end_cooldown()) end_recharge() return PROCESS_KILL /* * used to track how long is left on the spell cooldown * finds them time left, before we can cast (recharge_time - world.time) * then subtracts that from the total time. * then divides it by the total time. */ /datum/spell_cooldown/proc/get_availability_percentage() if(!is_on_cooldown()) // if off cooldown, we don't bother with the maths return 1 return (recharge_duration - (recharge_time - world.time)) / recharge_duration /datum/spell_cooldown/proc/start_recharge(recharge_duration_override = 0) var/recharge_increment = recharge_duration_override || recharge_duration recharge_time = world.time + recharge_increment if(spell_parent.action) spell_parent.action.UpdateButtonIcon() START_PROCESSING(SSfastprocess, src) /datum/spell_cooldown/proc/revert_cast() recharge_time = world.time /datum/spell_cooldown/proc/statpanel_info() return "[round(get_availability_percentage(), 0.01) * 100]%"