From 8af4bdee717e986b05b285370adb77868ea8cfcb Mon Sep 17 00:00:00 2001 From: ohle Date: Thu, 27 Jun 2013 21:29:40 +0200 Subject: [PATCH 1/3] colors for annotations-monsters --- plugins/annotations-monsters.pl | 141 ++++++++++++++++++++++---------- 1 file changed, 97 insertions(+), 44 deletions(-) diff --git a/plugins/annotations-monsters.pl b/plugins/annotations-monsters.pl index a87b1b3..9362d23 100644 --- a/plugins/annotations-monsters.pl +++ b/plugins/annotations-monsters.pl @@ -25,17 +25,22 @@ "X" => "explode", ); +my $ce = "\e[0m"; +my $instadeathc = $mc_instadeath || $colormap{'purple'}; +my $erosionc = $mc_erosion || $colormap{'brown'}; +my $helplessc = $mc_helpless || $colormap{'red'}; + my %damage_types = ( "A" => "acid", "C" => "cold", - "D" => "disint.", + "D" => $instadeathc."disint.$ce", "E" => "shock", "F" => "fire", "H" => "heal", "M" => "missiles", - "P" => "Poison", - "R" => "erode metal", - "S" => "sleep", + "P" => $instadeathc."poison$ce", + "R" => $erodec."erode metal$ce", + "S" => $helplessc."sleep$ce", "V" => "drain lev", "b" => "blind", "c" => "confuse", @@ -44,24 +49,24 @@ "h" => "hallu", "i" => "steal intrinsic", "m" => "stick", - "r" => "rot organics", + "r" => $erosionc."rot organics$ce", "s" => "stun", "t" => "teleport", - "w" => "wrap and drown", + "w" => $instadeathc."wrap and drown$ce", "x" => "prick legs", "z" => "special", - "." => "paralyse", + "." => $helplessc."paralyse$ce", "+" => "spell", "-" => "steal", - "\"" => "disenchant", - "&" => "disrobe", + "\"" => $erosionc."disenchant$ce", + "&" => $helplessc."disrobe$ce", "<" => "slow", "!C" => "drain con", "!D" => "drain dex", "!I" => "drain int", - "#" => "disease", + "#" => $instadeathc."disease$ce", "\$" => "steal \$", - "*" => "stone", + "*" => $instadeathc."stone$ce", "@" => "lycanthropy/slime", ); @@ -3105,53 +3110,101 @@ sub format_attacks $typestr .= $passive_attack_str{$passive} if $passive; $typestr .= ")" if ($dmgtype or $passive); + my $color = attackcolor($roll); if (!$first) { $result .= ", "; } $result .= "$attack_types{$kind} " if $kind; - $result .= $roll; + $result .= $color . $roll . ($color ? "\e[0m" : ""); $result .= " $typestr" if $typestr; if ($first) { $first = 0; } } return $result; }; -sub format_monster_annotation +sub attackstats { - my $name = shift; - my $s = "spd: $mondata{$name}{'spd'}; AC$mondata{$name}{'ac'}"; - $s .= "; MR: $mondata{$name}{'mr'}" if $mondata{$name}{'mr'} > 0; - if ($mondata{$name}{'resists'}) + my $attack = shift; + my ($dice, $sides) = $attack =~ /([0-9]+)d([0-9]+)?/; + my $min = $dice; + my $max = $min; + my $avg = $min; + if ($sides) { - $s .= "; resists "; - my $first = 1; - for my $r (split //, $mondata{$name}{'resists'}) - { - if (!$first) { $s .= ", "; } - $s .= $resist_types{lc $r}; - if ($first) { $first = 0; } - } + $avg = 0.5 * ($sides + 1) * $dice; + $max = $dice * $sides; } + return ($min, $avg, $max); +} - if ($mondata{$name}{'attacks'}) - { - $s .= "; attacks: " . format_attacks($mondata{$name}{'attacks'}); - } - return $s; -}; - +sub speedcolor +{ + my $name = shift; + + my $slowc = $mc_normalspeed || $colormap{'yellow'}; + my $fastc = $mc_fast || $colormap{'red'}; + my $vfastc = $mc_veryfast || $colormap{'bold&red'}; + + my $monspeed = $mondata{$name}{'spd'}; + my $spdcolor = ''; + if ($monspeed >= 12) { $spdcolor = $slowc; } #normal speed + if ($monspeed >= 16) { $spdcolor = $fastc; } #intrinsic speed + if ($monspeed >= 20) { $spdcolor = $vfastc; } #extrinsic speed +} + +sub attackcolor +{ + my $c1 = $mc_onehit || $colormap{'bold&red'}; + my $c2 = $mc_onehit || $colormap{'red'}; + my $c3 = $mc_onehit || $colormap{'yellow'}; + + my $attack = shift; + my ($min, $avg, $max) = attackstats($attack); + my $color = ""; + if (5*$max >= $curhp) { $color = $c3; } + if (2*$max >= $curhp) { $color = $c2; } + if (1*$max >= $curhp) { $color = $c1; } + return $color; +} + +# register annotations for my $monster (keys %mondata) { my $escaped_name = $monster; - $escaped_name =~ s/ /\\ /g; + $escaped_name =~ s/ /\\ /g; my $re = qr/ - ^(?:$species|~) - [^\(]+ - \( - (?:peaceful\ |tame\ |invisible\ |tail\ of\ a\ )? - $escaped_name - (?:\ called [\w\s]+)? - (?:, [\w\s]+)? # "holding you", "leashed to you" etc. - \) - \s+(?:\[seen:[^\]]+\]\s+)?$ - /x; - make_annotation $re => format_monster_annotation($monster); + ^(?:$species|~) + [^\(]+ + \( + (?:peaceful\ |tame\ |invisible\ |tail\ of\ a\ )? + $escaped_name + (?:\ called [\w\s]+)? + (?:, [\w\s]+)? # "holding you", "leashed to you" etc. + \) + \s+(?:\[seen:[^\]]+\]\s+)?$ + /x; + make_annotation $re => sub + { + my $spdcolor = speedcolor($monster); + my $s = $spdcolor . "spd: $mondata{$monster}{'spd'}" . ($spdcolor ? "\e[0m;" : ""); + + $s .= " AC$mondata{$monster}{'ac'}"; + $s .= "; MR: $mondata{$monster}{'mr'}" if $mondata{$monster}{'mr'} > 0; + if ($mondata{$monster}{'resists'}) + { + $s .= "; resists "; + my $first = 1; + for my $r (split //, $mondata{$monster}{'resists'}) + { + if (!$first) { $s .= ", "; } + $s .= $resist_types{lc $r}; + if ($first) { $first = 0; } + } + } + + if ($mondata{$monster}{'attacks'}) + { + $s .= "; attacks: " . format_attacks($mondata{$monster}{'attacks'}); + } + return $s; + }; } + From c61c2f0ca3a302cf3b618b1824efebaaa4f58ca3 Mon Sep 17 00:00:00 2001 From: ohle Date: Thu, 27 Jun 2013 22:11:21 +0200 Subject: [PATCH 2/3] fixed attack colors --- plugins/annotations-monsters.pl | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/plugins/annotations-monsters.pl b/plugins/annotations-monsters.pl index 9362d23..a4b8ca1 100644 --- a/plugins/annotations-monsters.pl +++ b/plugins/annotations-monsters.pl @@ -3152,14 +3152,14 @@ sub speedcolor sub attackcolor { - my $c1 = $mc_onehit || $colormap{'bold&red'}; - my $c2 = $mc_onehit || $colormap{'red'}; - my $c3 = $mc_onehit || $colormap{'yellow'}; + my $c1 = $mc_onehit || $colormap{'bold&red'}; + my $c2 = $mc_twohits || $colormap{'red'}; + my $c3 = $mc_threehits || $colormap{'yellow'}; my $attack = shift; my ($min, $avg, $max) = attackstats($attack); my $color = ""; - if (5*$max >= $curhp) { $color = $c3; } + if (3*$max >= $curhp) { $color = $c3; } if (2*$max >= $curhp) { $color = $c2; } if (1*$max >= $curhp) { $color = $c1; } return $color; From 7228183ce7ca27f4dd9232ca966f3ce521486b7c Mon Sep 17 00:00:00 2001 From: ohle Date: Mon, 1 Jul 2013 15:07:48 +0200 Subject: [PATCH 3/3] fix resetting of color --- plugins/annotations-monsters.pl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/annotations-monsters.pl b/plugins/annotations-monsters.pl index a4b8ca1..2a62b98 100644 --- a/plugins/annotations-monsters.pl +++ b/plugins/annotations-monsters.pl @@ -25,7 +25,7 @@ "X" => "explode", ); -my $ce = "\e[0m"; +my $ce = $colormap{'nhblack'}; my $instadeathc = $mc_instadeath || $colormap{'purple'}; my $erosionc = $mc_erosion || $colormap{'brown'}; my $helplessc = $mc_helpless || $colormap{'red'};