| 1 | package Vee::Schema::Moves; |
|---|
| 2 | |
|---|
| 3 | use strict; |
|---|
| 4 | use warnings; |
|---|
| 5 | use base 'DBIx::Class'; |
|---|
| 6 | |
|---|
| 7 | =head1 NAME |
|---|
| 8 | |
|---|
| 9 | Vee::Schema::Moves - DBIC class for the C<moves> table |
|---|
| 10 | |
|---|
| 11 | =cut |
|---|
| 12 | |
|---|
| 13 | __PACKAGE__->load_components('Core'); |
|---|
| 14 | __PACKAGE__->table('moves'); |
|---|
| 15 | __PACKAGE__->add_columns(qw/ |
|---|
| 16 | id |
|---|
| 17 | name |
|---|
| 18 | name_jp |
|---|
| 19 | name_romaji |
|---|
| 20 | type |
|---|
| 21 | power |
|---|
| 22 | pp |
|---|
| 23 | accuracy |
|---|
| 24 | target |
|---|
| 25 | class |
|---|
| 26 | flags |
|---|
| 27 | combos |
|---|
| 28 | effect_chance |
|---|
| 29 | kind |
|---|
| 30 | status |
|---|
| 31 | move_effect_id |
|---|
| 32 | blurb_rusa |
|---|
| 33 | blurb_dp |
|---|
| 34 | contest_type |
|---|
| 35 | contest_effect_id |
|---|
| 36 | notes |
|---|
| 37 | /); |
|---|
| 38 | __PACKAGE__->set_primary_key('id'); |
|---|
| 39 | |
|---|
| 40 | __PACKAGE__->belongs_to(contest_effect => 'Vee::Schema::ContestEffects', 'contest_effect_id'); |
|---|
| 41 | __PACKAGE__->belongs_to(effect => 'Vee::Schema::MoveEffects', 'move_effect_id'); |
|---|
| 42 | __PACKAGE__->has_many(pokemon_moves => 'Vee::Schema::PokemonMoves', 'move_id'); |
|---|
| 43 | |
|---|
| 44 | =head1 METHODS |
|---|
| 45 | |
|---|
| 46 | =head2 priority |
|---|
| 47 | |
|---|
| 48 | Returns the priority of the given move. Only exists for consistency, as this |
|---|
| 49 | is the only data commonly accessed via C<%MoveData> that is actually a column |
|---|
| 50 | of C<move_effects>. |
|---|
| 51 | |
|---|
| 52 | =cut |
|---|
| 53 | |
|---|
| 54 | sub priority { |
|---|
| 55 | my ($self) = @_; |
|---|
| 56 | return $self->effect->priority; |
|---|
| 57 | } |
|---|
| 58 | |
|---|
| 59 | =head2 description |
|---|
| 60 | |
|---|
| 61 | Returns the full description for this move. Applies C<_format_description> |
|---|
| 62 | effects, and converts tab-delimited tables to HTML. |
|---|
| 63 | |
|---|
| 64 | =cut |
|---|
| 65 | |
|---|
| 66 | sub description { |
|---|
| 67 | my ($self) = @_; |
|---|
| 68 | |
|---|
| 69 | my $desc = $self->_format_description( $self->effect->description ); |
|---|
| 70 | my @lines = split /\n/, $desc; |
|---|
| 71 | |
|---|
| 72 | my $table_open = 0; |
|---|
| 73 | for my $line (@lines) { |
|---|
| 74 | if ($line =~ /\t/) { |
|---|
| 75 | $line =~ s[\t][</td><td>]g; |
|---|
| 76 | $line = "<tr><td>$line</td></tr>"; |
|---|
| 77 | $line = "<table>\n$line" if not $table_open; |
|---|
| 78 | $table_open = 1; |
|---|
| 79 | } else { |
|---|
| 80 | $line = "<p>$line</p>"; |
|---|
| 81 | $line = "</table>\n$line" if $table_open; |
|---|
| 82 | $table_open = 0; |
|---|
| 83 | } |
|---|
| 84 | } |
|---|
| 85 | push @lines, "</table>" if $table_open; |
|---|
| 86 | |
|---|
| 87 | return join "\n", @lines; |
|---|
| 88 | } |
|---|
| 89 | |
|---|
| 90 | =head2 short_description |
|---|
| 91 | |
|---|
| 92 | Returns a short description for this move, suitable for putting in a move table. |
|---|
| 93 | Applies C<_format_description> effects. |
|---|
| 94 | |
|---|
| 95 | =cut |
|---|
| 96 | |
|---|
| 97 | sub short_description { |
|---|
| 98 | my ($self) = @_; |
|---|
| 99 | |
|---|
| 100 | return $self->_format_description( $self->effect->short_description ); |
|---|
| 101 | } |
|---|
| 102 | |
|---|
| 103 | =head2 _format_description($text) |
|---|
| 104 | |
|---|
| 105 | Inserts this move's effect chance and priority into the provided string, if |
|---|
| 106 | applicable. Used by C<description> and C<short_description>. |
|---|
| 107 | |
|---|
| 108 | =cut |
|---|
| 109 | |
|---|
| 110 | sub _format_description { |
|---|
| 111 | my ($self, $text) = @_; |
|---|
| 112 | |
|---|
| 113 | # effect chance |
|---|
| 114 | $text =~ s/a chance to/a ${\( $self->effect_chance )}% chance to/g |
|---|
| 115 | if $self->effect_chance; |
|---|
| 116 | |
|---|
| 117 | if ($self->effect->priority < 0) { |
|---|
| 118 | $text = "Goes last. $text"; |
|---|
| 119 | } elsif ($self->effect->priority > 0) { |
|---|
| 120 | $text = "Goes first. $text"; |
|---|
| 121 | } |
|---|
| 122 | |
|---|
| 123 | return $text; |
|---|
| 124 | } |
|---|
| 125 | |
|---|
| 126 | =head1 SEE ALSO |
|---|
| 127 | |
|---|
| 128 | L<Vee::Schema>, L<DBIx::Class> |
|---|
| 129 | |
|---|
| 130 | =head1 AUTHOR |
|---|
| 131 | |
|---|
| 132 | Maintainer: Alex "Eevee" Munroe (C<veekun@veekun.com>) |
|---|
| 133 | |
|---|
| 134 | See the included F<AUTHORS> file for a full list of contributers. |
|---|
| 135 | |
|---|
| 136 | =head1 LICENSE |
|---|
| 137 | |
|---|
| 138 | See the included F<LICENSE> file. |
|---|
| 139 | |
|---|
| 140 | =cut |
|---|
| 141 | |
|---|
| 142 | 1; |
|---|