| 1 | package Vee::Schema::Pokemon; |
|---|
| 2 | |
|---|
| 3 | use strict; |
|---|
| 4 | use warnings; |
|---|
| 5 | use base 'DBIx::Class'; |
|---|
| 6 | |
|---|
| 7 | =head1 NAME |
|---|
| 8 | |
|---|
| 9 | Vee::Schema::Pokemon - DBIC class for the C<pokemon> table |
|---|
| 10 | |
|---|
| 11 | =cut |
|---|
| 12 | |
|---|
| 13 | __PACKAGE__->load_components('Core'); |
|---|
| 14 | __PACKAGE__->table('pokemon'); |
|---|
| 15 | __PACKAGE__->add_columns(qw/ |
|---|
| 16 | id |
|---|
| 17 | id_johto |
|---|
| 18 | id_hoenn |
|---|
| 19 | id_sinnoh |
|---|
| 20 | |
|---|
| 21 | name |
|---|
| 22 | alt_form |
|---|
| 23 | name_jp |
|---|
| 24 | name_romaji |
|---|
| 25 | |
|---|
| 26 | evid |
|---|
| 27 | evparent |
|---|
| 28 | evmethod |
|---|
| 29 | evparam |
|---|
| 30 | |
|---|
| 31 | height |
|---|
| 32 | weight |
|---|
| 33 | type1 |
|---|
| 34 | type2 |
|---|
| 35 | species |
|---|
| 36 | color |
|---|
| 37 | habitat |
|---|
| 38 | |
|---|
| 39 | stat_at |
|---|
| 40 | stat_de |
|---|
| 41 | stat_sa |
|---|
| 42 | stat_sd |
|---|
| 43 | stat_sp |
|---|
| 44 | stat_hp |
|---|
| 45 | |
|---|
| 46 | effort |
|---|
| 47 | oldgs |
|---|
| 48 | caprate |
|---|
| 49 | baseexp |
|---|
| 50 | gender |
|---|
| 51 | happiness |
|---|
| 52 | root |
|---|
| 53 | eventred |
|---|
| 54 | eventblue |
|---|
| 55 | notes |
|---|
| 56 | flags |
|---|
| 57 | real_id |
|---|
| 58 | /); |
|---|
| 59 | __PACKAGE__->set_primary_key('id'); |
|---|
| 60 | |
|---|
| 61 | __PACKAGE__->belongs_to(evchain => 'Vee::Schema::EvChains', 'evid'); |
|---|
| 62 | __PACKAGE__->has_many(pokemoves => 'Vee::Schema::PokeMoves', 'pokeid'); |
|---|
| 63 | __PACKAGE__->has_many(flavors => 'Vee::Schema::FlavorText', 'pokeid'); |
|---|
| 64 | __PACKAGE__->has_many(encounters => 'Vee::Schema::LocationEncounters', 'pokemon_id'); |
|---|
| 65 | __PACKAGE__->has_many(breeds => 'Vee::Schema::PokemonBreeds', 'pokeid'); |
|---|
| 66 | |
|---|
| 67 | __PACKAGE__->has_many(pokemon_abilities => 'Vee::Schema::PokemonAbilities', 'pokeid', { order_by => 'slot ASC' }); |
|---|
| 68 | __PACKAGE__->many_to_many(abilities => 'pokemon_abilities', 'ability'); |
|---|
| 69 | |
|---|
| 70 | __PACKAGE__->has_many(pokemon_items => 'Vee::Schema::PokemonItems', 'pokemon_id'); |
|---|
| 71 | __PACKAGE__->many_to_many(items => 'pokemon_items', 'item'); |
|---|
| 72 | |
|---|
| 73 | __PACKAGE__->might_have(parent => 'Vee::Schema::Pokemon', 'evparent'); |
|---|
| 74 | __PACKAGE__->has_many(descendants => 'Vee::Schema::Pokemon', 'evparent'); |
|---|
| 75 | |
|---|
| 76 | =head1 METHODS |
|---|
| 77 | |
|---|
| 78 | =head2 can_breed |
|---|
| 79 | |
|---|
| 80 | Returns true if this Pokemon can breed, false otherwise. |
|---|
| 81 | |
|---|
| 82 | =cut |
|---|
| 83 | |
|---|
| 84 | sub can_breed { |
|---|
| 85 | my ($self) = @_; |
|---|
| 86 | |
|---|
| 87 | return not grep { $_ == 15 } $self->breeding_groups; |
|---|
| 88 | } |
|---|
| 89 | |
|---|
| 90 | =head2 can_breed |
|---|
| 91 | |
|---|
| 92 | Returns a list of egg group codes. |
|---|
| 93 | |
|---|
| 94 | =cut |
|---|
| 95 | |
|---|
| 96 | # TODO: rename this 'breeds' and rename the above join |
|---|
| 97 | sub breeding_groups { |
|---|
| 98 | my ($self) = @_; |
|---|
| 99 | return map { $_->breed } $self->breeds; |
|---|
| 100 | } |
|---|
| 101 | |
|---|
| 102 | =head2 can_breed |
|---|
| 103 | |
|---|
| 104 | Returns the in-game breeding code for this Pokemon. |
|---|
| 105 | |
|---|
| 106 | =cut |
|---|
| 107 | |
|---|
| 108 | sub breeding_code { |
|---|
| 109 | my ($self) = @_; |
|---|
| 110 | my @breeds = sort $self->breeding_groups; |
|---|
| 111 | @breeds = (@breeds) x 2 if @breeds == 1; # need two digits! |
|---|
| 112 | |
|---|
| 113 | return $breeds[0] * 16 + $breeds[1]; |
|---|
| 114 | } |
|---|
| 115 | |
|---|
| 116 | =head2 can_breed_with($pokemon) |
|---|
| 117 | |
|---|
| 118 | Returns true if this Pokemon can breed with the given Pokemon, false otherwise. |
|---|
| 119 | |
|---|
| 120 | =cut |
|---|
| 121 | |
|---|
| 122 | sub can_breed_with { |
|---|
| 123 | my ($poke1, $poke2) = @_; |
|---|
| 124 | my %breeds; |
|---|
| 125 | |
|---|
| 126 | # Egg groups cannot appear twice due to keying, so this is guaranteed to |
|---|
| 127 | # work |
|---|
| 128 | $breeds{$_}++ for $poke1->breeding_groups, $poke2->breeding_groups; |
|---|
| 129 | delete $breeds{15}; |
|---|
| 130 | |
|---|
| 131 | # Compatible if at least one egg group appears twice |
|---|
| 132 | return grep { $_ > 1 } values %breeds; |
|---|
| 133 | } |
|---|
| 134 | |
|---|
| 135 | =head1 SEE ALSO |
|---|
| 136 | |
|---|
| 137 | L<Vee::Schema>, L<DBIx::Class> |
|---|
| 138 | |
|---|
| 139 | =head1 AUTHOR |
|---|
| 140 | |
|---|
| 141 | Maintainer: Alex "Eevee" Munroe (C<veekun@veekun.com>) |
|---|
| 142 | |
|---|
| 143 | See the included F<AUTHORS> file for a full list of contributers. |
|---|
| 144 | |
|---|
| 145 | =head1 LICENSE |
|---|
| 146 | |
|---|
| 147 | See the included F<LICENSE> file. |
|---|
| 148 | |
|---|
| 149 | =cut |
|---|
| 150 | |
|---|
| 151 | 1; |
|---|