1 | #! perl |
1 | #! perl |
|
|
2 | #CONVERSION: PARTIAL |
2 | |
3 | |
3 | # implement a replacement for the built-in say/chat/shout/tell/reply commands |
4 | # implement a replacement for the built-in say/chat/shout/tell/reply commands |
4 | # adds ignore/unignore functionality |
5 | # adds ignore/unignore functionality |
5 | |
6 | |
6 | use NPC_Dialogue; |
7 | use NPC_Dialogue; |
… | |
… | |
21 | } |
22 | } |
22 | } |
23 | } |
23 | } |
24 | } |
24 | } |
25 | } |
25 | |
26 | |
26 | sub on_logout { |
27 | cf::attach_to_players |
|
|
28 | prio => -1000, |
|
|
29 | on_login => sub { |
27 | my ($pl, $host) = @_; |
30 | my ($pl) = @_; |
28 | |
31 | |
29 | clean_timeouts $pl->ob; |
32 | clean_timeouts $pl->ob; |
30 | } |
33 | }, |
|
|
34 | ; |
31 | |
35 | |
32 | cf::register_command listen => 0, sub { |
36 | cf::register_command listen => 0, sub { |
33 | my ($who, $msg) = @_; |
37 | my ($who, $msg) = @_; |
34 | my $player = cf::player::find $who->name; |
38 | my $player = cf::player::find $who->name; |
35 | |
39 | |
… | |
… | |
49 | cf::register_command say => 0, sub { |
53 | cf::register_command say => 0, sub { |
50 | my ($who, $msg) = @_; |
54 | my ($who, $msg) = @_; |
51 | |
55 | |
52 | utf8::decode $msg; |
56 | utf8::decode $msg; |
53 | |
57 | |
|
|
58 | return if $who->contr->invoke (cf::EVENT_PLAYER_SAY, $msg); |
|
|
59 | |
54 | if ($msg) { |
60 | if ($msg) { |
55 | my $name = $who->name; |
61 | my $name = $who->name; |
56 | |
62 | |
57 | utf8::encode $msg; # ->message not yet utf8-ified |
63 | utf8::encode $msg; # ->message not yet utf8-ified |
58 | $_->ob->message ("$name says: $msg", cf::NDI_GREY | cf::NDI_UNIQUE) |
64 | $_->ob->message ("$name says: $msg", cf::NDI_GREY | cf::NDI_UNIQUE) |
59 | for grep $who->on_same_map_as ($_->ob), cf::player::list; |
65 | for grep $who->on_same_map_as ($_->ob), cf::player::list; |
60 | utf8::decode $msg; |
66 | utf8::decode $msg; |
61 | |
67 | |
62 | # npcs, magic_ears etc. |
68 | # npcs, magic_ears etc. |
63 | # first find all objects and their inventories within a 5x5 square |
69 | # first find all objects and theirt-level inventories |
64 | # that have something resembling dialogue |
70 | # within a 5x5 square # that have something resembling |
|
|
71 | # dialogue or support on_say. |
65 | my ($map, $x, $y) = ($who->map, $who->x - 2, $who->y - 2); |
72 | my ($map, $x, $y) = ($who->map, $who->x - 2, $who->y - 2); |
66 | |
73 | |
67 | for my $npc ( |
74 | for my $npc ( |
68 | grep NPC_Dialogue::has_dialogue $_, |
75 | grep +($_->invoke (cf::EVENT_OBJECT_SAY, $who->contr, $msg) && return) || NPC_Dialogue::has_dialogue $_, |
69 | map +($_, $_->inv), |
76 | map +($_, $_->inv), |
70 | grep $_, |
77 | grep $_, |
71 | map $map->at ($x + $_ % 5, $y + (int $_ / 5)), |
78 | map $map->at ($x + $_ % 5, $y + (int $_ / 5)), |
72 | 0..24 |
79 | 0..24 |
73 | ) { |
80 | ) { |
… | |
… | |
106 | cf::register_command chat => 0, sub { |
113 | cf::register_command chat => 0, sub { |
107 | my ($who, $msg) = @_; |
114 | my ($who, $msg) = @_; |
108 | |
115 | |
109 | utf8::decode $msg; |
116 | utf8::decode $msg; |
110 | |
117 | |
|
|
118 | return if $who->contr->invoke (cf::EVENT_PLAYER_CHAT, $msg); |
|
|
119 | |
111 | if ($msg) { |
120 | if ($msg) { |
112 | my $name = $who->name; |
121 | my $name = $who->name; |
113 | my $NOW = time; |
122 | my $NOW = time; |
114 | |
123 | |
115 | utf8::encode $msg; # ->message not yet utf8-ified |
124 | utf8::encode $msg; # ->message not yet utf8-ified |
116 | cf::LOG cf::llevDebug, sprintf "QBERT [%s] %s\n", $name, $msg; |
125 | cf::LOG cf::llevDebug, sprintf "QBERT [%s] %s\n", $name, $msg; |
|
|
126 | ext::schmorp_irc::do_notice (sprintf "[%s] %s", $name, $msg); |
117 | |
127 | |
118 | $_->ob->message ("$name chats: $msg", cf::NDI_BLUE) |
128 | $_->ob->message ("$name chats: $msg", cf::NDI_BLUE) |
119 | for grep { $_->ob->{ext_ignore_shout}{$name} < $NOW && $_->listening >= 10 } cf::player::list; |
129 | for grep { $_->ob->{ext_ignore_shout}{$name} < $NOW && $_->listening >= 10 } cf::player::list; |
120 | |
130 | |
121 | } else { |
131 | } else { |
… | |
… | |
125 | |
135 | |
126 | cf::register_command shout => 0, sub { |
136 | cf::register_command shout => 0, sub { |
127 | my ($who, $msg) = @_; |
137 | my ($who, $msg) = @_; |
128 | |
138 | |
129 | utf8::decode $msg; |
139 | utf8::decode $msg; |
|
|
140 | |
|
|
141 | return if $who->contr->invoke (cf::EVENT_PLAYER_SHOUT, $msg); |
130 | |
142 | |
131 | if ($msg) { |
143 | if ($msg) { |
132 | my $NOW = time; |
144 | my $NOW = time; |
133 | my $name = $who->name; |
145 | my $name = $who->name; |
134 | |
146 | |
135 | cf::LOG cf::llevDebug, sprintf "QBERT {%s} %s\n", $name, $msg; |
147 | cf::LOG cf::llevDebug, sprintf "QBERT {%s} %s\n", $name, $msg; |
|
|
148 | ext::schmorp_irc::do_notice (sprintf "\0034{%s} %s\n", $name, $msg); |
136 | |
149 | |
137 | utf8::encode $msg; # ->message not yet utf8-ified |
150 | utf8::encode $msg; # ->message not yet utf8-ified |
138 | $_->ob->message ("$name shouts: $msg", cf::NDI_RED) |
151 | $_->ob->message ("$name shouts: $msg", cf::NDI_RED) |
139 | for grep { $_->ob->{ext_ignore_shout}{$name} < $NOW && $_->listening >= 2 } cf::player::list; |
152 | for grep { $_->ob->{ext_ignore_shout}{$name} < $NOW && $_->listening >= 2 } cf::player::list; |
140 | |
153 | |
… | |
… | |
148 | my ($who, $args) = @_; |
161 | my ($who, $args) = @_; |
149 | my ($target, $msg) = split /\s+/, $args, 2; |
162 | my ($target, $msg) = split /\s+/, $args, 2; |
150 | |
163 | |
151 | utf8::decode $msg; |
164 | utf8::decode $msg; |
152 | |
165 | |
|
|
166 | return if $who->contr->invoke (cf::EVENT_PLAYER_TELL, $target, $msg); |
|
|
167 | |
153 | my $name = $who->name; |
168 | my $name = $who->name; |
154 | |
169 | |
|
|
170 | if ($target =~ /irc\//) { |
|
|
171 | my (undef, $nick) = split /\//, $target, 2; |
|
|
172 | $who->message ("You tell $target: $args"); |
|
|
173 | ext::schmorp_irc::do_notice (sprintf "(%s) %s: %s\n", $name, $nick, $msg); |
155 | if (my $other = cf::player::find $target) { |
174 | } elsif (my $other = cf::player::find $target) { |
156 | |
175 | |
157 | if ($msg) { |
176 | if ($msg) { |
158 | if ($target eq $name) { |
177 | if ($target eq $name) { |
159 | $who->message ("You are talking to yourself, you freak!", cf::NDI_UNIQUE); |
178 | $who->message ("You are talking to yourself, you freak!", cf::NDI_UNIQUE); |
160 | } elsif ($other->ob->{ext_ignore_tell}{$name} >= time) { |
179 | } elsif ($other->ob->{ext_ignore_tell}{$name} >= time) { |
… | |
… | |
180 | my ($who, $args) = @_; |
199 | my ($who, $args) = @_; |
181 | my $name = $who->name; |
200 | my $name = $who->name; |
182 | |
201 | |
183 | utf8::decode $args; |
202 | utf8::decode $args; |
184 | |
203 | |
|
|
204 | return if $who->contr->invoke (cf::EVENT_PLAYER_TELL, $who->{ext_last_tell}, $args); |
|
|
205 | |
|
|
206 | if ($who->{ext_last_tell} =~ /irc\//) { |
|
|
207 | my (undef, $nick) = split /\//, $who->{ext_last_tell}, 2; |
|
|
208 | $who->message ("You tell " . $who->{ext_last_tell} . ": $args"); |
|
|
209 | ext::schmorp_irc::do_notice (sprintf "(%s) %s: %s\n", $name, $nick, $args); |
185 | if (my $other = cf::player::find $who->{ext_last_tell}) { |
210 | } elsif (my $other = cf::player::find $who->{ext_last_tell}) { |
|
|
211 | |
186 | if ($args) { |
212 | if ($args) { |
187 | |
|
|
188 | $other->ob->{ext_ignore_tell}{$name} >= time |
213 | $other->ob->{ext_ignore_tell}{$name} >= time |
189 | or delete $other->ob->{ext_ignore_tell}{$name}; |
214 | or delete $other->ob->{ext_ignore_tell}{$name}; |
190 | |
215 | |
191 | if ($other->ob->{ext_ignore_tell}{$name} < time) { |
216 | if ($other->ob->{ext_ignore_tell}{$name} < time) { |
192 | utf8::encode $msg; # ->message not yet utf8-ified |
217 | utf8::encode $args; # ->message not yet utf8-ified |
193 | cf::LOG cf::llevDebug, sprintf "TELL [%s>%s] %s\n", $name, $other->ob->name, $args; |
218 | cf::LOG cf::llevDebug, sprintf "TELL [%s>%s] %s\n", $name, $other->ob->name, $args; |
194 | |
219 | |
195 | $who->message ("You tell " . $other->ob->name . ": $args"); |
220 | $who->message ("You tell " . $other->ob->name . ": $args"); |
196 | $other->ob->message ("$name tells you: $args"); |
221 | $other->ob->message ("$name tells you: $args"); |
197 | $who->{ext_last_tell} = $other->ob->name; |
222 | $who->{ext_last_tell} = $other->ob->name; |
… | |
… | |
201 | } else { |
226 | } else { |
202 | $who->message ("What do you want to tell ".$other->ob->name."?", cf::NDI_UNIQUE); |
227 | $who->message ("What do you want to tell ".$other->ob->name."?", cf::NDI_UNIQUE); |
203 | } |
228 | } |
204 | |
229 | |
205 | } else { |
230 | } else { |
206 | $who->message ("Can't reply, player left. Your message: $args", cf::NDI_UNIQUE); |
231 | $who->message ("Can't reply, player left. Your message: $args".$who->{ext_last_tell}, cf::NDI_UNIQUE); |
207 | } |
232 | } |
208 | }; |
233 | }; |
209 | |
234 | |
210 | cf::register_command ignore => 0, sub { |
235 | cf::register_command ignore => 0, sub { |
211 | my ($who, $args) = @_; |
236 | my ($who, $args) = @_; |