Files
Mana-Loop/src/lib/game/crafting-actions/design-actions.ts
T
Refactoring Agent d2d28887b1
Build and Publish Mana Loop Docker Image / build-and-publish (push) Failing after 1m9s
Refactor large files into modular components
- Refactored page.tsx (613→252 lines) with GameOverScreen and LeftPanel extracted
- Refactored StatsTab.tsx (584→92 lines) with section components
- Refactored SkillsTab.tsx (434→54 lines) with sub-components
- Created modular structure for GameContext, LootInventory, and other components
- All extracted components organized into feature directories
2026-05-02 17:35:03 +02:00

114 lines
3.3 KiB
TypeScript

// ─── Enchantment Design Actions ────────────────────────────────────────────
import type { GameState, EnchantmentDesign, DesignEffect } from '../types';
import * as CraftingUtils from '../crafting-utils';
import * as CraftingDesign from '../crafting-design';
import { computeEffects } from '../upgrade-effects';
import { hasSpecial, SPECIAL_EFFECTS } from '../special-effects';
export function startDesigningEnchantment(
name: string,
equipmentTypeId: string,
effects: DesignEffect[],
get: () => GameState,
set: (fn: (state: GameState) => Partial<GameState>) => void
): boolean {
const state = get();
const enchantingLevel = state.skills.enchanting || 0;
const validation = CraftingDesign.validateDesignEffects(
effects,
equipmentTypeId,
enchantingLevel
);
if (!validation.valid) return false;
const equipType = CraftingUtils.getEquipmentType(equipmentTypeId);
if (!equipType) return false;
const efficiencyBonus = ((state.skillUpgrades || {})['efficientEnchant'] || [])?.length * 0.05 || 0;
const totalCapacityCost = CraftingDesign.calculateDesignCapacityCost(effects, efficiencyBonus);
if (totalCapacityCost > equipType.baseCapacity) {
return false;
}
const computedEffects = computeEffects(state.skillUpgrades || {}, state.skillTiers || {});
const hasEnchantMastery = hasSpecial(computedEffects, SPECIAL_EFFECTS.ENCHANT_MASTERY);
let updates: any = {};
if (!state.designProgress) {
updates = {
currentAction: 'design' as const,
designProgress: {
designId: CraftingUtils.generateDesignId(),
progress: 0,
required: CraftingDesign.calculateDesignTime(effects),
name,
equipmentType: equipmentTypeId,
effects,
},
};
} else if (hasEnchantMastery && !state.designProgress2) {
updates = {
designProgress2: {
designId: CraftingUtils.generateDesignId(),
progress: 0,
required: CraftingDesign.calculateDesignTime(effects),
name,
equipmentType: equipmentTypeId,
effects,
},
};
} else {
return false;
}
set(() => updates);
return true;
}
export function cancelDesign(
get: () => GameState,
set: (fn: (state: GameState) => Partial<GameState>) => void
) {
const state = get();
if (state.designProgress2 && !state.designProgress) {
set(() => ({ designProgress2: null }));
} else {
set(() => ({
currentAction: 'meditate' as const,
designProgress: null,
}));
}
}
export function saveDesign(
design: EnchantmentDesign,
get: () => GameState,
set: (fn: (state: GameState) => Partial<GameState>) => void
) {
const state = get();
if (state.designProgress2 && state.designProgress2.designId === design.id) {
set((state) => ({
enchantmentDesigns: [...state.enchantmentDesigns, design],
designProgress2: null,
}));
} else {
set((state) => ({
enchantmentDesigns: [...state.enchantmentDesigns, design],
designProgress: null,
currentAction: 'meditate' as const,
}));
}
}
export function deleteDesign(
designId: string,
set: (fn: (state: GameState) => Partial<GameState>) => void
) {
set((state) => ({
enchantmentDesigns: state.enchantmentDesigns.filter(d => d.id !== designId),
}));
}