ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/ext/commands.ext
(Generate patch)

Comparing deliantra/server/ext/commands.ext (file contents):
Revision 1.27 by pippijn, Fri Mar 2 11:41:14 2007 UTC vs.
Revision 1.38 by root, Sun Mar 18 03:05:40 2007 UTC

1#! perl 1#! perl # MANDATORY
2 2
3use POSIX (); 3use POSIX ();
4 4
5# miscellaneous commands 5# miscellaneous commands
6 6
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
118cf::register_command who => sub { 118cf::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
140for my $cmd ("run", "fire") {
141 my $oncmd = "${cmd}_on";
142 cf::register_command $cmd => sub {
119 my ($ob, $arg) = @_; 143 my ($ob, $arg) = @_;
120 144
121 $ob->speed_left ($ob->speed_left - 0.25); 145 $ob->reply (undef, "Can't $cmd into a non adjacent square.")
146 if $arg < 0 or $arg >= 9;
122 147
123 $ob->reply (undef, (join "\n", who_listing $ob->may ("extended_who")), cf::NDI_UNIQUE | cf::NDI_DK_ORANGE); 148 $ob->contr->$oncmd (1);
124 149 $ob->move_player ($arg);
150
151 1
152 };
125 1 153
126}; 154 cf::register_command "${cmd}_stop" => sub {
155 my ($ob) = @_;
156
157 $ob->contr->$oncmd (0);
158
159 1
160 };
161}
127 162
128cf::register_command mapinfo => sub { 163cf::register_command mapinfo => sub {
129 my ($ob) = @_; 164 my ($ob) = @_;
130 165
131 my $map = $ob->map 166 my $map = $ob->map
146 $ob->reply (undef, (sprintf "You are %s.\n%s", $reg->longname, $reg->msg)); 181 $ob->reply (undef, (sprintf "You are %s.\n%s", $reg->longname, $reg->msg));
147 182
148 1 183 1
149}; 184};
150 185
186sub _set_mode($$$@) {
187 my ($name, $ob, $arg, $slot, @choices) = @_;
188
189 my $oldmode = $ob->contr->$slot;
190
191 return $ob->reply (undef, "$name is set to $choices[$oldmode]")
192 unless $arg;
193
194 my ($idx) = grep $choices[$_] eq $arg, 0 .. $#choices
195 or return $ob->reply (undef, "$name: Unknown options '$arg', valid options are @choices"), 1;
196
197 $ob->contr->$slot ($idx);
198 $ob->reply (undef, "$name" . ($oldmode == $ob->contr->unapply ? "" : " now") . " set to " . $choices[$ob->contr->$slot]);
199}
200
151cf::register_command applymode => sub { 201cf::register_command applymode => sub {
152 my ($ob, $arg) = @_; 202 my ($ob, $arg) = @_;
153 my @types = ("nochoice", "never", "always");
154 my $mapping = {
155 nochoice => 1,
156 never => 2,
157 always => 3,
158 };
159 203
160 my $oldmode = $ob->contr->unapply; 204 _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 205
173 1 206 1
174}; 207};
175 208
176cf::register_command petmode => sub { 209cf::register_command petmode => sub {
177 my ($ob, $arg) = @_; 210 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 211
186 my $oldtype = $ob->contr->petmode; 212 _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 213
199 1 214 1
200}; 215};
201 216
202cf::register_command usekeys => sub { 217cf::register_command usekeys => sub {
203 my ($ob, $arg) = @_; 218 my ($ob, $arg) = @_;
204 my @types = ("inventory", "keyrings", "containers");
205 my $mapping = {
206 inventory => 1,
207 keyrings => 2,
208 containers => 3,
209 };
210 219
211 my $oldtype = $ob->contr->usekeys; 220 _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 221
224 1 222 1
225}; 223};
226 224
227cf::register_command afk => sub { 225cf::register_command afk => sub {
249 $ob->reply (undef, $ob->contr->braced ? "You are braced." : "Not braced."); 247 $ob->reply (undef, $ob->contr->braced ? "You are braced." : "Not braced.");
250 248
251 1 249 1
252}; 250};
253 251
252cf::register_command 'output-rate' => sub {
253 my ($ob, $arg) = @_;
254
255 return $ob->reply (undef, sprintf "Output rate is presently %dbps.", $ob->contr->ns->max_rate / $cf::TICK)
256 unless $arg > 0;
257
258 $ob->contr->ns->max_rate ($arg * $cf::TICK);
259 $ob->reply (undef, sprintf "Output rate now set to %dbps.", $ob->contr->ns->max_rate / $cf::TICK);
260
261 1
262};
263
254cf::register_command 'output-count' => sub { 264cf::register_command 'output-count' => sub {
255 my ($ob, $arg) = @_; 265 my ($ob, $arg) = @_;
256 266
257 return $ob->reply (undef, "Output count is presently " . $ob->contr->outputs_count) 267 return $ob->reply (undef, "Output count is presently " . $ob->contr->outputs_count)
258 unless $arg > 0; 268 unless $arg > 0;
264}; 274};
265 275
266cf::register_command 'output-sync' => sub { 276cf::register_command 'output-sync' => sub {
267 my ($ob, $arg) = @_; 277 my ($ob, $arg) = @_;
268 278
269 return $ob->reply (undef, "Output sync time is presently " . $ob->contr->outputs_sync) 279 return $ob->reply (undef, sprintf "Output sync time is presently %.1fs", $ob->contr->outputs_sync * $cf::TICK)
270 unless $arg > 0; 280 unless length $arg;
271 281
272 $ob->contr->outputs_sync ($arg); 282 $ob->contr->outputs_sync ($arg / $cf::TICK);
273 $ob->reply (undef, "Output sync time now set to " . $ob->contr->outputs_sync); 283 $ob->reply (undef, sprintf "Output sync time now set to %.1fs", $ob->contr->outputs_sync * $cf::TICK);
274 284
275 1 285 1
276}; 286};
277 287
278# XXX: This has a bug. After one sets his wimpy level to 0 and resets it to 288# XXX: This has a bug. After one sets his wimpy level to 0 and resets it to

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines