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_login { |
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; |
117 | cf::ext::schmorp_irc::do_notice (sprintf "[%s] %s", $name, $msg); |
126 | ext::schmorp_irc::do_notice (sprintf "[%s] %s", $name, $msg); |
118 | |
127 | |
119 | $_->ob->message ("$name chats: $msg", cf::NDI_BLUE) |
128 | $_->ob->message ("$name chats: $msg", cf::NDI_BLUE) |
120 | 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; |
121 | |
130 | |
122 | } else { |
131 | } else { |
… | |
… | |
126 | |
135 | |
127 | cf::register_command shout => 0, sub { |
136 | cf::register_command shout => 0, sub { |
128 | my ($who, $msg) = @_; |
137 | my ($who, $msg) = @_; |
129 | |
138 | |
130 | utf8::decode $msg; |
139 | utf8::decode $msg; |
|
|
140 | |
|
|
141 | return if $who->contr->invoke (cf::EVENT_PLAYER_SHOUT, $msg); |
131 | |
142 | |
132 | if ($msg) { |
143 | if ($msg) { |
133 | my $NOW = time; |
144 | my $NOW = time; |
134 | my $name = $who->name; |
145 | my $name = $who->name; |
135 | |
146 | |
136 | # cf::LOG cf::llevDebug, sprintf "QBERT {%s} %s\n", $name, $msg; |
147 | # cf::LOG cf::llevDebug, sprintf "QBERT {%s} %s\n", $name, $msg; |
137 | cf::ext::schmorp_irc::do_notice (sprintf "{%s} %s\n", $name, $msg); |
148 | ext::schmorp_irc::do_notice (sprintf "{%s} %s\n", $name, $msg); |
138 | |
149 | |
139 | utf8::encode $msg; # ->message not yet utf8-ified |
150 | utf8::encode $msg; # ->message not yet utf8-ified |
140 | $_->ob->message ("$name shouts: $msg", cf::NDI_RED) |
151 | $_->ob->message ("$name shouts: $msg", cf::NDI_RED) |
141 | 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; |
142 | |
153 | |
… | |
… | |
149 | cf::register_command tell => 0, sub { |
160 | cf::register_command tell => 0, sub { |
150 | my ($who, $args) = @_; |
161 | my ($who, $args) = @_; |
151 | my ($target, $msg) = split /\s+/, $args, 2; |
162 | my ($target, $msg) = split /\s+/, $args, 2; |
152 | |
163 | |
153 | utf8::decode $msg; |
164 | utf8::decode $msg; |
|
|
165 | |
|
|
166 | return if $who->contr->invoke (cf::EVENT_PLAYER_TELL, $target, $msg); |
154 | |
167 | |
155 | my $name = $who->name; |
168 | my $name = $who->name; |
156 | |
169 | |
157 | if (my $other = cf::player::find $target) { |
170 | if (my $other = cf::player::find $target) { |
158 | |
171 | |
… | |
… | |
182 | my ($who, $args) = @_; |
195 | my ($who, $args) = @_; |
183 | my $name = $who->name; |
196 | my $name = $who->name; |
184 | |
197 | |
185 | utf8::decode $args; |
198 | utf8::decode $args; |
186 | |
199 | |
|
|
200 | return if $who->contr->invoke (cf::EVENT_PLAYER_TELL, $who->{ext_last_tell}, $args); |
|
|
201 | |
187 | if (my $other = cf::player::find $who->{ext_last_tell}) { |
202 | if (my $other = cf::player::find $who->{ext_last_tell}) { |
|
|
203 | |
188 | if ($args) { |
204 | if ($args) { |
189 | |
|
|
190 | $other->ob->{ext_ignore_tell}{$name} >= time |
205 | $other->ob->{ext_ignore_tell}{$name} >= time |
191 | or delete $other->ob->{ext_ignore_tell}{$name}; |
206 | or delete $other->ob->{ext_ignore_tell}{$name}; |
192 | |
207 | |
193 | if ($other->ob->{ext_ignore_tell}{$name} < time) { |
208 | if ($other->ob->{ext_ignore_tell}{$name} < time) { |
194 | utf8::encode $args; # ->message not yet utf8-ified |
209 | utf8::encode $args; # ->message not yet utf8-ified |