| 1 | import { ItemCategory } from "./itemCategories.js"; |
| 2 | import { EquipmentKind } from "./equipmentKinds.js"; |
| 3 | import { equipImageName } from "./tileSprites.js"; |
| 4 | import |
| 5 | { |
| 6 | ClothTier, |
| 7 | CLOTH_TIER_ORDER, |
| 8 | CLOTH_DISPLAY_NAME, |
| 9 | leatherTierForCloth, |
| 10 | tierMinSkillLevel |
| 11 | } from "./materialTiers.js"; |
| 12 | |
| 13 | export const WIZARD_PIECES = Object.freeze([ |
| 14 | Object.freeze({ |
| 15 | templateId: "wizard-hat", |
| 16 | suffix: "hat", |
| 17 | slot: "head", |
| 18 | label: "hat", |
| 19 | idKey: "Hat", |
| 20 | pieceKey: "hat", |
| 21 | clothQty: 2, |
| 22 | leatherQty: 1, |
| 23 | dualTint: true |
| 24 | }), |
| 25 | Object.freeze({ |
| 26 | templateId: "wizard-robetop", |
| 27 | suffix: "robetop", |
| 28 | slot: "chest", |
| 29 | label: "robe top", |
| 30 | idKey: "RobeTop", |
| 31 | pieceKey: "robetop", |
| 32 | clothQty: 5, |
| 33 | leatherQty: 1, |
| 34 | dualTint: true |
| 35 | }), |
| 36 | Object.freeze({ |
| 37 | templateId: "wizard-robebottoms", |
| 38 | suffix: "robebottoms", |
| 39 | slot: "legs", |
| 40 | label: "robe bottoms", |
| 41 | idKey: "RobeBottoms", |
| 42 | pieceKey: "robebottoms", |
| 43 | clothQty: 4, |
| 44 | leatherQty: 0, |
| 45 | dualTint: false |
| 46 | }), |
| 47 | Object.freeze({ |
| 48 | templateId: "wizard-shoes", |
| 49 | suffix: "shoes", |
| 50 | slot: "boots", |
| 51 | label: "shoes", |
| 52 | idKey: "Shoes", |
| 53 | pieceKey: "shoes", |
| 54 | clothQty: 1, |
| 55 | leatherQty: 1, |
| 56 | dualTint: true |
| 57 | }) |
| 58 | ]); |
| 59 | |
| 60 | function buildWizardItemIds () |
| 61 | { |
| 62 | const ids = {}; |
| 63 | let nextId = 533; |
| 64 | for (const tier of CLOTH_TIER_ORDER) |
| 65 | { |
| 66 | for (const piece of WIZARD_PIECES) |
| 67 | { |
| 68 | ids[`${tier}${piece.idKey}`] = nextId++; |
| 69 | } |
| 70 | } |
| 71 | return Object.freeze(ids); |
| 72 | } |
| 73 | |
| 74 | export const WizardItemId = buildWizardItemIds(); |
| 75 | |
| 76 | export function wizardItemIdForTier (clothTier, idKey) |
| 77 | { |
| 78 | return WizardItemId[`${clothTier}${idKey}`] ?? null; |
| 79 | } |
| 80 | |
| 81 | function wizardPieceDef (itemId, clothTier, piece) |
| 82 | { |
| 83 | const name = CLOTH_DISPLAY_NAME[clothTier] ?? clothTier; |
| 84 | const leatherTier = leatherTierForCloth(clothTier); |
| 85 | const tierSlug = clothTier === ClothTier.cotton |
| 86 | ? "cotton" |
| 87 | : clothTier.replace(/([A-Z])/g, "-$1").toLowerCase(); |
| 88 | const def = { |
| 89 | itemId, |
| 90 | key: `${tierSlug}-wizard-${piece.suffix}`, |
| 91 | displayName: `${name} ${piece.label}`, |
| 92 | description: piece.suffix === "hat" |
| 93 | ? `A pointed ${name.toLowerCase()} hat, cut for study and spellcraft.` |
| 94 | : piece.suffix === "robetop" |
| 95 | ? `A long ${name.toLowerCase()} robe top, loose enough for gestures and runes.` |
| 96 | : piece.suffix === "robebottoms" |
| 97 | ? `Flowing ${name.toLowerCase()} robe bottoms that brush the ground when you walk.` |
| 98 | : `Soft ${name.toLowerCase()} shoes, quiet on stone floors.`, |
| 99 | seedValue: 8, |
| 100 | stackable: false, |
| 101 | maxStackSize: 1, |
| 102 | uniqueInstance: false, |
| 103 | category: ItemCategory.finished, |
| 104 | iconKey: "magicrobes", |
| 105 | defaultState: piece.suffix, |
| 106 | tier: clothTier, |
| 107 | dyeable: true, |
| 108 | equipment: Object.freeze({ |
| 109 | slot: piece.slot, |
| 110 | tier: clothTier, |
| 111 | kind: EquipmentKind.wizardCloth, |
| 112 | minSkillLevel: tierMinSkillLevel(clothTier), |
| 113 | equipSprite: equipImageName("item", "magicrobes", piece.suffix) |
| 114 | }) |
| 115 | }; |
| 116 | if (piece.dualTint) |
| 117 | { |
| 118 | def.leatherTier = leatherTier; |
| 119 | def.clothTier = clothTier; |
| 120 | def.dualTintLeatherCloth = true; |
| 121 | def.dualTintFromTier = true; |
| 122 | def.equipment = Object.freeze({ |
| 123 | ...def.equipment, |
| 124 | dualTintFromTier: true |
| 125 | }); |
| 126 | } |
| 127 | else |
| 128 | { |
| 129 | def.tintFromTier = true; |
| 130 | def.equipment = Object.freeze({ |
| 131 | ...def.equipment, |
| 132 | tintFromTier: true |
| 133 | }); |
| 134 | } |
| 135 | return Object.freeze(def); |
| 136 | } |
| 137 | |
| 138 | function buildWizardDefinitions () |
| 139 | { |
| 140 | const defs = {}; |
| 141 | for (const tier of CLOTH_TIER_ORDER) |
| 142 | { |
| 143 | for (const piece of WIZARD_PIECES) |
| 144 | { |
| 145 | const prop = `${tier}${piece.idKey}`; |
| 146 | const itemId = WizardItemId[prop]; |
| 147 | if (itemId == null) |
| 148 | { throw new Error(`Missing WizardItemId for ${prop}`); } |
| 149 | defs[itemId] = wizardPieceDef(itemId, tier, piece); |
| 150 | } |
| 151 | } |
| 152 | return Object.freeze(defs); |
| 153 | } |
| 154 | |
| 155 | export const WIZARD_ITEM_DEFINITIONS = buildWizardDefinitions(); |
| 156 | |
| 157 | /** Tailor bench templates for wizard robes. */ |
| 158 | export const WIZARD_TEMPLATES = Object.freeze( |
| 159 | Object.fromEntries(WIZARD_PIECES.map((piece) => |
| 160 | { |
| 161 | const inputs = [{ kind: "cloth", quantity: piece.clothQty }]; |
| 162 | if (piece.leatherQty > 0) |
| 163 | { inputs.push({ kind: "leather", quantity: piece.leatherQty }); } |
| 164 | return [piece.templateId, Object.freeze({ |
| 165 | templateId: piece.templateId, |
| 166 | displayName: piece.label.charAt(0).toUpperCase() + piece.label.slice(1), |
| 167 | slot: piece.slot, |
| 168 | inputs: Object.freeze(inputs), |
| 169 | outputItemIdForTier: (tier) => wizardItemIdForTier(tier, piece.idKey), |
| 170 | minSkillLevel: 1 |
| 171 | })]; |
| 172 | })) |
| 173 | ); |
| 174 | |
| 175 | export function wizardTemplate (templateId) |
| 176 | { |
| 177 | return WIZARD_TEMPLATES[templateId] ?? null; |
| 178 | } |
| 179 | |
| 180 | export function listWizardTemplates () |
| 181 | { |
| 182 | return Object.values(WIZARD_TEMPLATES); |
| 183 | } |
| 184 | |
| 185 | export function wizardHatItemId (tier) { return wizardItemIdForTier(tier, "Hat"); } |
| 186 | export function wizardRobeTopItemId (tier) { return wizardItemIdForTier(tier, "RobeTop"); } |
| 187 | export function wizardRobeBottomsItemId (tier) { return wizardItemIdForTier(tier, "RobeBottoms"); } |
| 188 | export function wizardShoesItemId (tier) { return wizardItemIdForTier(tier, "Shoes"); } |