| |
| |
| |
|
|
| import type { BattleMove } from '$lib/db/schema'; |
| import type { SpecialAbility } from '$lib/battle-engine/types'; |
|
|
| |
| |
| |
| |
| export function calculateMoveUnlockLevel(move: BattleMove, moveIndex: number): number { |
| |
| let baseLevel = 1; |
| |
| if (move.power === 0) { |
| |
| baseLevel = Math.floor(Math.random() * 20) + 5; |
| } else if (move.power <= 40) { |
| |
| baseLevel = Math.floor(Math.random() * 15) + 1; |
| } else if (move.power <= 60) { |
| |
| baseLevel = Math.floor(Math.random() * 25) + 10; |
| } else if (move.power <= 80) { |
| |
| baseLevel = Math.floor(Math.random() * 30) + 25; |
| } else { |
| |
| baseLevel = Math.floor(Math.random() * 25) + 40; |
| } |
| |
| |
| const positionBonus = moveIndex * 5; |
| baseLevel += positionBonus; |
| |
| |
| if (moveIndex === 0) { |
| baseLevel = 1; |
| } |
| |
| |
| return Math.min(baseLevel, 80); |
| } |
|
|
| |
| |
| |
| export function calculateSpecialAbilityUnlockLevel(ability: SpecialAbility): number { |
| |
| let baseLevel = 15; |
| |
| |
| 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': |
| |
| powerScore += 2; |
| break; |
| case 'applyStatus': |
| powerScore += 2; |
| break; |
| case 'removeStatus': |
| powerScore += 1; |
| break; |
| case 'manipulatePP': |
| powerScore += 1; |
| break; |
| default: |
| powerScore += 1; |
| } |
| } |
| |
| |
| if (powerScore <= 2) { |
| baseLevel = Math.floor(Math.random() * 20) + 10; |
| } else if (powerScore <= 4) { |
| baseLevel = Math.floor(Math.random() * 25) + 20; |
| } else if (powerScore <= 6) { |
| baseLevel = Math.floor(Math.random() * 25) + 30; |
| } else { |
| baseLevel = Math.floor(Math.random() * 25) + 40; |
| } |
| |
| |
| return Math.min(baseLevel, 80); |
| } |
|
|
| |
| |
| |
| export function getUnlockedMoves(moves: BattleMove[], currentLevel: number): BattleMove[] { |
| return moves.filter(move => move.unlockLevel <= currentLevel); |
| } |
|
|
| |
| |
| |
| export function isSpecialAbilityUnlocked(unlockLevel: number, currentLevel: number): boolean { |
| return currentLevel >= unlockLevel; |
| } |
|
|
| |
| |
| |
| |
| 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 |
| }; |
| } |