import { ItemId, itemDefinition } from "./items.js"; import { CraftingItemId } from "./craftingItems.js"; import { MetalItemId } from "./metalItems.js"; import { EquipmentKind } from "./equipmentKinds.js"; import { canEquipItem } from "../equipment/stats.js"; import { SkillId, skillLevel } from "./skills.js"; import { MaterialTier, GatherMaterialId, ORE_BEARING_MATERIALS, associatedBarTier, tierMineSkillLevel, tierSmeltSkillLevel, tierRank, miningDurationMs, oreExhaustDurationMs, smeltingDurationMs, SMELT_DURATION_PER_RANK_MS, EXHAUSTED_ORE_BOULDER_STATE, oreBoulderState, materialFromOreBoulderState, isOreBoulderState } from "./materialTiers.js"; export { ORE_BEARING_MATERIALS, associatedBarTier, tierMineSkillLevel, tierSmeltSkillLevel, miningDurationMs, oreExhaustDurationMs, smeltingDurationMs, SMELT_DURATION_PER_RANK_MS, EXHAUSTED_ORE_BOULDER_STATE, oreBoulderState, materialFromOreBoulderState, isOreBoulderState, EquipmentKind }; /** Ore item produced when mining a material node. */ export const ORE_ITEM_BY_MATERIAL = Object.freeze({ [GatherMaterialId.tin]: CraftingItemId.tinOre, [GatherMaterialId.copper]: CraftingItemId.copperOre, [MaterialTier.iron]: MetalItemId.ironOre, [MaterialTier.mithril]: MetalItemId.mithrilOre, [MaterialTier.adamantium]: MetalItemId.adamantiumOre, [MaterialTier.orichalcum]: MetalItemId.orichalcumOre, [MaterialTier.dragon]: MetalItemId.dragonOre, [GatherMaterialId.coal]: MetalItemId.coal }); export const BAR_ITEM_BY_MATERIAL = Object.freeze({ [MaterialTier.bronze]: CraftingItemId.bronzeBar, [MaterialTier.iron]: MetalItemId.ironBar, [MaterialTier.steel]: MetalItemId.steelBar, [MaterialTier.mithril]: MetalItemId.mithrilBar, [MaterialTier.adamantium]: MetalItemId.adamantiumBar, [MaterialTier.orichalcum]: MetalItemId.orichalcumBar, [MaterialTier.dragon]: MetalItemId.dragonBar }); export function oreItemIdForMaterial (materialId) { return ORE_ITEM_BY_MATERIAL[materialId] ?? null; } export function barItemIdForMaterial (materialId) { return BAR_ITEM_BY_MATERIAL[materialId] ?? null; } /** Mining XP awarded per successful ore (scales with associated bar rank). */ export function miningXpForMaterial (materialId) { return Math.max(1, tierRank(materialId) * 5); } /** Smithing XP awarded per successful smelt (scales with bar rank). */ export function smeltingXpForMaterial (materialId) { return Math.max(1, tierRank(materialId) * 5); } /** Mine skill / tool gates use the associated bar's equip tier. */ export function gatherEquipTier (materialId) { return associatedBarTier(materialId); } export function canMineMaterial (miningLevel, toolTier, materialId) { const gateTier = gatherEquipTier(materialId); const needSkill = tierMineSkillLevel(gateTier); if ((miningLevel | 0) < needSkill) { return { ok: false, reason: `Requires Mining ${needSkill}.` }; } if (tierRank(toolTier) < tierRank(gateTier)) { return { ok: false, reason: "You need a pickaxe to mine this!" }; } return { ok: true }; } /** * Tools of a given equipment kind in bag slots and/or the weapon slot. * Gathering uses inventory tools without requiring them to be equipped. */ export function listGatherTools (inventorySlots, equipmentSlots, kind) { const tools = []; for (const stack of inventorySlots ?? []) { if (!stack?.itemId) { continue; } const def = itemDefinition(stack.itemId); if (def?.equipment?.kind !== kind) { continue; } tools.push({ stack, def, tier: def.equipment.tier, source: "inventory" }); } const weapon = equipmentSlots?.weapon; if (weapon?.itemId) { const def = itemDefinition(weapon.itemId); if (def?.equipment?.kind === kind) { tools.push({ stack: weapon, def, tier: def.equipment.tier, source: "equipment" }); } } return tools; } /** * Best pickaxe the player can use for this ore (highest tier that meets gates). * @returns {{ ok: true, tool: object } | { ok: false, reason: string }} */ export function resolveMiningPickaxe ({ inventorySlots, equipmentSlots, skills, materialId }) { const miningLevel = skillLevel(skills, SkillId.mining); const gateTier = gatherEquipTier(materialId); const needSkill = tierMineSkillLevel(gateTier); if ((miningLevel | 0) < needSkill) { return { ok: false, reason: `Requires Mining ${needSkill}.` }; } const tools = listGatherTools(inventorySlots, equipmentSlots, EquipmentKind.pickaxeTool); const usable = tools .filter((tool) => canEquipItem(skills, tool.def).ok) .filter((tool) => tierRank(tool.tier) >= tierRank(gateTier)) .sort((a, b) => tierRank(b.tier) - tierRank(a.tier)); if (!usable.length) { return { ok: false, reason: "You need a pickaxe to mine this!" }; } return { ok: true, tool: usable[0] }; } /** Craft duration: furnace recipes scale by bar tier; others use the fixed craft duration. */ export function craftDurationMs (recipe, fallbackMs = 2000) { if (recipe?.xpMaterial) { return smeltingDurationMs(recipe.xpMaterial); } return Math.max(1, fallbackMs | 0 || 2000); } /** Re-export ItemId helpers used by recipes. */ export { ItemId, MaterialTier, GatherMaterialId };