/** * Utility functions for calculating unlock levels for moves and abilities */ import type { BattleMove } from '$lib/db/schema'; import type { SpecialAbility } from '$lib/battle-engine/types'; /** * Calculate unlock level for a move based on its power and characteristics * First 2 moves are always unlocked, moves 3-4 unlock at levels 9-14 */ export function calculateMoveUnlockLevel(move: BattleMove, moveIndex: number): number { // First two moves are always available at level 1 if (moveIndex === 0 || moveIndex === 1) { return 1; } // Third and fourth moves unlock at levels 9-14 if (moveIndex === 2) { // Third move unlocks between level 9-11 return Math.floor(Math.random() * 3) + 9; // Level 9, 10, or 11 } if (moveIndex === 3) { // Fourth move unlocks between level 12-14 return Math.floor(Math.random() * 3) + 12; // Level 12, 13, or 14 } // For any additional moves beyond the 4th (shouldn't normally happen) // They unlock at higher levels return 15 + (moveIndex - 4) * 5; } /** * Calculate unlock level for special ability based on its power and effects */ export function calculateSpecialAbilityUnlockLevel(ability: SpecialAbility): number { // Base level based on ability impact let baseLevel = 15; // Default mid-level unlock // Analyze ability effects to determine power level const effects = ability.effects || []; let powerScore = 0; for (const effect of effects) { switch (effect.type) { case 'damage': powerScore += effect.amount === 'strong' ? 3 : effect.amount === 'normal' ? 2 : 1; break; case 'heal': powerScore += effect.amount === 'large' ? 3 : effect.amount === 'medium' ? 2 : 1; break; case 'modifyStats': // Stat modifications are powerful powerScore += 2; break; case 'applyStatus': powerScore += 2; break; case 'removeStatus': powerScore += 1; break; case 'manipulatePP': powerScore += 1; break; default: powerScore += 1; } } // Convert power score to unlock level if (powerScore <= 2) { baseLevel = Math.floor(Math.random() * 20) + 10; // Level 10-30 } else if (powerScore <= 4) { baseLevel = Math.floor(Math.random() * 25) + 20; // Level 20-45 } else if (powerScore <= 6) { baseLevel = Math.floor(Math.random() * 25) + 30; // Level 30-55 } else { baseLevel = Math.floor(Math.random() * 25) + 40; // Level 40-65 } // Cap at level 80 return Math.min(baseLevel, 80); } /** * Get all unlocked moves for a Piclet at a given level */ export function getUnlockedMoves(moves: BattleMove[], currentLevel: number): BattleMove[] { return moves.filter(move => move.unlockLevel <= currentLevel); } /** * Check if special ability is unlocked at given level */ export function isSpecialAbilityUnlocked(unlockLevel: number, currentLevel: number): boolean { return currentLevel >= unlockLevel; } /** * Generate unlock levels for a new Piclet's moves and ability * This should be called when a Piclet is first generated */ export function generateUnlockLevels(moves: BattleMove[], specialAbility: SpecialAbility): { movesWithUnlocks: BattleMove[]; abilityUnlockLevel: number; } { const movesWithUnlocks = moves.map((move, index) => ({ ...move, unlockLevel: calculateMoveUnlockLevel(move, index) })); const abilityUnlockLevel = calculateSpecialAbilityUnlockLevel(specialAbility); return { movesWithUnlocks, abilityUnlockLevel }; }