--- deliantra/maps/perl/cfplus.ext 2006/06/19 10:15:10 1.3 +++ deliantra/maps/perl/cfplus.ext 2006/06/19 10:19:51 1.4 @@ -2,6 +2,8 @@ # additional support for cfplus client +use NPC_Dialogue; + cf::register_extcmd cfplus_support => sub { my ($pl, $data) = @_; @@ -10,72 +12,6 @@ $pl->send ("ext $token 1"); }; -{ - package NPC_Dialogue; - - sub has_dialogue { - my ($ob) = @_; - - $ob->get_message =~ /^\@match /; - } - - sub parse_message($) { - map [split /\n/, $_, 2], - grep length, - split /^\@match /m, - $_[0] - } - - sub new { - my ($class, %arg) = @_; - - my $self = bless { - %arg, - }, $class; - - $self->{match} ||= [parse_message $self->{npc}->get_message]; - - $self; - } - - sub greet { - my ($self) = @_; - - $self->tell ("hi") - } - - sub tell { - my ($self, $msg) = @_; - - for my $match (@{ $self->{match} }) { - for (split /\|/, $match->[0]) { - if ($_ eq "*" || 0 <= index $msg, $_) { - my $reply = $match->[1]; - - # combine lines into paragraphs - $reply =~ s/(?<=\S)\n(?=\w)/ /g; - $reply =~ s/\n\n/\n/g; - - my @kw; - # now mark up all matching keywords - for my $match (@{ $self->{match} }) { - for (sort { (length $b) <=> (length $a) } split /\|/, $match->[0]) { - if ($reply =~ /\b\Q$_\E\b/i) { - push @kw, $_; - last; - } - } - } - - return wantarray ? ($reply, @kw) : $reply; - } - } - } - } - - () -} - my %dialog; # currently active dialogs sub dialog_tell {