ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/maps/perl/chat.ext
(Generate patch)

Comparing deliantra/maps/perl/chat.ext (file contents):
Revision 1.19 by root, Fri Jun 9 04:18:02 2006 UTC vs.
Revision 1.21 by root, Wed Jul 19 22:20:07 2006 UTC

1#! perl 1#! perl
2 2
3# implement a replacement for the built-in say/chat/shout/tell/reply commands 3# implement a replacement for the built-in say/chat/shout/tell/reply commands
4# adds ignore/unignore functionality 4# adds ignore/unignore functionality
5 5
6sub valid_user($) { 6use NPC_Dialogue;
7 cf::player::find $_[0]
8 or -f sprintf "%s/%s/%s/%s.pl", cf::localdir, cf::playerdir, ($_[0]) x 2;
9}
10 7
11sub clean_timeouts($) { 8sub clean_timeouts($) {
12 my ($player) = @_; 9 my ($player) = @_;
13 my $NOW = time; 10 my $NOW = time;
14 11
15 for my $hash (@$player{qw(ext_ignore_shout ext_ignore_tell)}) { 12 for my $hash (@$player{qw(ext_ignore_shout ext_ignore_tell)}) {
16 while (my ($k, $v) = each %$hash) { 13 while (my ($k, $v) = each %$hash) {
17 if ($v < $NOW) { 14 if ($v < $NOW) {
18 $player->message ("Your ignore on $k has expired.", cf::NDI_GREEN); 15 $player->message ("Your ignore on $k has expired.", cf::NDI_GREEN | cf::NDI_UNIQUE);
19 delete $hash->{$k}; 16 delete $hash->{$k};
20 } elsif (!valid_user $k) { 17 } elsif (!valid_user $k) {
21 $player->message ("Your ignore on $k is no longer valid (no such user).", cf::NDI_GREEN); 18 $player->message ("Your ignore on $k is no longer valid (no such user).", cf::NDI_GREEN | cf::NDI_UNIQUE);
22 delete $hash->{$k}; 19 delete $hash->{$k};
23 } 20 }
24 } 21 }
25 } 22 }
26} 23}
37 34
38 if ($msg ne "") { 35 if ($msg ne "") {
39 my $prev_listen = $player->listening; 36 my $prev_listen = $player->listening;
40 $player->listening ($msg); 37 $player->listening ($msg);
41 if ($prev_listen == $player->listening) { 38 if ($prev_listen == $player->listening) {
42 $who->message ("Your verbose level stayed ".$prev_listen.".", cf::NDI_UNIQUE); 39 $who->message ("Your verbose level stayed $prev_listen.", cf::NDI_UNIQUE);
43 } else { 40 } else {
44 $who->message ("Your verbose level is now ".$player->listening.". (previously: ".$prev_listen.")", cf::NDI_UNIQUE); 41 $who->message ("Your verbose level is now " . $player->listening . ". (previously: $prev_listen)", cf::NDI_UNIQUE);
45 } 42 }
46 } else { 43 } else {
47 $who->message ("Your verbose level is ".$player->listening.".", cf::NDI_UNIQUE); 44 $who->message ("Your verbose level is " . $player->listening . ".", cf::NDI_UNIQUE);
48 } 45 }
49}; 46};
50 47
51#cf::register_command say => 0, sub { 48cf::register_command say => 0, sub {
52# my ($who, $msg) = @_; 49 my ($who, $msg) = @_;
53# 50
54# if ($msg) { 51 if ($msg) {
55# my $name = $who->name; 52 my $name = $who->name;
53
56# $_->ob->message ("$name says: $msg", cf::NDI_WHITE) 54 $_->ob->message ("$name says: $msg", cf::NDI_GREY | cf::NDI_UNIQUE)
57# for grep $who->on_same_map_as ($_->ob), cf::player::list; 55 for grep $who->on_same_map_as ($_->ob), cf::player::list;
56
57 # npcs, magic_ears etc.
58 # first find all objects and their inventories within a 5x5 square
59 # that have something resembling dialogue
60 my ($map, $x, $y) = ($who->map, $who->x - 2, $who->y - 2);
61
62 for my $npc (
63 grep NPC_Dialogue::has_dialogue $_,
64 map +($_, $_->inv),
65 grep $_,
66 map $map->at ($x + $_ % 5, $y + (int $_ / 5)),
67 0..24
68 ) {
69 # if some listener teleported us somewhere else, stop right here
70 last unless $map->path == $who->map->path;
71
72 my $dialog = new NPC_Dialogue ob => $who, npc => $npc;
73 my $reply = $dialog->tell ($msg);
74
75 if (defined $reply) {
76 if ($npc->type == cf::MAGIC_EAR) {
77 if (length $reply) {
78 $_->ob->message ($reply, cf::NDI_BROWN | cf::NDI_UNIQUE)
79 for grep $who->on_same_map_as ($_->ob), cf::player::list;
80 }
81 $npc->use_trigger;
82 } else {
83 if (length $reply) {
84 $_->ob->message ($npc->name . " says: $reply", cf::NDI_BROWN | cf::NDI_UNIQUE)
85 for grep $who->on_same_map_as ($_->ob), cf::player::list;
86 }
87 }
88 }
89 }
90
58# } else { 91 } else {
59# $who->message ("What do you want to say?", cf::NDI_UNIQUE); 92 $who->message ("What do you want to say?", cf::NDI_UNIQUE);
60# } 93 }
61#}; 94};
62 95
63cf::register_command chat => 0, sub { 96cf::register_command chat => 0, sub {
64 my ($who, $msg) = @_; 97 my ($who, $msg) = @_;
65 98
66 if ($msg) { 99 if ($msg) {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines