… | |
… | |
17 | |
17 | |
18 | if (length $from) { |
18 | if (length $from) { |
19 | $item = $ob->find_best_object_match ($from) |
19 | $item = $ob->find_best_object_match ($from) |
20 | or return $ob->message ("rename: could not find a matching item to rename."); |
20 | or return $ob->message ("rename: could not find a matching item to rename."); |
21 | } else { |
21 | } else { |
22 | $item = $ob->find_marked_object () |
22 | $item = $ob->find_marked_object |
23 | or return $ob->message ("rename: no from name and no marked item found to rename."); |
23 | or return $ob->message ("rename: no from name and no marked item found to rename."); |
24 | } |
24 | } |
25 | |
25 | |
26 | $item->custom_name (length $to ? $to : undef); |
26 | $item->custom_name (length $to ? $to : undef); |
27 | |
27 | |
… | |
… | |
113 | unless $ob->flag (cf::FLAG_USE_WEAPON); |
113 | unless $ob->flag (cf::FLAG_USE_WEAPON); |
114 | |
114 | |
115 | 1 |
115 | 1 |
116 | }; |
116 | }; |
117 | |
117 | |
|
|
118 | cf::register_command mark => sub { |
|
|
119 | my ($pl, $arg) = @_; |
|
|
120 | |
|
|
121 | if (length $arg) { |
|
|
122 | my $ob = $pl->find_best_object_match ($arg); |
|
|
123 | |
|
|
124 | return $pl->reply (undef, "Could not find an object that matches $arg") |
|
|
125 | unless $ob; |
|
|
126 | |
|
|
127 | $pl->contr->mark ($ob); |
|
|
128 | $pl->reply (undef, (sprintf "Marked item %s", $ob->name, $ob->title)); |
|
|
129 | } else { |
|
|
130 | my $ob = $pl->find_marked_object; |
|
|
131 | |
|
|
132 | $pl->reply (undef, $ob |
|
|
133 | ? (sprintf "%s %s * is marked.", $ob->name, $ob->title) |
|
|
134 | : "You have no marked object."); |
|
|
135 | } |
|
|
136 | |
|
|
137 | 1 |
|
|
138 | }; |
|
|
139 | |
118 | cf::register_command who => sub { |
140 | cf::register_command who => sub { |
119 | my ($ob, $arg) = @_; |
141 | my ($ob, $arg) = @_; |
120 | |
142 | |
121 | $ob->speed_left ($ob->speed_left - 0.25); |
143 | $ob->speed_left ($ob->speed_left - 0.25); |
122 | |
144 | |
123 | $ob->reply (undef, (join "\n", who_listing $ob->may ("extended_who")), cf::NDI_UNIQUE | cf::NDI_DK_ORANGE); |
145 | $ob->reply (undef, (join "\n", who_listing $ob->may ("extended_who")), cf::NDI_UNIQUE | cf::NDI_DK_ORANGE); |
124 | |
146 | |
125 | 1 |
147 | 1 |
126 | }; |
148 | }; |
|
|
149 | |
|
|
150 | for my $cmd ("run", "fire") { |
|
|
151 | my $oncmd = "${cmd}_on"; |
|
|
152 | cf::register_command $cmd => sub { |
|
|
153 | my ($ob, $arg) = @_; |
|
|
154 | |
|
|
155 | $ob->reply (undef, "Can't $cmd into a non adjacent square.") |
|
|
156 | if $arg < 0 or $arg >= 9; |
|
|
157 | |
|
|
158 | $ob->contr->$oncmd (1); |
|
|
159 | $ob->move_player ($arg); |
|
|
160 | |
|
|
161 | 1 |
|
|
162 | }; |
|
|
163 | |
|
|
164 | cf::register_command "${cmd}_stop" => sub { |
|
|
165 | my ($ob) = @_; |
|
|
166 | |
|
|
167 | $ob->contr->$oncmd (0); |
|
|
168 | |
|
|
169 | 1 |
|
|
170 | }; |
|
|
171 | } |
127 | |
172 | |
128 | cf::register_command mapinfo => sub { |
173 | cf::register_command mapinfo => sub { |
129 | my ($ob) = @_; |
174 | my ($ob) = @_; |
130 | |
175 | |
131 | my $map = $ob->map |
176 | my $map = $ob->map |
… | |
… | |
146 | $ob->reply (undef, (sprintf "You are %s.\n%s", $reg->longname, $reg->msg)); |
191 | $ob->reply (undef, (sprintf "You are %s.\n%s", $reg->longname, $reg->msg)); |
147 | |
192 | |
148 | 1 |
193 | 1 |
149 | }; |
194 | }; |
150 | |
195 | |
|
|
196 | sub _set_mode($$$@) { |
|
|
197 | my ($name, $ob, $arg, $slot, @choices) = @_; |
|
|
198 | |
|
|
199 | my $oldmode = $ob->contr->$slot; |
|
|
200 | |
|
|
201 | return $ob->reply (undef, "$name is set to $choices[$oldmode]") |
|
|
202 | unless $arg; |
|
|
203 | |
|
|
204 | my ($idx) = grep $choices[$_] eq $arg, 0 .. $#choices |
|
|
205 | or return $ob->reply (undef, "$name: Unknown options '$arg', valid options are @choices"), 1; |
|
|
206 | |
|
|
207 | $ob->contr->$slot ($idx); |
|
|
208 | $ob->reply (undef, "$name" . ($oldmode == $ob->contr->unapply ? "" : " now") . " set to " . $choices[$ob->contr->$slot]); |
|
|
209 | } |
|
|
210 | |
151 | cf::register_command applymode => sub { |
211 | cf::register_command applymode => sub { |
152 | my ($ob, $arg) = @_; |
212 | my ($ob, $arg) = @_; |
153 | my @types = ("nochoice", "never", "always"); |
|
|
154 | my $mapping = { |
|
|
155 | nochoice => 1, |
|
|
156 | never => 2, |
|
|
157 | always => 3, |
|
|
158 | }; |
|
|
159 | |
213 | |
160 | my $oldmode = $ob->contr->unapply; |
214 | _set_mode "applymode", $ob, $arg, unapply => qw(nochoice never always); |
161 | my $oldmode_name = $types[$oldmode]; |
|
|
162 | |
|
|
163 | return $ob->reply (undef, "applymode is set to $oldmode_name") |
|
|
164 | unless $arg; |
|
|
165 | |
|
|
166 | return $ob->reply (undef, "applymode: Unknown options '$arg', valid options are @types") |
|
|
167 | unless $mapping->{$arg}; |
|
|
168 | |
|
|
169 | $ob->contr->unapply ($mapping->{$arg} - 1); # HACK: because of the $mapping->{$arg} check before, where $arg should not be 0 |
|
|
170 | # but $arg would be 0 if a user enters an incorrect value |
|
|
171 | $ob->reply (undef, "applymode" . ($oldmode == $ob->contr->unapply ? "" : " now") . " set to " . $types[$ob->contr->unapply]); |
|
|
172 | |
215 | |
173 | 1 |
216 | 1 |
174 | }; |
217 | }; |
175 | |
218 | |
176 | cf::register_command petmode => sub { |
219 | cf::register_command petmode => sub { |
177 | my ($ob, $arg) = @_; |
220 | my ($ob, $arg) = @_; |
178 | my @types = ("normal", "sad", "defend", "arena"); |
|
|
179 | my $mapping = { |
|
|
180 | normal => 1, |
|
|
181 | sad => 2, |
|
|
182 | defend => 3, |
|
|
183 | arena => 4, |
|
|
184 | }; |
|
|
185 | |
221 | |
186 | my $oldtype = $ob->contr->petmode; |
222 | _set_mode "petmode", $ob, $arg, petmode => qw(normal sad defend arena); |
187 | my $oldtype_name = $types[$oldtype]; |
|
|
188 | |
|
|
189 | return $ob->reply (undef, "petmode is set to $oldtype_name") |
|
|
190 | unless $arg; |
|
|
191 | |
|
|
192 | return $ob->reply (undef, "petmode: Unknown options '$arg', valid options are @types") |
|
|
193 | unless $mapping->{$arg}; |
|
|
194 | |
|
|
195 | $ob->contr->petmode ($mapping->{$arg} - 1); # HACK: because of the $mapping->{$arg} check before, where $arg should not be 0 |
|
|
196 | # but $arg would be 0 if a user enters an incorrect value |
|
|
197 | $ob->reply (undef, "petmode" . ($oldtype == $ob->contr->petmode ? "" : " now") . " set to " . $types[$ob->contr->petmode]); |
|
|
198 | |
223 | |
199 | 1 |
224 | 1 |
200 | }; |
225 | }; |
201 | |
226 | |
202 | cf::register_command usekeys => sub { |
227 | cf::register_command usekeys => sub { |
203 | my ($ob, $arg) = @_; |
228 | my ($ob, $arg) = @_; |
204 | my @types = ("inventory", "keyrings", "containers"); |
|
|
205 | my $mapping = { |
|
|
206 | inventory => 1, |
|
|
207 | keyrings => 2, |
|
|
208 | containers => 3, |
|
|
209 | }; |
|
|
210 | |
229 | |
211 | my $oldtype = $ob->contr->usekeys; |
230 | _set_mode "usekeys", $ob, $arg, usekeys => qw(inventory keyrings containers); |
212 | my $oldtype_name = $types[$oldtype]; |
|
|
213 | |
|
|
214 | return $ob->reply (undef, "usekeys is set to $oldtype_name") |
|
|
215 | unless $arg; |
|
|
216 | |
|
|
217 | return $ob->reply (undef, "usekeys: Unknown options '$arg', valid options are @types") |
|
|
218 | unless $mapping->{$arg}; |
|
|
219 | |
|
|
220 | $ob->contr->usekeys ($mapping->{$arg} - 1); # HACK: because of the $mapping->{$arg} check before, where $arg should not be 0 |
|
|
221 | # but $arg would be 0 if a user enters an incorrect value |
|
|
222 | $ob->reply (undef, "usekeys" . ($oldtype == $ob->contr->usekeys ? "" : " now") . " set to " . $types[$ob->contr->usekeys]); |
|
|
223 | |
231 | |
224 | 1 |
232 | 1 |
225 | }; |
233 | }; |
226 | |
234 | |
227 | cf::register_command afk => sub { |
235 | cf::register_command afk => sub { |