Fix crafting tab crash, update attunement XP system
Some checks failed
Build and Publish Mana Loop Docker Image / build-and-publish (push) Failing after 33s

- Add missing EquipmentCraftingProgress interface to types.ts
- Fix CraftingTab to accept store prop like other tabs
- Update attunement XP calculation: 1 XP per 10 capacity used (min 1)
- Change XP requirements: 1000 for lv2, 2500 for lv3, doubling thereafter
- Grant Enchanter XP when enchantments are applied
- Add equipmentCraftingProgress to GameState and persist config
This commit is contained in:
2026-03-27 19:23:00 +00:00
parent 49fe47948f
commit 98309fbc85
5 changed files with 93 additions and 74 deletions

View File

@@ -1,11 +1,12 @@
// ─── Crafting Store Slice ─────────────────────────────────────────────────────────
// Handles equipment and enchantment system: design, prepare, apply stages
import type { GameState, EquipmentInstance, AppliedEnchantment, EnchantmentDesign, DesignEffect, EquipmentSlot, EquipmentCraftingProgress, LootInventory } from './types';
import type { GameState, EquipmentInstance, AppliedEnchantment, EnchantmentDesign, DesignEffect, EquipmentSlot, EquipmentCraftingProgress, LootInventory, AttunementState } from './types';
import { EQUIPMENT_TYPES, type EquipmentCategory } 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';
import { calculateEnchantingXP, getAttunementXPForLevel, MAX_ATTUNEMENT_LEVEL } from './data/attunements';
// ─── Helper Functions ─────────────────────────────────────────────────────────
@@ -687,11 +688,42 @@ export function processCraftingTick(
actualCost: eff.capacityCost,
}));
// Calculate and grant attunement XP to enchanter
const xpGained = calculateEnchantingXP(design.totalCapacityUsed);
let newAttunements = state.attunements;
if (state.attunements.enchanter?.active && xpGained > 0) {
const enchanterState = state.attunements.enchanter;
let newXP = enchanterState.experience + xpGained;
let newLevel = enchanterState.level;
// Check for level ups
while (newLevel < MAX_ATTUNEMENT_LEVEL) {
const xpNeeded = getAttunementXPForLevel(newLevel + 1);
if (newXP >= xpNeeded) {
newXP -= xpNeeded;
newLevel++;
} else {
break;
}
}
newAttunements = {
...state.attunements,
enchanter: {
...enchanterState,
level: newLevel,
experience: newXP,
},
};
}
updates = {
...updates,
rawMana: rawMana - manaCost,
applicationProgress: null,
currentAction: 'meditate',
attunements: newAttunements,
equipmentInstances: {
...state.equipmentInstances,
[app.equipmentInstanceId]: {
@@ -700,7 +732,7 @@ export function processCraftingTick(
usedCapacity: instance.usedCapacity + design.totalCapacityUsed,
},
},
log: [`✨ Enchantment "${design.name}" applied to ${instance.name}!`, ...log],
log: [`✨ Enchantment "${design.name}" applied to ${instance.name}! (+${xpGained} Enchanter XP)`, ...log],
};
}
} else {

View File

@@ -111,10 +111,22 @@ export function getAttunementConversionRate(attunementId: string, level: number)
// XP required for attunement level
export function getAttunementXPForLevel(level: number): number {
// Level 2: 100 XP, Level 3: 300 XP, Level 4: 900 XP, etc.
// Exponential: 100 * (3 ^ (level - 2))
// New scaling:
// Level 2: 1000 XP
// Level 3: 2500 XP
// Level 4: 5000 XP
// Level 5: 10000 XP
// etc. (each level requires 2x the previous, starting from 1000)
if (level <= 1) return 0;
return Math.floor(100 * Math.pow(3, level - 2));
if (level === 2) return 1000;
// For level 3+: 1000 * 2.5^(level-2), but rounded nicely
return Math.floor(1000 * Math.pow(2, level - 2) * (level >= 3 ? 1.25 : 1));
}
// Calculate XP gained from enchanting based on capacity used
export function calculateEnchantingXP(capacityUsed: number): number {
// 1 XP per 10 capacity used, floored, minimum 1
return Math.max(1, Math.floor(capacityUsed / 10));
}
// Max attunement level

View File

@@ -499,6 +499,7 @@ function makeInitial(overrides: Partial<GameState> = {}): GameState {
designProgress: null,
preparationProgress: null,
applicationProgress: null,
equipmentCraftingProgress: null,
unlockedEffects: [...BASE_UNLOCKED_EFFECTS], // Start with mana bolt only
equipmentSpellStates: [],
@@ -1875,6 +1876,8 @@ export const useGameStore = create<GameStore>()(
designProgress: state.designProgress,
preparationProgress: state.preparationProgress,
applicationProgress: state.applicationProgress,
equipmentCraftingProgress: state.equipmentCraftingProgress,
unlockedEffects: state.unlockedEffects,
// Loot inventory
lootInventory: state.lootInventory,
}),

View File

@@ -232,6 +232,15 @@ export interface ApplicationProgress {
manaSpent: number; // Total mana spent so far
}
// Equipment crafting progress (from blueprints)
export interface EquipmentCraftingProgress {
blueprintId: string;
equipmentTypeId: string;
progress: number; // Hours spent crafting
required: number; // Total hours needed
manaSpent: number; // Total mana spent so far
}
// Equipment spell state (for multi-spell casting)
export interface EquipmentSpellState {
spellId: string;
@@ -362,6 +371,7 @@ export interface GameState {
designProgress: DesignProgress | null;
preparationProgress: PreparationProgress | null;
applicationProgress: ApplicationProgress | null;
equipmentCraftingProgress: EquipmentCraftingProgress | null;
// Unlocked enchantment effects for designing
unlockedEffects: string[]; // Effect IDs that have been researched