| 368 | | my $encounters_rs = $row->encounters_rs(undef, { |
| 369 | | prefetch => 'location', |
| 370 | | group_by => [qw/ location_id section method /], |
| 371 | | |
| 372 | | # this minor hackery will essentially collapse multiple rows for a method into one short one we care about |
| 373 | | '+select' => [ |
| 374 | | \ 'MIN(rarity) AS rarity', |
| 375 | | \ 'MIN(min_level) AS min_level', |
| 376 | | \ 'MAX(max_level) AS max_level', |
| 377 | | ], |
| 378 | | '+as' => [qw/ rarity min_level max_level /], |
| 379 | | } ); |
| 380 | | my %locations; |
| 381 | | while (my $encounter = $encounters_rs->next) { |
| 382 | | my $level; |
| 383 | | if (not $encounter->min_level) { |
| 384 | | $level = ''; |
| 385 | | } elsif ($encounter->min_level == $encounter->max_level) { |
| 386 | | $level = $encounter->min_level; |
| 387 | | } else { |
| 388 | | $level = $encounter->min_level . ' - ' . $encounter->max_level; |
| 389 | | } |
| 390 | | $locations{ $encounter->location->name }{ $encounter->section }{ $encounter->method } = { level => $level, rarity => $encounter->rarity }; |
| 391 | | } |
| 392 | | $s->{encounters} = \%locations; |
| | 368 | $s->{encounters} = get_locations($row); |
| | 493 | sub pokemon_chain : Chained('/') : PathPart('dex/pokemon') : CaptureArgs(1) {;} |
| | 494 | |
| | 495 | =head2 strategery |
| | 496 | |
| | 497 | =cut |
| | 498 | |
| | 499 | sub strategery : Chained('pokemon_chain') : Args(0) { |
| | 500 | my ($self, $c) = @_; |
| | 501 | my $s = $c->stash; |
| | 502 | |
| | 503 | my $poke = $c->req->captures->[0]; |
| | 504 | my $gen = 'dp'; # TODO: CHEAP HACK PLZ MAKE THIS WORK RITE -- do by generation but split if versions disagree? |
| | 505 | |
| | 506 | my $row = get_row($c, 'Pokemon', $poke); |
| | 507 | $c->vee_abort('There is no such Pokémon ', $poke, '. If you are messing with my URLs, please stop. If you came here via a link, please inform its owner that it is invalid.') unless $row; |
| | 508 | |
| | 509 | $s->{generation} = my $generation = ( grep { $Generations[$_]{maxid} >= $row->id } 0 .. $#Generations )[0]; |
| | 510 | |
| | 511 | calculate_stats($c, $row); |
| | 512 | |
| | 513 | my $moves_rs = $c->model('DBIC::PokeMoves')->search({ pokeid => $row->id, -and => \ "FIND_IN_SET('$gen', version)" }); |
| | 514 | my %moves; |
| | 515 | |
| | 516 | while (my $move_row = $moves_rs->next) { |
| | 517 | push @{ $moves{ $move_row->moveid } }, $move_row; |
| | 518 | } |
| | 519 | $s->{moves} = \%moves; |
| | 520 | |
| | 521 | $s->{this} = $row; |
| | 522 | |
| | 523 | $s->{page_title} = $row->name . ' - Strategic Overview'; |
| | 524 | $s->{crumbs} = [ |
| | 525 | '<a href="' . $c->uri('Dex') . '">Pokédex</a>', |
| | 526 | '<a href="' . $c->uri('Dex', 'pokemon_list') . '">Pokémon</a>', |
| | 527 | '<a href="' . $c->uri('Dex', 'pokemon', lc $row->name) . '">' . $row->name . '</a>' |
| | 528 | ]; |
| | 529 | |
| | 530 | $s->{template} = 'dex/strategery.tt'; |
| | 531 | } |
| | 532 | |
| | 533 | =head2 map |
| | 534 | |
| | 535 | =cut |
| | 536 | |
| | 537 | sub map : Chained('pokemon_chain') : Args(0) { |
| | 538 | my ($self, $c) = @_; |
| | 539 | my $s = $c->stash; |
| | 540 | |
| | 541 | my $poke = $c->req->captures->[0]; |
| | 542 | my $gen = 'dp'; # TODO: CHEAP HACK PLZ MAKE THIS WORK RITE -- do by generation but split if versions disagree? |
| | 543 | |
| | 544 | my $row = get_row($c, 'Pokemon', $poke); |
| | 545 | $c->vee_abort('There is no such Pokémon ', $poke, '. If you are messing with my URLs, please stop. If you came here via a link, please inform its owner that it is invalid.') unless $row; |
| | 546 | |
| | 547 | $s->{encounters} = get_locations($row); |
| | 548 | $s->{location_coords} = { |
| | 549 | map { $_->name => $_->coordinates } |
| | 550 | $c->model('DBIC::Locations')->search(undef) |
| | 551 | }; |
| | 552 | |
| | 553 | $s->{this} = $row; |
| | 554 | |
| | 555 | $s->{page_title} = $row->name . ' - Location Map'; |
| | 556 | $s->{crumbs} = [ |
| | 557 | '<a href="' . $c->uri('Dex') . '">Pokédex</a>', |
| | 558 | '<a href="' . $c->uri('Dex', 'pokemon_list') . '">Pokémon</a>', |
| | 559 | '<a href="' . $c->uri('Dex', 'pokemon', lc $row->name) . '">' . $row->name . '</a>', |
| | 560 | 'Location Map', |
| | 561 | ]; |
| | 562 | |
| | 563 | $s->{template} = 'dex/page/pokemon/map.tt'; |
| | 564 | } |
| | 565 | |
| 614 | | =head2 strategery |
| 615 | | |
| 616 | | =cut |
| 617 | | |
| 618 | | sub pokemon_chain : Chained('/') : PathPart('dex/pokemon') : CaptureArgs(1) {;} |
| 619 | | |
| 620 | | sub strategery : Chained('pokemon_chain') : Args(0) { |
| 621 | | my ($self, $c) = @_; |
| 622 | | my $s = $c->stash; |
| 623 | | |
| 624 | | my $poke = $c->req->captures->[0]; |
| 625 | | my $gen = 'dp'; # TODO: CHEAP HACK PLZ MAKE THIS WORK RITE -- do by generation but split if versions disagree? |
| 626 | | |
| 627 | | my $row = get_row($c, 'Pokemon', $poke); |
| 628 | | $c->vee_abort('There is no such Pokémon ', $poke, '. If you are messing with my URLs, please stop. If you came here via a link, please inform its owner that it is invalid.') unless $row; |
| 629 | | |
| 630 | | $s->{generation} = my $generation = ( grep { $Generations[$_]{maxid} >= $row->id } 0 .. $#Generations )[0]; |
| 631 | | |
| 632 | | calculate_stats($c, $row); |
| 633 | | |
| 634 | | my $moves_rs = $c->model('DBIC::PokeMoves')->search({ pokeid => $row->id, -and => \ "FIND_IN_SET('$gen', version)" }); |
| 635 | | my %moves; |
| 636 | | |
| 637 | | while (my $move_row = $moves_rs->next) { |
| 638 | | push @{ $moves{ $move_row->moveid } }, $move_row; |
| 639 | | } |
| 640 | | $s->{moves} = \%moves; |
| 641 | | |
| 642 | | $s->{this} = $row; |
| 643 | | |
| 644 | | $s->{page_title} = $row->name . ' - Strategic Overview'; |
| 645 | | $s->{crumbs} = [ |
| 646 | | '<a href="' . $c->uri('Dex') . '">Pokédex</a>', |
| 647 | | '<a href="' . $c->uri('Dex', 'pokemon_list') . '">Pokémon</a>', |
| 648 | | '<a href="' . $c->uri('Dex', 'pokemon', lc $row->name) . '">' . $row->name . '</a>' |
| 649 | | ]; |
| 650 | | |
| 651 | | $s->{template} = 'dex/strategery.tt'; |
| 652 | | } |
| 653 | | |
| 654 | | ################################################################################ |
| 655 | | |
| | 843 | =head2 get_locations |
| | 844 | |
| | 845 | Fetches the locations for a given Pokemon (row) and returns a hash. |
| | 846 | |
| | 847 | In: Pokemon db row |
| | 848 | |
| | 849 | Out: { location => { section => { method => { level => "a - b", rarity => x } } } } |
| | 850 | |
| | 851 | =cut |
| | 852 | |
| | 853 | sub get_locations { |
| | 854 | my ($pokemon) = @_; |
| | 855 | |
| | 856 | my $encounters_rs = $pokemon->encounters_rs(undef, { |
| | 857 | prefetch => 'location', |
| | 858 | group_by => [qw/ location_id section method /], |
| | 859 | |
| | 860 | # this minor hackery will essentially collapse multiple rows for a method into one short one we care about |
| | 861 | '+select' => [ |
| | 862 | \ 'MIN(rarity) AS rarity', |
| | 863 | \ 'MIN(min_level) AS min_level', |
| | 864 | \ 'MAX(max_level) AS max_level', |
| | 865 | ], |
| | 866 | '+as' => [qw/ rarity min_level max_level /], |
| | 867 | } ); |
| | 868 | |
| | 869 | my %locations; |
| | 870 | while (my $encounter = $encounters_rs->next) { |
| | 871 | my $level; |
| | 872 | if (not $encounter->min_level) { |
| | 873 | $level = ''; |
| | 874 | } elsif ($encounter->min_level == $encounter->max_level) { |
| | 875 | $level = $encounter->min_level; |
| | 876 | } else { |
| | 877 | $level = $encounter->min_level . ' - ' . $encounter->max_level; |
| | 878 | } |
| | 879 | $locations{ $encounter->location->name }{ $encounter->section }{ $encounter->method } = { level => $level, rarity => $encounter->rarity }; |
| | 880 | } |
| | 881 | |
| | 882 | return \%locations; |
| | 883 | } |
| | 884 | |