fix: canEquipInSlot uses instance ID as type ID — two-handed weapon check broken #30

Closed
opened 2026-05-18 15:57:50 +02:00 by Anexim · 1 comment
Owner

Severity: Major

File: src/lib/game/crafting-utils.ts (line 151)

Problem: In canEquipInSlot, the offhand two-handed check does:

const mainHandType = EQUIPMENT_TYPES[currentlyEquipped.mainHand];

But currentlyEquipped.mainHand is an instance ID (e.g., 'equip_1234567890_abc'), not a type ID. EQUIPMENT_TYPES is keyed by type ID, so this lookup always returns undefined, meaning the two-handed weapon restriction in the offhand slot is silently broken.

Impact: Players can equip any item in the offhand slot even when holding a two-handed weapon in main hand. The two-handed weapon validation is non-functional.

Fix: Look up the instance first, then get its type:

const mainHandInstanceId = currentlyEquipped.mainHand;
const mainHandInstance = instances[mainHandInstanceId];
const mainHandType = mainHandInstance ? EQUIPMENT_TYPES[mainHandInstance.typeId] : undefined;

This requires passing instances as an additional parameter to canEquipInSlot.

**Severity:** Major **File:** `src/lib/game/crafting-utils.ts` (line 151) **Problem:** In `canEquipInSlot`, the offhand two-handed check does: ```ts const mainHandType = EQUIPMENT_TYPES[currentlyEquipped.mainHand]; ``` But `currentlyEquipped.mainHand` is an **instance ID** (e.g., `'equip_1234567890_abc'`), not a **type ID**. `EQUIPMENT_TYPES` is keyed by type ID, so this lookup always returns `undefined`, meaning the two-handed weapon restriction in the offhand slot is silently broken. **Impact:** Players can equip any item in the offhand slot even when holding a two-handed weapon in main hand. The two-handed weapon validation is non-functional. **Fix:** Look up the instance first, then get its type: ```ts const mainHandInstanceId = currentlyEquipped.mainHand; const mainHandInstance = instances[mainHandInstanceId]; const mainHandType = mainHandInstance ? EQUIPMENT_TYPES[mainHandInstance.typeId] : undefined; ``` This requires passing `instances` as an additional parameter to `canEquipInSlot`.
Anexim added the ai:todo label 2026-05-18 15:57:50 +02:00
n8n-gitea was assigned by Anexim 2026-05-18 15:57:50 +02:00
Author
Owner

Fixed: canEquipInSlot now accepts an optional instances parameter and looks up the main hand instance before getting its type. Updated call site in equipment-actions.ts to pass state.equipmentInstances.

Fixed: canEquipInSlot now accepts an optional `instances` parameter and looks up the main hand instance before getting its type. Updated call site in equipment-actions.ts to pass state.equipmentInstances.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: Anexim/Mana-Loop#30