| 1 | import test from "node:test"; |
| 2 | import assert from "node:assert/strict"; |
| 3 | import { ItemId, itemDefinition, itemEquipSprite, EQUIPMENT_SLOT, EQUIPMENT_DRAW_ORDER } from "../../shared/definitions/items.js"; |
| 4 | import { JewelryItemId, jewelryCraftRecipes, jewelryMetalIdForGemTier } from "../../shared/definitions/jewelryItems.js"; |
| 5 | import { GemItemId } from "../../shared/definitions/gemItems.js"; |
| 6 | import { MetalItemId } from "../../shared/definitions/metalItems.js"; |
| 7 | import { ClothItemId } from "../../shared/definitions/clothItems.js"; |
| 8 | import { GatherMaterialId, GemTier } from "../../shared/definitions/materialTiers.js"; |
| 9 | import { resolveItemDualTint } from "../../shared/render/tint.js"; |
| 10 | import { EQUIPMENT_SLOTS, emptyEquipment } from "../../shared/items/inventory.js"; |
| 11 | import { recipeDefinition } from "../../shared/crafting/recipes.js"; |
| 12 | import |
| 13 | { |
| 14 | JADEITE_FAIRY_RESPAWN_MS, |
| 15 | JEWELRY_TELEPORT_MS, |
| 16 | canTeleportToBank, |
| 17 | canTeleportToChurch, |
| 18 | summonsJadeiteFairy |
| 19 | } from "../../shared/equipment/jewelryEffects.js"; |
| 20 | |
| 21 | test("equipment slots include ring bracelet amulet", () => |
| 22 | { |
| 23 | assert.ok(EQUIPMENT_SLOTS.includes("ring")); |
| 24 | assert.ok(EQUIPMENT_SLOTS.includes("bracelet")); |
| 25 | assert.ok(EQUIPMENT_SLOTS.includes("amulet")); |
| 26 | const empty = emptyEquipment(); |
| 27 | assert.equal(empty.slots.ring, null); |
| 28 | assert.equal(empty.slots.amulet, null); |
| 29 | const ringIdx = EQUIPMENT_DRAW_ORDER.indexOf(EQUIPMENT_SLOT.ring); |
| 30 | const chestIdx = EQUIPMENT_DRAW_ORDER.indexOf(EQUIPMENT_SLOT.chest); |
| 31 | const amuletIdx = EQUIPMENT_DRAW_ORDER.indexOf(EQUIPMENT_SLOT.amulet); |
| 32 | assert.ok(ringIdx < chestIdx, "ring draws under clothing"); |
| 33 | assert.ok(amuletIdx > chestIdx, "amulet draws over clothing"); |
| 34 | }); |
| 35 | |
| 36 | test("jewellery uses silver gold electrum by gem tier", () => |
| 37 | { |
| 38 | assert.equal(jewelryMetalIdForGemTier(GemTier.tourmaline), GatherMaterialId.silver); |
| 39 | assert.equal(jewelryMetalIdForGemTier(GemTier.diamond), GatherMaterialId.gold); |
| 40 | assert.equal(jewelryMetalIdForGemTier(GemTier.jadeite), GatherMaterialId.electrum); |
| 41 | }); |
| 42 | |
| 43 | test("precious bars describe the jewelering station, not the anvil", () => |
| 44 | { |
| 45 | for (const itemId of [MetalItemId.silverBar, MetalItemId.goldBar, MetalItemId.electrumBar]) |
| 46 | { |
| 47 | const def = itemDefinition(itemId); |
| 48 | assert.match(def.description, /jewelering station/i); |
| 49 | assert.doesNotMatch(def.description, /anvil/i); |
| 50 | } |
| 51 | assert.match(itemDefinition(MetalItemId.ironBar).description, /anvil/i); |
| 52 | }); |
| 53 | |
| 54 | test("jewellery recipes take one bar one cut gem and yarn for amulets", () => |
| 55 | { |
| 56 | const ring = recipeDefinition("ring-opal"); |
| 57 | assert.ok(ring); |
| 58 | assert.deepEqual(ring.inputs, [ |
| 59 | { itemId: MetalItemId.silverBar, quantity: 1 }, |
| 60 | { itemId: GemItemId.opalCut, quantity: 1 } |
| 61 | ]); |
| 62 | const amulet = recipeDefinition("amulet-ruby"); |
| 63 | assert.ok(amulet); |
| 64 | assert.equal(amulet.inputs.length, 3); |
| 65 | assert.ok(amulet.inputs.some((row) => row.itemId === MetalItemId.goldBar)); |
| 66 | assert.ok(amulet.inputs.some((row) => row.itemId === GemItemId.rubyCut)); |
| 67 | assert.ok(amulet.inputs.some((row) => row.itemId === ClothItemId.fairySilkYarn)); |
| 68 | assert.equal(jewelryCraftRecipes().length, 21); |
| 69 | }); |
| 70 | |
| 71 | test("jewellery dual tint maps metal gem and yarn channels", () => |
| 72 | { |
| 73 | const ring = resolveItemDualTint({ itemId: JewelryItemId.tourmalineRing }); |
| 74 | assert.ok(ring?.shaft); |
| 75 | assert.ok(ring?.tip); |
| 76 | assert.equal(ring.coat, undefined); |
| 77 | const amulet = resolveItemDualTint({ itemId: JewelryItemId.jadeiteAmulet }); |
| 78 | assert.ok(amulet?.shaft); |
| 79 | assert.ok(amulet?.tip); |
| 80 | assert.ok(amulet?.coat); |
| 81 | assert.equal(itemDefinition(JewelryItemId.diamondBracelet)?.equipment?.slot, EQUIPMENT_SLOT.bracelet); |
| 82 | assert.equal(ItemId.diamondRing, JewelryItemId.diamondRing); |
| 83 | }); |
| 84 | |
| 85 | test("jewellery equip sprites use catalog :equip names (not double-equip)", () => |
| 86 | { |
| 87 | assert.equal( |
| 88 | itemDefinition(JewelryItemId.opalRing)?.equipment?.equipSprite, |
| 89 | "item:jewelery:ring:equip" |
| 90 | ); |
| 91 | assert.equal( |
| 92 | itemDefinition(JewelryItemId.diamondBracelet)?.equipment?.equipSprite, |
| 93 | "item:jewelery:bracelet:equip" |
| 94 | ); |
| 95 | assert.equal( |
| 96 | itemDefinition(JewelryItemId.rubyAmulet)?.equipment?.equipSprite, |
| 97 | "item:jewelery:amulet:equip" |
| 98 | ); |
| 99 | assert.equal(itemEquipSprite(JewelryItemId.opalRing), "item:jewelery:ring:equip"); |
| 100 | assert.equal(itemEquipSprite(JewelryItemId.rubyAmulet), "item:jewelery:amulet:equip"); |
| 101 | }); |
| 102 | |
| 103 | test("jadeite fairy and jewelry teleport helpers gate on worn pieces", () => |
| 104 | { |
| 105 | assert.equal(JADEITE_FAIRY_RESPAWN_MS, 60_000); |
| 106 | assert.equal(JEWELRY_TELEPORT_MS, 3000); |
| 107 | const empty = emptyEquipment(); |
| 108 | assert.equal(summonsJadeiteFairy(empty), false); |
| 109 | assert.equal(canTeleportToChurch(empty), false); |
| 110 | assert.equal(canTeleportToBank(empty), false); |
| 111 | |
| 112 | const withFairy = emptyEquipment(); |
| 113 | withFairy.slots.amulet = { itemId: JewelryItemId.jadeiteAmulet, quantity: 1 }; |
| 114 | assert.equal(summonsJadeiteFairy(withFairy), true); |
| 115 | assert.equal(canTeleportToChurch(withFairy), false); |
| 116 | |
| 117 | const withChurch = emptyEquipment(); |
| 118 | withChurch.slots.bracelet = { itemId: JewelryItemId.emeraldBracelet, quantity: 1 }; |
| 119 | assert.equal(canTeleportToChurch(withChurch), true); |
| 120 | assert.equal(canTeleportToBank(withChurch), false); |
| 121 | |
| 122 | const withBank = emptyEquipment(); |
| 123 | withBank.slots.ring = { itemId: JewelryItemId.rubyRing, quantity: 1 }; |
| 124 | assert.equal(canTeleportToBank(withBank), true); |
| 125 | assert.equal(canTeleportToChurch(withBank), false); |
| 126 | }); |