BlueGit

timfa questward

Files

questward / shared / definitions / materialTiers.js

materialTiers.js

materialTiers.js 5.4 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/** Ordered low → high (metal smithing / tools). */
16export const MATERIAL_TIER_ORDER = Object.freeze([
17 MaterialTier.bronze,
18 MaterialTier.iron,
19 MaterialTier.steel,
20 MaterialTier.mithril,
21 MaterialTier.adamantium,
22 MaterialTier.orichalcum,
23 MaterialTier.dragon
24]);
25
26/** Non-metal gatherable that shares ore-boulder art (dark gray tint). */
27export const GatherMaterialId = Object.freeze({
28 ...MaterialTier,
29 coal: "coal"
30});
31
32/** Minimum relevant skill level required to equip tools/gear of this tier. */
33export const TIER_MIN_SKILL_LEVEL = Object.freeze({
34 [MaterialTier.bronze]: 1,
35 [MaterialTier.iron]: 10,
36 [MaterialTier.steel]: 20,
37 [MaterialTier.mithril]: 35,
38 [MaterialTier.adamantium]: 50,
39 [MaterialTier.orichalcum]: 70,
40 [MaterialTier.dragon]: 90
41});
42
43/** Rank used for mining duration and relative power (1 = bronze … 7 = dragon). */
44export const TIER_RANK = Object.freeze({
45 [MaterialTier.bronze]: 1,
46 [MaterialTier.iron]: 2,
47 [MaterialTier.steel]: 3,
48 [MaterialTier.mithril]: 4,
49 [MaterialTier.adamantium]: 5,
50 [MaterialTier.orichalcum]: 6,
51 [MaterialTier.dragon]: 7,
52 [GatherMaterialId.coal]: 2
53});
54
55/** Stat bonus granted by tier for the equipment's bonus category. */
56export const TIER_STAT_BONUS = Object.freeze({
57 [MaterialTier.bronze]: 1,
58 [MaterialTier.iron]: 2,
59 [MaterialTier.steel]: 4,
60 [MaterialTier.mithril]: 6,
61 [MaterialTier.adamantium]: 8,
62 [MaterialTier.orichalcum]: 10,
63 [MaterialTier.dragon]: 12
64});
65
66/** Display names for UI / editor. */
67export const MATERIAL_DISPLAY_NAME = Object.freeze({
68 [MaterialTier.bronze]: "Bronze",
69 [MaterialTier.iron]: "Iron",
70 [MaterialTier.steel]: "Steel",
71 [MaterialTier.mithril]: "Mithril",
72 [MaterialTier.adamantium]: "Adamantium",
73 [MaterialTier.orichalcum]: "Orichalcum",
74 [MaterialTier.dragon]: "Dragon",
75 [GatherMaterialId.coal]: "Coal"
76});
77
78/**
79 * Display tint colors (0–1 RGB) for magenta-tinted sprites.
80 * Steel is slightly darker than iron; orichalcum is coppery-gold; dragon is red.
81 */
82export const MATERIAL_TINT_COLOR = Object.freeze({
83 [MaterialTier.bronze]: Object.freeze({ r: 0.72, g: 0.48, b: 0.28 }),
84 [MaterialTier.iron]: Object.freeze({ r: 0.62, g: 0.64, b: 0.68 }),
85 [MaterialTier.steel]: Object.freeze({ r: 0.48, g: 0.50, b: 0.54 }),
86 [MaterialTier.mithril]: Object.freeze({ r: 0.40, g: 0.55, b: 0.88 }),
87 [MaterialTier.adamantium]: Object.freeze({ r: 0.35, g: 0.75, b: 0.45 }),
88 [MaterialTier.orichalcum]: Object.freeze({ r: 0.90, g: 0.55, b: 0.22 }),
89 [MaterialTier.dragon]: Object.freeze({ r: 0.88, g: 0.18, b: 0.16 }),
90 [GatherMaterialId.coal]: Object.freeze({ r: 0.22, g: 0.22, b: 0.25 })
91});
92
93export function materialDisplayName (materialId)
94{
95 return MATERIAL_DISPLAY_NAME[materialId] ?? materialId;
96}
97
98export function materialTintColor (materialId)
99{
100 return MATERIAL_TINT_COLOR[materialId] ?? MATERIAL_TINT_COLOR[MaterialTier.bronze];
101}
102
103export function tierStatBonus (tier)
104{
105 return TIER_STAT_BONUS[tier] ?? TIER_STAT_BONUS[MaterialTier.bronze];
106}
107
108export function tierMinSkillLevel (tier)
109{
110 return TIER_MIN_SKILL_LEVEL[tier] ?? TIER_MIN_SKILL_LEVEL[MaterialTier.bronze];
111}
112
113export function tierRank (tier)
114{
115 return TIER_RANK[tier] ?? 1;
116}
117
118/** Mining skill required to mine this material's ore (half of equip gate, ceil). */
119export function tierMineSkillLevel (tier)
120{
121 return Math.max(1, Math.ceil(tierMinSkillLevel(tier) / 2));
122}
123
124/** Smithing skill required to smelt this metal (75% of equip gate, ceil). */
125export function tierSmeltSkillLevel (tier)
126{
127 return Math.max(1, Math.ceil(tierMinSkillLevel(tier) * 0.75));
128}
129
130/**
131 * Mining action duration in ms.
132 * (resourceRank * 8s) − (toolRank * 3s), floored at 0.5s.
133 */
134export function miningDurationMs (resourceMaterialId, toolTier)
135{
136 const resourceRank = tierRank(resourceMaterialId);
137 const toolRank = tierRank(toolTier);
138 const seconds = Math.max(0.5, resourceRank * 8 - toolRank * 3);
139 return Math.round(seconds * 1000);
140}
141
142/** After a successful mine, nodes stay exhausted for 10s × material rank. */
143export function oreExhaustDurationMs (materialId)
144{
145 return Math.max(1, tierRank(materialId)) * 10_000;
146}
147
148/** Visual / interact state while an ore boulder is depleted (plain rock). */
149export const EXHAUSTED_ORE_BOULDER_STATE = "boulder";
150
151/** Metals that have an ore node (steel is smelted from iron + coal). */
152export const ORE_BEARING_MATERIALS = Object.freeze([
153 MaterialTier.bronze,
154 MaterialTier.iron,
155 MaterialTier.mithril,
156 MaterialTier.adamantium,
157 MaterialTier.orichalcum,
158 MaterialTier.dragon,
159 GatherMaterialId.coal
160]);
161
162/** Boulder visual state for a gatherable ore (editor / world). */
163export function oreBoulderState (materialId)
164{
165 if (materialId === GatherMaterialId.coal)
166 { return "coal"; }
167 return `${materialId}-ore`;
168}
169
170export function materialFromOreBoulderState (state)
171{
172 if (!state || state === "boulder")
173 { return null; }
174 if (state === "coal")
175 { return GatherMaterialId.coal; }
176 if (state.endsWith("-ore"))
177 {
178 const id = state.slice(0, -"-ore".length);
179 if (ORE_BEARING_MATERIALS.includes(id))
180 { return id; }
181 }
182 return null;
183}
184
185export function isOreBoulderState (state)
186{
187 return materialFromOreBoulderState(state) != null;
188}