BlueGit

timfa questward

Files

questward / shared / definitions / materialTiers.js

materialTiers.js

materialTiers.js 18.8 KiB Download Raw
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 */
5export 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 */
19export 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 */
33export 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). */
44export 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). */
55export 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). */
66export 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 */
79export 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). */
90export 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
100export 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 * Gemstone materials — mined for staves and jewellery.
112 * Ranks / equip gates match metal / wood (tourmaline↔pine/bronze … jadeite↔elder/dragon).
113 */
114export const GemTier = Object.freeze({
115 tourmaline: "tourmaline",
116 alexandrite: "alexandrite",
117 opal: "opal",
118 diamond: "diamond",
119 emerald: "emerald",
120 ruby: "ruby",
121 jadeite: "jadeite"
122});
123
124/** Ordered low → high (gem mining / jewellery). */
125export const GEM_TIER_ORDER = Object.freeze([
126 GemTier.tourmaline,
127 GemTier.alexandrite,
128 GemTier.opal,
129 GemTier.diamond,
130 GemTier.emerald,
131 GemTier.ruby,
132 GemTier.jadeite
133]);
134
135/**
136 * Gatherable ores / fuels that are not always 1:1 with a gear tier.
137 * Tin + copper smelt into bronze; coal fuels steel. Gold and silver have ore +
138 * bars but no tools (jewelry). Electrum is furnace-only (gold + silver + coal).
139 * Mine/smelt timing uses {@link associatedBarTier}. Gemstones map onto the
140 * matching metal gate.
141 */
142export const GatherMaterialId = Object.freeze({
143 ...MaterialTier,
144 ...GemTier,
145 tin: "tin",
146 copper: "copper",
147 coal: "coal",
148 silver: "silver",
149 gold: "gold",
150 /** Smelted only: 1 gold ore + 1 silver ore + 3 coal → electrum bar. */
151 electrum: "electrum"
152});
153
154/** Minimum relevant skill level required to equip tools/gear of this tier. */
155export const TIER_MIN_SKILL_LEVEL = Object.freeze({
156 [MaterialTier.bronze]: 1,
157 [MaterialTier.iron]: 10,
158 [MaterialTier.steel]: 20,
159 [MaterialTier.mithril]: 35,
160 [MaterialTier.adamantium]: 50,
161 [MaterialTier.orichalcum]: 70,
162 [MaterialTier.dragon]: 90,
163 [GatherMaterialId.silver]: 10,
164 [GatherMaterialId.gold]: 20,
165 [GatherMaterialId.electrum]: 90,
166 [GemTier.tourmaline]: 1,
167 [GemTier.alexandrite]: 10,
168 [GemTier.opal]: 20,
169 [GemTier.diamond]: 35,
170 [GemTier.emerald]: 50,
171 [GemTier.ruby]: 70,
172 [GemTier.jadeite]: 90,
173 [WoodTier.pine]: 1,
174 [WoodTier.birch]: 10,
175 [WoodTier.oak]: 20,
176 [WoodTier.ebony]: 35,
177 [WoodTier.lignum]: 50,
178 [WoodTier.heartwood]: 70,
179 [WoodTier.elder]: 90,
180 [ClothTier.cotton]: 1,
181 [ClothTier.wool]: 10,
182 [ClothTier.linen]: 20,
183 [ClothTier.cashmere]: 35,
184 [ClothTier.silk]: 50,
185 [ClothTier.fairySilk]: 70,
186 [ClothTier.dragonweave]: 90,
187 [LeatherTier.softLeather]: 1,
188 [LeatherTier.hardLeather]: 10,
189 [LeatherTier.studdedLeather]: 20,
190 [LeatherTier.reinforcedLeather]: 35,
191 [LeatherTier.scaledLeather]: 50,
192 [LeatherTier.wyvernHide]: 70,
193 [LeatherTier.dragonhide]: 90
194});
195
196/** Rank used for mining duration and relative power (1 = bronze/pine … 7 = dragon/elder). */
197export const TIER_RANK = Object.freeze({
198 [MaterialTier.bronze]: 1,
199 [MaterialTier.iron]: 2,
200 [MaterialTier.steel]: 3,
201 [MaterialTier.mithril]: 4,
202 [MaterialTier.adamantium]: 5,
203 [MaterialTier.orichalcum]: 6,
204 [MaterialTier.dragon]: 7,
205 [GatherMaterialId.silver]: 2,
206 [GatherMaterialId.gold]: 3,
207 [GatherMaterialId.electrum]: 7,
208 [GemTier.tourmaline]: 1,
209 [GemTier.alexandrite]: 2,
210 [GemTier.opal]: 3,
211 [GemTier.diamond]: 4,
212 [GemTier.emerald]: 5,
213 [GemTier.ruby]: 6,
214 [GemTier.jadeite]: 7,
215 [WoodTier.pine]: 1,
216 [WoodTier.birch]: 2,
217 [WoodTier.oak]: 3,
218 [WoodTier.ebony]: 4,
219 [WoodTier.lignum]: 5,
220 [WoodTier.heartwood]: 6,
221 [WoodTier.elder]: 7,
222 [ClothTier.cotton]: 1,
223 [ClothTier.wool]: 2,
224 [ClothTier.linen]: 3,
225 [ClothTier.cashmere]: 4,
226 [ClothTier.silk]: 5,
227 [ClothTier.fairySilk]: 6,
228 [ClothTier.dragonweave]: 7,
229 [LeatherTier.softLeather]: 1,
230 [LeatherTier.hardLeather]: 2,
231 [LeatherTier.studdedLeather]: 3,
232 [LeatherTier.reinforcedLeather]: 4,
233 [LeatherTier.scaledLeather]: 5,
234 [LeatherTier.wyvernHide]: 6,
235 [LeatherTier.dragonhide]: 7
236});
237
238/** Stat bonus granted by tier for the equipment's bonus category. */
239export const TIER_STAT_BONUS = Object.freeze({
240 [MaterialTier.bronze]: 1,
241 [MaterialTier.iron]: 2,
242 [MaterialTier.steel]: 4,
243 [MaterialTier.mithril]: 6,
244 [MaterialTier.adamantium]: 8,
245 [MaterialTier.orichalcum]: 10,
246 [MaterialTier.dragon]: 12,
247 [WoodTier.pine]: 1,
248 [WoodTier.birch]: 2,
249 [WoodTier.oak]: 4,
250 [WoodTier.ebony]: 6,
251 [WoodTier.lignum]: 8,
252 [WoodTier.heartwood]: 10,
253 [WoodTier.elder]: 12,
254 [ClothTier.cotton]: 1,
255 [ClothTier.wool]: 2,
256 [ClothTier.linen]: 4,
257 [ClothTier.cashmere]: 6,
258 [ClothTier.silk]: 8,
259 [ClothTier.fairySilk]: 10,
260 [ClothTier.dragonweave]: 12,
261 [LeatherTier.softLeather]: 1,
262 [LeatherTier.hardLeather]: 2,
263 [LeatherTier.studdedLeather]: 4,
264 [LeatherTier.reinforcedLeather]: 6,
265 [LeatherTier.scaledLeather]: 8,
266 [LeatherTier.wyvernHide]: 10,
267 [LeatherTier.dragonhide]: 12
268});
269
270/** Display names for UI / editor. */
271export const MATERIAL_DISPLAY_NAME = Object.freeze({
272 [MaterialTier.bronze]: "Bronze",
273 [MaterialTier.iron]: "Iron",
274 [MaterialTier.steel]: "Steel",
275 [MaterialTier.mithril]: "Mithril",
276 [MaterialTier.adamantium]: "Adamantium",
277 [MaterialTier.orichalcum]: "Orichalcum",
278 [MaterialTier.dragon]: "Dragon",
279 [GatherMaterialId.tin]: "Tin",
280 [GatherMaterialId.copper]: "Copper",
281 [GatherMaterialId.coal]: "Coal",
282 [GatherMaterialId.silver]: "Silver",
283 [GatherMaterialId.gold]: "Gold",
284 [GatherMaterialId.electrum]: "Electrum",
285 [GemTier.tourmaline]: "Tourmaline",
286 [GemTier.alexandrite]: "Alexandrite",
287 [GemTier.opal]: "Opal",
288 [GemTier.diamond]: "Diamond",
289 [GemTier.emerald]: "Emerald",
290 [GemTier.ruby]: "Ruby",
291 [GemTier.jadeite]: "Jadeite",
292 [WoodTier.pine]: "Pine",
293 [WoodTier.birch]: "Birch",
294 [WoodTier.oak]: "Oak",
295 [WoodTier.ebony]: "Ebony",
296 [WoodTier.lignum]: "Lignum",
297 [WoodTier.heartwood]: "Heartwood",
298 [WoodTier.elder]: "Elder"
299});
300
301export const CLOTH_DISPLAY_NAME = Object.freeze({
302 [ClothTier.cotton]: "Cotton",
303 [ClothTier.wool]: "Wool",
304 [ClothTier.linen]: "Linen",
305 [ClothTier.cashmere]: "Cashmere",
306 [ClothTier.silk]: "Silk",
307 [ClothTier.fairySilk]: "Fairy silk",
308 [ClothTier.dragonweave]: "Dragonweave"
309});
310
311/**
312 * Author tint swatches via {@link rgb} (0–255) so editors can offer a colour picker.
313 * Also accepts `0xRRGGBB` / `"#RRGGBB"`; all forms become 0–1 RGB at module load.
314 * Steel is slightly darker than iron; silver is bright gray; gold is yellow;
315 * orichalcum is coppery; dragon is red.
316 */
317export function rgb (r, g, b)
318{
319 return Object.freeze({
320 r: clampByte(r) / 255,
321 g: clampByte(g) / 255,
322 b: clampByte(b) / 255
323 });
324}
325
326function clampByte (n)
327{
328 return Math.min(255, Math.max(0, Math.round(Number(n) || 0)));
329}
330
331export const MATERIAL_TINT_HEX = Object.freeze({
332 [MaterialTier.bronze]: rgb(184, 122, 71),
333 [MaterialTier.iron]: rgb(158, 163, 173),
334 [MaterialTier.steel]: rgb(75, 76, 80),
335 [MaterialTier.mithril]: rgb(3, 120, 255),
336 [MaterialTier.adamantium]: rgb(108, 202, 132),
337 [MaterialTier.orichalcum]: rgb(230, 140, 31),
338 [MaterialTier.dragon]: rgb(228, 19, 15),
339 [GatherMaterialId.tin]: rgb(221, 221, 221),
340 [GatherMaterialId.copper]: rgb(255, 94, 0),
341 [GatherMaterialId.coal]: rgb(45, 45, 48),
342 [GatherMaterialId.silver]: rgb(214, 220, 230),
343 [GatherMaterialId.gold]: rgb(255, 200, 0),
344 [GatherMaterialId.electrum]: rgb(232, 198, 128),
345 [GemTier.tourmaline]: rgb(200, 55, 120),
346 [GemTier.alexandrite]: rgb(120, 70, 180),
347 [GemTier.opal]: rgb(230, 210, 220),
348 [GemTier.diamond]: rgb(200, 235, 255),
349 [GemTier.emerald]: rgb(35, 165, 95),
350 [GemTier.ruby]: rgb(190, 25, 45),
351 [GemTier.jadeite]: rgb(55, 145, 105),
352 [WoodTier.pine]: rgb(199, 158, 97),
353 [WoodTier.birch]: rgb(224, 209, 173),
354 [WoodTier.oak]: rgb(158, 107, 61),
355 [WoodTier.ebony]: rgb(56, 41, 51),
356 [WoodTier.lignum]: rgb(107, 97, 56),
357 [WoodTier.heartwood]: rgb(184, 71, 56),
358 [WoodTier.elder]: rgb(184, 189, 199),
359 [ClothTier.cotton]: rgb(245, 240, 230),
360 [ClothTier.wool]: rgb(220, 210, 195),
361 [ClothTier.linen]: rgb(200, 185, 140),
362 [ClothTier.cashmere]: rgb(210, 175, 150),
363 [ClothTier.silk]: rgb(230, 220, 240),
364 [ClothTier.fairySilk]: rgb(180, 230, 255),
365 [ClothTier.dragonweave]: rgb(200, 60, 50),
366 [LeatherTier.softLeather]: rgb(210, 180, 140),
367 [LeatherTier.hardLeather]: rgb(140, 90, 50),
368 [LeatherTier.studdedLeather]: rgb(110, 70, 40),
369 [LeatherTier.reinforcedLeather]: rgb(120, 100, 85),
370 [LeatherTier.scaledLeather]: rgb(150, 70, 55),
371 [LeatherTier.wyvernHide]: rgb(70, 85, 75),
372 [LeatherTier.dragonhide]: rgb(180, 40, 35)
373});
374
375/**
376 * Optional ore-only tint overrides (boulders + ore items).
377 * Missing entries fall back to {@link MATERIAL_TINT_HEX}.
378 */
379export const MATERIAL_ORE_TINT_HEX = Object.freeze({
380 [MaterialTier.iron]: rgb(210, 118, 48),
381 [GatherMaterialId.copper]: rgb(81, 153, 105)
382});
383
384/**
385 * Normalize tint authoring forms to frozen 0–1 `{ r, g, b }`:
386 * - number `0xRRGGBB`
387 * - string `"#RGB"` / `"#RRGGBB"` / `"rgb(r,g,b)"`
388 * - object from {@link rgb}
389 */
390export function hexToRgb01 (hex)
391{
392 if (hex && typeof hex === "object" && "r" in hex && "g" in hex && "b" in hex)
393 {
394 return Object.freeze({
395 r: clamp01Channel(hex.r),
396 g: clamp01Channel(hex.g),
397 b: clamp01Channel(hex.b)
398 });
399 }
400 if (typeof hex === "number" && Number.isFinite(hex))
401 {
402 const value = hex >>> 0;
403 return Object.freeze({
404 r: ((value >> 16) & 255) / 255,
405 g: ((value >> 8) & 255) / 255,
406 b: (value & 255) / 255
407 });
408 }
409 const text = String(hex ?? "").trim();
410 const rgbMatch = /^rgba?\(\s*([0-9.]+)\s*,\s*([0-9.]+)\s*,\s*([0-9.]+)/i.exec(text);
411 if (rgbMatch)
412 { return rgb(rgbMatch[1], rgbMatch[2], rgbMatch[3]); }
413 const raw = text.replace(/^#/, "");
414 const full = raw.length === 3
415 ? raw.split("").map((ch) => ch + ch).join("")
416 : raw;
417 if (!/^[0-9a-fA-F]{6}$/.test(full))
418 { return Object.freeze({ r: 0.7, g: 0.7, b: 0.7 }); }
419 const value = Number.parseInt(full, 16);
420 return Object.freeze({
421 r: ((value >> 16) & 255) / 255,
422 g: ((value >> 8) & 255) / 255,
423 b: (value & 255) / 255
424 });
425}
426
427function clamp01Channel (n)
428{
429 const value = Number(n);
430 if (!Number.isFinite(value))
431 { return 0; }
432 if (value > 1)
433 { return clampByte(value) / 255; }
434 return Math.min(1, Math.max(0, value));
435}
436
437/** 0–1 RGB map derived from {@link MATERIAL_TINT_HEX}. */
438export const MATERIAL_TINT_COLOR = Object.freeze(
439 Object.fromEntries(
440 Object.entries(MATERIAL_TINT_HEX).map(([id, hex]) => [id, hexToRgb01(hex)])
441 )
442);
443
444/** 0–1 RGB map derived from {@link MATERIAL_ORE_TINT_HEX}. */
445export const MATERIAL_ORE_TINT_COLOR = Object.freeze(
446 Object.fromEntries(
447 Object.entries(MATERIAL_ORE_TINT_HEX).map(([id, hex]) => [id, hexToRgb01(hex)])
448 )
449);
450
451/** Wood tier that matches a metal tier's rank (for tool hafts). */
452export const WOOD_TIER_FOR_METAL = Object.freeze({
453 [MaterialTier.bronze]: WoodTier.pine,
454 [MaterialTier.iron]: WoodTier.birch,
455 [MaterialTier.steel]: WoodTier.oak,
456 [MaterialTier.mithril]: WoodTier.ebony,
457 [MaterialTier.adamantium]: WoodTier.lignum,
458 [MaterialTier.orichalcum]: WoodTier.heartwood,
459 [MaterialTier.dragon]: WoodTier.elder
460});
461
462export const METAL_TIER_FOR_WOOD = Object.freeze(Object.fromEntries(
463 Object.entries(WOOD_TIER_FOR_METAL).map(([metal, wood]) => [wood, metal])
464));
465
466/**
467 * Bar tier that drives mine/smelt duration and gates for a gatherable.
468 * Tin/copper → bronze; coal → steel; gold/silver and gear metals map to themselves.
469 */
470export function associatedBarTier (materialId)
471{
472 if (materialId === GatherMaterialId.tin || materialId === GatherMaterialId.copper)
473 { return MaterialTier.bronze; }
474 if (materialId === GatherMaterialId.coal)
475 { return MaterialTier.steel; }
476 const gemIdx = GEM_TIER_ORDER.indexOf(materialId);
477 if (gemIdx >= 0)
478 { return MATERIAL_TIER_ORDER[gemIdx] ?? MaterialTier.bronze; }
479 return materialId;
480}
481
482export function materialDisplayName (materialId)
483{
484 return MATERIAL_DISPLAY_NAME[materialId] ?? materialId;
485}
486
487/**
488 * Tint for a material. When `ore` is true, prefer {@link MATERIAL_ORE_TINT_COLOR}
489 * if defined for that material; otherwise the normal material tint.
490 */
491export function materialTintColor (materialId, { ore = false } = {})
492{
493 if (ore)
494 {
495 const oreTint = MATERIAL_ORE_TINT_COLOR[materialId];
496 if (oreTint)
497 { return oreTint; }
498 }
499 return MATERIAL_TINT_COLOR[materialId] ?? MATERIAL_TINT_COLOR[MaterialTier.bronze];
500}
501
502export function tierStatBonus (tier)
503{
504 return TIER_STAT_BONUS[tier] ?? TIER_STAT_BONUS[MaterialTier.bronze];
505}
506
507/** Alias for equipment combat boosts derived from material tier. */
508export const statBoostPerTier = tierStatBonus;
509
510export function tierMinSkillLevel (tier)
511{
512 return TIER_MIN_SKILL_LEVEL[tier] ?? TIER_MIN_SKILL_LEVEL[MaterialTier.bronze];
513}
514
515export function tierRank (tier)
516{
517 return TIER_RANK[associatedBarTier(tier)] ?? TIER_RANK[tier] ?? 1;
518}
519
520/** Mining / woodcutting skill required (half of equip gate, ceil). */
521export function tierMineSkillLevel (tier)
522{
523 return Math.max(1, Math.ceil(tierMinSkillLevel(associatedBarTier(tier)) / 2));
524}
525
526/** Smithing / woodcraft skill required to process this material (75% of equip gate, ceil). */
527export function tierSmeltSkillLevel (tier)
528{
529 return Math.max(1, Math.ceil(tierMinSkillLevel(associatedBarTier(tier)) * 0.75));
530}
531
532/** Alias for woodworking / general craft gates (same curve as smelting). */
533export function tierCraftSkillLevel (tier)
534{
535 return tierSmeltSkillLevel(tier);
536}
537
538export function woodTierForMetal (metalTier)
539{
540 return WOOD_TIER_FOR_METAL[metalTier] ?? WoodTier.pine;
541}
542
543/** Matching leather material for a metal tier (bronze↔soft … dragon↔dragonhide). */
544export function leatherTierForMetal (metalTier)
545{
546 const idx = MATERIAL_TIER_ORDER.indexOf(metalTier);
547 return LEATHER_TIER_ORDER[idx >= 0 ? idx : 0] ?? LeatherTier.softLeather;
548}
549
550export function metalTierForLeather (leatherTier)
551{
552 const idx = LEATHER_TIER_ORDER.indexOf(leatherTier);
553 return MATERIAL_TIER_ORDER[idx >= 0 ? idx : 0] ?? MaterialTier.bronze;
554}
555
556/** Matching wood tier for a gemstone (tourmaline↔pine … jadeite↔elder). */
557export function woodTierForGem (gemTier)
558{
559 const idx = GEM_TIER_ORDER.indexOf(gemTier);
560 return WOOD_TIER_ORDER[idx >= 0 ? idx : 0] ?? WoodTier.pine;
561}
562
563/** Matching gemstone for a wood tier. */
564export function gemTierForWood (woodTier)
565{
566 const idx = WOOD_TIER_ORDER.indexOf(woodTier);
567 return GEM_TIER_ORDER[idx >= 0 ? idx : 0] ?? GemTier.tourmaline;
568}
569
570export function isGemstoneMaterial (materialId)
571{
572 return GEM_TIER_ORDER.includes(materialId);
573}
574
575/** Matching cloth tier for a wood tier (pine↔cotton, birch↔wool, …). */
576export function clothTierForWood (woodTier)
577{
578 const idx = WOOD_TIER_ORDER.indexOf(woodTier);
579 return CLOTH_TIER_ORDER[idx >= 0 ? idx : 0] ?? ClothTier.cotton;
580}
581
582export function metalTierForWood (woodTier)
583{
584 return METAL_TIER_FOR_WOOD[woodTier] ?? MaterialTier.bronze;
585}
586
587/**
588 * Mining action duration in ms.
589 * (resourceRank * 8s) − (toolRank * 3s), floored at 0.5s.
590 * Tin/copper/coal use their associated bar's rank.
591 */
592export function miningDurationMs (resourceMaterialId, toolTier)
593{
594 const resourceRank = tierRank(resourceMaterialId);
595 const toolRank = tierRank(toolTier);
596 const seconds = Math.max(0.5, resourceRank * 8 - toolRank * 3);
597 return Math.round(seconds * 1000);
598}
599
600/** After a successful mine, nodes stay exhausted for 10s × associated bar rank. */
601export function oreExhaustDurationMs (materialId)
602{
603 return Math.max(1, tierRank(materialId)) * 10_000;
604}
605
606/** Base craft duration per bar rank (bronze = 2s, iron = 4s, …). */
607export const SMELT_DURATION_PER_RANK_MS = 2000;
608
609/**
610 * Furnace smelt duration from the output bar's associated tier rank.
611 * Tin/copper/coal map to bronze/steel so ingredient timing matches that bar.
612 */
613export function smeltingDurationMs (barOrMaterialId)
614{
615 return Math.max(1, tierRank(barOrMaterialId)) * SMELT_DURATION_PER_RANK_MS;
616}
617
618/** Visual / interact state while an ore boulder is depleted (plain rock). */
619export const EXHAUSTED_ORE_BOULDER_STATE = "boulder";
620
621/**
622 * Materials that have an ore boulder node.
623 * Bronze has no ore (tin + copper); steel has no ore (iron + coal).
624 * Gold and silver are precious only (ore + bars, no tools).
625 */
626export const ORE_BEARING_MATERIALS = Object.freeze([
627 GatherMaterialId.tin,
628 GatherMaterialId.copper,
629 MaterialTier.iron,
630 GatherMaterialId.silver,
631 GatherMaterialId.gold,
632 MaterialTier.mithril,
633 MaterialTier.adamantium,
634 MaterialTier.orichalcum,
635 MaterialTier.dragon,
636 GatherMaterialId.coal,
637 ...GEM_TIER_ORDER
638]);
639
640/** Boulder visual state for a gatherable ore (editor / world). */
641export function oreBoulderState (materialId)
642{
643 if (materialId === GatherMaterialId.coal)
644 { return "coal"; }
645 return `${materialId}-ore`;
646}
647
648export function materialFromOreBoulderState (state)
649{
650 if (!state || state === "boulder")
651 { return null; }
652 if (state === "coal")
653 { return GatherMaterialId.coal; }
654 if (state.endsWith("-ore"))
655 {
656 const id = state.slice(0, -"-ore".length);
657 if (ORE_BEARING_MATERIALS.includes(id))
658 { return id; }
659 }
660 return null;
661}
662
663export function isOreBoulderState (state)
664{
665 return materialFromOreBoulderState(state) != null;
666}