Adding gain experience.
This commit is contained in:
parent
e6833001c3
commit
9765d3b0dc
@ -15,6 +15,7 @@ requires(
|
|||||||
'uuid', 'race_string', 'nick', 'born_stats',
|
'uuid', 'race_string', 'nick', 'born_stats',
|
||||||
'health', 'mana', 'training_stats', 'experience',
|
'health', 'mana', 'training_stats', 'experience',
|
||||||
'combat_action', 'combat_target', 'team', 'update',
|
'combat_action', 'combat_target', 'team', 'update',
|
||||||
|
'gain_experience', 'update_team_sprites'
|
||||||
);
|
);
|
||||||
|
|
||||||
sub append_log_line {
|
sub append_log_line {
|
||||||
@ -75,14 +76,6 @@ sub attack ( $self, $enemy_entity ) {
|
|||||||
}
|
}
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
if ( $enemy_entity->health == 0 ) {
|
|
||||||
$member->append_log_line(
|
|
||||||
[
|
|
||||||
{ color => 'red', text => "@{[$enemy_entity->nick]}" },
|
|
||||||
{ text => " se ha debilitado." },
|
|
||||||
]
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
for my $member ( $team2->combat_members->@* ) {
|
for my $member ( $team2->combat_members->@* ) {
|
||||||
$member->append_log_line(
|
$member->append_log_line(
|
||||||
@ -101,15 +94,32 @@ sub attack ( $self, $enemy_entity ) {
|
|||||||
}
|
}
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
|
}
|
||||||
if ( $enemy_entity->health == 0 ) {
|
if ( $enemy_entity->health == 0 ) {
|
||||||
|
$enemy_entity->on_faint($self);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
sub on_faint($self, $attacker) {
|
||||||
|
my $team2 = $self->team;
|
||||||
|
my $team1 = $attacker->team;
|
||||||
|
for my $member ( $team1->combat_members->@* ) {
|
||||||
$member->append_log_line(
|
$member->append_log_line(
|
||||||
[
|
[
|
||||||
{ color => 'green', text => "@{[$enemy_entity->nick]}" },
|
{ color => 'red', text => "@{[$self->nick]}" },
|
||||||
{ text => " se ha debilitado." },
|
{ text => " se ha debilitado." },
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
for my $member ( $team2->combat_members->@* ) {
|
||||||
|
$member->append_log_line(
|
||||||
|
[
|
||||||
|
{ color => 'green', text => "@{[$self->nick]}" },
|
||||||
|
{ text => " se ha debilitado." },
|
||||||
|
]
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
$attacker->gain_experience((($self->race->experience_drop_base * $self->level)/7)*1.5);
|
||||||
}
|
}
|
||||||
|
|
||||||
sub level ($self) {
|
sub level ($self) {
|
||||||
|
@ -9,7 +9,7 @@ use feature 'signatures';
|
|||||||
|
|
||||||
use Moo::Role;
|
use Moo::Role;
|
||||||
|
|
||||||
requires qw/uuid combat_members current_battle to_serializable from_serializable update is_defeated on_win_combat on_lose_combat update/;
|
requires qw/uuid combat_members current_battle to_serializable from_serializable update is_defeated on_win_combat on_lose_combat update on_end_combat/;
|
||||||
|
|
||||||
sub get_from_storage($self) {
|
sub get_from_storage($self) {
|
||||||
return $self;
|
return $self;
|
||||||
|
@ -74,6 +74,9 @@ after team => sub ( $self, @extra ) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
sub update_team_sprites ($self) {
|
||||||
|
}
|
||||||
|
|
||||||
sub _build_born_stats ($self) {
|
sub _build_born_stats ($self) {
|
||||||
return LasTres::Stats->new(
|
return LasTres::Stats->new(
|
||||||
health => int( rand(32) ),
|
health => int( rand(32) ),
|
||||||
@ -123,7 +126,8 @@ sub combat_target ($self, @extra) {
|
|||||||
if ( !@$target_team_members ) {
|
if ( !@$target_team_members ) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
my $target_index = LasTres::Util::rand_range_int(0, $#$target_team_members);
|
my $target_index =
|
||||||
|
LasTres::Util::rand_range_int( 0, $#$target_team_members );
|
||||||
$self->_combat_target( $target_team_members->[$target_index]->uuid );
|
$self->_combat_target( $target_team_members->[$target_index]->uuid );
|
||||||
}
|
}
|
||||||
if ( defined $set ) {
|
if ( defined $set ) {
|
||||||
@ -132,6 +136,9 @@ sub combat_target ($self, @extra) {
|
|||||||
return $self->_combat_target;
|
return $self->_combat_target;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sub gain_experience {
|
||||||
|
}
|
||||||
|
|
||||||
sub update ($self) {
|
sub update ($self) {
|
||||||
return $self;
|
return $self;
|
||||||
}
|
}
|
||||||
|
@ -56,6 +56,9 @@ sub to_serializable ($self) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sub on_end_combat($self) {
|
||||||
|
}
|
||||||
|
|
||||||
sub from_serializable ( $class, $hash ) {
|
sub from_serializable ( $class, $hash ) {
|
||||||
if ( $hash->{is_db} ) {
|
if ( $hash->{is_db} ) {
|
||||||
die "This is not an Enemy Team but a DB Team.";
|
die "This is not an Enemy Team but a DB Team.";
|
||||||
|
@ -9,7 +9,7 @@ use feature 'signatures';
|
|||||||
|
|
||||||
use Moo::Role;
|
use Moo::Role;
|
||||||
|
|
||||||
requires qw/spawn identifier name name_selection description is_playable base_stats/;
|
requires qw/spawn identifier name name_selection description is_playable base_stats experience_drop_base/;
|
||||||
|
|
||||||
sub hash($self) {
|
sub hash($self) {
|
||||||
return {
|
return {
|
||||||
|
@ -92,4 +92,8 @@ sub _build_description {
|
|||||||
sub _build_is_playable {
|
sub _build_is_playable {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sub experience_drop_base {
|
||||||
|
return 263;
|
||||||
|
}
|
||||||
1;
|
1;
|
||||||
|
@ -36,6 +36,10 @@ sub is_playable {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sub experience_drop_base {
|
||||||
|
return 51;
|
||||||
|
}
|
||||||
|
|
||||||
sub base_stats {
|
sub base_stats {
|
||||||
return LasTres::Stats->new(
|
return LasTres::Stats->new(
|
||||||
health => 40,
|
health => 40,
|
||||||
|
@ -6,8 +6,8 @@ use strict;
|
|||||||
use warnings;
|
use warnings;
|
||||||
|
|
||||||
use feature 'signatures';
|
use feature 'signatures';
|
||||||
|
|
||||||
use parent 'DBIx::Class::Core';
|
use parent 'DBIx::Class::Core';
|
||||||
|
use utf8;
|
||||||
|
|
||||||
use UUID::URandom qw/create_uuid_string/;
|
use UUID::URandom qw/create_uuid_string/;
|
||||||
use List::AllUtils;
|
use List::AllUtils;
|
||||||
@ -158,8 +158,8 @@ sub set_known_location ( $self, $location ) {
|
|||||||
my ( $planet, $super_area, $area ) = @$array[ 0 .. 2 ];
|
my ( $planet, $super_area, $area ) = @$array[ 0 .. 2 ];
|
||||||
$location = $array->[3];
|
$location = $array->[3];
|
||||||
my $schema = LasTres::Schema->Schema;
|
my $schema = LasTres::Schema->Schema;
|
||||||
$schema->resultset('PJKnownPlaces')
|
$schema->resultset('PJKnownPlaces')->new(
|
||||||
->new( {
|
{
|
||||||
owner => $self->uuid,
|
owner => $self->uuid,
|
||||||
planet => $planet,
|
planet => $planet,
|
||||||
super_area => $super_area,
|
super_area => $super_area,
|
||||||
@ -185,8 +185,10 @@ sub hash ($self) {
|
|||||||
max_health => $self->max_health,
|
max_health => $self->max_health,
|
||||||
mana => $self->mana,
|
mana => $self->mana,
|
||||||
level => $self->level,
|
level => $self->level,
|
||||||
experience_to_next_level_complete => $self->experience_to_next_level_complete,
|
experience_to_next_level_complete =>
|
||||||
experience_to_next_level_current => $self->experience_to_next_level_current,
|
$self->experience_to_next_level_complete,
|
||||||
|
experience_to_next_level_current =>
|
||||||
|
$self->experience_to_next_level_current,
|
||||||
max_mana => $self->max_mana,
|
max_mana => $self->max_mana,
|
||||||
(
|
(
|
||||||
( defined $image )
|
( defined $image )
|
||||||
@ -220,12 +222,117 @@ for my $column_name ( keys %$columns ) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
sub last_50_log ($self) {
|
sub last_50_log ($self) {
|
||||||
return $self->logs->search( {},
|
return $self->logs->search( {},
|
||||||
{ limit => 50, order_by => { -desc => 'date' } } );
|
{ limit => 50, order_by => { -desc => 'date' } } );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sub update_team_sprites ($self) {
|
||||||
|
require LasTres::Redis;
|
||||||
|
my $redis = LasTres::Redis->new;
|
||||||
|
$redis->publish( $redis->pj_subscription($self),
|
||||||
|
to_json( { command => 'update-team-sprites' } ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
sub on_level_up ( $self, $old_level ) {
|
||||||
|
my $old_experience = $self->experience;
|
||||||
|
my $team = $self->team;
|
||||||
|
my $enemy_team = $self->_enemy_team;
|
||||||
|
$self->health($self->max_health);
|
||||||
|
$self->update;
|
||||||
|
for my $member ( $team->combat_members->@* ) {
|
||||||
|
$member->update_team_sprites;
|
||||||
|
$member->append_log_line(
|
||||||
|
[
|
||||||
|
{
|
||||||
|
text => $self->nick,
|
||||||
|
color => 'green',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
text => ' subió al nivel ' . $self->level
|
||||||
|
}
|
||||||
|
]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if ( defined $enemy_team ) {
|
||||||
|
for my $member ( $enemy_team->combat_members->@* ) {
|
||||||
|
$member->update_team_sprites;
|
||||||
|
$member->append_log_line(
|
||||||
|
[
|
||||||
|
{
|
||||||
|
text => $self->nick,
|
||||||
|
color => 'red',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
text => ' subió al nivel ' . $self->level
|
||||||
|
}
|
||||||
|
]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
sub _enemy_team ($self) {
|
||||||
|
my $team = $self->team;
|
||||||
|
my $enemy_team;
|
||||||
|
my $current_battle = $team->current_battle;
|
||||||
|
{
|
||||||
|
if ( !defined $current_battle ) {
|
||||||
|
next;
|
||||||
|
}
|
||||||
|
my $battle = LasTres::Battle->get_redis($current_battle);
|
||||||
|
if ( !defined $battle ) {
|
||||||
|
next;
|
||||||
|
}
|
||||||
|
$enemy_team = $battle->get_enemy_team($team);
|
||||||
|
}
|
||||||
|
return $enemy_team;
|
||||||
|
}
|
||||||
|
|
||||||
|
sub gain_experience ( $self, $experience_to_gain ) {
|
||||||
|
$experience_to_gain = int($experience_to_gain);
|
||||||
|
my $redis = LasTres::Redis->new;
|
||||||
|
my $old_experience = $self->experience;
|
||||||
|
my $old_level = $self->level;
|
||||||
|
my $team = $self->team;
|
||||||
|
my $current_battle = $team->current_battle;
|
||||||
|
$self->experience( $old_experience + $experience_to_gain );
|
||||||
|
$self->update;
|
||||||
|
for my $member ( $team->combat_members->@* ) {
|
||||||
|
$member->append_log_line(
|
||||||
|
[
|
||||||
|
{
|
||||||
|
text => $self->nick,
|
||||||
|
color => 'green',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
text => " ganó $experience_to_gain puntos de experiencia."
|
||||||
|
}
|
||||||
|
]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
my $enemy_team = $self->_enemy_team;
|
||||||
|
if ( defined $enemy_team ) {
|
||||||
|
for my $member ( $enemy_team->combat_members->@* ) {
|
||||||
|
$member->append_log_line(
|
||||||
|
[
|
||||||
|
{
|
||||||
|
text => $self->nick,
|
||||||
|
color => 'red',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
text =>
|
||||||
|
" ganó $experience_to_gain puntos de experiencia."
|
||||||
|
}
|
||||||
|
]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ( $old_level != $self->level ) {
|
||||||
|
$self->on_level_up($old_level);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
sub append_log_line ( $self, $content ) {
|
sub append_log_line ( $self, $content ) {
|
||||||
require LasTres::Schema;
|
require LasTres::Schema;
|
||||||
require LasTres::Redis;
|
require LasTres::Redis;
|
||||||
@ -275,7 +382,6 @@ sub location ($self) {
|
|||||||
return $self->team->location;
|
return $self->team->location;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
sub set_flag ( $self, $name ) {
|
sub set_flag ( $self, $name ) {
|
||||||
require LasTres::Schema;
|
require LasTres::Schema;
|
||||||
my $schema = LasTres::Schema->Schema;
|
my $schema = LasTres::Schema->Schema;
|
||||||
|
@ -188,6 +188,9 @@ sub combat_members ($self) {
|
|||||||
return [@members];
|
return [@members];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sub on_end_combat($self) {
|
||||||
|
}
|
||||||
|
|
||||||
sub to_serializable ($self) {
|
sub to_serializable ($self) {
|
||||||
return {
|
return {
|
||||||
is_db => $JSON::true,
|
is_db => $JSON::true,
|
||||||
|
Loading…
Reference in New Issue
Block a user