| 995 | | my $encounters_rs = $row->encounters_rs({ |
| 996 | | method => { '!=' => [qw/ surfing old-rod good-rod super-rod /] }, # temporary |
| 997 | | }, { |
| 998 | | order_by => 'section ASC, method = "grass" DESC', |
| 999 | | }); |
| 1000 | | while (my $encounter_row = $encounters_rs->next) { |
| 1001 | | my $arrayref = $encounters{ $encounter_row->section } |
| 1002 | | ->{ $encounter_row->method } ||= []; |
| 1003 | | |
| 1004 | | # copy the grass values over for replacement rows whose mechanics we're |
| 1005 | | # pretty sure about |
| 1006 | | @$arrayref = @{ dclone $encounters{ $encounter_row->section }{grass} } |
| 1007 | | if not @$arrayref and |
| 1008 | | (grep { $encounter_row->method eq $_ } qw/ daytime night poketore swarm / |
| 1009 | | or $encounter_row->method =~ /^ds-/); |
| 1010 | | |
| 1011 | | if (defined $arrayref->[ $encounter_row->rarity ]) { |
| 1012 | | $arrayref->[ $encounter_row->rarity ]{pokemon} = |
| 1013 | | $encounter_row->pokemon_id; |
| 1014 | | } else { |
| 1015 | | $arrayref->[ $encounter_row->rarity ] = { |
| 1016 | | pokemon => $encounter_row->pokemon_id, |
| 1017 | | level => $encounter_row->level, |
| 1018 | | }; |
| 1019 | | } |
| 1020 | | } |
| 1021 | | |
| 1022 | | my %pokemon; |
| 1023 | | # my $rarity_key = ($method =~ /rod|surfing/) ? 'locsurfpercents' : 'locpercents'; |
| 1024 | | my $rarity_ct = scalar @{ $Generations[-1]{locpercents} }; |
| 1025 | | for my $section (keys %encounters) { |
| 1026 | | for my $method (keys %{ $encounters{$section} }) { |
| 1027 | | my @poke_list = @{ $encounters{$section}{$method} }; |
| 1028 | | |
| 1029 | | # if this isn't a full list, leave it alone and return |
| 1030 | | if (@poke_list != $rarity_ct or not defined $poke_list[0]) { |
| 1031 | | # WRONG: $pokemon{$section}{$method} = [ uniq map { $_->{pokemon} } grep { $_ } @poke_list ]; |
| 1032 | | next; |
| 1033 | | } |
| 1034 | | |
| 1035 | | for my $index (0 .. $rarity_ct - 1) { |
| 1036 | | $pokemon{$section}{ $poke_list[$index]{pokemon} } |
| 1037 | | { $poke_list[$index]{level} }{$method} += |
| 1038 | | $Generations[-1]{locpercents}[$index]; |
| 1039 | | } |
| 1040 | | } |
| 1041 | | } |
| 1042 | | |
| | 995 | |
| | 996 | my $sections_rs = $row->sections_rs; |
| | 997 | while (my $section = $sections_rs->next) { |
| | 998 | my $grouped_pokemon_rs = $section->encounters_rs( { |
| | 999 | version => 'diamond', |
| | 1000 | }, { |
| | 1001 | group_by => 'pokemon_id', |
| | 1002 | } ); |
| | 1003 | |
| | 1004 | while (my $enc_pokemon = $grouped_pokemon_rs->next) { |
| | 1005 | my $encounters_rs = $section->encounters_rs( { |
| | 1006 | version => 'diamond', |
| | 1007 | pokemon_id => $enc_pokemon->pokemon->id, |
| | 1008 | } ); |
| | 1009 | $encounters_rs->reset; |
| | 1010 | |
| | 1011 | push @{ $encounters{$section->name} }, Vee::Dex::EncounterSet->new( |
| | 1012 | $encounters_rs, |
| | 1013 | $enc_pokemon->pokemon, |
| | 1014 | ); |
| | 1015 | } |
| | 1016 | |
| | 1017 | @{ $encounters{$section->name} } = sort { |
| | 1018 | $a->pokemon->name cmp $b->pokemon->name |
| | 1019 | } @{ $encounters{$section->name} }; |
| | 1020 | } |
| | 1021 | |