| 1 | import { StatusEffectType } from "./rules.js"; |
| 2 | |
| 3 | /** |
| 4 | * Player-facing copy + icon paths for HUD buff/debuff icons. |
| 5 | * Art lives under `client/assets/status-effects/<iconKey>.png` (placeholders until final art). |
| 6 | */ |
| 7 | export const STATUS_EFFECT_DISPLAY = Object.freeze({ |
| 8 | [StatusEffectType.healthRegen]: Object.freeze({ |
| 9 | iconKey: "health-regen", |
| 10 | title: "Health regeneration", |
| 11 | polarity: "buff", |
| 12 | describe (effect) |
| 13 | { |
| 14 | const rate = Number(effect?.amountPerSecond) || 1; |
| 15 | return `Restores ${rate} health each second.`; |
| 16 | } |
| 17 | }), |
| 18 | [StatusEffectType.healthDrain]: Object.freeze({ |
| 19 | iconKey: "stamina-drain", |
| 20 | title: "Poison", |
| 21 | polarity: "debuff", |
| 22 | describe (effect) |
| 23 | { |
| 24 | const rate = Number(effect?.amountPerSecond) || 1; |
| 25 | return `Loses ${rate} health each second.`; |
| 26 | } |
| 27 | }), |
| 28 | [StatusEffectType.foodPoisoning]: Object.freeze({ |
| 29 | iconKey: "stamina-drain", |
| 30 | title: "Food Poisoning", |
| 31 | polarity: "debuff", |
| 32 | describe (effect) |
| 33 | { |
| 34 | const rate = Number(effect?.amountPerSecond) || 1; |
| 35 | return `Loses ${rate} health each second.`; |
| 36 | } |
| 37 | }), |
| 38 | [StatusEffectType.staminaRegen]: Object.freeze({ |
| 39 | iconKey: "stamina-regen", |
| 40 | title: "Stamina regeneration", |
| 41 | polarity: "buff", |
| 42 | describe (effect) |
| 43 | { |
| 44 | const rate = Number(effect?.amountPerSecond) || 1; |
| 45 | return `Restores ${rate} stamina each second.`; |
| 46 | } |
| 47 | }), |
| 48 | [StatusEffectType.strengthBonus]: Object.freeze({ |
| 49 | iconKey: "strength-bonus", |
| 50 | title: "Strength", |
| 51 | polarity: "buff", |
| 52 | describe (effect) |
| 53 | { |
| 54 | const amount = effect?.amount | 0 || 0; |
| 55 | return `Increases Strength by ${amount}.`; |
| 56 | } |
| 57 | }), |
| 58 | [StatusEffectType.mindBonus]: Object.freeze({ |
| 59 | iconKey: "mind-bonus", |
| 60 | title: "Clarity", |
| 61 | polarity: "buff", |
| 62 | describe (effect) |
| 63 | { |
| 64 | const amount = effect?.amount | 0 || 0; |
| 65 | return `Increases Mind by ${amount}.`; |
| 66 | } |
| 67 | }), |
| 68 | [StatusEffectType.staminaDrain]: Object.freeze({ |
| 69 | iconKey: "stamina-drain", |
| 70 | title: "Stamina drain", |
| 71 | polarity: "debuff", |
| 72 | describe (effect) |
| 73 | { |
| 74 | const rate = Number(effect?.amountPerSecond) || 1; |
| 75 | return `Drains ${rate} stamina each second.`; |
| 76 | } |
| 77 | }), |
| 78 | [StatusEffectType.staminaBlock]: Object.freeze({ |
| 79 | iconKey: "stamina-drain", |
| 80 | title: "Winded", |
| 81 | polarity: "debuff", |
| 82 | describe () |
| 83 | { |
| 84 | return "Cannot recover stamina."; |
| 85 | } |
| 86 | }), |
| 87 | [StatusEffectType.glow]: Object.freeze({ |
| 88 | iconKey: "glow", |
| 89 | title: "Glow", |
| 90 | polarity: "debuff", |
| 91 | describe () |
| 92 | { |
| 93 | return "You cast a faint light around yourself."; |
| 94 | } |
| 95 | }), |
| 96 | [StatusEffectType.shrink]: Object.freeze({ |
| 97 | iconKey: "shrink", |
| 98 | title: "Diminished", |
| 99 | polarity: "debuff", |
| 100 | describe (effect) |
| 101 | { |
| 102 | const scale = Math.round((Number(effect?.scale) || 0.5) * 100); |
| 103 | return `Your body is shrunk to ${scale}% size.`; |
| 104 | } |
| 105 | }), |
| 106 | [StatusEffectType.blind]: Object.freeze({ |
| 107 | iconKey: "blind", |
| 108 | title: "Blindness", |
| 109 | polarity: "debuff", |
| 110 | describe () |
| 111 | { |
| 112 | return "Darkness closes in; you can barely see what is next to you."; |
| 113 | } |
| 114 | }) |
| 115 | }); |
| 116 | |
| 117 | export function statusEffectDisplay (type) |
| 118 | { |
| 119 | return STATUS_EFFECT_DISPLAY[type] ?? null; |
| 120 | } |
| 121 | |
| 122 | export function statusEffectIconPath (type) |
| 123 | { |
| 124 | const display = statusEffectDisplay(type); |
| 125 | const key = display?.iconKey ?? String(type ?? "unknown"); |
| 126 | return `/assets/status-effects/${key}.png`; |
| 127 | } |
| 128 | |
| 129 | export function formatStatusRemaining (ms) |
| 130 | { |
| 131 | const total = Math.max(0, Math.ceil((ms | 0) / 1000)); |
| 132 | if (total < 60) |
| 133 | { return `${total}s`; } |
| 134 | const minutes = (total / 60) | 0; |
| 135 | const seconds = total % 60; |
| 136 | return seconds > 0 ? `${minutes}m ${seconds}s` : `${minutes}m`; |
| 137 | } |