Task 2: Equipment System - support 2-handed weapons, staves block offhand slot
Build and Publish Mana Loop Docker Image / build-and-publish (push) Successful in 1m40s

This commit is contained in:
Refactoring Agent
2026-04-25 19:24:23 +02:00
parent 7c05bea896
commit 5e0bee8820
3 changed files with 97 additions and 7 deletions
+35 -2
View File
@@ -1,8 +1,8 @@
// ─── Crafting Store Slice ─────────────────────────────────────────────────────────
// Handles equipment and enchantment system: design, prepare, apply stages
import type { GameState, EquipmentInstance, AppliedEnchantment, EnchantmentDesign, DesignEffect, EquipmentSlot, EquipmentCraftingProgress, LootInventory, AttunementState } from './types';
import { EQUIPMENT_TYPES, type EquipmentCategory } from './data/equipment';
import type { GameState, EquipmentInstance, AppliedEnchantment, EnchantmentDesign, DesignEffect, EquipmentCraftingProgress, LootInventory, AttunementState } from './types';
import { EQUIPMENT_TYPES, type EquipmentCategory, type EquipmentSlot } from './data/equipment';
import { ENCHANTMENT_EFFECTS, calculateEffectCapacityCost } from './data/enchantment-effects';
import { CRAFTING_RECIPES, canCraftRecipe, type CraftingRecipe } from './data/crafting-recipes';
import { SPELLS_DEF } from './constants';
@@ -221,6 +221,34 @@ export function createCraftingSlice(
const currentEquipped = state.equippedInstances[slot];
if (currentEquipped === instanceId) return true; // Already equipped here
// 2-handed weapon checks
const isTwoHanded = type.twoHanded === true;
if (isTwoHanded) {
// Cannot equip 2-handed weapon if main hand or offhand is occupied
if (state.equippedInstances.mainHand || state.equippedInstances.offHand) {
return false;
}
// 2-handed weapons can only be equipped to main hand
if (slot !== 'mainHand') return false;
}
// If equipping to main hand, check if a 2-handed weapon is in main hand (block offhand)
if (slot === 'offHand' && state.equippedInstances.mainHand) {
const mainHandType = EQUIPMENT_TYPES[state.equippedInstances.mainHand];
if (mainHandType?.twoHanded) {
return false; // Cannot equip offhand when 2-handed weapon is equipped
}
}
// If equipping to offhand, check if a 2-handed weapon is in main hand
if (slot === 'offHand' && state.equippedInstances.mainHand) {
const mainHandType = EQUIPMENT_TYPES[state.equippedInstances.mainHand];
if (mainHandType?.twoHanded) {
return false; // Cannot equip offhand when 2-handed weapon is in main hand
}
}
// If this item is equipped elsewhere, unequip it first
let newEquipped = { ...state.equippedInstances };
for (const [s, id] of Object.entries(newEquipped)) {
@@ -232,6 +260,11 @@ export function createCraftingSlice(
// Equip to new slot
newEquipped[slot] = instanceId;
// If 2-handed weapon, also clear offhand slot (should already be null from check above)
if (isTwoHanded && slot === 'mainHand') {
newEquipped.offHand = null;
}
set(() => ({ equippedInstances: newEquipped }));
return true;
},