18 lines
524 B
TypeScript
18 lines
524 B
TypeScript
import { clamp } from './rules'
|
|
|
|
export function tickSeconds(tickMs: number) {
|
|
return tickMs / 1000
|
|
}
|
|
|
|
export function advanceCooldowns(cooldowns: Record<string, number>, elapsedSeconds: number) {
|
|
const nextCooldowns: Record<string, number> = {}
|
|
for (const id in cooldowns) {
|
|
nextCooldowns[id] = Math.max(0, cooldowns[id] - elapsedSeconds)
|
|
}
|
|
return nextCooldowns
|
|
}
|
|
|
|
export function regenerateResource(resource: number, amount: number, maxResource: number) {
|
|
return clamp(resource + amount, 0, maxResource)
|
|
}
|