@@ -549,27 +549,61 @@ class Pokestop extends Model {
549549 invasion . andWhere ( 'confirmed' , onlyConfirmed )
550550 }
551551 invasion . andWhere ( ( subQuery ) => {
552- if ( hasConfirmed ) {
553- if ( rocketPokemon . length ) {
554- subQuery
555- . whereIn ( 'slot_1_pokemon_id' , rocketPokemon )
556- . orWhereIn ( 'slot_2_pokemon_id' , rocketPokemon )
557- . orWhereIn ( 'slot_3_pokemon_id' , rocketPokemon )
558- . orWhereIn (
552+ // Case (a): Include if the invasion character/grunt type is checked
553+ subQuery . whereIn (
554+ isMad ? 'character_display' : 'character' ,
555+ invasions ,
556+ )
557+
558+ // Case (b): Include if invasion has potential rewards that are checked
559+ if ( rocketPokemon . length ) {
560+ // For confirmed invasions, check actual Pokemon slots
561+ if ( hasConfirmed )
562+ subQuery . orWhere ( ( confirmedQuery ) => {
563+ confirmedQuery
564+ . where ( 'confirmed' , 1 )
565+ . andWhere ( ( pokemonQuery ) => {
566+ pokemonQuery
567+ . whereIn ( 'slot_1_pokemon_id' , rocketPokemon )
568+ . orWhereIn ( 'slot_2_pokemon_id' , rocketPokemon )
569+ . orWhereIn ( 'slot_3_pokemon_id' , rocketPokemon )
570+ } )
571+ } )
572+
573+ // For unconfirmed invasions, check if their potential rewards match
574+ // Get all grunt types that have potential rewards matching the filter
575+ const gruntTypesWithMatchingRewards = [ ]
576+ Object . entries ( state . event . invasions ) . forEach (
577+ ( [ gruntType , info ] ) => {
578+ if ( ! info ) return
579+ if (
580+ [
581+ ...( info . firstReward ? info . encounters . first : [ ] ) ,
582+ ...( info . secondReward ? info . encounters . second : [ ] ) ,
583+ ...( info . thirdReward ? info . encounters . third : [ ] ) ,
584+ ] . some ( ( poke ) =>
585+ rocketPokemon . includes ( String ( poke . id ) ) ,
586+ )
587+ ) {
588+ gruntTypesWithMatchingRewards . push ( gruntType )
589+ }
590+ } ,
591+ )
592+
593+ if ( gruntTypesWithMatchingRewards . length > 0 ) {
594+ subQuery . orWhere ( ( unconfirmedQuery ) => {
595+ unconfirmedQuery . whereIn (
559596 isMad ? 'character_display' : 'character' ,
560- invasions ,
597+ gruntTypesWithMatchingRewards ,
561598 )
562- } else {
563- subQuery . whereIn (
564- isMad ? 'character_display' : 'character' ,
565- invasions ,
566- )
599+ if ( hasConfirmed )
600+ unconfirmedQuery . andWhere ( ( confirmationQuery ) => {
601+ confirmationQuery
602+ . where ( 'confirmed' , 0 )
603+ . orWhereNull ( 'confirmed' )
604+ } )
605+ } )
567606 }
568- } else {
569- subQuery . whereIn (
570- isMad ? 'character_display' : 'character' ,
571- invasions ,
572- )
573607 }
574608 } )
575609 if ( onlyExcludeGrunts ) {
@@ -1530,6 +1564,37 @@ class Pokestop extends Model {
15301564 }
15311565 } )
15321566 }
1567+
1568+ if ( config . getSafe ( 'map.misc.fallbackRocketPokemonFiltering' ) ) {
1569+ // Always include potential rocket Pokemon from state.event.invasions as backup
1570+ Object . values ( state . event . invasions ) . forEach ( ( invasionInfo ) => {
1571+ if ( invasionInfo ) {
1572+ // Add all potential first slot rewards
1573+ if ( invasionInfo . firstReward && invasionInfo . encounters . first ) {
1574+ invasionInfo . encounters . first . forEach ( ( poke ) => {
1575+ finalList . add ( `a${ poke . id } -${ poke . form } ` )
1576+ } )
1577+ }
1578+
1579+ // Add all potential second slot rewards
1580+ if (
1581+ invasionInfo . secondReward &&
1582+ invasionInfo . encounters . second
1583+ ) {
1584+ invasionInfo . encounters . second . forEach ( ( poke ) => {
1585+ finalList . add ( `a${ poke . id } -${ poke . form } ` )
1586+ } )
1587+ }
1588+
1589+ // Add all potential third slot rewards
1590+ if ( invasionInfo . thirdReward && invasionInfo . encounters . third ) {
1591+ invasionInfo . encounters . third . forEach ( ( poke ) => {
1592+ finalList . add ( `a${ poke . id } -${ poke . form } ` )
1593+ } )
1594+ }
1595+ }
1596+ } )
1597+ }
15331598 break
15341599 case 'showcase' :
15351600 if ( hasShowcaseData ) {
@@ -2004,6 +2069,16 @@ class Pokestop extends Model {
20042069 * @returns {Promise<{ hasConfirmedInvasions: boolean }> }
20052070 */
20062071 static async getFilterContext ( { isMad, hasConfirmed } ) {
2072+ // Check if rocket Pokemon filtering should be forced via config
2073+ const fallback = config . getSafe ( 'map.misc.fallbackRocketPokemonFiltering' )
2074+
2075+ if ( fallback ) {
2076+ // Always enable rocket Pokemon filtering regardless of database support
2077+ // This allows filtering by potential rocket Pokemon even without confirmed invasions
2078+ return { hasConfirmedInvasions : true }
2079+ }
2080+
2081+ // Use original behavior when config is disabled
20072082 if ( isMad || ! hasConfirmed ) return { hasConfirmedInvasions : false }
20082083 const result = await this . query ( )
20092084 . from ( 'incident' )
0 commit comments