changeset 344:55edb7d42ce4 misc

Possibly improve spell crit detection/handling.
author Matti Hamalainen <ccr@tnsp.org>
date Wed, 10 Aug 2016 00:21:04 +0300
parents 9267d2b51e57
children 4dce0dd371a5
files magestats.pl
diffstat 1 files changed, 21 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/magestats.pl	Tue Aug 09 23:06:01 2016 +0300
+++ b/magestats.pl	Wed Aug 10 00:21:04 2016 +0300
@@ -224,6 +224,7 @@
 my $essence_flag = 0;
 my $crit_flag = 0;
 my $crit_type;
+my $crit_dist;
 my $last_spell = "";
 my $staff_worn = 0;
 my $spell_active = 0;
@@ -270,8 +271,21 @@
 }
 
 
+sub crit_update()
+{
+  if ($crit_flag) {
+    my $type = get_spell_type($last_spell);
+#    print STDERR "crit: $type : $last_spell : $crit_type [$crit_dist]\n";
+    $$spells{$type}{"crits"}{$crit_type}++;
+    $crit_flag = 0;
+  }
+}
+
+
 sub spell_update($)
 {
+  crit_update();
+
   $last_spell = $_[0];
 
   $spell_active = $nline;
@@ -306,13 +320,6 @@
       }
     }
   }
-
-  # Crit hits
-  if ($crit_flag) {
-    $crit_flag = 0;
-#    print STDERR "crit: $type : $last_spell : $crit_type\n";
-    $$spells{$type}{"crits"}{$crit_type}++;
-  }
 }
 
 
@@ -396,10 +403,15 @@
       $s =~ /^You feel like you managed to channel additional (POWER) to your spell\./ ||
       $s =~ /^You feel like your spell gained additional (power)\./ ||
       $s =~ /^(Unseen) BURSTS of magic are absorbed into the spell/) {
-      $crit_type = $1;
-      $crit_flag = 1;
+      $crit_dist = $nline - $spell_active;
+      if ($spell_active > 0 && $crit_dist <= 5) {
+        $crit_type = $1;
+        $crit_flag = 1;
+      }
     }
   }
+
+  crit_update();
 }