@@ -10,7 +10,8 @@ const {
1010 TutorMoves,
1111 GAMEDATA2
1212} = require ( '../../../__gamedata' ) ;
13- const { getPokemonFormId, getPokemonName } = require ( './name' ) ;
13+ const { FORM_MAP , isValidPokemon } = require ( './functions' ) ;
14+ const { getPokemonFormId, getPokemonName, getPokemonMonsNoAndFormNoFromPokemonId } = require ( './name' ) ;
1415
1516const IS_MOVE_INDEX = false ;
1617const MAX_TM_COUNT = 104 ;
@@ -321,6 +322,56 @@ function getTutorMoves(monsno = 0, formno = 0, mode = GAMEDATA2) {
321322 return tutorSet ;
322323}
323324
325+ function searchForMovesOnPokemon ( moveId = 0 , mode = GAMEDATA2 ) {
326+ // This is a wild function.
327+ // I may want to make a json specifically for loading this in the movedex
328+ // Just depends on the load times for it
329+ // This maps over every pokemon in a mode,
330+ // then maps over their entire learnset to see if it can learn a move
331+ return Object . values ( FORM_MAP [ mode ] )
332+ . flat ( )
333+ . slice ( 1 )
334+ . map ( ( id ) => {
335+ // This is a map and not a filter because
336+ // we want to return which method(s) a pokemon can learn a move
337+ const isValid = isValidPokemon ( id , mode ) ;
338+ if ( ! isValid ) {
339+ return null ; // Skip invalid Pokémon
340+ }
341+ let monsNo = 0 , formNo = 0 ;
342+ try {
343+ [ monsNo , formNo ] = getPokemonMonsNoAndFormNoFromPokemonId ( id , mode ) ;
344+ } catch ( error ) {
345+ console . log ( "This pokemonID didn't work" , id , mode ) ;
346+ }
347+ const learnsets = {
348+ level : getLevelLearnset ( id , mode ) ,
349+ tm : getTechMachineLearnset ( id , mode ) ,
350+ egg : getEggMoves ( id , mode ) ,
351+ tutor : getTutorMoves ( monsNo , formNo , mode )
352+ } ;
353+
354+ // Find which learnsets contain the move
355+ const setsContainingMove = Object . entries ( learnsets )
356+ . filter ( ( [ key , moves ] ) =>
357+ Array . isArray ( moves ) &&
358+ moves . some ( move => move . move ?. moveId === moveId ) // Check moveId
359+ )
360+ . map ( ( [ key ] ) => key ) ; // Only keep the keys (e.g., "level", "tm")
361+
362+ if ( setsContainingMove . length > 0 ) {
363+ return {
364+ id :`${ monsNo } -${ formNo } ` ,
365+ mode,
366+ learnsets : setsContainingMove // Include only the relevant learnset names
367+ } ;
368+ }
369+
370+ return null ; // Skip if no learnsets contain the move
371+ } )
372+ . filter ( Boolean ) ; // Remove null values }
373+ }
374+
324375module . exports = {
325376 generateMovesViaLearnset,
326377 getMoveId,
@@ -332,5 +383,6 @@ module.exports = {
332383 getPokemonLearnset,
333384 getMoveLevelLearned,
334385 getLevelLearnset,
335- getTutorMoves
386+ getTutorMoves,
387+ searchForMovesOnPokemon,
336388} ;
0 commit comments