#!/usr/bin/perl -w # Holy Lance research tool / logparser # (C) Copyright 2008 Matti 'ccr' Hämäläinen (Ggr Pupunen) # # Takes in (via stdin) a BatMUD logfile with lance research scroll # outputs (obtained via 'look at scroll') and parses the data, # and outputs an ANSI coloured table showing the researched words. # use strict; # Set this to 0, if you don't want, or can't use ANSI colours. my $useANSI = 1; # Nothing to touch here ... my @ansiColors = (31,31,31, 31,33,33, 32, 37); my @ansiAttr = ( 1, 1, 0, 0, 0, 1, 1, 1); my @positions = ("First", "Middle", "Last"); my %values = ( "Worthless" => 0, "Very very bad" => 1, "Very bad" => 2, "Bad" => 3, "Mediocre" => 4, "Good" => 5, "Very Good" => 6, "Perfect" => 7 ); ### ANSI colour output functions sub setANSI($) { if ($useANSI) { printf "\x1b[0;%d;%dm", $ansiAttr[$_[0] % scalar @ansiAttr], $ansiColors[$_[0] % scalar @ansiColors]; } } sub offANSI() { if ($useANSI) { printf "\x1b[0m"; } } ### Parse stdin as a logfile my %spellwords = (); while () { if (/^ (First|Middle|Last) +spellword +([A-Za-z']+) +Analysis: (.+)$/) { if ($2 ne "none") { my $def = defined($spellwords{$2}{$1}); if (!$def || ($def && $3 ne "Not casted")) { $spellwords{$2}{$1} = $3; } } } } ### Print output header my $s = sprintf "%-10s: ", "Chant"; foreach my $k (@positions) { $s .= sprintf "%-15s| ", $k; } print "$s\n"; $s =~ s/[^|]/-/g; $s =~ s/[|]/+/g; print "$s\n"; ### Print the table, alphabetically sorted by spellword my @sortedwords = sort { $a cmp $b } keys %spellwords; foreach my $word (@sortedwords) { printf "%-10s: ", $word; foreach my $k (@positions) { my $s = ""; if (defined($spellwords{$word}{$k})) { $s = $spellwords{$word}{$k}; } if (defined($values{$s})) { setANSI($values{$s}); } printf "%-15s", $s; offANSI(); print "| "; } print "\n"; }