BlueGit

timfa questward

Files

questward / shared / definitions / gemItems.js

gemItems.js

gem fix
timfa Tim Falken · pushed by timfa · 2 months ago
b67f970b History
gemItems.js 4.0 KiB Download Raw
1import { ItemCategory } from "./itemCategories.js";
2import
3 {
4 GemTier,
5 GEM_TIER_ORDER,
6 MATERIAL_DISPLAY_NAME,
7 WOOD_TIER_ORDER,
8 gemTierForWood,
9 tierMinSkillLevel,
10 tierRank
11 } from "./materialTiers.js";
12import { EquipmentKind } from "./equipmentKinds.js";
13import { CraftingStationId } from "./craftingStations.js";
14import { logItemIdForWood, ashItemIdForWood } from "./woodItems.js";
15
16const DEFAULT_STACK = 99;
17
18/**
19 * Raw gemstones (377–383) and magic staves (384–390).
20 * Staves: red = wood, blue = gem (dual-tint staff sprite).
21 */
22export const GemItemId = Object.freeze({
23 tourmaline: 377,
24 alexandrite: 378,
25 opal: 379,
26 diamond: 380,
27 emerald: 381,
28 ruby: 382,
29 jadeite: 383,
30 pineStaff: 384,
31 birchStaff: 385,
32 oakStaff: 386,
33 ebonyStaff: 387,
34 lignumStaff: 388,
35 heartwoodStaff: 389,
36 elderStaff: 390
37});
38
39export const GEM_ITEM_BY_TIER = Object.freeze({
40 [GemTier.tourmaline]: GemItemId.tourmaline,
41 [GemTier.alexandrite]: GemItemId.alexandrite,
42 [GemTier.opal]: GemItemId.opal,
43 [GemTier.diamond]: GemItemId.diamond,
44 [GemTier.emerald]: GemItemId.emerald,
45 [GemTier.ruby]: GemItemId.ruby,
46 [GemTier.jadeite]: GemItemId.jadeite
47});
48
49export const STAFF_ITEM_BY_WOOD = Object.freeze({
50 pine: GemItemId.pineStaff,
51 birch: GemItemId.birchStaff,
52 oak: GemItemId.oakStaff,
53 ebony: GemItemId.ebonyStaff,
54 lignum: GemItemId.lignumStaff,
55 heartwood: GemItemId.heartwoodStaff,
56 elder: GemItemId.elderStaff
57});
58
59export function gemItemId (gemTier)
60{
61 return GEM_ITEM_BY_TIER[gemTier] ?? null;
62}
63
64export function staffItemIdForWood (woodTier)
65{
66 return STAFF_ITEM_BY_WOOD[woodTier] ?? null;
67}
68
69function buildGemDefinitions ()
70{
71 const out = {};
72 for (const gemTier of GEM_TIER_ORDER)
73 {
74 const itemId = GEM_ITEM_BY_TIER[gemTier];
75 const name = MATERIAL_DISPLAY_NAME[gemTier] ?? gemTier;
76 out[itemId] = Object.freeze({
77 itemId,
78 key: `${gemTier}-gem`,
79 displayName: name,
80 description: `A polished ${name.toLowerCase()}, cool and bright in the hand.`,
81 seedValue: tierRank(gemTier) * 3,
82 stackable: true,
83 maxStackSize: DEFAULT_STACK,
84 uniqueInstance: false,
85 category: ItemCategory.ingredient,
86 iconKey: "metal",
87 defaultState: "ore",
88 tier: gemTier,
89 tintFromTier: true,
90 gemstone: true,
91 npcShopAllowed: true
92 });
93 }
94 return out;
95}
96
97function buildStaffDefinitions ()
98{
99 const out = {};
100 for (const woodTier of WOOD_TIER_ORDER)
101 {
102 const itemId = STAFF_ITEM_BY_WOOD[woodTier];
103 const gemTier = gemTierForWood(woodTier);
104 const woodName = MATERIAL_DISPLAY_NAME[woodTier] ?? woodTier;
105 const gemName = MATERIAL_DISPLAY_NAME[gemTier] ?? gemTier;
106 out[itemId] = Object.freeze({
107 itemId,
108 key: `${woodTier}-staff`,
109 displayName: `${woodName} staff`,
110 description: `A ${woodName.toLowerCase()} shaft capped with ${gemName.toLowerCase()}.`,
111 seedValue: tierRank(woodTier) * 4,
112 stackable: false,
113 maxStackSize: 1,
114 uniqueInstance: false,
115 category: ItemCategory.tool,
116 iconKey: "staff",
117 defaultState: "staff",
118 tier: woodTier,
119 gemTier,
120 tintFromTier: true,
121 dualTintFromTier: true,
122 equipment: Object.freeze({
123 slot: "weapon",
124 tier: woodTier,
125 kind: EquipmentKind.staff,
126 tintFromTier: true,
127 dualTintFromTier: true
128 }),
129 npcShopAllowed: true
130 });
131 }
132 return out;
133}
134
135export const GEM_ITEM_DEFINITIONS = Object.freeze({
136 ...buildGemDefinitions(),
137 ...buildStaffDefinitions()
138});
139
140/** Craft recipes: 1 log + 1 gem + 1 ash → staff (matching wood/gem tier). */
141export function staffCraftRecipes ()
142{
143 return WOOD_TIER_ORDER.map((woodTier) =>
144 {
145 const gemTier = gemTierForWood(woodTier);
146 return Object.freeze({
147 recipeId: `staff-${woodTier}`,
148 craftGroup: "staff",
149 craftGroupLabel: "Staff",
150 stationId: CraftingStationId.craftingBench,
151 output: { itemId: staffItemIdForWood(woodTier), quantity: 1 },
152 inputs: [
153 { itemId: logItemIdForWood(woodTier), quantity: 1 },
154 { itemId: gemItemId(gemTier), quantity: 1 },
155 { itemId: ashItemIdForWood(woodTier), quantity: 1 }
156 ],
157 minSkillLevel: tierMinSkillLevel(woodTier),
158 skillId: "crafting",
159 xpMaterial: woodTier
160 });
161 });
162}