diff --git a/lib/LasTres/Location.pm b/lib/LasTres/Location.pm index 40adb29..45e2491 100644 --- a/lib/LasTres/Location.pm +++ b/lib/LasTres/Location.pm @@ -27,14 +27,14 @@ my $planets = LasTres::Planets->new; # The available actions to do in # this location, must return hashref, # can be an empty one though. -sub actions($self, $pj) { +sub actions ( $self, $pj ) { return []; } ## OVERRIDE # The available persons to talk with # Must return a hashref, can be a empty # one though. -sub npcs($self, $pj) { +sub npcs ( $self, $pj ) { return []; } @@ -75,20 +75,20 @@ sub order ($self) { } ## OVERRIDE -# A place that is a spawn will have a healing action that can be changed +# A place that is a spawn will have a healing action that can be changed # and if a team faints they will be teleported there and the action will # be triggered, the healing action may cost some resource when the action # is triggered manually by the user, if the player cannot pay it the # action may appear as disabled. -sub is_spawn($self) { +sub is_spawn ($self) { return 0; } ## OVERRIDE # Return object should ideally extend LasTres::PJAction::DefaultHeal # following the advice in this file. -sub healing_action($self) { - if ($self->is_spawn) { +sub healing_action ($self) { + if ( $self->is_spawn ) { require LasTres::PJAction::DefaultHeal; return LasTres::PJAction::DefaultHeal->new; } @@ -136,10 +136,10 @@ sub show_intro ( $self, $pj ) { } ## OVERRIDE (Always use $self->SUPER) -sub on_leave($self, $team) { +sub on_leave ( $self, $team ) { require LasTres::Vars; - for my $member ($team->members) { - $member->clear_var(LasTres::Vars::LOCATION_TEMPORAL()); + for my $member ( $team->members ) { + $member->clear_var( LasTres::Vars::LOCATION_TEMPORAL() ); } } @@ -201,7 +201,7 @@ sub on_pj_moving ( $self, $pj ) { ## DO NOT EXTEND NOT SUPPORTED. sub place_team ( $self, $team ) { $team = $team->get_from_storage; - if ($self->is_spawn) { + if ( $self->is_spawn ) { $team->last_spawn( $self->to_json_array ); } $team->location($self); @@ -253,8 +253,10 @@ sub get_available_locations_to_move_to ( $self, $pj = undef ) { ); @$connected_places = grep { $_->to_json_array ne $location->to_json_array } - grep { $_->to_json_array; $_->to_json_array ne to_json(from_json($pj->team->moving_to)) } - @$connected_places; + grep { + $_->to_json_array; + $_->to_json_array ne to_json( from_json( $pj->team->moving_to ) ) + } @$connected_places; if ( defined $pj ) { @$connected_places = grep { $_->can_visit($pj) } @$connected_places; } @@ -342,4 +344,16 @@ sub hash ($self) { }, }; } + +{ + my %instances; + + sub instance { + my $class = shift; + if ( !defined $instances{$class} ) { + $instances{$class} = $class->new(@_); + } + return $instances{$class}; + } +} 1; diff --git a/lib/LasTres/Planet/Bahdder/BosqueDelHeroe/BosqueDelHeroeI/Llano.pm b/lib/LasTres/Planet/Bahdder/BosqueDelHeroe/BosqueDelHeroeI/Llano.pm index 69f8864..68e3285 100644 --- a/lib/LasTres/Planet/Bahdder/BosqueDelHeroe/BosqueDelHeroeI/Llano.pm +++ b/lib/LasTres/Planet/Bahdder/BosqueDelHeroe/BosqueDelHeroeI/Llano.pm @@ -10,7 +10,7 @@ use Moo; use LasTres::Planet::Bahdder::BosqueDelHeroe::BosqueDelHeroeI; -with 'LasTres::Location'; +use parent 'LasTres::Location'; sub identifier { return 'llano'; @@ -32,13 +32,4 @@ sub connected_places { LasTres::Planet::Bahdder::BosqueDelHeroe::TribuDeLaLima::Entrada->instance, ]; } - -my $singleton; -sub instance { - my $class = shift; - if (!defined $singleton) { - $singleton = $class->new(@_); - } - return $singleton; -} 1; diff --git a/lib/LasTres/Planet/Bahdder/BosqueDelHeroe/BosqueDelHeroeI/TribuDeLaLima.pm b/lib/LasTres/Planet/Bahdder/BosqueDelHeroe/BosqueDelHeroeI/TribuDeLaLima.pm index d2a8243..2cabe76 100644 --- a/lib/LasTres/Planet/Bahdder/BosqueDelHeroe/BosqueDelHeroeI/TribuDeLaLima.pm +++ b/lib/LasTres/Planet/Bahdder/BosqueDelHeroe/BosqueDelHeroeI/TribuDeLaLima.pm @@ -10,7 +10,7 @@ use Moo; use LasTres::Planet::Bahdder::BosqueDelHeroe::BosqueDelHeroeI; -with 'LasTres::Location'; +use parent 'LasTres::Location'; sub identifier { return 'tribu_de_la_lima'; @@ -35,13 +35,4 @@ sub connected_places { LasTres::Planet::Bahdder::BosqueDelHeroe::TribuDeLaLima::Entrada->instance, ]; } - -my $singleton; -sub instance { - my $class = shift; - if (!defined $singleton) { - $singleton = $class->new(@_); - } - return $singleton; -} 1; diff --git a/lib/LasTres/Planet/Bahdder/BosqueDelHeroe/TribuDeLaLima/ArbolCentral.pm b/lib/LasTres/Planet/Bahdder/BosqueDelHeroe/TribuDeLaLima/ArbolCentral.pm index 6eb93eb..d338a5c 100644 --- a/lib/LasTres/Planet/Bahdder/BosqueDelHeroe/TribuDeLaLima/ArbolCentral.pm +++ b/lib/LasTres/Planet/Bahdder/BosqueDelHeroe/TribuDeLaLima/ArbolCentral.pm @@ -15,7 +15,7 @@ use LasTres::Planet::Bahdder::BosqueDelHeroe::TribuDeLaLima; use LasTres::PJAction::GolpearArbolCentralTribuDeLaLima; use LasTres::TalkingNPC::AncianoTribuLima; -with 'LasTres::Location'; +use parent 'LasTres::Location'; sub identifier { return 'arbol_central'; @@ -46,16 +46,6 @@ sub connected_places { return []; } -my $singleton; - -sub instance { - my $class = shift; - if ( !defined $singleton ) { - $singleton = $class->new(@_); - } - return $singleton; -} - sub is_spawn { return 1; } diff --git a/lib/LasTres/Planet/Bahdder/BosqueDelHeroe/TribuDeLaLima/CasaDePiedra.pm b/lib/LasTres/Planet/Bahdder/BosqueDelHeroe/TribuDeLaLima/CasaDePiedra.pm index b832516..00c53c6 100644 --- a/lib/LasTres/Planet/Bahdder/BosqueDelHeroe/TribuDeLaLima/CasaDePiedra.pm +++ b/lib/LasTres/Planet/Bahdder/BosqueDelHeroe/TribuDeLaLima/CasaDePiedra.pm @@ -14,7 +14,7 @@ use Moo; use LasTres::Planet::Bahdder::BosqueDelHeroe::TribuDeLaLima; use LasTres::TalkingNPC::VeteranoCalizor; -with 'LasTres::Location'; +use parent 'LasTres::Location'; sub identifier { return 'casa_de_piedra'; @@ -53,16 +53,6 @@ sub connected_places { return []; } -my $singleton; - -sub instance { - my $class = shift; - if ( !defined $singleton ) { - $singleton = $class->new(@_); - } - return $singleton; -} - sub is_spawn { return 0; } diff --git a/lib/LasTres/Planet/Bahdder/BosqueDelHeroe/TribuDeLaLima/Entrada.pm b/lib/LasTres/Planet/Bahdder/BosqueDelHeroe/TribuDeLaLima/Entrada.pm index 13d91f6..896f39d 100644 --- a/lib/LasTres/Planet/Bahdder/BosqueDelHeroe/TribuDeLaLima/Entrada.pm +++ b/lib/LasTres/Planet/Bahdder/BosqueDelHeroe/TribuDeLaLima/Entrada.pm @@ -12,13 +12,14 @@ use utf8; use Moo; use LasTres::Planet::Bahdder::BosqueDelHeroe::TribuDeLaLima; +use LasTres::Planet::Bahdder::BosqueDelHeroe::BosqueDelHeroeI::TribuDeLaLima has parent => ( is => 'ro', builder => \&_build_parent, ); -with 'LasTres::Location'; +use parent 'LasTres::Location'; sub is_spawn { return 0; @@ -47,13 +48,4 @@ sub connected_places { LasTres::Planet::Bahdder::BosqueDelHeroe::BosqueDelHeroeI::TribuDeLaLima->instance, ]; } - -my $singleton; -sub instance { - my $class = shift; - if (!defined $singleton) { - $singleton = $class->new(@_); - } - return $singleton; -} 1; diff --git a/lib/LasTres/Planet/Bahdder/BosqueDelHeroe/TribuDeLaLima/TemploDeAyazel.pm b/lib/LasTres/Planet/Bahdder/BosqueDelHeroe/TribuDeLaLima/TemploDeAyazel.pm index fa72da7..d092d35 100644 --- a/lib/LasTres/Planet/Bahdder/BosqueDelHeroe/TribuDeLaLima/TemploDeAyazel.pm +++ b/lib/LasTres/Planet/Bahdder/BosqueDelHeroe/TribuDeLaLima/TemploDeAyazel.pm @@ -15,7 +15,7 @@ use LasTres::Planet::Bahdder::BosqueDelHeroe::TribuDeLaLima; use LasTres::TalkingNPC::Chaman; use LasTres::PJAction::RezarAyazelTribuDeLaLima; -with 'LasTres::Location'; +use parent 'LasTres::Location'; sub identifier { return 'templo_de_ayazel'; @@ -53,16 +53,6 @@ sub connected_places { return []; } -my $singleton; - -sub instance { - my $class = shift; - if ( !defined $singleton ) { - $singleton = $class->new(@_); - } - return $singleton; -} - sub is_spawn { return 0; }