# MCL Corpse Rep by Urquart
print "${BGreen}Loading corpse.pl\n";

my %corpsestocheck = ();
my $checkcorpse = 0;
my $corpses = 1;
my $checkcheckcorpse = 0;
my $corpsestring = "\n${BGreen}CORPSEREPORT ${BCyan}for ${BYellow}MCL ${BCyan}by ${BGreen}Urquart";
my $ccorpsestring = "%l${col_G}CORPSEREPORT ${col_C}for ${col_Y}MCL ${col_C}by ${col_G}Urquart";

my $counter = 0;

sub cmd_showcorpse { print "$corpsestring"; }
sub cmd_chatcorpse { run("/chatall emote $ccorpsestring"); }

sub cmd_corpseon {
        $corpsestring = "\n${BGreen}CORPSEREPORT ${BCyan}for ${BYellow}MCL ${BCyan}by ${BGreen}Urquart";
        $ccorpsestring = "%l${col_G}CORPSEREPORT ${col_C}for ${col_Y}MCL ${col_C}by ${col_G}Urquart";
	$corpses = 0;
	$checkcheckcorpse = 1;
	run("c loc corpse");
}

sub corpsetrig {
	if (/(.*)Press return or Q/) {
	 if ($checkcorpse == 1) { run("\n"); }
	}
	if (/the corpse of (.*) in (.*)/) {
	 if ($checkcorpse == 1) {
	  foreach $corpsestocheck (keys %corpsestocheck) {
	   if ($1 eq $corpsestocheck) {
     	    $corpses = $corpses + 1;
            $ccorpsestring = "$ccorpsestring%l${col_B}$corpses. ${col_G}$1 ${col_W}- ${col_Y}$2 ";
	    $corpsestring = "$corpsestring\n${BBlue}$corpses. ${BGreen}$1 ${White}- ${BYellow}$2 ";
	   }
	  }
	 }
	}
	if (/You chant out the arcane words and are drained of 20 mana./) {
         if ($checkcheckcorpse == 1) {
  	  $checkcorpse = 1;
	  $checkcheckcorpse = 0;
         }
	}	 
}

sub cmd_corpseadd {
 s/\n//g;
 if (/^.{3,}$/) {
  $corpsestocheck{$_} = 0;
  print "\n${BGreen}Corpse${BWhite}: '${BYellow}$_${BWhite}' added to list.\n" unless $Loading;
 }
}

sub cmd_corpsedel {
 s/\n//g;
 $counter = 0;
 if (/^(\d+)/) {
   # Remove a certain corpse
    foreach (keys %corpsestocheck) {
      if (++$counter == $1) {
        print "\n${BGreen}Deleted corpse${BWhite}: ${BYellow}$_\n";
        delete $corpsestocheck{$_};
        return;
      }
    }
    print "\n${BGreen}No such corpse ${BWhite}(${BYellow}there are only $count!${BWhite}) - ${BBlue}type corpselist to see a list.\n";
   }
}

sub cmd_corpselist {
 s/\n//g;
 $counter = 0;
 print "\n${BGreen}CORPSEREPORT ${White}for ${BYellow}MCL ${White}by ${BBlue}Urquart\n";
 foreach (keys %corpsestocheck) {
      printf "${BGreen}%2d. ${BYellow}$_\n${White}", ++$counter, $corpsestocheck{$_};
    }
 $counter = 0;
}

sub savecorpses {
  local (*FH) = $_[0];
  foreach (keys %corpsestocheck) {
    print FH "corpse $_\n";
  }
}

save_add(\&savecorpses);
output_add(\&corpsetrig);
load_add("corpse", \&cmd_corpseadd);


#1;