ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/ext/chat.ext
Revision: 1.13
Committed: Fri Apr 13 05:32:12 2007 UTC (17 years, 1 month ago) by root
Branch: MAIN
Changes since 1.12: +0 -23 lines
Log Message:
move seen to commands.ext and fix it while doing so

File Contents

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