BlueGit

timfa questward

Files

questward / shared / definitions / materialTiers.js

materialTiers.js

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