#
# util.pl -- Perl module for misc. user commands.
#
# Sean Butler
#

print "${BGreen}Loading util.pl\n";    

$mob_num = 1;

%global_vars = ();

#--------------------------------------------------------------------
# lc : Look in corpses in a loop.
#
# USAGE: lc [number] 
# [number] = number of corpses, default = 1 
#
# Example: "lc 3"
# Performs:
# look in 1.corpse;
# look in 2.corpse;
# look in 3.corpse;
#---------------------------------------------------------------------
sub cmd_loots { run("lc $_"); }

sub cmd_lc {
    my $nCorpses = 1;
    if (/^\d+$/) {
	if ($_ > 0) {
	    $nCorpses = $_;
	}
    }
    else {
	print "USAGE: lc [number]\n";
	return 1;
    }
    for ($i = 1; $i <= $nCorpses; $i++) {
      run ("look in ${i}.corpse");
    }
}

#--------------------------------------------------------------------
# gc : Loot all corpses in a loop.
#
# USAGE: gc [number] 
# [number] = number of corpses, default = 1 
#
# Example: "gc 3"
# Performs:
# get all 1.corpse;get all 2.corpse;get all 3.corpse
#---------------------------------------------------------------------
sub cmd_gc {
    my $nCorpses = 1;
    if (/^\d+$/) {
	if ($_ > 0) {
	    $nCorpses = $_;
	}
    }
    else {
	print "USAGE: gc [number]\n";
	return 1;
    }
    for ($i = 1; $i <= $nCorpses; $i++) {
      run("get all ${i}.corpse");
    }
}

#--------------------------------------------------------------------
# tc : Sacrifice (tap) all corpses in a loop.
#
# USAGE: tc [number] 
# [number] = number of corpses, default = 1 
#
# Example: "tc 3"
# Performs:
# sac corpse;sac corpse;sac corpse
#---------------------------------------------------------------------
sub cmd_tc {
    my $nCorpses = 1;
    if (/^\d+$/) {
	if ($_ > 0) {
	    $nCorpses = $_;
	}
    }
    else {
	print "USAGE: tc [number]\n";
	return 1;
    }
    for ($i=0; $i < $nCorpses; $i++) {
	run("sac corpse");
    }
}

#--------------------------------------------------------------------
# ga : Loot a corpse by number.
#
# USAGE: ga <number>
# <number> = number of corpse, default = 1 
#
# Example: "ga 3"
# Performs:
# get all 3.corpse
#---------------------------------------------------------------------
sub cmd_ga {
    my $nCorpse;
    if (/^(\w+)\s+(\d+)$/) {
	$sItem = $1;
	$nCorpse = $2;
    }
    else {
	print "USAGE: ga <item> <number>\n";
	return 1;
    }
    if ($nCorpse < 1) {
	$nCorpse = 1;
    }
    run ("get all.${sItem} ${nCorpse}.corpse");
}

sub cmd_ll {
    my $sObject;
    my $nObject;
    if (/^(\d+)\s+(\w+)$/) {
	$nObject = $1;
	$sObject = $2;
    }
    else {
	print "USAGE: ll <number> <object>\n";
	return 1;
    }
    if ($nObject < 1) {
	$nObject = 1;
    }
    for ($i = 1; $i <= $nObject; $i++) {
      run("look ${i}.${sObject}");
    }
}

sub cmd_wn {
    my $sObject;
    my $nObject;
    $mob_num = 1;

    if (/^(\d+)\s+(\d+)\s+(\w+)$/) {
	$nObject = $1;
	$nMax    = $2;
	$sObject = $3;
    }
    else {
	print "USAGE: wn <number from> <number to> <mob>\n";
	return 1;
    }
    if ($nObject < 1) {
	$nObject = 1;
    }
    if ($nMax < 1) {
	$nMax = 1;
    }
    for ($mob_num = $nObject; $mob_num <= $nMax; $mob_num++) {
	run("who -n ${mob_num}.${sObject}");
    }
}

1;
