Adding logic to get the level of every pokemon.

This commit is contained in:
Sergiotarxz 2024-03-08 21:09:22 +01:00
parent fe98d9a8d9
commit 780477c52d
5 changed files with 1462 additions and 14 deletions

61
create_species_data.pl Normal file
View File

@ -0,0 +1,61 @@
#!/usr/bin/env perl
use v5.16.1;
use strict;
use warnings;
use Path::Tiny;
use Data::Dumper;
my $output_file = path('lib/Rsaves/Constants/Emerald/SpeciesData.pm');
my $input_file = path('pokeemerald/src/data/pokemon/species_info.h');
my $fh_output = $output_file->openw;
open my $fh_input, '-|', 'cpp', $input_file;
print $fh_output <<'EOF';
package Rsaves::Constants::Emerald::SpeciesData;
use v5.16.3;
use strict;
use warnings;
EOF
$Data::Dumper::Terse = 1;
my %all_species_data;
{
my $species;
my %species_data;
while (defined (my $line = <$fh_input>)) {
if ($line =~ /^\s*\[SPECIES_(\w+)\]\s*=/) {
if (defined $species) {
$all_species_data{$species} = {%species_data};
}
%species_data = ();
$species = $1;
if ($species eq 'NONE') {
$species = undef;
}
}
if (defined $species) {
if ($line =~ /\.growthRate\s*=\s*(\w+)/) {
my $growth_rate = $1;
$species_data{growth_rate} = $1;
}
}
}
}
print $fh_output 'our %SPECIES_DATA = %{';
my $dumper = Data::Dumper::Dumper \%all_species_data;
chomp($dumper);
print $fh_output $dumper;
say $fh_output '};';
say $fh_output '1;';
system 'perltidy', '-b', $output_file;
1;

View File

