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;
},
+17
View File
@@ -15,6 +15,7 @@ export interface EquipmentType {
description: string;
baseDamage?: number; // For swords
baseCastSpeed?: number; // For swords (higher = faster)
twoHanded?: boolean; // If true, weapon occupies both main hand and offhand slots
}
// ─── Equipment Types Definition ─────────────────────────────────────────────
@@ -28,6 +29,7 @@ export const EQUIPMENT_TYPES: Record<string, EquipmentType> = {
slot: 'mainHand',
baseCapacity: 50,
description: 'A simple wooden staff, basic but reliable for channeling mana.',
twoHanded: true,
},
apprenticeWand: {
id: 'apprenticeWand',
@@ -44,6 +46,7 @@ export const EQUIPMENT_TYPES: Record<string, EquipmentType> = {
slot: 'mainHand',
baseCapacity: 65,
description: 'A sturdy oak staff with decent mana capacity.',
twoHanded: true,
},
crystalWand: {
id: 'crystalWand',
@@ -60,6 +63,7 @@ export const EQUIPMENT_TYPES: Record<string, EquipmentType> = {
slot: 'mainHand',
baseCapacity: 80,
description: 'A staff designed for advanced spellcasters. High capacity for complex enchantments.',
twoHanded: true,
},
battlestaff: {
id: 'battlestaff',
@@ -68,6 +72,7 @@ export const EQUIPMENT_TYPES: Record<string, EquipmentType> = {
slot: 'mainHand',
baseCapacity: 70,
description: 'A reinforced staff suitable for both casting and combat.',
twoHanded: true,
},
// ─── Main Hand - Catalysts ────────────────────────────────────────────────
@@ -438,6 +443,7 @@ export function getAllEquipmentTypes(): EquipmentType[] {
}
// Get valid slots for a category
// Note: For 2-handed weapons, use getValidSlotsForEquipmentType instead
export function getValidSlotsForCategory(category: EquipmentCategory): EquipmentSlot[] {
switch (category) {
case 'caster':
@@ -461,6 +467,17 @@ export function getValidSlotsForCategory(category: EquipmentCategory): Equipment
}
}
// Get valid slots for a specific equipment type (considers 2-handed weapons)
export function getValidSlotsForEquipmentType(equipType: EquipmentType): EquipmentSlot[] {
// 2-handed weapons occupy both main hand and offhand
if (equipType.twoHanded) {
return ['mainHand', 'offHand'];
}
// Otherwise use category-based slots
return getValidSlotsForCategory(equipType.category);
}
// Check if an equipment type can be equipped in a specific slot
export function canEquipInSlot(equipmentType: EquipmentType, slot: EquipmentSlot): boolean {
const validSlots = getValidSlotsForCategory(equipmentType.category);