#!/mit/perl5/bin/perl -w

use strict;

my ($boss, $file);
if (0) {
    $boss="Ayamiss the Hunter";
    $file="log-ayamiss-all-060702.txt";
} else {
    $boss="Ossirian the Unscarred";
    $file="log-ossirian-all-060702.txt";
}
open(IN, $file) || die "crap.\n";
my %suffer;
my %resist;
my %outright_resist;
my $frost_hits;
while(<IN>) {
    next if /Shoot/;
    if (/$boss suffers (\d+) ([A-Za-z]+) [\sA-Za-z\'\.]+ \((\d+) resisted\)/) {
	$suffer{$2}+=$1;
	$resist{$2}+=$3;
    } elsif (/hits $boss for (\d+) ([A-Za-z]+) damage. \((\d+) resisted\)/) {
	$suffer{$2}+=$1;
	$resist{$2}+=$3;
    } elsif (/hits $boss for (\d+) ([A-Za-z]+) damage./) {
	$suffer{$2}+=$1;
	$frost_hits++ if ($2 eq "Frost");
    } elsif (/\w+\'s ([\w\s]+) was resisted by $boss/) {
	$outright_resist{$1}++;
    }
}
close(IN);
my ($suffer, $resist);
print "$boss\n\n";
print "\tby school:\n";
foreach my $type (sort keys %suffer) {
    next if $type eq "Physical";

    if ($type eq "Frost") {
	print "Frost: $frost_hits hits\n";
	next;
    }

    $suffer=$suffer{$type};
    $resist=$resist{$type};

    printf ("$type: %.2f%% resisted\n", $resist/($suffer+$resist)*100);
}
print "\n";
print "\tcompleted resisted spells:\n";
foreach my $spell (sort keys %outright_resist) {
    print "$spell: $outright_resist{$spell}\n";
}
