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