Primitive conversations now working.
This commit is contained in:
parent
cbecf68f9f
commit
b5534788d1
|
@ -4,6 +4,7 @@ import type { Action, ActionHash } from '@lastres/action'
|
|||
import type { TalkNPCs, TalkNPC } from '@lastres/talk-npc'
|
||||
|
||||
import OutputPacketExecuteAction from '@lastres/output-packet/execute_action'
|
||||
import OutputPacketTalk from '@lastres/output-packet/talk';
|
||||
|
||||
import PresentationItem from '@lastres/components/presentation-item'
|
||||
import Presentation from '@lastres/components/presentation'
|
||||
|
@ -81,6 +82,13 @@ export default function BottomPanel (props: BottomPanelProps): JSX.Element {
|
|||
<img src={npc.icon}/><div className="shadow"/>
|
||||
</div>
|
||||
}
|
||||
|
||||
function onWordlesslyTalk (npc: TalkNPC): void {
|
||||
if (props.websocket === null) {
|
||||
return
|
||||
}
|
||||
new OutputPacketTalk(npc.identifier).send(props.websocket)
|
||||
}
|
||||
function printTalkNpcs (): JSX.Element {
|
||||
const npcs = props.talkNPCs
|
||||
if (npcs === null) {
|
||||
|
@ -102,8 +110,10 @@ export default function BottomPanel (props: BottomPanelProps): JSX.Element {
|
|||
</div>
|
||||
</div>
|
||||
<div className="buttons">
|
||||
<button>Hablar.</button>
|
||||
<button>Decir palabra.</button>
|
||||
<button onClick={() => {
|
||||
onWordlesslyTalk(npc)
|
||||
}}>Hablar</button>
|
||||
<button>Decir palabra</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -76,7 +76,7 @@ export default function Game (props: GameProps): JSX.Element {
|
|||
return
|
||||
}
|
||||
window.clearInterval(interval)
|
||||
}, 100000)
|
||||
}, 50000)
|
||||
}
|
||||
const inputPackets = new InputPackets(setTeamPJs,
|
||||
setEnemyTeamPJs, setIsBattling,
|
||||
|
|
|
@ -0,0 +1,30 @@
|
|||
import OutputPacket from '@lastres/output-packet'
|
||||
|
||||
export interface OutputPacketTalkData {
|
||||
npc: string
|
||||
word?: string
|
||||
}
|
||||
|
||||
export default class OutputPacketTalk extends OutputPacket {
|
||||
npc: string
|
||||
word: string | null
|
||||
constructor (npc: string, word: string | null = null) {
|
||||
super()
|
||||
this.npc = npc
|
||||
this.word = word
|
||||
}
|
||||
|
||||
command (): string {
|
||||
return 'talk'
|
||||
}
|
||||
|
||||
data (): OutputPacketTalkData {
|
||||
const output: OutputPacketTalkData = {
|
||||
npc: this.npc
|
||||
}
|
||||
if (this.word !== null) {
|
||||
output.word = this.word
|
||||
}
|
||||
return output
|
||||
}
|
||||
}
|
|
@ -0,0 +1,6 @@
|
|||
export type TalkNPCs = Record<string, TalkNPC>
|
||||
export interface TalkNPC {
|
||||
icon?: string
|
||||
name: string
|
||||
identifier: string
|
||||
}
|
|
@ -15,10 +15,23 @@ requires(
|
|||
'uuid', 'race_string', 'nick', 'born_stats',
|
||||
'health', 'mana', 'training_stats', 'experience',
|
||||
'combat_action', 'combat_target', 'team',
|
||||
'gain_experience', 'update_team_sprites', 'get_from_storage',
|
||||
'gain_experience', 'get_from_storage',
|
||||
);
|
||||
|
||||
## OVERRIDE
|
||||
sub update_location {
|
||||
}
|
||||
|
||||
## OVERRIDE
|
||||
sub update_actions {
|
||||
}
|
||||
|
||||
## OVERRIDE
|
||||
sub append_log_line {
|
||||
}
|
||||
|
||||
## OVERRIDE
|
||||
sub update_team_sprites {
|
||||
}
|
||||
|
||||
sub race ($self) {
|
||||
|
|
|
@ -0,0 +1,63 @@
|
|||
package LasTres::Controller::Websocket::InputPacket::Talk;
|
||||
|
||||
use v5.36.0;
|
||||
use strict;
|
||||
use warnings;
|
||||
use utf8;
|
||||
|
||||
use Moo;
|
||||
use List::AllUtils;
|
||||
|
||||
use JSON qw/to_json/;
|
||||
|
||||
sub identifier {
|
||||
return 'talk';
|
||||
}
|
||||
|
||||
sub handle ( $self, $ws, $session, $data ) {
|
||||
if ( ref $data ne 'HASH' ) {
|
||||
return $ws->send( to_json( { error => "Data should be a hashref." } ) );
|
||||
}
|
||||
if ( !defined $session->{pj} ) {
|
||||
return $ws->send(
|
||||
to_json( { error => 'The pj for this session does not exist.' } ) );
|
||||
}
|
||||
$session->{pj} = $session->{pj}->get_from_storage;
|
||||
my $pj = $session->{pj};
|
||||
my $npc_identifier = $data->{npc};
|
||||
if ( !defined $npc_identifier ) {
|
||||
return $ws->send(
|
||||
to_json( { error => 'You did not send a npc to talk with.' } ) );
|
||||
}
|
||||
my $available_npcs = $pj->talk_npcs;
|
||||
my $npc = $available_npcs->{$npc_identifier};
|
||||
if ( !defined $npc ) {
|
||||
return $ws->send(
|
||||
to_json(
|
||||
{ error => 'The npc you sent is not available to talk with.' }
|
||||
)
|
||||
);
|
||||
}
|
||||
my $possible_word_identifier = $data->{word};
|
||||
if ( !defined $possible_word_identifier ) {
|
||||
$self->handle_wordlessly_talk( $ws, $pj, $npc );
|
||||
return;
|
||||
}
|
||||
return $ws->send(
|
||||
to_json( { error => 'Sending a word still not supported.' } ) );
|
||||
}
|
||||
|
||||
sub handle_wordlessly_talk ( $self, $ws, $pj, $npc ) {
|
||||
$npc->talk( $pj, undef );
|
||||
$self->end_conversation($pj);
|
||||
}
|
||||
|
||||
sub end_conversation ( $self, $pj ) {
|
||||
my $team = $pj->team;
|
||||
for my $member ( $team->combat_members->@* ) {
|
||||
$pj->update_location;
|
||||
$pj->update_actions;
|
||||
$pj->update_team_sprites;
|
||||
}
|
||||
}
|
||||
1;
|
|
@ -160,7 +160,7 @@ sub teach_word ( $self, $word ) {
|
|||
}
|
||||
my $known_word = $result_set_words->new(
|
||||
{ identifier => $word->identifier, owner => $self->uuid } );
|
||||
$known_word->insert;
|
||||
$known_word->insert_or_update;
|
||||
my $team = $self->team;
|
||||
$team->append_log_line([
|
||||
{
|
||||
|
@ -205,18 +205,19 @@ sub knows_location ( $self, $location ) {
|
|||
sub set_known_location ( $self, $location ) {
|
||||
require LasTres::Schema;
|
||||
my $array = $location->to_array;
|
||||
my ( $planet, $super_area, $area ) = @$array[ 0 .. 2 ];
|
||||
$location = $array->[3];
|
||||
my ( $planet, $super_area, $area, $location_id ) = @$array[ 0 .. 3 ];
|
||||
my $schema = LasTres::Schema->Schema;
|
||||
$schema->resultset('PJKnownPlaces')->new(
|
||||
{
|
||||
owner => $self->uuid,
|
||||
planet => $planet,
|
||||
super_area => $super_area,
|
||||
area => $area,
|
||||
location => $location
|
||||
}
|
||||
)->insert;
|
||||
if (!$self->knows_location($location)) {
|
||||
$schema->resultset('PJKnownPlaces')->new(
|
||||
{
|
||||
owner => $self->uuid,
|
||||
planet => $planet,
|
||||
super_area => $super_area,
|
||||
area => $area,
|
||||
location => $location_id
|
||||
}
|
||||
)->insert;
|
||||
}
|
||||
}
|
||||
|
||||
sub hash ($self) {
|
||||
|
@ -559,9 +560,11 @@ sub talk_npcs ($self) {
|
|||
my $team = $self->team;
|
||||
my $location = $team->location;
|
||||
if ( defined $team->battle ) {
|
||||
return $self->_npc_list_to_hash( \@npcs );
|
||||
return {};
|
||||
}
|
||||
if ( $team->is_moving ) {
|
||||
# There will be random encounters for
|
||||
# some movement frames in certain areas.
|
||||
return $self->_npc_list_to_hash( \@npcs );
|
||||
}
|
||||
my $location_npcs = $location->npcs($self);
|
||||
|
|
|
@ -136,7 +136,7 @@ sub show_wordlessly_talk_started ( $self, $pj ) {
|
|||
## 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
|
||||
# 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
|
||||
|
|
|
@ -10,10 +10,12 @@ use feature 'signatures';
|
|||
use Moo;
|
||||
|
||||
use LasTres::Flags;
|
||||
use LasTres::Word::Devota;
|
||||
|
||||
with 'LasTres::TalkingNPC';
|
||||
use parent 'LasTres::TalkingNPC';
|
||||
|
||||
sub talk ( $self, $pj, $word ) {
|
||||
$self->SUPER::talk( $pj, $word );
|
||||
if ( !defined $word ) {
|
||||
$self->wordlessly_talk($pj);
|
||||
return;
|
||||
|
@ -32,16 +34,27 @@ sub name {
|
|||
return 'Anciano';
|
||||
}
|
||||
|
||||
sub verb ( $self, $pj ) {
|
||||
if ( $pj->knows_word( LasTres::Word::Devota->instance ) ) {
|
||||
return 'indica';
|
||||
}
|
||||
return 'farfulla';
|
||||
}
|
||||
|
||||
sub wordlessly_talk ( $self, $pj ) {
|
||||
if ($pj->get_flag(LasTres::Flags::TALKED_WITH_OLD_MAN_AND_LEARNED_TO_SAY_DEVOTA)) {
|
||||
$self->send_response_dialog([
|
||||
{
|
||||
text => '¿A que esperas, ve a hablar con la Devota?'
|
||||
}
|
||||
]);
|
||||
if ( $pj->knows_word( LasTres::Word::Devota->instance ) ) {
|
||||
$self->send_response_dialog(
|
||||
$pj,
|
||||
[
|
||||
{
|
||||
text => '¿A que esperas? Ve a hablar con la Devota.'
|
||||
}
|
||||
]
|
||||
);
|
||||
return;
|
||||
}
|
||||
$self->send_response_dialog(
|
||||
$pj,
|
||||
[
|
||||
{
|
||||
text => (
|
||||
|
@ -57,6 +70,6 @@ sub wordlessly_talk ( $self, $pj ) {
|
|||
}
|
||||
]
|
||||
);
|
||||
$pj->set_flag(LasTres::Flags::TALKED_WITH_OLD_MAN_AND_LEARNED_TO_SAY_DEVOTA);
|
||||
$pj->teach_word( LasTres::Word::Devota->instance );
|
||||
}
|
||||
1;
|
||||
|
|
|
@ -7,6 +7,10 @@ use utf8;
|
|||
|
||||
use feature 'signatures';
|
||||
|
||||
use Moo;
|
||||
|
||||
with 'LasTres::Word';
|
||||
|
||||
sub name {
|
||||
return 'Devota';
|
||||
}
|
||||
|
@ -14,3 +18,4 @@ sub name {
|
|||
sub identifier {
|
||||
return 'devota';
|
||||
}
|
||||
1;
|
||||
|
|
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue