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 | |
6 | sub valid_user($) { |
6 | use NPC_Dialogue; |
7 | -f sprintf "%s/%s/%s/%s.pl", cf::localdir, cf::playerdir, ($_[0]) x 2; |
|
|
8 | } |
|
|
9 | |
7 | |
10 | sub clean_timeouts($) { |
8 | sub clean_timeouts($) { |
11 | my ($player) = @_; |
9 | my ($player) = @_; |
12 | my $NOW = time; |
10 | my $NOW = time; |
13 | |
11 | |
14 | for my $hash (@$player{qw(ext_ignore_shout ext_ignore_tell)}) { |
12 | for my $hash (@$player{qw(ext_ignore_shout ext_ignore_tell)}) { |
15 | while (my ($k, $v) = each %$hash) { |
13 | while (my ($k, $v) = each %$hash) { |
16 | if ($v < $NOW) { |
14 | if ($v < $NOW) { |
17 | $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); |
18 | delete $hash->{$k}; |
16 | delete $hash->{$k}; |
19 | } elsif (!valid_user $k) { |
17 | } elsif (!cf::player::exists $k) { |
20 | $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); |
21 | delete $hash->{$k}; |
19 | delete $hash->{$k}; |
22 | } |
20 | } |
23 | } |
21 | } |
24 | } |
22 | } |
25 | } |
23 | } |
… | |
… | |
32 | |
30 | |
33 | cf::register_command listen => 0, sub { |
31 | cf::register_command listen => 0, sub { |
34 | my ($who, $msg) = @_; |
32 | my ($who, $msg) = @_; |
35 | my $player = cf::player::find $who->name; |
33 | my $player = cf::player::find $who->name; |
36 | |
34 | |
37 | if ($msg) { |
35 | if ($msg ne "") { |
38 | my $prev_listen = $player->listening; |
36 | my $prev_listen = $player->listening; |
39 | $player->listening ($msg); |
37 | $player->listening ($msg); |
40 | if ($prev_listen == $player->listening) { |
38 | if ($prev_listen == $player->listening) { |
41 | $who->message ("Your verbose level stayed ".$prev_listen.".", cf::NDI_UNIQUE); |
39 | $who->message ("Your verbose level stayed $prev_listen.", cf::NDI_UNIQUE); |
42 | } else { |
40 | } else { |
43 | $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); |
44 | } |
42 | } |
45 | } else { |
43 | } else { |
46 | $who->message ("Your verbose level is ".$player->listening.".", cf::NDI_UNIQUE); |
44 | $who->message ("Your verbose level is " . $player->listening . ".", cf::NDI_UNIQUE); |
47 | } |
45 | } |
48 | }; |
46 | }; |
49 | |
47 | |
50 | #cf::register_command say => 0, sub { |
48 | cf::register_command say => 0, sub { |
51 | # my ($who, $msg) = @_; |
49 | my ($who, $msg) = @_; |
52 | # |
50 | |
53 | # if ($msg) { |
51 | if ($msg) { |
54 | # my $name = $who->name; |
52 | my $name = $who->name; |
|
|
53 | |
55 | # $_->ob->message ("$name says: $msg", cf::NDI_WHITE) |
54 | $_->ob->message ("$name says: $msg", cf::NDI_GREY | cf::NDI_UNIQUE) |
56 | # 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 | |
57 | # } else { |
91 | } else { |
58 | # $who->message ("What do you want to say?", cf::NDI_UNIQUE); |
92 | $who->message ("What do you want to say?", cf::NDI_UNIQUE); |
59 | # } |
93 | } |
60 | #}; |
94 | }; |
61 | |
95 | |
62 | cf::register_command chat => 0, sub { |
96 | cf::register_command chat => 0, sub { |
63 | my ($who, $msg) = @_; |
97 | my ($who, $msg) = @_; |
64 | |
98 | |
65 | if ($msg) { |
99 | if ($msg) { |
66 | my $name = $who->name; |
100 | my $name = $who->name; |
67 | my $NOW = time; |
101 | my $NOW = time; |
68 | |
102 | |
|
|
103 | cf::LOG cf::llevDebug, sprintf "QBERT [%s] %s\n", $name, $msg; |
|
|
104 | |
69 | $_->ob->message ("$name chats: $msg", cf::NDI_BLUE) |
105 | $_->ob->message ("$name chats: $msg", cf::NDI_BLUE) |
70 | for grep { $_->ob->{ext_ignore_shout}{$name} < $NOW && $_->listening >= 10 } cf::player::list; |
106 | for grep { $_->ob->{ext_ignore_shout}{$name} < $NOW && $_->listening >= 10 } cf::player::list; |
71 | |
107 | |
72 | } else { |
108 | } else { |
73 | $who->message ("Chat what?", cf::NDI_UNIQUE); |
109 | $who->message ("Chat what?", cf::NDI_UNIQUE); |
… | |
… | |
78 | my ($who, $msg) = @_; |
114 | my ($who, $msg) = @_; |
79 | |
115 | |
80 | if ($msg) { |
116 | if ($msg) { |
81 | my $NOW = time; |
117 | my $NOW = time; |
82 | my $name = $who->name; |
118 | my $name = $who->name; |
|
|
119 | |
|
|
120 | cf::LOG cf::llevDebug, sprintf "QBERT {%s} %s\n", $name, $msg; |
83 | |
121 | |
84 | $_->ob->message ("$name shouts: $msg", cf::NDI_RED) |
122 | $_->ob->message ("$name shouts: $msg", cf::NDI_RED) |
85 | for grep { $_->ob->{ext_ignore_shout}{$name} < $NOW && $_->listening >= 2 } cf::player::list; |
123 | for grep { $_->ob->{ext_ignore_shout}{$name} < $NOW && $_->listening >= 2 } cf::player::list; |
86 | |
124 | |
87 | } else { |
125 | } else { |
… | |
… | |
102 | if ($target eq $name) { |
140 | if ($target eq $name) { |
103 | $who->message ("You are talking to yourself, you freak!", cf::NDI_UNIQUE); |
141 | $who->message ("You are talking to yourself, you freak!", cf::NDI_UNIQUE); |
104 | } elsif ($other->ob->{ext_ignore_tell}{$name} >= time) { |
142 | } elsif ($other->ob->{ext_ignore_tell}{$name} >= time) { |
105 | $who->message ("$target ignores what you say. Give up on it.", cf::NDI_UNIQUE); |
143 | $who->message ("$target ignores what you say. Give up on it.", cf::NDI_UNIQUE); |
106 | } else { |
144 | } else { |
|
|
145 | cf::LOG cf::llevDebug, sprintf "TELL [%s>%s] %s\n", $name, $target, $msg; |
|
|
146 | |
107 | $who->message ("You tell $target: $msg"); |
147 | $who->message ("You tell $target: $msg"); |
108 | $other->ob->message ("$name tells you: $msg"); |
148 | $other->ob->message ("$name tells you: $msg"); |
109 | $other->ob->{ext_last_tell} = $name; |
149 | $other->ob->{ext_last_tell} = $name; |
110 | } |
150 | } |
111 | } else { |
151 | } else { |
… | |
… | |
126 | |
166 | |
127 | $other->ob->{ext_ignore_tell}{$name} >= time |
167 | $other->ob->{ext_ignore_tell}{$name} >= time |
128 | or delete $other->ob->{ext_ignore_tell}{$name}; |
168 | or delete $other->ob->{ext_ignore_tell}{$name}; |
129 | |
169 | |
130 | if ($other->ob->{ext_ignore_tell}{$name} < time) { |
170 | if ($other->ob->{ext_ignore_tell}{$name} < time) { |
|
|
171 | cf::LOG cf::llevDebug, sprintf "TELL [%s>%s] %s\n", $name, $other->ob->name, $args; |
|
|
172 | |
131 | $who->message ("You tell " . $other->ob->name . ": $args"); |
173 | $who->message ("You tell " . $other->ob->name . ": $args"); |
132 | $other->ob->message ("$name tells you: $args"); |
174 | $other->ob->message ("$name tells you: $args"); |
133 | $who->{ext_last_tell} = $other->ob->name; |
175 | $who->{ext_last_tell} = $other->ob->name; |
134 | } else { |
176 | } else { |
135 | $who->message ($other->ob->name . " ignores what you say. Give up on it.", cf::NDI_UNIQUE); |
177 | $who->message ($other->ob->name . " ignores what you say. Give up on it.", cf::NDI_UNIQUE); |
… | |
… | |
164 | } elsif ($target && $type) { |
206 | } elsif ($target && $type) { |
165 | |
207 | |
166 | $timeout ne "" or $timeout = 24; |
208 | $timeout ne "" or $timeout = 24; |
167 | my $absolute_timeout = time + $timeout * 3600; |
209 | my $absolute_timeout = time + $timeout * 3600; |
168 | |
210 | |
169 | if (valid_user $target) { |
211 | if (cf::player::exists $target) { |
170 | if ($type eq "tell") { |
212 | if ($type eq "tell") { |
171 | $who->message ("Now ignoring private messages from $target for $timeout hours.", cf::NDI_UNIQUE); |
213 | $who->message ("Now ignoring private messages from $target for $timeout hours.", cf::NDI_UNIQUE); |
172 | $who->{ext_ignore_tell}{$target} = $absolute_timeout; |
214 | $who->{ext_ignore_tell}{$target} = $absolute_timeout; |
173 | } elsif ($type eq "shout") { |
215 | } elsif ($type eq "shout") { |
174 | $who->message ("Now ignoring shouts from $target for $timeout hours.", cf::NDI_UNIQUE); |
216 | $who->message ("Now ignoring shouts from $target for $timeout hours.", cf::NDI_UNIQUE); |
… | |
… | |
205 | } else { |
247 | } else { |
206 | $who->message ("Not ignoring anyone", cf::NDI_UNIQUE); |
248 | $who->message ("Not ignoring anyone", cf::NDI_UNIQUE); |
207 | } |
249 | } |
208 | } else { |
250 | } else { |
209 | |
251 | |
210 | if (valid_user $target) { |
252 | if (cf::player::exists $target) { |
211 | if ($type eq "tell") { |
253 | if ($type eq "tell") { |
212 | $who->message ("Not ignoring private messages from $target anymore.", cf::NDI_UNIQUE); |
254 | $who->message ("Not ignoring private messages from $target anymore.", cf::NDI_UNIQUE); |
213 | delete $who->{ext_ignore_tell} {$target}; |
255 | delete $who->{ext_ignore_tell} {$target}; |
214 | } elsif ($type eq "shout") { |
256 | } elsif ($type eq "shout") { |
215 | $who->message ("Not ignoring shouts from $target anymore.", cf::NDI_UNIQUE); |
257 | $who->message ("Not ignoring shouts from $target anymore.", cf::NDI_UNIQUE); |