| 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 on normal ground. |
| 13 | * Path tiles use {@link PATH_RUN_STAMINA_FACTOR}. |
| 14 | */ |
| 15 | export const PATH_RUN_STAMINA_FACTOR = 0.5; |
| 16 | |
| 17 | export function staminaCostPerRunStep (walkTilesPerSecond = 2, { onPath = false } = {}) |
| 18 | { |
| 19 | const movementHz = Math.max(0.25, (Number(walkTilesPerSecond) || 2) * 2); |
| 20 | const base = 1 / movementHz; |
| 21 | return onPath ? base * PATH_RUN_STAMINA_FACTOR : base; |
| 22 | } |
| 23 | |
| 24 | export function clampStamina (stamina, skills) |
| 25 | { |
| 26 | if (!stamina) |
| 27 | { return null; } |
| 28 | const max = Math.max(1, playerMaxStamina(skills) | 0); |
| 29 | stamina.max = max; |
| 30 | const current = Number(stamina.current); |
| 31 | stamina.current = Math.min(max, Math.max(0, Number.isFinite(current) ? current : max)); |
| 32 | return stamina; |
| 33 | } |
| 34 | |
| 35 | export function publicStaminaView (stamina) |
| 36 | { |
| 37 | if (!stamina) |
| 38 | { return { current: 0, max: 1 }; } |
| 39 | return { |
| 40 | current: Number(stamina.current) || 0, |
| 41 | max: Math.max(1, stamina.max | 0) |
| 42 | }; |
| 43 | } |