Adding preliminar NPC support.
This commit is contained in:
parent
31f3ebcfbc
commit
c189bb1f08
@ -91,7 +91,11 @@ export default class InputPackets {
|
||||
if (logPresentationRef.current === null) {
|
||||
return
|
||||
}
|
||||
scrollData = [logPresentationRef.current.scrollHeight, logPresentationRef.current.scrollTop, logPresentationRef.current.offsetHeight]
|
||||
scrollData = [
|
||||
logPresentationRef.current.scrollHeight,
|
||||
logPresentationRef.current.scrollTop,
|
||||
logPresentationRef.current.offsetHeight
|
||||
]
|
||||
}
|
||||
function applyScroll (): void {
|
||||
if (scrollData.length < 3) {
|
||||
|
@ -13,6 +13,7 @@ use Moo;
|
||||
|
||||
use LasTres::Planet::Bahdder::BosqueDelHeroe::TribuDeLaLima;
|
||||
use LasTres::PJAction::GolpearArbolCentralTribuDeLaLima;
|
||||
use LasTres::TalkingNPC::AncianoTribuLima;
|
||||
|
||||
with 'LasTres::Location';
|
||||
|
||||
@ -25,7 +26,8 @@ sub name {
|
||||
}
|
||||
|
||||
sub description {
|
||||
return 'Desde este árbol se puede contemplar toda la Tribu de la Lima, sus casitas de paja y los cultivos de lima.';
|
||||
return
|
||||
'Desde este árbol se puede contemplar toda la Tribu de la Lima, sus casitas de paja y los cultivos de lima.';
|
||||
}
|
||||
|
||||
sub parent {
|
||||
@ -33,13 +35,11 @@ sub parent {
|
||||
}
|
||||
|
||||
sub actions {
|
||||
return [
|
||||
LasTres::PJAction::GolpearArbolCentralTribuDeLaLima->new
|
||||
];
|
||||
return [ LasTres::PJAction::GolpearArbolCentralTribuDeLaLima->new ];
|
||||
}
|
||||
|
||||
sub npcs {
|
||||
return [];
|
||||
return [ LasTres::TalkingNPC::AncianoTribuLima->new ];
|
||||
}
|
||||
|
||||
sub connected_places {
|
||||
@ -47,9 +47,10 @@ sub connected_places {
|
||||
}
|
||||
|
||||
my $singleton;
|
||||
|
||||
sub instance {
|
||||
my $class = shift;
|
||||
if (!defined $singleton) {
|
||||
if ( !defined $singleton ) {
|
||||
$singleton = $class->new(@_);
|
||||
}
|
||||
return $singleton;
|
||||
|
@ -502,5 +502,10 @@ sub actions ($self) {
|
||||
@actions = ( @actions, @$location_actions );
|
||||
return \@actions;
|
||||
}
|
||||
|
||||
sub talking_npcs($self) {
|
||||
return [];
|
||||
}
|
||||
|
||||
with 'LasTres::CombatCapableEntity';
|
||||
1;
|
||||
|
172
lib/LasTres/TalkingNPC.pm
Normal file
172
lib/LasTres/TalkingNPC.pm
Normal file
@ -0,0 +1,172 @@
|
||||
package LasTres::TalkingNPC;
|
||||
|
||||
use v5.36.0;
|
||||
use strict;
|
||||
use warnings;
|
||||
use utf8;
|
||||
|
||||
use feature 'signatures';
|
||||
|
||||
use Moo::Role;
|
||||
|
||||
requires qw/identifier name/;
|
||||
|
||||
## IMPLEMENTORS MUST IMPLEMENT
|
||||
# sub identifier;
|
||||
#
|
||||
# Identifier must be unique across
|
||||
# npcs, failure to do so may
|
||||
# result in a runtime error and
|
||||
# is not supported.
|
||||
#
|
||||
# sub name($self, $pj);
|
||||
#
|
||||
## IMPLEMENTORS MUST EXTEND
|
||||
# sub talk($self,$pj,$word);
|
||||
|
||||
## OVERRIDE
|
||||
sub icon {
|
||||
return undef;
|
||||
}
|
||||
|
||||
## OVERRIDE
|
||||
sub color ( $self, $pj ) {
|
||||
return 'blue',;
|
||||
}
|
||||
|
||||
## OVERRIDE
|
||||
# Refer to show_wordlessly_talk_started for
|
||||
# detail about when it is convenient to
|
||||
# override.
|
||||
sub show_told_word($self, $pj, $word) {
|
||||
my $team = $pj->team;
|
||||
$team->append_log_line(
|
||||
[
|
||||
{
|
||||
text => $pj,
|
||||
color => 'green',
|
||||
},
|
||||
{
|
||||
text => ' dijo "',
|
||||
|
||||
},
|
||||
{
|
||||
text => $word,
|
||||
color => 'purple',
|
||||
},
|
||||
{
|
||||
text => '" a ',
|
||||
},
|
||||
{
|
||||
text => $self->name($pj),
|
||||
color => $self->color($pj),
|
||||
},
|
||||
{
|
||||
text => '.',
|
||||
},
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
## OVERRIDE
|
||||
# Override this if you want a special text
|
||||
# on the dialog start.
|
||||
# This is useful when the pj is talking
|
||||
# with a not talk capable life form.
|
||||
# For example a for a dog this function
|
||||
# could be.
|
||||
# sub show_wordlessly_talk_started($self, $pj) {
|
||||
# my $team = $pj->team;
|
||||
# $team->append_log_line(
|
||||
# [
|
||||
# {
|
||||
# text => $self->name($pj),
|
||||
# color => $self->color($pj),
|
||||
# },
|
||||
# {
|
||||
# text => ' ladra a ',
|
||||
#
|
||||
# },
|
||||
# {
|
||||
# text => $pj,
|
||||
# color => 'green',
|
||||
# },
|
||||
# {
|
||||
# text => '.',
|
||||
# },
|
||||
# ]
|
||||
# );
|
||||
# }
|
||||
sub show_wordlessly_talk_started($self, $pj) {
|
||||
my $team = $pj->team;
|
||||
$team->append_log_line(
|
||||
[
|
||||
{
|
||||
text => $pj,
|
||||
color => 'green',
|
||||
},
|
||||
{
|
||||
text => ' habló con ',
|
||||
|
||||
},
|
||||
{
|
||||
text => $self->name($pj),
|
||||
color => $self->color($pj),
|
||||
},
|
||||
{
|
||||
text => '.',
|
||||
},
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
## OVERRIDE (Always use $self->SUPER::talk.)
|
||||
# You should override with whatever is going to be said
|
||||
# by the npc using send_response_dialog($self,$pj,$array_text)
|
||||
# and if you want with what happens on talk with
|
||||
# the npc that is not a dialog with the common
|
||||
# append_log_line, is polite to send all
|
||||
# the team members the contents of
|
||||
# the conversation so they get context about
|
||||
# what their partners need to do.
|
||||
sub talk ( $self, $pj, $word ) {
|
||||
$pj = $pj->get_from_storage;
|
||||
my $team = $pj->team;
|
||||
if ( defined $word ) {
|
||||
$self->show_told_word($pj, $word);
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
## OVERRIDE
|
||||
sub verb($self, $pj) {
|
||||
return 'dice';
|
||||
}
|
||||
|
||||
## DO NOT EXTEND NOT SUPPORTED.
|
||||
sub send_response_dialog ( $self, $pj, $array_text ) {
|
||||
$pj = $pj->get_from_storage;
|
||||
my $team = $pj->team;
|
||||
if ( !ref $array_text eq 'ARRAY' ) {
|
||||
die '$array_text should be an array.';
|
||||
}
|
||||
$team->append_log_line(
|
||||
[
|
||||
{ text => $self->name($pj), color => $self->color($pj) },
|
||||
{ text => " @{[$self->verb($pj)]}.- " }, @$array_text
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
## DO NOT EXTEND NOT SUPPORTED.
|
||||
{
|
||||
my %hash;
|
||||
sub instance($class) {
|
||||
if (!exists $hash{$class}) {
|
||||
$hash{$class} = $class->new;
|
||||
}
|
||||
return $hash{$class};
|
||||
}
|
||||
}
|
||||
1;
|
0
lib/LasTres/TalkingNPC/.exists
Normal file
0
lib/LasTres/TalkingNPC/.exists
Normal file
47
lib/LasTres/TalkingNPC/AncianoTribuLima.pm
Normal file
47
lib/LasTres/TalkingNPC/AncianoTribuLima.pm
Normal file
@ -0,0 +1,47 @@
|
||||
package LasTres::TalkingNPC::AncianoTribuLima;
|
||||
|
||||
use v5.36.0;
|
||||
use strict;
|
||||
use warnings;
|
||||
use utf8;
|
||||
|
||||
use feature 'signatures';
|
||||
|
||||
use Moo;
|
||||
|
||||
with 'LasTres::TalkingNPC';
|
||||
|
||||
sub talk ( $self, $pj, $word ) {
|
||||
if ( !defined $word ) {
|
||||
$self->wordlessly_talk($pj);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
sub identifier {
|
||||
return 'anciano_tribu_de_la_lima';
|
||||
}
|
||||
|
||||
sub name {
|
||||
return 'Anciano';
|
||||
}
|
||||
|
||||
sub wordlessly_talk ( $self, $pj ) {
|
||||
$self->send_response_dialog(
|
||||
[
|
||||
{
|
||||
text => (
|
||||
'¿De verdad estabas dormido?'
|
||||
. ' Una lastima que no hayas visto ese gran pájaro que acaba de pasar'
|
||||
. ' justo ahora. En cualquier caso, no deberías estar vagueando, ¿Hoy'
|
||||
. ' no era el día que te marchabas a la Torre? Si se hace de noche'
|
||||
. ' será demasiado peligroso y tendrás que salir mañana. Ve a hablar'
|
||||
. ' ahora mismo con la Devota, sin su bendición nadie emprende el viaje a la Torre.'
|
||||
. ' ¿No sabes donde puede estar la Devota? No tiene perdida, es la única casa hecha de piedra.'
|
||||
. ' Si no la encuentras siempre puedes preguntar a la gente de la tribu.'
|
||||
)
|
||||
}
|
||||
]
|
||||
);
|
||||
}
|
||||
1;
|
37
lib/LasTres/TalkingNPCs.pm
Normal file
37
lib/LasTres/TalkingNPCs.pm
Normal file
@ -0,0 +1,37 @@
|
||||
package LasTres::TalkingNPCs;
|
||||
|
||||
use v5.36.0;
|
||||
use strict;
|
||||
use warnings;
|
||||
use utf8;
|
||||
|
||||
use feature 'signatures';
|
||||
|
||||
use Moo;
|
||||
use Scalar::Util;
|
||||
use Module::Pluggable
|
||||
search_path => ['LasTres::Word'],
|
||||
instantiate => 'instance',
|
||||
on_require_error => sub ( $plugin, $error ) {
|
||||
die $error;
|
||||
};
|
||||
|
||||
has hash => (
|
||||
is => 'rw',
|
||||
lazy => 1,
|
||||
builder => \&_build_hash,
|
||||
);
|
||||
|
||||
sub _build_hash ($self) {
|
||||
my @talking_npcs = $self->plugins();
|
||||
my %hash;
|
||||
for my $talking_npc (@talking_npcs) {
|
||||
my $class = Scalar::Util::blessed($talking_npc);
|
||||
if ( !$talking_npc->does('LasTres::TalkingNPC') ) {
|
||||
die "$class must implement LasTres::TalkingNPC.";
|
||||
}
|
||||
$hash{ $talking_npc->identifier } = $talking_npc;
|
||||
}
|
||||
return \%hash;
|
||||
}
|
||||
1;
|
20
lib/LasTres/Word.pm
Normal file
20
lib/LasTres/Word.pm
Normal file
@ -0,0 +1,20 @@
|
||||
package LasTres::Word;
|
||||
|
||||
use v5.36.0;
|
||||
use strict;
|
||||
use warnings;
|
||||
use utf8;
|
||||
|
||||
use feature 'signatures';
|
||||
|
||||
use Moo::Role;
|
||||
|
||||
requires qw/name identifier/;
|
||||
## IMPLEMENTORS MUST IMPLEMENT
|
||||
# sub name($self,$pj);
|
||||
# sub identifier;
|
||||
#
|
||||
# Identifier must be unique across words, failure
|
||||
# to do so can result in a error or undefined
|
||||
# behavior.
|
||||
1;
|
0
lib/LasTres/Word/.exists
Normal file
0
lib/LasTres/Word/.exists
Normal file
32
lib/LasTres/Words.pm
Normal file
32
lib/LasTres/Words.pm
Normal file
@ -0,0 +1,32 @@
|
||||
package LasTres::Words;
|
||||
|
||||
use v5.36.0;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use feature 'signatures';
|
||||
|
||||
use Moo;
|
||||
|
||||
use Module::Pluggable search_path => ['LasTres::Word'],
|
||||
instantiate => 'instance',
|
||||
on_require_error => sub ($plugin, $error) {
|
||||
die $error;
|
||||
};
|
||||
|
||||
has hash => (
|
||||
is => 'rw',
|
||||
lazy => 1,
|
||||
builder => \&_build_hash,
|
||||
);
|
||||
|
||||
sub _build_hash($self) {
|
||||
my @words = $self->plugins();
|
||||
my %hash;
|
||||
for my $word (@words) {
|
||||
$hash{$word->identifier} = $word;
|
||||
}
|
||||
return \%hash;
|
||||
}
|
||||
1;
|
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue
Block a user