| 1 | /** |
| 2 | * Metal materials (and coal) — name, tint, rank, and skill gates. |
| 3 | * Equip min level is the tier gate; mining = half (ceil), smelting = 75% (ceil). |
| 4 | */ |
| 5 | export const MaterialTier = Object.freeze({ |
| 6 | bronze: "bronze", |
| 7 | iron: "iron", |
| 8 | steel: "steel", |
| 9 | mithril: "mithril", |
| 10 | adamantium: "adamantium", |
| 11 | orichalcum: "orichalcum", |
| 12 | dragon: "dragon" |
| 13 | }); |
| 14 | |
| 15 | /** |
| 16 | * Wood materials — same ranks / skill gates as metals (gather with axe later). |
| 17 | * Matching metal: pine↔bronze … elder↔dragon. |
| 18 | */ |
| 19 | export const WoodTier = Object.freeze({ |
| 20 | pine: "pine", |
| 21 | birch: "birch", |
| 22 | oak: "oak", |
| 23 | ebony: "ebony", |
| 24 | lignum: "lignum", |
| 25 | heartwood: "heartwood", |
| 26 | elder: "elder" |
| 27 | }); |
| 28 | |
| 29 | /** |
| 30 | * Cloth / fibre tiers (tailoring). Gathering methods vary (plant / shear / drop); |
| 31 | * ranks and equip gates match metal / wood. |
| 32 | */ |
| 33 | export const ClothTier = Object.freeze({ |
| 34 | cotton: "cotton", |
| 35 | wool: "wool", |
| 36 | linen: "linen", |
| 37 | cashmere: "cashmere", |
| 38 | silk: "silk", |
| 39 | fairySilk: "fairySilk", |
| 40 | dragonweave: "dragonweave" |
| 41 | }); |
| 42 | |
| 43 | /** Ordered low → high (metal smithing / tools). */ |
| 44 | export const MATERIAL_TIER_ORDER = Object.freeze([ |
| 45 | MaterialTier.bronze, |
| 46 | MaterialTier.iron, |
| 47 | MaterialTier.steel, |
| 48 | MaterialTier.mithril, |
| 49 | MaterialTier.adamantium, |
| 50 | MaterialTier.orichalcum, |
| 51 | MaterialTier.dragon |
| 52 | ]); |
| 53 | |
| 54 | /** Ordered low → high (woodcutting / woodcraft). */ |
| 55 | export const WOOD_TIER_ORDER = Object.freeze([ |
| 56 | WoodTier.pine, |
| 57 | WoodTier.birch, |
| 58 | WoodTier.oak, |
| 59 | WoodTier.ebony, |
| 60 | WoodTier.lignum, |
| 61 | WoodTier.heartwood, |
| 62 | WoodTier.elder |
| 63 | ]); |
| 64 | |
| 65 | /** Ordered low → high (tailoring). */ |
| 66 | export const CLOTH_TIER_ORDER = Object.freeze([ |
| 67 | ClothTier.cotton, |
| 68 | ClothTier.wool, |
| 69 | ClothTier.linen, |
| 70 | ClothTier.cashmere, |
| 71 | ClothTier.silk, |
| 72 | ClothTier.fairySilk, |
| 73 | ClothTier.dragonweave |
| 74 | ]); |
| 75 | |
| 76 | /** |
| 77 | * Leather tiers (leatherworking). Rank gates mirror cloth/metal families. |
| 78 | */ |
| 79 | export const LeatherTier = Object.freeze({ |
| 80 | softLeather: "softLeather", |
| 81 | hardLeather: "hardLeather", |
| 82 | studdedLeather: "studdedLeather", |
| 83 | reinforcedLeather: "reinforcedLeather", |
| 84 | scaledLeather: "scaledLeather", |
| 85 | wyvernHide: "wyvernHide", |
| 86 | dragonhide: "dragonhide" |
| 87 | }); |
| 88 | |
| 89 | /** Ordered low → high (leatherworking). */ |
| 90 | export const LEATHER_TIER_ORDER = Object.freeze([ |
| 91 | LeatherTier.softLeather, |
| 92 | LeatherTier.hardLeather, |
| 93 | LeatherTier.studdedLeather, |
| 94 | LeatherTier.reinforcedLeather, |
| 95 | LeatherTier.scaledLeather, |
| 96 | LeatherTier.wyvernHide, |
| 97 | LeatherTier.dragonhide |
| 98 | ]); |
| 99 | |
| 100 | export const LEATHER_DISPLAY_NAME = Object.freeze({ |
| 101 | [LeatherTier.softLeather]: "Soft leather", |
| 102 | [LeatherTier.hardLeather]: "Hard leather", |
| 103 | [LeatherTier.studdedLeather]: "Studded leather", |
| 104 | [LeatherTier.reinforcedLeather]: "Reinforced leather", |
| 105 | [LeatherTier.scaledLeather]: "Scaled leather", |
| 106 | [LeatherTier.wyvernHide]: "Wyvern hide", |
| 107 | [LeatherTier.dragonhide]: "Dragonhide" |
| 108 | }); |
| 109 | |
| 110 | /** |
| 111 | * Gatherable ores / fuels that are not always 1:1 with a gear tier. |
| 112 | * Tin + copper smelt into bronze; coal fuels steel. Gold and silver have ore + |
| 113 | * bars but no tools (jewelry / future recipes). Mine/smelt timing uses |
| 114 | * {@link associatedBarTier}. |
| 115 | */ |
| 116 | export const GatherMaterialId = Object.freeze({ |
| 117 | ...MaterialTier, |
| 118 | tin: "tin", |
| 119 | copper: "copper", |
| 120 | coal: "coal", |
| 121 | silver: "silver", |
| 122 | gold: "gold" |
| 123 | }); |
| 124 | |
| 125 | /** Minimum relevant skill level required to equip tools/gear of this tier. */ |
| 126 | export const TIER_MIN_SKILL_LEVEL = Object.freeze({ |
| 127 | [MaterialTier.bronze]: 1, |
| 128 | [MaterialTier.iron]: 10, |
| 129 | [MaterialTier.steel]: 20, |
| 130 | [MaterialTier.mithril]: 35, |
| 131 | [MaterialTier.adamantium]: 50, |
| 132 | [MaterialTier.orichalcum]: 70, |
| 133 | [MaterialTier.dragon]: 90, |
| 134 | [GatherMaterialId.silver]: 10, |
| 135 | [GatherMaterialId.gold]: 20, |
| 136 | [WoodTier.pine]: 1, |
| 137 | [WoodTier.birch]: 10, |
| 138 | [WoodTier.oak]: 20, |
| 139 | [WoodTier.ebony]: 35, |
| 140 | [WoodTier.lignum]: 50, |
| 141 | [WoodTier.heartwood]: 70, |
| 142 | [WoodTier.elder]: 90, |
| 143 | [ClothTier.cotton]: 1, |
| 144 | [ClothTier.wool]: 10, |
| 145 | [ClothTier.linen]: 20, |
| 146 | [ClothTier.cashmere]: 35, |
| 147 | [ClothTier.silk]: 50, |
| 148 | [ClothTier.fairySilk]: 70, |
| 149 | [ClothTier.dragonweave]: 90, |
| 150 | [LeatherTier.softLeather]: 1, |
| 151 | [LeatherTier.hardLeather]: 10, |
| 152 | [LeatherTier.studdedLeather]: 20, |
| 153 | [LeatherTier.reinforcedLeather]: 35, |
| 154 | [LeatherTier.scaledLeather]: 50, |
| 155 | [LeatherTier.wyvernHide]: 70, |
| 156 | [LeatherTier.dragonhide]: 90 |
| 157 | }); |
| 158 | |
| 159 | /** Rank used for mining duration and relative power (1 = bronze/pine … 7 = dragon/elder). */ |
| 160 | export const TIER_RANK = Object.freeze({ |
| 161 | [MaterialTier.bronze]: 1, |
| 162 | [MaterialTier.iron]: 2, |
| 163 | [MaterialTier.steel]: 3, |
| 164 | [MaterialTier.mithril]: 4, |
| 165 | [MaterialTier.adamantium]: 5, |
| 166 | [MaterialTier.orichalcum]: 6, |
| 167 | [MaterialTier.dragon]: 7, |
| 168 | [GatherMaterialId.silver]: 2, |
| 169 | [GatherMaterialId.gold]: 3, |
| 170 | [WoodTier.pine]: 1, |
| 171 | [WoodTier.birch]: 2, |
| 172 | [WoodTier.oak]: 3, |
| 173 | [WoodTier.ebony]: 4, |
| 174 | [WoodTier.lignum]: 5, |
| 175 | [WoodTier.heartwood]: 6, |
| 176 | [WoodTier.elder]: 7, |
| 177 | [ClothTier.cotton]: 1, |
| 178 | [ClothTier.wool]: 2, |
| 179 | [ClothTier.linen]: 3, |
| 180 | [ClothTier.cashmere]: 4, |
| 181 | [ClothTier.silk]: 5, |
| 182 | [ClothTier.fairySilk]: 6, |
| 183 | [ClothTier.dragonweave]: 7, |
| 184 | [LeatherTier.softLeather]: 1, |
| 185 | [LeatherTier.hardLeather]: 2, |
| 186 | [LeatherTier.studdedLeather]: 3, |
| 187 | [LeatherTier.reinforcedLeather]: 4, |
| 188 | [LeatherTier.scaledLeather]: 5, |
| 189 | [LeatherTier.wyvernHide]: 6, |
| 190 | [LeatherTier.dragonhide]: 7 |
| 191 | }); |
| 192 | |
| 193 | /** Stat bonus granted by tier for the equipment's bonus category. */ |
| 194 | export const TIER_STAT_BONUS = Object.freeze({ |
| 195 | [MaterialTier.bronze]: 1, |
| 196 | [MaterialTier.iron]: 2, |
| 197 | [MaterialTier.steel]: 4, |
| 198 | [MaterialTier.mithril]: 6, |
| 199 | [MaterialTier.adamantium]: 8, |
| 200 | [MaterialTier.orichalcum]: 10, |
| 201 | [MaterialTier.dragon]: 12, |
| 202 | [WoodTier.pine]: 1, |
| 203 | [WoodTier.birch]: 2, |
| 204 | [WoodTier.oak]: 4, |
| 205 | [WoodTier.ebony]: 6, |
| 206 | [WoodTier.lignum]: 8, |
| 207 | [WoodTier.heartwood]: 10, |
| 208 | [WoodTier.elder]: 12, |
| 209 | [ClothTier.cotton]: 1, |
| 210 | [ClothTier.wool]: 2, |
| 211 | [ClothTier.linen]: 4, |
| 212 | [ClothTier.cashmere]: 6, |
| 213 | [ClothTier.silk]: 8, |
| 214 | [ClothTier.fairySilk]: 10, |
| 215 | [ClothTier.dragonweave]: 12, |
| 216 | [LeatherTier.softLeather]: 1, |
| 217 | [LeatherTier.hardLeather]: 2, |
| 218 | [LeatherTier.studdedLeather]: 4, |
| 219 | [LeatherTier.reinforcedLeather]: 6, |
| 220 | [LeatherTier.scaledLeather]: 8, |
| 221 | [LeatherTier.wyvernHide]: 10, |
| 222 | [LeatherTier.dragonhide]: 12 |
| 223 | }); |
| 224 | |
| 225 | /** Display names for UI / editor. */ |
| 226 | export const MATERIAL_DISPLAY_NAME = Object.freeze({ |
| 227 | [MaterialTier.bronze]: "Bronze", |
| 228 | [MaterialTier.iron]: "Iron", |
| 229 | [MaterialTier.steel]: "Steel", |
| 230 | [MaterialTier.mithril]: "Mithril", |
| 231 | [MaterialTier.adamantium]: "Adamantium", |
| 232 | [MaterialTier.orichalcum]: "Orichalcum", |
| 233 | [MaterialTier.dragon]: "Dragon", |
| 234 | [GatherMaterialId.tin]: "Tin", |
| 235 | [GatherMaterialId.copper]: "Copper", |
| 236 | [GatherMaterialId.coal]: "Coal", |
| 237 | [GatherMaterialId.silver]: "Silver", |
| 238 | [GatherMaterialId.gold]: "Gold", |
| 239 | [WoodTier.pine]: "Pine", |
| 240 | [WoodTier.birch]: "Birch", |
| 241 | [WoodTier.oak]: "Oak", |
| 242 | [WoodTier.ebony]: "Ebony", |
| 243 | [WoodTier.lignum]: "Lignum", |
| 244 | [WoodTier.heartwood]: "Heartwood", |
| 245 | [WoodTier.elder]: "Elder" |
| 246 | }); |
| 247 | |
| 248 | export const CLOTH_DISPLAY_NAME = Object.freeze({ |
| 249 | [ClothTier.cotton]: "Cotton", |
| 250 | [ClothTier.wool]: "Wool", |
| 251 | [ClothTier.linen]: "Linen", |
| 252 | [ClothTier.cashmere]: "Cashmere", |
| 253 | [ClothTier.silk]: "Silk", |
| 254 | [ClothTier.fairySilk]: "Fairy silk", |
| 255 | [ClothTier.dragonweave]: "Dragonweave" |
| 256 | }); |
| 257 | |
| 258 | /** |
| 259 | * Author tint swatches via {@link rgb} (0–255) so editors can offer a colour picker. |
| 260 | * Also accepts `0xRRGGBB` / `"#RRGGBB"`; all forms become 0–1 RGB at module load. |
| 261 | * Steel is slightly darker than iron; silver is bright gray; gold is yellow; |
| 262 | * orichalcum is coppery; dragon is red. |
| 263 | */ |
| 264 | export function rgb (r, g, b) |
| 265 | { |
| 266 | return Object.freeze({ |
| 267 | r: clampByte(r) / 255, |
| 268 | g: clampByte(g) / 255, |
| 269 | b: clampByte(b) / 255 |
| 270 | }); |
| 271 | } |
| 272 | |
| 273 | function clampByte (n) |
| 274 | { |
| 275 | return Math.min(255, Math.max(0, Math.round(Number(n) || 0))); |
| 276 | } |
| 277 | |
| 278 | export const MATERIAL_TINT_HEX = Object.freeze({ |
| 279 | [MaterialTier.bronze]: rgb(184, 122, 71), |
| 280 | [MaterialTier.iron]: rgb(158, 163, 173), |
| 281 | [MaterialTier.steel]: rgb(75, 76, 80), |
| 282 | [MaterialTier.mithril]: rgb(3, 120, 255), |
| 283 | [MaterialTier.adamantium]: rgb(108, 202, 132), |
| 284 | [MaterialTier.orichalcum]: rgb(230, 140, 31), |
| 285 | [MaterialTier.dragon]: rgb(228, 19, 15), |
| 286 | [GatherMaterialId.tin]: rgb(221, 221, 221), |
| 287 | [GatherMaterialId.copper]: rgb(255, 94, 0), |
| 288 | [GatherMaterialId.coal]: rgb(45, 45, 48), |
| 289 | [GatherMaterialId.silver]: rgb(214, 220, 230), |
| 290 | [GatherMaterialId.gold]: rgb(255, 200, 0), |
| 291 | [WoodTier.pine]: rgb(199, 158, 97), |
| 292 | [WoodTier.birch]: rgb(224, 209, 173), |
| 293 | [WoodTier.oak]: rgb(158, 107, 61), |
| 294 | [WoodTier.ebony]: rgb(56, 41, 51), |
| 295 | [WoodTier.lignum]: rgb(107, 97, 56), |
| 296 | [WoodTier.heartwood]: rgb(184, 71, 56), |
| 297 | [WoodTier.elder]: rgb(184, 189, 199), |
| 298 | [ClothTier.cotton]: rgb(245, 240, 230), |
| 299 | [ClothTier.wool]: rgb(220, 210, 195), |
| 300 | [ClothTier.linen]: rgb(200, 185, 140), |
| 301 | [ClothTier.cashmere]: rgb(210, 175, 150), |
| 302 | [ClothTier.silk]: rgb(230, 220, 240), |
| 303 | [ClothTier.fairySilk]: rgb(180, 230, 255), |
| 304 | [ClothTier.dragonweave]: rgb(200, 60, 50), |
| 305 | [LeatherTier.softLeather]: rgb(210, 180, 140), |
| 306 | [LeatherTier.hardLeather]: rgb(140, 90, 50), |
| 307 | [LeatherTier.studdedLeather]: rgb(110, 70, 40), |
| 308 | [LeatherTier.reinforcedLeather]: rgb(120, 100, 85), |
| 309 | [LeatherTier.scaledLeather]: rgb(150, 70, 55), |
| 310 | [LeatherTier.wyvernHide]: rgb(70, 85, 75), |
| 311 | [LeatherTier.dragonhide]: rgb(180, 40, 35) |
| 312 | }); |
| 313 | |
| 314 | /** |
| 315 | * Optional ore-only tint overrides (boulders + ore items). |
| 316 | * Missing entries fall back to {@link MATERIAL_TINT_HEX}. |
| 317 | */ |
| 318 | export const MATERIAL_ORE_TINT_HEX = Object.freeze({ |
| 319 | [MaterialTier.iron]: rgb(210, 118, 48), |
| 320 | [GatherMaterialId.copper]: rgb(81, 153, 105) |
| 321 | }); |
| 322 | |
| 323 | /** |
| 324 | * Normalize tint authoring forms to frozen 0–1 `{ r, g, b }`: |
| 325 | * - number `0xRRGGBB` |
| 326 | * - string `"#RGB"` / `"#RRGGBB"` / `"rgb(r,g,b)"` |
| 327 | * - object from {@link rgb} |
| 328 | */ |
| 329 | export function hexToRgb01 (hex) |
| 330 | { |
| 331 | if (hex && typeof hex === "object" && "r" in hex && "g" in hex && "b" in hex) |
| 332 | { |
| 333 | return Object.freeze({ |
| 334 | r: clamp01Channel(hex.r), |
| 335 | g: clamp01Channel(hex.g), |
| 336 | b: clamp01Channel(hex.b) |
| 337 | }); |
| 338 | } |
| 339 | if (typeof hex === "number" && Number.isFinite(hex)) |
| 340 | { |
| 341 | const value = hex >>> 0; |
| 342 | return Object.freeze({ |
| 343 | r: ((value >> 16) & 255) / 255, |
| 344 | g: ((value >> 8) & 255) / 255, |
| 345 | b: (value & 255) / 255 |
| 346 | }); |
| 347 | } |
| 348 | const text = String(hex ?? "").trim(); |
| 349 | const rgbMatch = /^rgba?\(\s*([0-9.]+)\s*,\s*([0-9.]+)\s*,\s*([0-9.]+)/i.exec(text); |
| 350 | if (rgbMatch) |
| 351 | { return rgb(rgbMatch[1], rgbMatch[2], rgbMatch[3]); } |
| 352 | const raw = text.replace(/^#/, ""); |
| 353 | const full = raw.length === 3 |
| 354 | ? raw.split("").map((ch) => ch + ch).join("") |
| 355 | : raw; |
| 356 | if (!/^[0-9a-fA-F]{6}$/.test(full)) |
| 357 | { return Object.freeze({ r: 0.7, g: 0.7, b: 0.7 }); } |
| 358 | const value = Number.parseInt(full, 16); |
| 359 | return Object.freeze({ |
| 360 | r: ((value >> 16) & 255) / 255, |
| 361 | g: ((value >> 8) & 255) / 255, |
| 362 | b: (value & 255) / 255 |
| 363 | }); |
| 364 | } |
| 365 | |
| 366 | function clamp01Channel (n) |
| 367 | { |
| 368 | const value = Number(n); |
| 369 | if (!Number.isFinite(value)) |
| 370 | { return 0; } |
| 371 | if (value > 1) |
| 372 | { return clampByte(value) / 255; } |
| 373 | return Math.min(1, Math.max(0, value)); |
| 374 | } |
| 375 | |
| 376 | /** 0–1 RGB map derived from {@link MATERIAL_TINT_HEX}. */ |
| 377 | export const MATERIAL_TINT_COLOR = Object.freeze( |
| 378 | Object.fromEntries( |
| 379 | Object.entries(MATERIAL_TINT_HEX).map(([id, hex]) => [id, hexToRgb01(hex)]) |
| 380 | ) |
| 381 | ); |
| 382 | |
| 383 | /** 0–1 RGB map derived from {@link MATERIAL_ORE_TINT_HEX}. */ |
| 384 | export const MATERIAL_ORE_TINT_COLOR = Object.freeze( |
| 385 | Object.fromEntries( |
| 386 | Object.entries(MATERIAL_ORE_TINT_HEX).map(([id, hex]) => [id, hexToRgb01(hex)]) |
| 387 | ) |
| 388 | ); |
| 389 | |
| 390 | /** Wood tier that matches a metal tier's rank (for tool hafts). */ |
| 391 | export const WOOD_TIER_FOR_METAL = Object.freeze({ |
| 392 | [MaterialTier.bronze]: WoodTier.pine, |
| 393 | [MaterialTier.iron]: WoodTier.birch, |
| 394 | [MaterialTier.steel]: WoodTier.oak, |
| 395 | [MaterialTier.mithril]: WoodTier.ebony, |
| 396 | [MaterialTier.adamantium]: WoodTier.lignum, |
| 397 | [MaterialTier.orichalcum]: WoodTier.heartwood, |
| 398 | [MaterialTier.dragon]: WoodTier.elder |
| 399 | }); |
| 400 | |
| 401 | export const METAL_TIER_FOR_WOOD = Object.freeze(Object.fromEntries( |
| 402 | Object.entries(WOOD_TIER_FOR_METAL).map(([metal, wood]) => [wood, metal]) |
| 403 | )); |
| 404 | |
| 405 | /** |
| 406 | * Bar tier that drives mine/smelt duration and gates for a gatherable. |
| 407 | * Tin/copper → bronze; coal → steel; gold/silver and gear metals map to themselves. |
| 408 | */ |
| 409 | export function associatedBarTier (materialId) |
| 410 | { |
| 411 | if (materialId === GatherMaterialId.tin || materialId === GatherMaterialId.copper) |
| 412 | { return MaterialTier.bronze; } |
| 413 | if (materialId === GatherMaterialId.coal) |
| 414 | { return MaterialTier.steel; } |
| 415 | return materialId; |
| 416 | } |
| 417 | |
| 418 | export function materialDisplayName (materialId) |
| 419 | { |
| 420 | return MATERIAL_DISPLAY_NAME[materialId] ?? materialId; |
| 421 | } |
| 422 | |
| 423 | /** |
| 424 | * Tint for a material. When `ore` is true, prefer {@link MATERIAL_ORE_TINT_COLOR} |
| 425 | * if defined for that material; otherwise the normal material tint. |
| 426 | */ |
| 427 | export function materialTintColor (materialId, { ore = false } = {}) |
| 428 | { |
| 429 | if (ore) |
| 430 | { |
| 431 | const oreTint = MATERIAL_ORE_TINT_COLOR[materialId]; |
| 432 | if (oreTint) |
| 433 | { return oreTint; } |
| 434 | } |
| 435 | return MATERIAL_TINT_COLOR[materialId] ?? MATERIAL_TINT_COLOR[MaterialTier.bronze]; |
| 436 | } |
| 437 | |
| 438 | export function tierStatBonus (tier) |
| 439 | { |
| 440 | return TIER_STAT_BONUS[tier] ?? TIER_STAT_BONUS[MaterialTier.bronze]; |
| 441 | } |
| 442 | |
| 443 | /** Alias for equipment combat boosts derived from material tier. */ |
| 444 | export const statBoostPerTier = tierStatBonus; |
| 445 | |
| 446 | export function tierMinSkillLevel (tier) |
| 447 | { |
| 448 | return TIER_MIN_SKILL_LEVEL[tier] ?? TIER_MIN_SKILL_LEVEL[MaterialTier.bronze]; |
| 449 | } |
| 450 | |
| 451 | export function tierRank (tier) |
| 452 | { |
| 453 | return TIER_RANK[associatedBarTier(tier)] ?? TIER_RANK[tier] ?? 1; |
| 454 | } |
| 455 | |
| 456 | /** Mining / woodcutting skill required (half of equip gate, ceil). */ |
| 457 | export function tierMineSkillLevel (tier) |
| 458 | { |
| 459 | return Math.max(1, Math.ceil(tierMinSkillLevel(associatedBarTier(tier)) / 2)); |
| 460 | } |
| 461 | |
| 462 | /** Smithing / woodcraft skill required to process this material (75% of equip gate, ceil). */ |
| 463 | export function tierSmeltSkillLevel (tier) |
| 464 | { |
| 465 | return Math.max(1, Math.ceil(tierMinSkillLevel(associatedBarTier(tier)) * 0.75)); |
| 466 | } |
| 467 | |
| 468 | /** Alias for woodworking / general craft gates (same curve as smelting). */ |
| 469 | export function tierCraftSkillLevel (tier) |
| 470 | { |
| 471 | return tierSmeltSkillLevel(tier); |
| 472 | } |
| 473 | |
| 474 | export function woodTierForMetal (metalTier) |
| 475 | { |
| 476 | return WOOD_TIER_FOR_METAL[metalTier] ?? WoodTier.pine; |
| 477 | } |
| 478 | |
| 479 | /** Matching cloth tier for a wood tier (pine↔cotton, birch↔wool, …). */ |
| 480 | export function clothTierForWood (woodTier) |
| 481 | { |
| 482 | const idx = WOOD_TIER_ORDER.indexOf(woodTier); |
| 483 | return CLOTH_TIER_ORDER[idx >= 0 ? idx : 0] ?? ClothTier.cotton; |
| 484 | } |
| 485 | |
| 486 | export function metalTierForWood (woodTier) |
| 487 | { |
| 488 | return METAL_TIER_FOR_WOOD[woodTier] ?? MaterialTier.bronze; |
| 489 | } |
| 490 | |
| 491 | /** |
| 492 | * Mining action duration in ms. |
| 493 | * (resourceRank * 8s) − (toolRank * 3s), floored at 0.5s. |
| 494 | * Tin/copper/coal use their associated bar's rank. |
| 495 | */ |
| 496 | export function miningDurationMs (resourceMaterialId, toolTier) |
| 497 | { |
| 498 | const resourceRank = tierRank(resourceMaterialId); |
| 499 | const toolRank = tierRank(toolTier); |
| 500 | const seconds = Math.max(0.5, resourceRank * 8 - toolRank * 3); |
| 501 | return Math.round(seconds * 1000); |
| 502 | } |
| 503 | |
| 504 | /** After a successful mine, nodes stay exhausted for 10s × associated bar rank. */ |
| 505 | export function oreExhaustDurationMs (materialId) |
| 506 | { |
| 507 | return Math.max(1, tierRank(materialId)) * 10_000; |
| 508 | } |
| 509 | |
| 510 | /** Base craft duration per bar rank (bronze = 2s, iron = 4s, …). */ |
| 511 | export const SMELT_DURATION_PER_RANK_MS = 2000; |
| 512 | |
| 513 | /** |
| 514 | * Furnace smelt duration from the output bar's associated tier rank. |
| 515 | * Tin/copper/coal map to bronze/steel so ingredient timing matches that bar. |
| 516 | */ |
| 517 | export function smeltingDurationMs (barOrMaterialId) |
| 518 | { |
| 519 | return Math.max(1, tierRank(barOrMaterialId)) * SMELT_DURATION_PER_RANK_MS; |
| 520 | } |
| 521 | |
| 522 | /** Visual / interact state while an ore boulder is depleted (plain rock). */ |
| 523 | export const EXHAUSTED_ORE_BOULDER_STATE = "boulder"; |
| 524 | |
| 525 | /** |
| 526 | * Materials that have an ore boulder node. |
| 527 | * Bronze has no ore (tin + copper); steel has no ore (iron + coal). |
| 528 | * Gold and silver are precious only (ore + bars, no tools). |
| 529 | */ |
| 530 | export const ORE_BEARING_MATERIALS = Object.freeze([ |
| 531 | GatherMaterialId.tin, |
| 532 | GatherMaterialId.copper, |
| 533 | MaterialTier.iron, |
| 534 | GatherMaterialId.silver, |
| 535 | GatherMaterialId.gold, |
| 536 | MaterialTier.mithril, |
| 537 | MaterialTier.adamantium, |
| 538 | MaterialTier.orichalcum, |
| 539 | MaterialTier.dragon, |
| 540 | GatherMaterialId.coal |
| 541 | ]); |
| 542 | |
| 543 | /** Boulder visual state for a gatherable ore (editor / world). */ |
| 544 | export function oreBoulderState (materialId) |
| 545 | { |
| 546 | if (materialId === GatherMaterialId.coal) |
| 547 | { return "coal"; } |
| 548 | return `${materialId}-ore`; |
| 549 | } |
| 550 | |
| 551 | export function materialFromOreBoulderState (state) |
| 552 | { |
| 553 | if (!state || state === "boulder") |
| 554 | { return null; } |
| 555 | if (state === "coal") |
| 556 | { return GatherMaterialId.coal; } |
| 557 | if (state.endsWith("-ore")) |
| 558 | { |
| 559 | const id = state.slice(0, -"-ore".length); |
| 560 | if (ORE_BEARING_MATERIALS.includes(id)) |
| 561 | { return id; } |
| 562 | } |
| 563 | return null; |
| 564 | } |
| 565 | |
| 566 | export function isOreBoulderState (state) |
| 567 | { |
| 568 | return materialFromOreBoulderState(state) != null; |
| 569 | } |