File size: 3,578 Bytes
74f8c2c
 
 
 
 
 
 
 
 
89b51fc
74f8c2c
 
89b51fc
 
 
74f8c2c
 
89b51fc
 
 
 
 
74f8c2c
89b51fc
 
 
74f8c2c
 
89b51fc
 
 
74f8c2c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
/**
 * 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
  };
}