ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/maps/perl/cfplus.ext
Revision: 1.4
Committed: Mon Jun 19 10:19:51 2006 UTC (17 years, 11 months ago) by root
Branch: MAIN
Changes since 1.3: +2 -66 lines
Log Message:
unbundled npc_dialogue module for use in other scripts

File Contents

# User Rev Content
1 root 1.1 #! perl
2    
3     # additional support for cfplus client
4    
5 root 1.4 use NPC_Dialogue;
6    
7 root 1.1 cf::register_extcmd cfplus_support => sub {
8     my ($pl, $data) = @_;
9    
10     my ($token, $client_version) = split / /, $data, 2;
11    
12     $pl->send ("ext $token 1");
13     };
14    
15 root 1.3 my %dialog; # currently active dialogs
16    
17     sub dialog_tell {
18     my ($token, $dialog, $msg) = @_;
19    
20     my $pl = $dialog->{ob}->contr;
21     my ($reply, @kw) = $dialog->tell ($msg);
22     $reply = "..." unless $reply;
23     $pl->send ("ext $token msg " . join "\x00", $reply, @kw);
24 root 1.1 }
25    
26     # return "interesting" information about the given tile
27     # currently only returns the npc_dialog title when a dialog is possible
28     cf::register_extcmd lookat => sub {
29     my ($pl, $data) = @_;
30    
31     my ($token, $dx, $dy) = split / /, $data;
32 root 1.3 my $near = (abs $dx) <= 2 && (abs $dy) <= 2;
33 root 1.1
34     my %res;
35    
36     if ($pl->cell_visible ($dx, $dy)) {
37     for my $ob ($pl->ob->map->at ($pl->ob->x + $dx, $pl->ob->y + $dy)) {
38     $res{npc_dialog} = $ob->name
39 root 1.3 if $near && NPC_Dialogue::has_dialogue $ob;
40 root 1.1 }
41     }
42    
43     $pl->send ("ext $token " . join "\x00", %res);
44     };
45    
46     cf::register_extcmd npc_dialog_begin => sub {
47     my ($pl, $data) = @_;
48    
49     my ($token, $dx, $dy) = split / /, $data;
50    
51 root 1.2 return unless (abs $dx) <= 2 && (abs $dy) <= 2;
52 root 1.1 return unless $pl->cell_visible ($dx, $dy);
53    
54     for my $npc ($pl->ob->map->at ($pl->ob->x + $dx, $pl->ob->y + $dy)) {
55 root 1.3 if (NPC_Dialogue::has_dialogue $npc) {
56     $dialog{$token} = new NPC_Dialogue ob => $pl->ob, npc => $npc;
57     dialog_tell $token, $dialog{$token}, "hi";
58 root 1.1 return;
59     }
60     }
61    
62     $pl->send ("ext $token error");
63     };
64    
65     cf::register_extcmd npc_dialog_tell => sub {
66     my ($pl, $data) = @_;
67    
68     my ($token, $msg) = split / /, $data, 2;
69    
70 root 1.3 dialog_tell $token, $dialog{$token}, $msg
71 root 1.1 if $dialog{$token};
72     };
73    
74     cf::register_extcmd npc_dialog_end => sub {
75     my ($pl, $token) = @_;
76    
77     delete $dialog{$token};
78     };
79    
80 root 1.3 sub on_logout {
81     my ($pl, $host) = @_;
82    
83     delete $dialog{$_} for grep $pl->ob == $dialog{$_}{ob}, keys %dialog;
84    
85     0
86     }
87    
88 root 1.2 sub on_clock {
89     return 0 unless %dialog;
90    
91     while (my ($token, $dialog) = each %dialog) {
92 root 1.3 my (undef, $dx, $dy) = $dialog->{ob}->rangevector ($dialog->{npc});
93     next if (abs $dx) <= 2 && (abs $dy) <= 2;
94 root 1.2
95 root 1.3 $dialog->{ob}->contr->send ("ext $token out_of_range");
96 root 1.2 delete $dialog{$token};
97     }
98    
99     0
100     }
101