@ -8,22 +8,140 @@ use warnings;
use Moo;
use Rsaves;
use Rsaves::Constants::Emerald::Species;
use Rsaves::Constants::Emerald::SpeciesData;
has _pokemon => (
is => 'rw',
);
has _pokemon => ( is => 'rw', );
sub species {
my $self = shift;
my $self = shift;
my $pokemon = $self->_pokemon;
my $substruct_0 = Rsaves::find_pokemon_substruct($pokemon->{substructures}, 0);
my $substruct_0 =
Rsaves::find_pokemon_substruct( $pokemon->{substructures}, 0 );
return $substruct_0->{species};
}
sub level {
my $self = shift;
my $arg = shift;
if ( defined $arg ) {
die 'Not implemented';
}
my $pokemon = $self->_pokemon;
my $experience = $pokemon->{substructures}[0]{experience};
my $growth_func = $self->growth_function;
my $level = 1;
while ($level <= 100 && $growth_func->($level) <= $experience) {
$level++;
}
$level -= 1;
return $level;
}
sub growth_function {
my $self = shift;
my $growth = $self->growth;
if ($growth eq 'GROWTH_FAST') {
return \&_exp_fast;
}
if ($growth eq 'GROWTH_MEDIUM_FAST') {
return \&_exp_medium_fast;
}
if ($growth eq 'GROWTH_MEDIUM_SLOW') {
return \&_exp_medium_slow;
}
if ($growth eq 'GROWTH_SLOW') {
return \&_exp_slow;
}
if ($growth eq 'GROWTH_ERRATIC') {
return \&_exp_erratic;
}
if ($growth eq 'GROWTH_FLUCTUATING') {
return \&_exp_fluctuating;
}
}
sub growth {
my $self = shift;
my $pokemon_name = $self->pokemon_name;
my %pokemon_data = %Rsaves::Constants::Emerald::SpeciesData::SPECIES_DATA;
my $data = $pokemon_data{$pokemon_name};
return $data->{growth_rate};
}
sub _square {
return $_[0]**2;
}
sub _cube {
return $_[0]**3;
}
sub _exp_slow {
my $n = shift;
return ( 5 * _cube($n) ) / 4;
}
sub _exp_fast {
my $n = shift;
return ( 4 * _cube($n) ) / 5;
}
sub _exp_medium_fast {
return _cube( $_[0] );
}
sub _exp_medium_slow {
my $n = shift;
return (
( 6 * _cube($n) ) / 5 - ( 15 * _square($n) ) + ( 100 * $n ) - 140 );
}
sub _exp_erratic {
my $n = shift;
if ( $n <= 50 ) {
return ( ( 100 - $n ) * _cube($n) / 50 );
}
if ( $n <= 68 ) {
return ( ( 150 - $n ) * _cube($n) / 100 );
}
if ( $n <= 98 ) {
return ( ( 1911 - 10 * $n ) / 3 * _cube($n) / 500 );
}
return ( ( 160 - $n ) * _cube($n) / 100 );
}
sub _exp_fluctuating {
my $n = shift;
if ( $n <= 15 ) {
return ( ( ( $n + 1 ) / 3 + 24 ) * _cube($n) / 50 );
}
if ( $n <= 36 ) {
return ( ( $n + 14 ) * _cube($n) / 50 );
}
return ( ( ( $n / 2 ) + 32 ) * _cube($n) / 50 );
}
sub pokemon_name {
my $self = shift;
return $Rsaves::Constants::Emerald::Species::SPECIES[ $self->species ];
}
sub nickname {
my $self = shift;
my $arg = shift;
if ( defined $arg ) {
die "Invalid nickname" if length $arg != 10;
$self->_pokemon->{nickname} = $arg;
}
return $self->_pokemon->{nickname};
}
sub get_icon {
my $self = shift;
my $pokemon_name = $Rsaves::Constants::Emerald::Species::SPECIES[$self->species];
if (lc($pokemon_name) eq 'unown') {
my $pokemon_name =
$Rsaves::Constants::Emerald::Species::SPECIES[ $self->species ];
if ( lc($pokemon_name) eq 'unown' ) {
return "pokeemerald/graphics/pokemon/@{[lc($pokemon_name)]}/z/icon.png";
}
return "pokeemerald/graphics/pokemon/@{[lc($pokemon_name)]}/icon.png";
@ -31,15 +149,18 @@ sub get_icon {
sub get_front {
my $self = shift;
my $pokemon_name = $Rsaves::Constants::Emerald::Species::SPECIES[$self->species];
if (Rsaves::pokemon_is_shiny($self->_pokemon)) {
my $pokemon_name =
$Rsaves::Constants::Emerald::Species::SPECIES[ $self->species ];
if ( Rsaves::pokemon_is_shiny( $self->_pokemon ) ) {
return "resources/shiny/@{[lc($pokemon_name)]}.png";
}
if (lc($pokemon_name) eq 'castform') {
return "pokeemerald/graphics/pokemon/@{[lc($pokemon_name)]}/normal/front.png";
if ( lc($pokemon_name) eq 'castform' ) {
return
"pokeemerald/graphics/pokemon/@{[lc($pokemon_name)]}/normal/front.png";
}
if (lc($pokemon_name) eq 'unown') {
return "pokeemerald/graphics/pokemon/@{[lc($pokemon_name)]}/z/front.png";
if ( lc($pokemon_name) eq 'unown' ) {
return
"pokeemerald/graphics/pokemon/@{[lc($pokemon_name)]}/z/front.png";
}
return "pokeemerald/graphics/pokemon/@{[lc($pokemon_name)]}/front.png";
}

View File

@ -10,6 +10,7 @@ use Glib;
use Glib::IO;
use Path::Tiny;
use Math::Trig;
use Rsaves;
use Moo;
@ -162,6 +163,7 @@ sub draw_pokemon_details {
my $cairo = shift;
my $selected_pokemon = shift;
return if !defined $selected_pokemon;
return if $selected_pokemon->species == 0;
my $output_image = Cairo::ImageSurface->create( 'argb32', 64, 64 );
my $image_context = Cairo::Context->create($output_image);
my $surface = Cairo::ImageSurface->create_from_png(
@ -173,9 +175,30 @@ sub draw_pokemon_details {
$image_context->paint;
$cairo->set_source_surface( $output_image, 20, 30 );
$cairo->get_source()->set_filter('nearest');
$cairo->scale( ( 1 / $scale_factor ) x 2 );
$cairo->paint;
my $pokemon_species = $Rsaves::Constants::Emerald::Species::SPECIES[$selected_pokemon->species];
$cairo->select_font_face( 'Sans', 'normal', 'normal' );
$cairo->set_source_rgb( 1, 1, 1 );
$cairo->set_font_size(8);
$cairo->move_to( 5, 120 );
$cairo->text_path(Rsaves::translate_3rd_encoding($selected_pokemon->nickname));
$cairo->fill;
$cairo->move_to( 5, 128 );
$cairo->text_path('/'.$pokemon_species);
$cairo->set_source_rgb( 1, 1, 1 );
$cairo->fill_preserve;
# $cairo->set_source_rgb( 0, 0, 0 );
# $cairo->set_line_width(0.8);
# $cairo->stroke;
$cairo->move_to( 5, 136 );
$cairo->text_path("Lv@{[$selected_pokemon->level]}");
$cairo->set_source_rgb( 1, 1, 1 );
$cairo->fill_preserve;
$cairo->scale( ( 1 / $scale_factor ) x 2 );
}
sub draw_pc {

View File

@ -8,6 +8,7 @@ use warnings;
use feature 'signatures';
use Data::Dumper;
use utf8;
use Rsaves::Constants::Ruby::Flags
qw/$FLAG_SYS_HAS_EON_TICKET $FLAG_LEGENDARY_BATTLE_COMPLETED $FLAG_HIDE_LEGEND_MON_CAVE_OF_ORIGIN/;

File diff suppressed because it is too large Load Diff