ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/maps/perl/cfplus.ext
(Generate patch)

Comparing deliantra/maps/perl/cfplus.ext (file contents):
Revision 1.3 by root, Mon Jun 19 10:15:10 2006 UTC vs.
Revision 1.4 by root, Mon Jun 19 10:19:51 2006 UTC

1#! perl 1#! perl
2 2
3# additional support for cfplus client 3# additional support for cfplus client
4
5use NPC_Dialogue;
4 6
5cf::register_extcmd cfplus_support => sub { 7cf::register_extcmd cfplus_support => sub {
6 my ($pl, $data) = @_; 8 my ($pl, $data) = @_;
7 9
8 my ($token, $client_version) = split / /, $data, 2; 10 my ($token, $client_version) = split / /, $data, 2;
9 11
10 $pl->send ("ext $token 1"); 12 $pl->send ("ext $token 1");
11}; 13};
12
13{
14 package NPC_Dialogue;
15
16 sub has_dialogue {
17 my ($ob) = @_;
18
19 $ob->get_message =~ /^\@match /;
20 }
21
22 sub parse_message($) {
23 map [split /\n/, $_, 2],
24 grep length,
25 split /^\@match /m,
26 $_[0]
27 }
28
29 sub new {
30 my ($class, %arg) = @_;
31
32 my $self = bless {
33 %arg,
34 }, $class;
35
36 $self->{match} ||= [parse_message $self->{npc}->get_message];
37
38 $self;
39 }
40
41 sub greet {
42 my ($self) = @_;
43
44 $self->tell ("hi")
45 }
46
47 sub tell {
48 my ($self, $msg) = @_;
49
50 for my $match (@{ $self->{match} }) {
51 for (split /\|/, $match->[0]) {
52 if ($_ eq "*" || 0 <= index $msg, $_) {
53 my $reply = $match->[1];
54
55 # combine lines into paragraphs
56 $reply =~ s/(?<=\S)\n(?=\w)/ /g;
57 $reply =~ s/\n\n/\n/g;
58
59 my @kw;
60 # now mark up all matching keywords
61 for my $match (@{ $self->{match} }) {
62 for (sort { (length $b) <=> (length $a) } split /\|/, $match->[0]) {
63 if ($reply =~ /\b\Q$_\E\b/i) {
64 push @kw, $_;
65 last;
66 }
67 }
68 }
69
70 return wantarray ? ($reply, @kw) : $reply;
71 }
72 }
73 }
74 }
75
76 ()
77}
78 14
79my %dialog; # currently active dialogs 15my %dialog; # currently active dialogs
80 16
81sub dialog_tell { 17sub dialog_tell {
82 my ($token, $dialog, $msg) = @_; 18 my ($token, $dialog, $msg) = @_;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines