root/veekun/trunk/lib/Vee/Schema/EvoChains.pm

Revision 432, 1.5 KB (checked in by eevee, 22 months ago)

Changed breeding chain calculator to interpret its Pokemon input as a target rather than.. whatever it was before. (#309)
Also added some more detail on reading the results.

Line 
1package Vee::Schema::EvoChains;
2
3use strict;
4use warnings;
5use base 'DBIx::Class';
6
7=head1 NAME
8
9Vee::Schema::EvoChains - DBIC class for the C<evo_chains> table
10
11=cut
12
13__PACKAGE__->load_components('Core');
14__PACKAGE__->table('evo_chains');
15__PACKAGE__->add_columns(qw/
16    id
17    growth_rate
18    steps
19    baby_item
20/);
21__PACKAGE__->set_primary_key('id');
22
23__PACKAGE__->has_many(pokemon => 'Vee::Schema::Pokemon', 'evo_chain_id');
24
25=head2 baby_form
26
27Returns the baby Pokemon in this chain, if any.
28
29=cut
30
31sub baby_form {
32    my ($self) = @_;
33
34    return $self->pokemon( \ 'FIND_IN_SET(flags, "baby")' )->single;
35}
36
37=head2 basic_form
38
39Returns the basic form of this Pokemon.
40
41=cut
42
43sub basic_form {
44    my ($self) = @_;
45
46    return $self->pokemon(
47        \ 'NOT FIND_IN_SET(flags, "baby")',
48    {
49        order_by => 'id ASC',
50    })->first;
51}
52
53=head2 egg_forms
54
55Returns any Pokemon that can result from a breeding in this chain.
56
57=cut
58
59sub egg_forms {
60    my ($self) = @_;
61    my @ret;
62
63    my $baby_form  = $self->baby_form;
64    if ($baby_form) {
65        push @ret, $baby_form;
66    }
67
68    my $basic_form = $self->basic_form;
69    if (not $baby_form
70        or $self->baby_item)  # e.g. Munchlax with incense
71    {
72        push @ret, $basic_form;
73    }
74
75    return @ret;
76}
77
78=head1 SEE ALSO
79
80L<Vee::Schema>, L<DBIx::Class>
81
82=head1 AUTHOR
83
84Maintainer: Alex "Eevee" Munroe (C<veekun@veekun.com>)
85
86See the included F<AUTHORS> file for a full list of contributers.
87
88=head1 LICENSE
89
90See the included F<LICENSE> file.
91
92=cut
93
941;
Note: See TracBrowser for help on using the browser.