--- deliantra/server/ext/commands.ext 2007/03/02 10:44:56 1.22 +++ deliantra/server/ext/commands.ext 2007/03/02 10:54:59 1.23 @@ -89,6 +89,57 @@ 1 }; +cf::register_command applymode => sub { + my ($ob, $arg) = @_; + my @types = ("nochoice", "never", "always"); + my $mapping = { + nochoice => 1, + never => 2, + always => 3, + }; + + my $oldmode = $ob->contr->unapply; + my $oldmode_name = $types[$oldmode]; + + return $ob->reply (undef, "applymode is set to $oldmode_name") + unless $arg; + + return $ob->reply (undef, "applymode: Unknown options '$arg', valid options are @types") + unless $mapping->{$arg}; + + $ob->contr->unapply ($mapping->{$arg} - 1); # HACK: because of the $mapping->{$arg} check before, where $arg should not be 0 + # but $arg would be 0 if a user enters an incorrect value + $ob->reply (undef, "applymode" . ($oldmode == $ob->contr->unapply ? "" : " now") . " set to " . $types[$ob->contr->unapply]); + + 1 +}; + +cf::register_command petmode => sub { + my ($ob, $arg) = @_; + my @types = ("normal", "sad", "defend", "arena"); + my $mapping = { + normal => 1, + sad => 2, + defend => 3, + arena => 4, + }; + + my $oldtype = $ob->contr->petmode; + my $oldtype_name = $types[$oldtype]; + + return $ob->reply (undef, "petmode is set to $oldtype_name") + unless $arg; + + return $ob->reply (undef, "petmode: Unknown options '$arg', valid options are @types") + unless $mapping->{$arg}; + + $ob->contr->petmode ($mapping->{$arg} - 1); # HACK: because of the $mapping->{$arg} check before, where $arg should not be 0 + # but $arg would be 0 if a user enters an incorrect value + $ob->reply (undef, "petmode" . ($oldtype == $ob->contr->petmode ? "" : " now") . " set to " . $types[$ob->contr->petmode]); + + 1 +}; + cf::register_command usekeys => sub { my ($ob, $arg) = @_; my @types = ("inventory", "keyrings", "containers"); @@ -104,7 +155,7 @@ return $ob->reply (undef, "usekeys is set to $oldtype_name") unless $arg; - return $ob->reply (undef, "usekeys: Unknown options '$arg', valid options are inventory, keyrings, containers") + return $ob->reply (undef, "usekeys: Unknown options '$arg', valid options are @types") unless $mapping->{$arg}; $ob->contr->usekeys ($mapping->{$arg} - 1); # HACK: because of the $mapping->{$arg} check before, where $arg should not be 0