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 | |
… | |
… | |
47 | }; |
51 | }; |
48 | |
52 | |
49 | cf::register_command say => 0, sub { |
53 | cf::register_command say => 0, sub { |
50 | my ($who, $msg) = @_; |
54 | my ($who, $msg) = @_; |
51 | |
55 | |
|
|
56 | utf8::decode $msg; |
|
|
57 | |
|
|
58 | return if $who->contr->invoke (cf::EVENT_PLAYER_SAY, $msg); |
|
|
59 | |
52 | if ($msg) { |
60 | if ($msg) { |
53 | my $name = $who->name; |
61 | my $name = $who->name; |
54 | |
62 | |
|
|
63 | utf8::encode $msg; # ->message not yet utf8-ified |
55 | $_->ob->message ("$name says: $msg", cf::NDI_GREY | cf::NDI_UNIQUE) |
64 | $_->ob->message ("$name says: $msg", cf::NDI_GREY | cf::NDI_UNIQUE) |
56 | for grep $who->on_same_map_as ($_->ob), cf::player::list; |
65 | for grep $who->on_same_map_as ($_->ob), cf::player::list; |
|
|
66 | utf8::decode $msg; |
57 | |
67 | |
58 | # npcs, magic_ears etc. |
68 | # npcs, magic_ears etc. |
59 | # first find all objects and their inventories within a 5x5 square |
69 | # first find all objects and theirt-level inventories |
60 | # that have something resembling dialogue |
70 | # within a 5x5 square # that have something resembling |
|
|
71 | # dialogue or support on_say. |
61 | 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); |
62 | |
73 | |
63 | for my $npc ( |
74 | for my $npc ( |
64 | grep NPC_Dialogue::has_dialogue $_, |
75 | grep +($_->invoke (cf::EVENT_OBJECT_SAY, $who, $msg) && return) || NPC_Dialogue::has_dialogue $_, |
65 | map +($_, $_->inv), |
76 | map +($_, $_->inv), |
66 | grep $_, |
77 | grep $_, |
67 | map $map->at ($x + $_ % 5, $y + (int $_ / 5)), |
78 | map $map->at ($x + $_ % 5, $y + (int $_ / 5)), |
68 | 0..24 |
79 | 0..24 |
69 | ) { |
80 | ) { |
… | |
… | |
100 | }; |
111 | }; |
101 | |
112 | |
102 | cf::register_command chat => 0, sub { |
113 | cf::register_command chat => 0, sub { |
103 | my ($who, $msg) = @_; |
114 | my ($who, $msg) = @_; |
104 | |
115 | |
|
|
116 | utf8::decode $msg; |
|
|
117 | |
|
|
118 | return if $who->contr->invoke (cf::EVENT_PLAYER_CHAT, $msg); |
|
|
119 | |
105 | if ($msg) { |
120 | if ($msg) { |
106 | my $name = $who->name; |
121 | my $name = $who->name; |
107 | my $NOW = time; |
122 | my $NOW = time; |
108 | |
123 | |
|
|
124 | utf8::encode $msg; # ->message not yet utf8-ified |
109 | 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); |
110 | |
127 | |
111 | $_->ob->message ("$name chats: $msg", cf::NDI_BLUE) |
128 | $_->ob->message ("$name chats: $msg", cf::NDI_BLUE) |
112 | 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; |
113 | |
130 | |
114 | } else { |
131 | } else { |
… | |
… | |
116 | } |
133 | } |
117 | }; |
134 | }; |
118 | |
135 | |
119 | cf::register_command shout => 0, sub { |
136 | cf::register_command shout => 0, sub { |
120 | my ($who, $msg) = @_; |
137 | my ($who, $msg) = @_; |
|
|
138 | |
|
|
139 | utf8::decode $msg; |
|
|
140 | |
|
|
141 | return if $who->contr->invoke (cf::EVENT_PLAYER_SHOUT, $msg); |
121 | |
142 | |
122 | if ($msg) { |
143 | if ($msg) { |
123 | my $NOW = time; |
144 | my $NOW = time; |
124 | my $name = $who->name; |
145 | my $name = $who->name; |
125 | |
146 | |
126 | 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 "{%s} %s\n", $name, $msg); |
127 | |
149 | |
|
|
150 | utf8::encode $msg; # ->message not yet utf8-ified |
128 | $_->ob->message ("$name shouts: $msg", cf::NDI_RED) |
151 | $_->ob->message ("$name shouts: $msg", cf::NDI_RED) |
129 | 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; |
130 | |
153 | |
131 | } else { |
154 | } else { |
132 | $who->message ("Shout what?", cf::NDI_UNIQUE); |
155 | $who->message ("Shout what?", cf::NDI_UNIQUE); |
… | |
… | |
135 | }; |
158 | }; |
136 | |
159 | |
137 | cf::register_command tell => 0, sub { |
160 | cf::register_command tell => 0, sub { |
138 | my ($who, $args) = @_; |
161 | my ($who, $args) = @_; |
139 | my ($target, $msg) = split /\s+/, $args, 2; |
162 | my ($target, $msg) = split /\s+/, $args, 2; |
|
|
163 | |
|
|
164 | utf8::decode $msg; |
|
|
165 | |
|
|
166 | return if $who->contr->invoke (cf::EVENT_PLAYER_TELL, $target, $msg); |
140 | |
167 | |
141 | my $name = $who->name; |
168 | my $name = $who->name; |
142 | |
169 | |
143 | if (my $other = cf::player::find $target) { |
170 | if (my $other = cf::player::find $target) { |
144 | |
171 | |
… | |
… | |
146 | if ($target eq $name) { |
173 | if ($target eq $name) { |
147 | $who->message ("You are talking to yourself, you freak!", cf::NDI_UNIQUE); |
174 | $who->message ("You are talking to yourself, you freak!", cf::NDI_UNIQUE); |
148 | } elsif ($other->ob->{ext_ignore_tell}{$name} >= time) { |
175 | } elsif ($other->ob->{ext_ignore_tell}{$name} >= time) { |
149 | $who->message ("$target ignores what you say. Give up on it.", cf::NDI_UNIQUE); |
176 | $who->message ("$target ignores what you say. Give up on it.", cf::NDI_UNIQUE); |
150 | } else { |
177 | } else { |
|
|
178 | utf8::encode $msg; # ->message not yet utf8-ified |
151 | cf::LOG cf::llevDebug, sprintf "TELL [%s>%s] %s\n", $name, $target, $msg; |
179 | cf::LOG cf::llevDebug, sprintf "TELL [%s>%s] %s\n", $name, $target, $msg; |
152 | |
180 | |
153 | $who->message ("You tell $target: $msg"); |
181 | $who->message ("You tell $target: $msg"); |
154 | $other->ob->message ("$name tells you: $msg"); |
182 | $other->ob->message ("$name tells you: $msg"); |
155 | $other->ob->{ext_last_tell} = $name; |
183 | $other->ob->{ext_last_tell} = $name; |
… | |
… | |
165 | |
193 | |
166 | cf::register_command reply => 0, sub { |
194 | cf::register_command reply => 0, sub { |
167 | my ($who, $args) = @_; |
195 | my ($who, $args) = @_; |
168 | my $name = $who->name; |
196 | my $name = $who->name; |
169 | |
197 | |
|
|
198 | utf8::decode $args; |
|
|
199 | |
|
|
200 | return if $who->contr->invoke (cf::EVENT_PLAYER_TELL, $who->{ext_last_tell}, $args); |
|
|
201 | |
170 | if (my $other = cf::player::find $who->{ext_last_tell}) { |
202 | if (my $other = cf::player::find $who->{ext_last_tell}) { |
|
|
203 | |
171 | if ($args) { |
204 | if ($args) { |
172 | |
|
|
173 | $other->ob->{ext_ignore_tell}{$name} >= time |
205 | $other->ob->{ext_ignore_tell}{$name} >= time |
174 | or delete $other->ob->{ext_ignore_tell}{$name}; |
206 | or delete $other->ob->{ext_ignore_tell}{$name}; |
175 | |
207 | |
176 | if ($other->ob->{ext_ignore_tell}{$name} < time) { |
208 | if ($other->ob->{ext_ignore_tell}{$name} < time) { |
|
|
209 | utf8::encode $args; # ->message not yet utf8-ified |
177 | cf::LOG cf::llevDebug, sprintf "TELL [%s>%s] %s\n", $name, $other->ob->name, $args; |
210 | cf::LOG cf::llevDebug, sprintf "TELL [%s>%s] %s\n", $name, $other->ob->name, $args; |
178 | |
211 | |
179 | $who->message ("You tell " . $other->ob->name . ": $args"); |
212 | $who->message ("You tell " . $other->ob->name . ": $args"); |
180 | $other->ob->message ("$name tells you: $args"); |
213 | $other->ob->message ("$name tells you: $args"); |
181 | $who->{ext_last_tell} = $other->ob->name; |
214 | $who->{ext_last_tell} = $other->ob->name; |