ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/maps/perl/chat.ext
Revision: 1.21
Committed: Wed Jul 19 22:20:07 2006 UTC (17 years, 10 months ago) by root
Branch: MAIN
Changes since 1.20: +11 -17 lines
Log Message:
make perl say the default say, convert bank script to new dialogue system

File Contents

# User Rev Content
1 pippijn 1.1 #! perl
2 root 1.5
3 pippijn 1.15 # implement a replacement for the built-in say/chat/shout/tell/reply commands
4 root 1.5 # adds ignore/unignore functionality
5    
6 root 1.20 use NPC_Dialogue;
7    
8 root 1.12 sub clean_timeouts($) {
9 root 1.8 my ($player) = @_;
10     my $NOW = time;
11    
12     for my $hash (@$player{qw(ext_ignore_shout ext_ignore_tell)}) {
13 root 1.12 while (my ($k, $v) = each %$hash) {
14     if ($v < $NOW) {
15 root 1.20 $player->message ("Your ignore on $k has expired.", cf::NDI_GREEN | cf::NDI_UNIQUE);
16 root 1.12 delete $hash->{$k};
17     } elsif (!valid_user $k) {
18 root 1.20 $player->message ("Your ignore on $k is no longer valid (no such user).", cf::NDI_GREEN | cf::NDI_UNIQUE);
19 root 1.12 delete $hash->{$k};
20     }
21     }
22 root 1.8 }
23     }
24    
25     sub on_logout {
26     my ($pl, $host) = @_;
27    
28     clean_timeouts $pl->ob;
29     }
30    
31 pippijn 1.15 cf::register_command listen => 0, sub {
32     my ($who, $msg) = @_;
33     my $player = cf::player::find $who->name;
34    
35 pippijn 1.17 if ($msg ne "") {
36 pippijn 1.15 my $prev_listen = $player->listening;
37     $player->listening ($msg);
38     if ($prev_listen == $player->listening) {
39 root 1.20 $who->message ("Your verbose level stayed $prev_listen.", cf::NDI_UNIQUE);
40 pippijn 1.15 } else {
41 root 1.20 $who->message ("Your verbose level is now " . $player->listening . ". (previously: $prev_listen)", cf::NDI_UNIQUE);
42 pippijn 1.15 }
43     } else {
44 root 1.20 $who->message ("Your verbose level is " . $player->listening . ".", cf::NDI_UNIQUE);
45 pippijn 1.15 }
46     };
47    
48 root 1.21 cf::register_command say => 0, sub {
49 root 1.20 my ($who, $msg) = @_;
50    
51     if ($msg) {
52     my $name = $who->name;
53    
54 root 1.21 $_->ob->message ("$name says: $msg", cf::NDI_GREY | cf::NDI_UNIQUE)
55     for grep $who->on_same_map_as ($_->ob), cf::player::list;
56 root 1.20
57     # npcs, magic_ears etc.
58     # first find all objects and their inventories within a 5x5 square
59     # that have something resembling dialogue
60     my ($map, $x, $y) = ($who->map, $who->x - 2, $who->y - 2);
61    
62     for my $npc (
63     grep NPC_Dialogue::has_dialogue $_,
64     map +($_, $_->inv),
65     grep $_,
66     map $map->at ($x + $_ % 5, $y + (int $_ / 5)),
67     0..24
68     ) {
69     # if some listener teleported us somewhere else, stop right here
70     last unless $map->path == $who->map->path;
71    
72     my $dialog = new NPC_Dialogue ob => $who, npc => $npc;
73     my $reply = $dialog->tell ($msg);
74    
75     if (defined $reply) {
76     if ($npc->type == cf::MAGIC_EAR) {
77 root 1.21 if (length $reply) {
78     $_->ob->message ($reply, cf::NDI_BROWN | cf::NDI_UNIQUE)
79     for grep $who->on_same_map_as ($_->ob), cf::player::list;
80     }
81 root 1.20 $npc->use_trigger;
82     } else {
83 root 1.21 if (length $reply) {
84     $_->ob->message ($npc->name . " says: $reply", cf::NDI_BROWN | cf::NDI_UNIQUE)
85     for grep $who->on_same_map_as ($_->ob), cf::player::list;
86     }
87 root 1.20 }
88     }
89     }
90    
91     } else {
92     $who->message ("What do you want to say?", cf::NDI_UNIQUE);
93     }
94     };
95 pippijn 1.15
96 pippijn 1.6 cf::register_command chat => 0, sub {
97 pippijn 1.1 my ($who, $msg) = @_;
98    
99     if ($msg) {
100     my $name = $who->name;
101 root 1.8 my $NOW = time;
102 pippijn 1.1
103 root 1.19 cf::LOG cf::llevDebug, sprintf "QBERT [%s] %s\n", $name, $msg;
104    
105 root 1.4 $_->ob->message ("$name chats: $msg", cf::NDI_BLUE)
106 pippijn 1.15 for grep { $_->ob->{ext_ignore_shout}{$name} < $NOW && $_->listening >= 10 } cf::player::list;
107 root 1.4
108 pippijn 1.1 } else {
109     $who->message ("Chat what?", cf::NDI_UNIQUE);
110     }
111     };
112    
113 pippijn 1.6 cf::register_command shout => 0, sub {
114 pippijn 1.1 my ($who, $msg) = @_;
115    
116     if ($msg) {
117 root 1.8 my $NOW = time;
118 pippijn 1.1 my $name = $who->name;
119    
120 root 1.19 cf::LOG cf::llevDebug, sprintf "QBERT {%s} %s\n", $name, $msg;
121    
122 root 1.4 $_->ob->message ("$name shouts: $msg", cf::NDI_RED)
123 pippijn 1.15 for grep { $_->ob->{ext_ignore_shout}{$name} < $NOW && $_->listening >= 2 } cf::player::list;
124 root 1.4
125 pippijn 1.1 } else {
126     $who->message ("Shout what?", cf::NDI_UNIQUE);
127     }
128    
129     };
130 root 1.5
131     cf::register_command tell => 0, sub {
132     my ($who, $args) = @_;
133     my ($target, $msg) = split /\s+/, $args, 2;
134    
135     my $name = $who->name;
136    
137 pippijn 1.11 if (my $other = cf::player::find $target) {
138 root 1.12
139 pippijn 1.11 if ($msg) {
140 root 1.12 if ($target eq $name) {
141     $who->message ("You are talking to yourself, you freak!", cf::NDI_UNIQUE);
142     } elsif ($other->ob->{ext_ignore_tell}{$name} >= time) {
143     $who->message ("$target ignores what you say. Give up on it.", cf::NDI_UNIQUE);
144     } else {
145 root 1.19 cf::LOG cf::llevDebug, sprintf "TELL [%s>%s] %s\n", $name, $target, $msg;
146    
147 pippijn 1.9 $who->message ("You tell $target: $msg");
148     $other->ob->message ("$name tells you: $msg");
149     $other->ob->{ext_last_tell} = $name;
150     }
151 root 1.5 } else {
152 pippijn 1.11 $who->message ("What do you want to tell $target?", cf::NDI_UNIQUE);
153 root 1.5 }
154 root 1.12
155 root 1.5 } else {
156 root 1.12 $who->message ("No such player. Your message: $msg", cf::NDI_UNIQUE);
157 root 1.5 }
158     };
159    
160     cf::register_command reply => 0, sub {
161     my ($who, $args) = @_;
162     my $name = $who->name;
163    
164 pippijn 1.11 if (my $other = cf::player::find $who->{ext_last_tell}) {
165     if ($args) {
166 root 1.5
167 pippijn 1.9 $other->ob->{ext_ignore_tell}{$name} >= time
168     or delete $other->ob->{ext_ignore_tell}{$name};
169    
170     if ($other->ob->{ext_ignore_tell}{$name} < time) {
171 root 1.19 cf::LOG cf::llevDebug, sprintf "TELL [%s>%s] %s\n", $name, $other->ob->name, $args;
172    
173 pippijn 1.9 $who->message ("You tell " . $other->ob->name . ": $args");
174     $other->ob->message ("$name tells you: $args");
175     $who->{ext_last_tell} = $other->ob->name;
176     } else {
177     $who->message ($other->ob->name . " ignores what you say. Give up on it.", cf::NDI_UNIQUE);
178     }
179 root 1.5 } else {
180 pippijn 1.11 $who->message ("What do you want to tell ".$other->ob->name."?", cf::NDI_UNIQUE);
181 root 1.5 }
182 pippijn 1.11
183 root 1.5 } else {
184 pippijn 1.11 $who->message ("Can't reply, player left. Your message: $args", cf::NDI_UNIQUE);
185 root 1.5 }
186     };
187    
188     cf::register_command ignore => 0, sub {
189     my ($who, $args) = @_;
190     my ($target, $type, $timeout) = split /\s+/, $args;
191    
192     if ($args eq "list") {
193 root 1.8 clean_timeouts $who;
194    
195 root 1.5 if ((my @ignored_tell = sort keys %{$who->{ext_ignore_tell}})
196     + (my @ignored_shout = sort keys %{$who->{ext_ignore_shout}})) {
197     $who->message ("Currently ignoring private messages from: ", cf::NDI_UNIQUE);
198     $who->message ((join ", ", @ignored_tell), cf::NDI_UNIQUE);
199     $who->message ("Currently ignoring shouts from: ", cf::NDI_UNIQUE);
200     $who->message ((join ", ", @ignored_shout), cf::NDI_UNIQUE);
201     $who->message ("To stop ignoring one, use unignore.", cf::NDI_UNIQUE);
202     } else {
203     $who->message ("Not ignoring anyone", cf::NDI_UNIQUE);
204     }
205    
206     } elsif ($target && $type) {
207    
208     $timeout ne "" or $timeout = 24;
209     my $absolute_timeout = time + $timeout * 3600;
210    
211 root 1.12 if (valid_user $target) {
212 root 1.5 if ($type eq "tell") {
213 root 1.12 $who->message ("Now ignoring private messages from $target for $timeout hours.", cf::NDI_UNIQUE);
214     $who->{ext_ignore_tell}{$target} = $absolute_timeout;
215 root 1.5 } elsif ($type eq "shout") {
216 root 1.12 $who->message ("Now ignoring shouts from $target for $timeout hours.", cf::NDI_UNIQUE);
217     $who->{ext_ignore_shout}{$target} = $absolute_timeout;
218 root 1.5 } elsif ($type eq "all") {
219 root 1.12 $who->message ("Now ignoring everything from $target for $timeout hours.", cf::NDI_UNIQUE);
220     $who->{ext_ignore_tell}{$target} = $absolute_timeout;
221     $who->{ext_ignore_shout}{$target} = $absolute_timeout;
222 root 1.5 } else {
223     $who->message ("You need to specify tell, shout or all.", cf::NDI_UNIQUE);
224     }
225     } else {
226 root 1.12 $who->message ("No such player: $target", cf::NDI_UNIQUE);
227 root 1.5 }
228    
229     } else {
230 root 1.12 $who->message ("Usage: ignore <player> <tell | shout | all> <timeout>\n"
231     . "will ignore a player for <timeout> hours.\n"
232     . "Usage: ignore list\n"
233     . "will show you a list of players currently ignored.", cf::NDI_UNIQUE);
234 root 1.5 }
235     };
236    
237     cf::register_command unignore => 0, sub {
238     my ($who, $args) = @_;
239     my ($target, $type) = split /\s+/, $args;
240    
241     if ($args eq "") {
242 root 1.12 if ($who->{ext_ignore_tell}) {
243 root 1.5 $who->message ("Currently ignoring private messages from: ", cf::NDI_UNIQUE);
244     $who->message ((join ", ", sort keys %{ $who->{ext_ignore_tell} }), cf::NDI_UNIQUE);
245     $who->message ("Currently ignoring shouts from: ", cf::NDI_UNIQUE);
246     $who->message ((join ", ", sort keys %{ $who->{ext_ignore_shout} }), cf::NDI_UNIQUE);
247     } else {
248     $who->message ("Not ignoring anyone", cf::NDI_UNIQUE);
249     }
250     } else {
251    
252 root 1.12 if (valid_user $target) {
253 root 1.5 if ($type eq "tell") {
254 root 1.12 $who->message ("Not ignoring private messages from $target anymore.", cf::NDI_UNIQUE);
255     delete $who->{ext_ignore_tell} {$target};
256 root 1.5 } elsif ($type eq "shout") {
257 root 1.12 $who->message ("Not ignoring shouts from $target anymore.", cf::NDI_UNIQUE);
258     delete $who->{ext_ignore_shout}{$target};
259 root 1.5 } elsif ($type eq "all") {
260 root 1.12 $who->message ("Not ignoring anything from $target anymore.", cf::NDI_UNIQUE);
261     delete $who->{ext_ignore_tell} {$target};
262     delete $who->{ext_ignore_shout}{$target};
263 root 1.5 } else {
264     $who->message ("You need to specify tell, shout or all.", cf::NDI_UNIQUE);
265     }
266     } else {
267     $who->message ("No such player or ambiguous name: $target", cf::NDI_UNIQUE);
268     }
269    
270     }
271     };
272