1 |
#! perl # depends=irc mandatory |
2 |
|
3 |
# implement a replacement for the built-in say/chat/shout/tell/reply commands |
4 |
# adds ignore/unignore functionality |
5 |
|
6 |
use NPC_Dialogue; |
7 |
use POSIX (); # for strftime only |
8 |
|
9 |
our $SAY_CHANNEL = { |
10 |
id => "say", |
11 |
title => "Map", |
12 |
reply => "say ", |
13 |
tooltip => "Things said to and replied from npcs near you and other players on the same map only.", |
14 |
}; |
15 |
|
16 |
our $CHAT_CHANNEL = { |
17 |
id => "chat", |
18 |
title => "Chat", |
19 |
reply => "chat ", |
20 |
tooltip => "Player chat and shouts, global to the server.", |
21 |
}; |
22 |
|
23 |
sub tell_channel($) { |
24 |
my ($target) = @_; |
25 |
|
26 |
{ |
27 |
id => "tell-$target", |
28 |
title => "$target", |
29 |
reply => "tell $target ", |
30 |
tooltip => "Private messages from/to $target", |
31 |
} |
32 |
} |
33 |
|
34 |
sub clean_timeouts($) { |
35 |
my ($player) = @_; |
36 |
my $NOW = time; |
37 |
|
38 |
for my $hash (@$player{qw(ext_ignore_shout ext_ignore_tell)}) { |
39 |
while (my ($k, $v) = each %$hash) { |
40 |
if ($v < $NOW) { |
41 |
$player->message ("Your ignore on $k has expired.", cf::NDI_GREEN); |
42 |
delete $hash->{$k}; |
43 |
} elsif (!cf::player::exists $k) { |
44 |
$player->message ("Your ignore on $k is no longer valid (no such user).", cf::NDI_GREEN); |
45 |
delete $hash->{$k}; |
46 |
} |
47 |
} |
48 |
} |
49 |
} |
50 |
|
51 |
# send_irc ($format, @args, $msg) |
52 |
# make sure the last argument is the message! |
53 |
sub send_irc { |
54 |
my ($format, @args) = @_; |
55 |
my $msg = pop @args; |
56 |
for (split /\n/, $msg) { |
57 |
ext::irc::do_notice (sprintf $format, @args, $_) |
58 |
} |
59 |
} |
60 |
|
61 |
cf::player->attach ( |
62 |
prio => -1000, |
63 |
on_login => sub { |
64 |
my ($pl) = @_; |
65 |
|
66 |
clean_timeouts $pl->ob; |
67 |
|
68 |
$pl->send_msg ($SAY_CHANNEL); |
69 |
$pl->send_msg ($CHAT_CHANNEL); |
70 |
}, |
71 |
); |
72 |
|
73 |
cf::register_command listen => sub { |
74 |
my ($pl, $msg) = @_; |
75 |
my $player = cf::player::find_active $pl->name; |
76 |
|
77 |
if ($msg ne "") { |
78 |
$msg = 10 if $msg > 10; |
79 |
|
80 |
my $prev_listen = $player->listening; |
81 |
$player->listening ($msg); |
82 |
if ($prev_listen == $player->listening) { |
83 |
$pl->message ("Your verbose level stays at $prev_listen.", cf::NDI_REPLY); |
84 |
} else { |
85 |
$pl->message ("Your verbose level is now " . $player->listening . ". (previously: $prev_listen)", cf::NDI_REPLY); |
86 |
} |
87 |
} else { |
88 |
$pl->message ("Your verbose level is " . $player->listening . ".", cf::NDI_REPLY); |
89 |
} |
90 |
}; |
91 |
|
92 |
cf::register_command cointoss => sub { |
93 |
my ($ob, $msg) = @_; |
94 |
|
95 |
my $pl = $ob->contr; |
96 |
my $name = $ob->name; |
97 |
|
98 |
my $coin = int rand 2 ? "Heads" : "Tails"; |
99 |
|
100 |
$_->send_msg ($SAY_CHANNEL => "$name flips a coin.... $coin!", cf::NDI_GREY) |
101 |
for grep { $ob->on_same_map_as ($_->ob) && $_ != $pl} cf::player::list; |
102 |
|
103 |
$pl->send_msg ($SAY_CHANNEL => "You flip a coin.... $coin!", cf::NDI_GREY | cf::NDI_REPLY); |
104 |
}; |
105 |
|
106 |
cf::register_command orcknuckle => sub { |
107 |
my ($ob, $msg) = @_; |
108 |
|
109 |
my $pl = $ob->contr; |
110 |
my $name = $ob->name; |
111 |
|
112 |
my @orcknuckle = ("beholder", "ghost", "knight", "princess", "dragon", "orc"); |
113 |
my ($i, $j, $k, $l) = (rand 5, rand 5, rand 5, rand 6); |
114 |
my $result = "$orcknuckle[$i], $orcknuckle[$j], $orcknuckle[$k], $orcknuckle[$l]"; |
115 |
|
116 |
$_->send_msg ($SAY_CHANNEL => "$name throws his orc-knuckles and rolls $result!", cf::NDI_GREY) |
117 |
for grep { $ob->on_same_map_as ($_->ob) && $_ != $pl} cf::player::list; |
118 |
|
119 |
$pl->send_msg ($SAY_CHANNEL => "You roll $result!", cf::NDI_GREY | cf::NDI_REPLY); |
120 |
}; |
121 |
|
122 |
my $emotes = { |
123 |
growl => { |
124 |
noparams => { |
125 |
other => "<self> growls.", |
126 |
self => "Grrrrrrrrr....", |
127 |
}, |
128 |
params => { |
129 |
}, |
130 |
self => { |
131 |
}, |
132 |
}, |
133 |
giggle => { |
134 |
noparams => { |
135 |
other => "<self> giggles.", |
136 |
self => "You giggle.", |
137 |
}, |
138 |
params => { |
139 |
}, |
140 |
self => { |
141 |
}, |
142 |
}, |
143 |
shiver => { |
144 |
noparams => { |
145 |
other => "<self> shivers uncomfortably.", |
146 |
self => "Brrrrrrrrr.", |
147 |
}, |
148 |
params => { |
149 |
}, |
150 |
self => { |
151 |
}, |
152 |
}, |
153 |
chuckle => { |
154 |
noparams => { |
155 |
other => "<self> chuckles politely.", |
156 |
self => "You chuckle politely", |
157 |
}, |
158 |
params => { |
159 |
}, |
160 |
self => { |
161 |
}, |
162 |
}, |
163 |
sigh => { |
164 |
noparams => { |
165 |
other => "<self> sighs loudly.", |
166 |
self => "You sigh.", |
167 |
}, |
168 |
params => { |
169 |
}, |
170 |
self => { |
171 |
}, |
172 |
}, |
173 |
scream => { |
174 |
noparams => { |
175 |
other => "<self> screams at the top of his lungs!", |
176 |
self => "ARRRRRRRRRRGH!!!!!", |
177 |
}, |
178 |
params => { |
179 |
}, |
180 |
self => { |
181 |
}, |
182 |
}, |
183 |
puke => { |
184 |
noparams => { |
185 |
other => "<self> pukes.", |
186 |
self => "Bleaaaaaghhhhhhh!", |
187 |
}, |
188 |
params => { |
189 |
target => "<self> pukes on your clothes!", |
190 |
other => "<self> pukes on <other>.", |
191 |
self => "You puke on <other>.", |
192 |
}, |
193 |
self => { |
194 |
other => "<self> pukes on his clothes.", |
195 |
self => "You puke on yourself.", |
196 |
}, |
197 |
}, |
198 |
strut => { |
199 |
noparams => { |
200 |
other => "<self> struts proudly.", |
201 |
self => "Strut your stuff.", |
202 |
}, |
203 |
params => { |
204 |
}, |
205 |
self => { |
206 |
}, |
207 |
}, |
208 |
cringe => { |
209 |
noparams => { |
210 |
other => "<self> cringes in terror!", |
211 |
self => "You cringe in terror.", |
212 |
}, |
213 |
params => { |
214 |
target => "<self> cringes away from <other> in mortal terror.", |
215 |
self => "You cringe away from <other>.", |
216 |
}, |
217 |
self => { |
218 |
}, |
219 |
}, |
220 |
hiccup => { |
221 |
noparams => { |
222 |
other => "<self> hiccups.", |
223 |
self => "*HIC*", |
224 |
}, |
225 |
params => { |
226 |
}, |
227 |
self => { |
228 |
}, |
229 |
}, |
230 |
clap => { |
231 |
noparams => { |
232 |
other => "<self> gives a round of applause.", |
233 |
self => "Clap, clap, clap.", |
234 |
}, |
235 |
params => { |
236 |
}, |
237 |
self => { |
238 |
}, |
239 |
}, |
240 |
kiss => { |
241 |
noparams => { |
242 |
other => "<self> makes a weird facial contortion", |
243 |
self => "All the lonely people..", |
244 |
}, |
245 |
params => { |
246 |
target => "<self> kisses you.", |
247 |
other => "<self> kisses <other>.", |
248 |
self => "You kiss <other>.", |
249 |
}, |
250 |
self => { |
251 |
}, |
252 |
}, |
253 |
wink => { |
254 |
noparams => { |
255 |
other => "<self> winks suggestively.", |
256 |
self => "Have you got something in your eye?", |
257 |
}, |
258 |
params => { |
259 |
target => "<self> winks at you.", |
260 |
other => "<self> winks at <other>.", |
261 |
self => "You wink suggestively at <other>.", |
262 |
}, |
263 |
self => { |
264 |
other => "<self> winks at himself - something strange is going on...", |
265 |
self => "You wink at yourself?? What are you up to?", |
266 |
}, |
267 |
}, |
268 |
pout => { |
269 |
noparams => { |
270 |
other => "<self> pouts.", |
271 |
self => "Aww, don't take it so hard.", |
272 |
}, |
273 |
params => { |
274 |
}, |
275 |
self => { |
276 |
}, |
277 |
}, |
278 |
cackle => { |
279 |
noparams => { |
280 |
other => "<self> throws back his head and cackles with insane glee!", |
281 |
self => "You cackle gleefully.", |
282 |
}, |
283 |
params => { |
284 |
}, |
285 |
self => { |
286 |
}, |
287 |
}, |
288 |
sniff => { |
289 |
noparams => { |
290 |
other => "<self> sniffs sadly.", |
291 |
self => "You sniff sadly. *SNIFF*", |
292 |
}, |
293 |
params => { |
294 |
target => "<self> sniffs you.", |
295 |
other => "<self> sniffs <other>", |
296 |
self => "You sniff <other>.", |
297 |
}, |
298 |
self => { |
299 |
other => "<self> sniffs himself.", |
300 |
self => "You sniff yourself.", |
301 |
}, |
302 |
}, |
303 |
nod => { |
304 |
noparams => { |
305 |
other => "<self> nods solemnly.", |
306 |
self => "You nod solemnly.", |
307 |
}, |
308 |
params => { |
309 |
target => "<self> nods solemnly to you.", |
310 |
other => "<self> nods solemnly to <other>.", |
311 |
self => "You nod solemnly to <other>.", |
312 |
}, |
313 |
self => { |
314 |
}, |
315 |
}, |
316 |
frown => { |
317 |
noparams => { |
318 |
other => "<self> frowns.", |
319 |
self => "What's bothering you?", |
320 |
}, |
321 |
params => { |
322 |
target => "<self> frowns darkly at you.", |
323 |
other => "<self> frowns darkly at <other>.", |
324 |
self => "You frown darkly at <other>.", |
325 |
}, |
326 |
self => { |
327 |
other => "<self> frowns at himself.", |
328 |
self => "You frown at yourself.", |
329 |
}, |
330 |
}, |
331 |
snicker => { |
332 |
noparams => { |
333 |
other => "<self> snickers softly.", |
334 |
self => "You snicker softly.", |
335 |
}, |
336 |
params => { |
337 |
}, |
338 |
self => { |
339 |
}, |
340 |
}, |
341 |
shrug => { |
342 |
noparams => { |
343 |
other => "<self> shrugs helplessly.", |
344 |
self => "You shrug.", |
345 |
}, |
346 |
params => { |
347 |
target => "<self> shrugs at you.", |
348 |
other => "<self> shrugs at <other>.", |
349 |
self => "You shrug at <other>.", |
350 |
}, |
351 |
self => { |
352 |
}, |
353 |
}, |
354 |
bleed => { |
355 |
noparams => { |
356 |
other => "<self> is bleeding all over the carpet - got a spare tourniquet?", |
357 |
self => "You bleed all over your nice new armour.", |
358 |
}, |
359 |
params => { |
360 |
target => "<self> slashes his wrist and bleeds all over you.", |
361 |
other => "<self> slashes his wrist and bleeds all over <other>.", |
362 |
self => "You slash your wrist and bleed all over <other>", |
363 |
}, |
364 |
self => { |
365 |
other => "<self> performs some satanic ritual while wiping his blood on himself.", |
366 |
self => "Very impressive! You wipe your blood all over yourself.", |
367 |
}, |
368 |
}, |
369 |
twiddle => { |
370 |
noparams => { |
371 |
other => "<self> patiently twiddles his thumbs.", |
372 |
self => "You patiently twiddle your thumbs.", |
373 |
}, |
374 |
params => { |
375 |
}, |
376 |
self => { |
377 |
}, |
378 |
}, |
379 |
spit => { |
380 |
noparams => { |
381 |
other => "<self> spits over his left shoulder.", |
382 |
self => "You spit over your left shoulder.", |
383 |
}, |
384 |
params => { |
385 |
target => "<self> spits in your face!", |
386 |
other => "<self> spits in <other>'s face.", |
387 |
self => "You spit on <other>.", |
388 |
}, |
389 |
self => { |
390 |
other => "<self> drools all over himself.", |
391 |
self => "You drool all over yourself.", |
392 |
}, |
393 |
}, |
394 |
glare => { |
395 |
noparams => { |
396 |
other => "<self> glares around him.", |
397 |
self => "You glare at nothing in particular.", |
398 |
}, |
399 |
params => { |
400 |
target => "<self> glares icily at you, you feel cold to your bones.", |
401 |
other => "<self> glares at <other>.", |
402 |
self => "You glare icily at <other>.", |
403 |
}, |
404 |
self => { |
405 |
other => "<self> glares at his feet, what is bothering him?", |
406 |
self => "You glare icily at your feet, they are suddenly very cold.", |
407 |
}, |
408 |
}, |
409 |
bow => { |
410 |
noparams => { |
411 |
other => "<self> bows deeply.", |
412 |
self => "You bow deeply.", |
413 |
}, |
414 |
params => { |
415 |
target => "<self> bows before you.", |
416 |
other => "<self> bows before <other>.", |
417 |
self => "You bow before <other>.", |
418 |
}, |
419 |
self => { |
420 |
other => "<self> folds up like a jackknife and kisses his own toes.", |
421 |
self => "You kiss your toes.", |
422 |
}, |
423 |
}, |
424 |
dance => { |
425 |
noparams => { |
426 |
other => "<self> expresses himself through interpretive dance.", |
427 |
self => "You dance with glee.", |
428 |
}, |
429 |
params => { |
430 |
target => "<self> grabs you, and begins dancing!", |
431 |
other => "Yipe! <self> and <other> are doing the Macarena!", |
432 |
self => "You grab <other> and begin doing the Cha-Cha!", |
433 |
}, |
434 |
self => { |
435 |
other => "<self> embraces himself and begins to dance!", |
436 |
self => "You skip and dance around by yourself.", |
437 |
}, |
438 |
}, |
439 |
snore => { |
440 |
noparams => { |
441 |
other => "<self> snores loudly.", |
442 |
self => "Zzzzzzzzzzzzzzz.", |
443 |
}, |
444 |
params => { |
445 |
}, |
446 |
self => { |
447 |
}, |
448 |
}, |
449 |
blush => { |
450 |
noparams => { |
451 |
other => "<self> blushes.", |
452 |
self => "Your cheeks are burning.", |
453 |
}, |
454 |
params => { |
455 |
}, |
456 |
self => { |
457 |
}, |
458 |
}, |
459 |
snap => { |
460 |
noparams => { |
461 |
other => "<self> snaps his fingers.", |
462 |
self => "PRONTO! you snap your fingers.", |
463 |
}, |
464 |
params => { |
465 |
}, |
466 |
self => { |
467 |
}, |
468 |
}, |
469 |
wave => { |
470 |
noparams => { |
471 |
other => "<self> waves happily.", |
472 |
self => "You wave.", |
473 |
}, |
474 |
params => { |
475 |
target => "<self> waves goodbye to you. Have a good journey.", |
476 |
other => "<self> waves goodbye to <other>.", |
477 |
self => "You wave goodbye to <other>.", |
478 |
}, |
479 |
self => { |
480 |
other => "<self> waves goodbye to himself.", |
481 |
self => "Are you going on adventures as well??", |
482 |
}, |
483 |
}, |
484 |
smile => { |
485 |
noparams => { |
486 |
other => "<self> smiles happily.", |
487 |
self => "You smile happily.", |
488 |
}, |
489 |
params => { |
490 |
target => "<self> smiles at you.", |
491 |
other => "<self> beams a smile at <other>.", |
492 |
self => "You smile at <other>.", |
493 |
}, |
494 |
self => { |
495 |
}, |
496 |
}, |
497 |
sneeze => { |
498 |
noparams => { |
499 |
other => "<self> sneezes.", |
500 |
self => "Gesundheit!", |
501 |
}, |
502 |
params => { |
503 |
target => "<self> sneezes on you, you feel the snot cover you. EEEEEEW.", |
504 |
other => "<self> sneezes on <other> and a film of snot covers him.", |
505 |
self => "You sneeze at <other> and a film of snot shoots onto him.", |
506 |
}, |
507 |
self => { |
508 |
other => "<self> sneezes, and covers himself in a slimy substance.", |
509 |
self => "You sneeze on yourself, what a mess!", |
510 |
}, |
511 |
}, |
512 |
bounce => { |
513 |
noparams => { |
514 |
other => "<self> bounces around.", |
515 |
self => "BOIINNNNNNGG!", |
516 |
}, |
517 |
params => { |
518 |
target => "<self> bounces around the room with you.", |
519 |
other => "<self> bounces around the room with <other>.", |
520 |
self => "You bounce around the room with <other>.", |
521 |
}, |
522 |
self => { |
523 |
}, |
524 |
}, |
525 |
shake => { |
526 |
noparams => { |
527 |
other => "<self> shakes his head.", |
528 |
self => "You shake your head.", |
529 |
}, |
530 |
params => { |
531 |
target => "<self> shakes your hand.", |
532 |
other => "<self> shakes <other>'s hand.", |
533 |
self => "You shake <other>'s hand.", |
534 |
}, |
535 |
self => { |
536 |
other => "<self> shakes and quivers like a bowlful of jelly.", |
537 |
self => "You are shaken by yourself.", |
538 |
}, |
539 |
}, |
540 |
lick => { |
541 |
noparams => { |
542 |
other => "<self> licks his mouth and smiles.", |
543 |
self => "You lick your mouth and smile.", |
544 |
}, |
545 |
params => { |
546 |
target => "<self> licks you.", |
547 |
other => "<self> licks <other>.", |
548 |
self => "You lick <other>.", |
549 |
}, |
550 |
self => { |
551 |
other => "<self> licks himself - YUCK.", |
552 |
self => "You lick yourself.", |
553 |
}, |
554 |
}, |
555 |
flip => { |
556 |
noparams => { |
557 |
other => "<self> flips head over heels.", |
558 |
self => "You flip head over heels.", |
559 |
}, |
560 |
params => { |
561 |
}, |
562 |
self => { |
563 |
}, |
564 |
}, |
565 |
think => { |
566 |
noparams => { |
567 |
other => "<self> closes his eyes and thinks really hard.", |
568 |
self => "Anything in particular that you'd care to think about?", |
569 |
}, |
570 |
params => { |
571 |
}, |
572 |
self => { |
573 |
}, |
574 |
}, |
575 |
yawn => { |
576 |
noparams => { |
577 |
other => "<self> yawns sleepily.", |
578 |
self => "You open up your yap and let out a big breeze of stale air.", |
579 |
}, |
580 |
params => { |
581 |
}, |
582 |
self => { |
583 |
}, |
584 |
}, |
585 |
laugh => { |
586 |
noparams => { |
587 |
other => "<self> falls down laughing.", |
588 |
self => "You fall down laughing.", |
589 |
}, |
590 |
params => { |
591 |
target => "<self> looks at you and falls down on the ground laughing.", |
592 |
other => "<self> looks at <other> and falls down on the ground laughing.", |
593 |
self => "You take one look at <other> and fall down laughing.", |
594 |
}, |
595 |
self => { |
596 |
other => "<self> is laughing at something.", |
597 |
self => "Laugh at yourself all you want, the others won't understand.", |
598 |
}, |
599 |
}, |
600 |
burp => { |
601 |
noparams => { |
602 |
other => "<self> burps loudly.", |
603 |
self => "You burp loudly.", |
604 |
}, |
605 |
params => { |
606 |
}, |
607 |
self => { |
608 |
}, |
609 |
}, |
610 |
gasp => { |
611 |
noparams => { |
612 |
other => "<self> gasps in astonishment.", |
613 |
self => "You gasp in astonishment.", |
614 |
}, |
615 |
params => { |
616 |
}, |
617 |
self => { |
618 |
}, |
619 |
}, |
620 |
smirk => { |
621 |
noparams => { |
622 |
other => "<self> smirks.", |
623 |
self => "You smirk.", |
624 |
}, |
625 |
params => { |
626 |
}, |
627 |
self => { |
628 |
}, |
629 |
}, |
630 |
cry => { |
631 |
noparams => { |
632 |
other => "<self> bursts into tears.", |
633 |
self => "Waaaaaaahhh..", |
634 |
}, |
635 |
params => { |
636 |
target => "<self> cries on your shoulder.", |
637 |
other => "<self> cries on <other>'s shoulder.", |
638 |
self => "You cry on <other>'s shoulder.", |
639 |
}, |
640 |
self => { |
641 |
other => "<self> sobs quietly to himself.", |
642 |
self => "You cry to yourself.", |
643 |
}, |
644 |
}, |
645 |
sulk => { |
646 |
noparams => { |
647 |
other => "<self> sulks in the corner.", |
648 |
self => "You sulk.", |
649 |
}, |
650 |
params => { |
651 |
}, |
652 |
self => { |
653 |
}, |
654 |
}, |
655 |
whistle => { |
656 |
noparams => { |
657 |
other => "<self> whistles appreciatively.", |
658 |
self => "You whistle appreciatively.", |
659 |
}, |
660 |
params => { |
661 |
target => "<self> whistles at <other>.", |
662 |
self => "You whistle at <other>.", |
663 |
}, |
664 |
self => { |
665 |
other => "<self> whistles to himself in boredom.", |
666 |
self => "You whistle while you work.", |
667 |
}, |
668 |
}, |
669 |
groan => { |
670 |
noparams => { |
671 |
other => "<self> groans loudly.", |
672 |
self => "You groan loudly.", |
673 |
}, |
674 |
params => { |
675 |
}, |
676 |
self => { |
677 |
}, |
678 |
}, |
679 |
cough => { |
680 |
noparams => { |
681 |
other => "<self> coughs loudly.", |
682 |
self => "Yuck, try to cover your mouth next time!", |
683 |
}, |
684 |
params => { |
685 |
}, |
686 |
self => { |
687 |
}, |
688 |
}, |
689 |
grin => { |
690 |
noparams => { |
691 |
other => "<self> grins evilly.", |
692 |
self => "You grin evilly.", |
693 |
}, |
694 |
params => { |
695 |
target => "<self> grins evilly at you.", |
696 |
other => "<self> grins evilly at <other>.", |
697 |
self => "You grin at <other>.", |
698 |
}, |
699 |
self => { |
700 |
}, |
701 |
}, |
702 |
}; |
703 |
|
704 |
for my $emotion (keys %$emotes) { |
705 |
cf::register_command $emotion => sub { |
706 |
my ($ob, $tname) = @_; |
707 |
|
708 |
my $pl = $ob->contr; |
709 |
|
710 |
cf::async { |
711 |
my $name = $ob->name; |
712 |
$Coro::current->{desc} = "emote handler for $name"; |
713 |
|
714 |
if ($tname eq $name) { |
715 |
my %emote = %{ $emotes->{$emotion}->{self} || {} }; |
716 |
|
717 |
$emote{other} ||= "You look away from <self>."; |
718 |
$emote{self} ||= "My god! Is that LEGAL?"; |
719 |
|
720 |
$emote{other} =~ s/<self>/$name/; |
721 |
|
722 |
$_->send_msg ($CHAT_CHANNEL, $emote{other}, cf::NDI_GREY) |
723 |
for grep { $ob->on_same_map_as ($_->ob) && $_ != $ob} cf::player::list; |
724 |
|
725 |
$pl->send_msg ($emote{self}, cf::NDI_GREY | cf::NDI_REPLY); |
726 |
} elsif ($tname) { |
727 |
my $target = cf::player::find $tname |
728 |
or return $pl->send_msg (tell_channel $tname, "$tname is not around.", cf::NDI_DK_ORANGE | cf::NDI_REPLY); |
729 |
|
730 |
my %emote = %{ $emotes->{$emotion}->{params} || {} }; |
731 |
|
732 |
$emote{other} ||= "<self> is eyeing <other> quizzically."; |
733 |
$emote{self} ||= "You are still nuts."; |
734 |
$emote{target} ||= "You get the distinct feeling that <other> is nuts."; |
735 |
|
736 |
$emote{self} =~ s/<other>/$tname/; |
737 |
$emote{target} =~ s/<self>/$name/; |
738 |
$emote{other} =~ s/<other>/$tname/; |
739 |
$emote{other} =~ s/<self>/$name/; |
740 |
|
741 |
$_->send_msg ($CHAT_CHANNEL, $emote{other}, cf::NDI_GREY) |
742 |
for grep { $_ != $pl && $_ != $target && $ob->on_same_map_as ($_->ob) } cf::player::list; |
743 |
|
744 |
$target->send_msg (tell_channel $name, $emote{target}, cf::NDI_GREY); |
745 |
$pl->send_msg (tell_channel $tname, $emote{self}, cf::NDI_GREY | cf::NDI_REPLY); |
746 |
} else { |
747 |
my %emote = %{ $emotes->{$emotion}->{noparams} || {} }; |
748 |
|
749 |
$emote{other} ||= "<self> dances with glee."; |
750 |
$emote{self} ||= "You are a nut."; |
751 |
|
752 |
$emote{other} =~ s/<self>/$name/; |
753 |
|
754 |
$_->send_msg ($CHAT_CHANNEL, $emote{other}, cf::NDI_GREY) |
755 |
for grep { $ob->on_same_map_as ($_->ob) && $_ != $pl } cf::player::list; |
756 |
|
757 |
$pl->send_msg ($CHAT_CHANNEL, $emote{self}, cf::NDI_GREY | cf::NDI_REPLY); |
758 |
} |
759 |
}; |
760 |
}; |
761 |
} |
762 |
|
763 |
cf::register_command me => sub { |
764 |
my ($pl, $msg) = @_; |
765 |
|
766 |
my $name = $pl->name; |
767 |
|
768 |
$_->send_msg ($SAY_CHANNEL => "* $name $msg", cf::NDI_GREY | cf::NDI_DEF | ($_ == $pl ? cf::NDI_REPLY : 0)) |
769 |
for grep $pl->on_same_map_as ($_->ob), cf::player::list; |
770 |
}; |
771 |
|
772 |
cf::register_command say => sub { |
773 |
my ($ob, $msg) = @_; |
774 |
|
775 |
utf8::decode $msg; |
776 |
|
777 |
return if $ob->contr->invoke (cf::EVENT_PLAYER_SAY, $msg); |
778 |
|
779 |
if ($msg) { |
780 |
my $name = $ob->name; |
781 |
my @plonmap = grep $ob->on_same_map_as ($_->ob), cf::player::list; |
782 |
|
783 |
$_->send_msg ($SAY_CHANNEL => "$name says: $msg", cf::NDI_GREY | ($_ == $ob->contr ? cf::NDI_REPLY : 0)) |
784 |
for @plonmap; |
785 |
|
786 |
# npcs, magic_ears etc. |
787 |
# first find all objects and their first-level inventories |
788 |
# within a 5x5 square that have something resembling |
789 |
# dialogue or support on_say. |
790 |
my ($map, $x, $y) = ($ob->map, $ob->x - 2, $ob->y - 2); |
791 |
|
792 |
for my $npc ( |
793 |
grep +($_->invoke (cf::EVENT_OBJECT_SAY, $ob->contr, $msg) && return) || NPC_Dialogue::has_dialogue $_, |
794 |
map +($_, $_->inv), |
795 |
grep $_, |
796 |
map $map->at ($x + $_ % 5, $y + (int $_ / 5)), |
797 |
0..24 |
798 |
) { |
799 |
# if some listener teleported us somewhere else, stop right here |
800 |
last unless $map->path == $ob->map->path; |
801 |
|
802 |
my $dialog = new NPC_Dialogue pl => $ob->contr, npc => $npc; |
803 |
my ($reply, @kw) = $dialog->tell ($msg); |
804 |
|
805 |
if (defined $reply) { |
806 |
if ($npc->type == cf::MAGIC_EAR) { |
807 |
if (length $reply) { |
808 |
$_->send_msg ($SAY_CHANNEL => $reply, cf::NDI_BROWN) |
809 |
for @plonmap; |
810 |
} |
811 |
$npc->use_trigger; |
812 |
} else { |
813 |
if (length $reply) { |
814 |
$_->send_msg ($SAY_CHANNEL => $npc->name . " says: $reply", cf::NDI_BROWN) |
815 |
for @plonmap; |
816 |
} |
817 |
} |
818 |
} |
819 |
|
820 |
if (@kw) { |
821 |
$_->send_msg ($SAY_CHANNEL => "[further topics: " . (join ", ", @kw) . "]", cf::NDI_BROWN) |
822 |
for @plonmap; |
823 |
} |
824 |
} |
825 |
|
826 |
} else { |
827 |
$ob->send_msg ($SAY_CHANNEL => "What do you want to say?", cf::NDI_GREY | cf::NDI_REPLY); |
828 |
} |
829 |
}; |
830 |
|
831 |
cf::register_command chat => sub { |
832 |
my ($ob, $msg) = @_; |
833 |
|
834 |
utf8::decode $msg; |
835 |
|
836 |
my $pl = $ob->contr; |
837 |
|
838 |
return if $pl->invoke (cf::EVENT_PLAYER_CHAT, $msg); |
839 |
|
840 |
if ($msg) { |
841 |
my $name = $ob->name; |
842 |
my $NOW = time; |
843 |
|
844 |
cf::LOG cf::llevDebug, sprintf "QBERT [%s] %s\n", $name, $msg; |
845 |
send_irc ("[%s] %s", $name, $msg); |
846 |
|
847 |
$_->send_msg ($CHAT_CHANNEL => "$name chats: $msg", cf::NDI_BLUE | cf::NDI_DEF | ($_ == $pl ? cf::NDI_REPLY : 0)) |
848 |
for grep { $_->ob->{ext_ignore_shout}{$name} < $NOW && $_->listening >= 10 } cf::player::list; |
849 |
|
850 |
} else { |
851 |
$pl->send_msg ($CHAT_CHANNEL => "Chat what?", cf::NDI_BLUE | cf::NDI_DEF | cf::NDI_REPLY); |
852 |
} |
853 |
}; |
854 |
|
855 |
cf::register_command shout => sub { |
856 |
my ($ob, $msg) = @_; |
857 |
|
858 |
utf8::decode $msg; |
859 |
|
860 |
my $pl = $ob->contr; |
861 |
|
862 |
return if $pl->invoke (cf::EVENT_PLAYER_SHOUT, $msg); |
863 |
|
864 |
if ($msg) { |
865 |
my $NOW = time; |
866 |
my $name = $ob->name; |
867 |
|
868 |
cf::LOG cf::llevDebug, sprintf "QBERT {%s} %s\n", $name, $msg; |
869 |
send_irc ("\007\0034{%s} %s\n", $name, $msg); |
870 |
|
871 |
$_->send_msg ($CHAT_CHANNEL => "$name shouts: $msg", cf::NDI_RED | cf::NDI_DEF | ($_ == $pl ? cf::NDI_REPLY : 0)) |
872 |
for grep { $_->ob->{ext_ignore_shout}{$name} < $NOW && $_->listening >= 2 } cf::player::list; |
873 |
|
874 |
} else { |
875 |
$pl->send_msg ($CHAT_CHANNEL => "Shout what?", cf::NDI_RED | cf::NDI_DEF | cf::NDI_REPLY); |
876 |
} |
877 |
}; |
878 |
|
879 |
cf::register_command tell => sub { |
880 |
my ($ob, $args) = @_; |
881 |
my ($target, $msg) = split /\s+/, $args, 2; |
882 |
|
883 |
utf8::decode $msg; |
884 |
|
885 |
my $pl = $ob->contr; |
886 |
my $ns = $pl->ns |
887 |
or return; |
888 |
my $name = $ob->name; |
889 |
|
890 |
return if $pl->invoke (cf::EVENT_PLAYER_TELL, $target, $msg); |
891 |
|
892 |
my $pl_channel = tell_channel $target; |
893 |
|
894 |
if ($target =~ /irc\//) { |
895 |
my (undef, $nick) = split /\//, $target, 2; |
896 |
$ns->send_msg ($pl_channel => "You tell $target: $args", cf::NDI_DK_ORANGE | cf::NDI_DEF | cf::NDI_REPLY); |
897 |
send_irc ("(%s) %s: %s\n", $name, $nick, $msg); |
898 |
|
899 |
} elsif (my $other = cf::player::find_active $target) { |
900 |
my $other_channel = tell_channel $name; |
901 |
|
902 |
if ($msg) { |
903 |
if ($target eq $name) { |
904 |
$ns->send_msg ($pl_channel => "You are talking to yourself, you freak!", cf::NDI_DK_ORANGE | cf::NDI_DEF | cf::NDI_REPLY); |
905 |
} elsif ($other->ob->{ext_ignore_tell}{$name} >= time) { |
906 |
$ns->send_msg ($pl_channel => "$target ignores what you say. Give up on it.", cf::NDI_DK_ORANGE | cf::NDI_DEF | cf::NDI_REPLY); |
907 |
} else { |
908 |
return if $other->invoke (cf::EVENT_PLAYER_TOLD, $pl, $msg); |
909 |
cf::LOG cf::llevDebug, sprintf "TELL [%s>%s] %s\n", $name, $target, $msg; |
910 |
|
911 |
$ns->send_msg ($pl_channel => "You tell $target: $msg", cf::NDI_DK_ORANGE | cf::NDI_DEF | cf::NDI_REPLY); |
912 |
$other->send_msg ($other_channel => "$name tells you: $msg", cf::NDI_DK_ORANGE | cf::NDI_DEF); |
913 |
} |
914 |
} else { |
915 |
$ns->send_msg ($pl_channel => "What do you want to tell $target?", cf::NDI_DK_ORANGE | cf::NDI_DEF | cf::NDI_REPLY); |
916 |
} |
917 |
|
918 |
} else { |
919 |
$ns->send_msg ($pl_channel => "No such player. Your message: $msg", cf::NDI_DK_ORANGE | cf::NDI_DEF | cf::NDI_REPLY); |
920 |
} |
921 |
}; |
922 |
|
923 |
cf::register_command ignore => sub { |
924 |
my ($pl, $args) = @_; |
925 |
my ($target, $type, $timeout) = split /\s+/, $args; |
926 |
|
927 |
if ($args eq "list") { |
928 |
clean_timeouts $pl; |
929 |
|
930 |
if ((my @ignored_tell = sort keys %{$pl->{ext_ignore_tell}}) |
931 |
+ (my @ignored_shout = sort keys %{$pl->{ext_ignore_shout}})) { |
932 |
$pl->message ("Currently ignoring private messages from: ", cf::NDI_REPLY); |
933 |
$pl->message ((join ", ", @ignored_tell), cf::NDI_REPLY); |
934 |
$pl->message ("Currently ignoring shouts from: ", cf::NDI_REPLY); |
935 |
$pl->message ((join ", ", @ignored_shout), cf::NDI_REPLY); |
936 |
$pl->message ("To stop ignoring one, use unignore.", cf::NDI_REPLY); |
937 |
} else { |
938 |
$pl->message ("Not ignoring anyone", cf::NDI_REPLY); |
939 |
} |
940 |
|
941 |
} elsif ($target && $type) { |
942 |
|
943 |
$timeout ne "" or $timeout = 24; |
944 |
my $absolute_timeout = time + $timeout * 3600; |
945 |
|
946 |
if (cf::player::exists $target) { |
947 |
if ($type eq "tell") { |
948 |
$pl->message ("Now ignoring private messages from $target for $timeout hours.", cf::NDI_REPLY); |
949 |
$pl->{ext_ignore_tell}{$target} = $absolute_timeout; |
950 |
} elsif ($type eq "shout") { |
951 |
$pl->message ("Now ignoring shouts from $target for $timeout hours.", cf::NDI_REPLY); |
952 |
$pl->{ext_ignore_shout}{$target} = $absolute_timeout; |
953 |
} elsif ($type eq "all") { |
954 |
$pl->message ("Now ignoring everything from $target for $timeout hours.", cf::NDI_REPLY); |
955 |
$pl->{ext_ignore_tell}{$target} = $absolute_timeout; |
956 |
$pl->{ext_ignore_shout}{$target} = $absolute_timeout; |
957 |
} else { |
958 |
$pl->message ("You need to specify tell, shout or all.", cf::NDI_REPLY); |
959 |
} |
960 |
} else { |
961 |
$pl->message ("No such player: $target", cf::NDI_REPLY); |
962 |
} |
963 |
|
964 |
} else { |
965 |
$pl->message ("Usage: ignore <player> <tell|shout|all> <timeout>\n" |
966 |
. "will ignore a player for <timeout> hours.\n" |
967 |
. "Usage: ignore list\n" |
968 |
. "will show you a list of players currently ignored.", cf::NDI_REPLY); |
969 |
} |
970 |
}; |
971 |
|
972 |
cf::register_command unignore => sub { |
973 |
my ($pl, $args) = @_; |
974 |
my ($target, $type) = split /\s+/, $args; |
975 |
|
976 |
if ($args eq "") { |
977 |
if ($pl->{ext_ignore_tell}) { |
978 |
$pl->message ("Currently ignoring private messages from: ", cf::NDI_REPLY); |
979 |
$pl->message ((join ", ", sort keys %{ $pl->{ext_ignore_tell} }), cf::NDI_REPLY); |
980 |
$pl->message ("Currently ignoring shouts from: ", cf::NDI_REPLY); |
981 |
$pl->message ((join ", ", sort keys %{ $pl->{ext_ignore_shout} }), cf::NDI_REPLY); |
982 |
} else { |
983 |
$pl->message ("Not ignoring anyone", cf::NDI_REPLY); |
984 |
} |
985 |
} else { |
986 |
if (cf::player::exists $target) { |
987 |
if ($type eq "tell") { |
988 |
$pl->message ("Not ignoring private messages from $target anymore.", cf::NDI_REPLY); |
989 |
delete $pl->{ext_ignore_tell} {$target}; |
990 |
} elsif ($type eq "shout") { |
991 |
$pl->message ("Not ignoring shouts from $target anymore.", cf::NDI_REPLY); |
992 |
delete $pl->{ext_ignore_shout}{$target}; |
993 |
} elsif ($type eq "all") { |
994 |
$pl->message ("Not ignoring anything from $target anymore.", cf::NDI_REPLY); |
995 |
delete $pl->{ext_ignore_tell} {$target}; |
996 |
delete $pl->{ext_ignore_shout}{$target}; |
997 |
} else { |
998 |
$pl->message ("You need to specify tell, shout or all.", cf::NDI_REPLY); |
999 |
} |
1000 |
} else { |
1001 |
$pl->message ("No such player or ambiguous name: $target", cf::NDI_REPLY); |
1002 |
} |
1003 |
} |
1004 |
}; |
1005 |
|