| 1 | import { playerMaxStamina } from "../definitions/skills.js"; |
| 2 | |
| 3 | /** Stamina points restored per second while walking, idle, or run-gait without movement. */ |
| 4 | export const STAMINA_REGEN_PER_SECOND = 1; |
| 5 | |
| 6 | /** Stamina XP granted per full stamina point spent while running. */ |
| 7 | export const STAMINA_XP_PER_POINT_SPENT = 1; |
| 8 | |
| 9 | /** |
| 10 | * Stamina cost for one successful run tile step. |
| 11 | * Run steps once per movement tick; movementHz = walkTilesPerSecond * 2, |
| 12 | * so continuous running drains 1 stamina per second. |
| 13 | */ |
| 14 | export function staminaCostPerRunStep (walkTilesPerSecond = 2) |
| 15 | { |
| 16 | const movementHz = Math.max(0.25, (Number(walkTilesPerSecond) || 2) * 2); |
| 17 | return 1 / movementHz; |
| 18 | } |
| 19 | |
| 20 | export function clampStamina (stamina, skills) |
| 21 | { |
| 22 | if (!stamina) |
| 23 | { return null; } |
| 24 | const max = Math.max(1, playerMaxStamina(skills) | 0); |
| 25 | stamina.max = max; |
| 26 | const current = Number(stamina.current); |
| 27 | stamina.current = Math.min(max, Math.max(0, Number.isFinite(current) ? current : max)); |
| 28 | return stamina; |
| 29 | } |
| 30 | |
| 31 | export function publicStaminaView (stamina) |
| 32 | { |
| 33 | if (!stamina) |
| 34 | { return { current: 0, max: 1 }; } |
| 35 | return { |
| 36 | current: Number(stamina.current) || 0, |
| 37 | max: Math.max(1, stamina.max | 0) |
| 38 | }; |
| 39 | } |