Refactoring locations.

This commit is contained in:
Sergiotarxz 2023-07-22 17:58:48 +02:00
parent 8690a94b3a
commit aff1619de0
7 changed files with 33 additions and 75 deletions

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;

View File

@ -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;
}