#! /usr/bin/perl -w
use strict;
use diagnostics;

#####################
# Given set of stats, calc
# battle stats.
#####################
# Formula:
# Stat * ((((Level**2)/sqrt(Level)) / Level) +BASE_VALUE)
#####################

### These are the 4 test stats... only have 1 uncommented at a time.
### order: Power(0), Quickness(1), Toughness(2), Intellect(3), Will(4), Presense(5)
#my @stats	= (4, 2, 4, 6, 4, 1);  ## 4+2+4+6+4+1 = 6+10+6 = 21
#my @stats	= (5, 4, 1, 5, 5, 1);  ## 5+4+1+5+5+1 = 9+6+6  = 21
#my @stats	= (6, 5, 2, 1, 5, 2);  ## 6+5+2+1+5+2 = 11+3+7 = 21
my @stats	= (2, 3, 5, 4, 1, 6);  ## 2+3+5+4+1+6 = 5+9+7  = 21

my $BASE_HP		= 9;
my $BASE_LEVEL		= 1;
my ($hit_points, $attack, $defense, $accuracy,
	 $evasion, $min_damage, $max_damage, $crit, $exp_bonus);

$BASE_LEVEL = 1;

my $messy = (((($BASE_LEVEL*$BASE_LEVEL) / (sqrt($BASE_LEVEL)) / $BASE_LEVEL) + $BASE_LEVEL));

calcAttack();
calcDefense();
calcAccuracy();
calcEvasion();
calcHitPoints();
calcDamage();
calcCritical();
calcExpBonus();

sub calcAttack {
 ## Based on Power (0)
 $attack = int($stats[0] * $messy);
 print "Attack = $attack\n";
}

sub calcDefense {
 ## Based on Toughness (2)
 $defense = int($stats[2] * $messy);
 print "Defense = $defense\n";
}


sub calcAccuracy {
 ## Based on Intellect (3)
 $accuracy = int($stats[3] * $messy);
 print "Accuracy = $accuracy\n";
}

sub calcEvasion {
 ## Based on Quickness (1)
 $evasion = int($stats[1] * $messy);
 print "Evasion = $evasion\n";
}

sub calcHitPoints {
 ## Based on Will (4)
 $hit_points = int($stats[4] * (((($BASE_LEVEL*$BASE_LEVEL) / (sqrt($BASE_LEVEL)) / $BASE_LEVEL) + ($BASE_HP + $BASE_LEVEL))));
 print "Hit Points = $hit_points\n";
}

sub calcDamage {
 $min_damage = int(($stats[0] / 15) * $messy);
 $max_damage = int(($stats[0] / 4) * $messy);
 if ($min_damage == 0) { $min_damage++; }
 if ($max_damage == 0) { $max_damage++; }
 print "Damage = $min_damage - $max_damage\n";
}

sub calcCritical {
 ## Based on Intellect(3)
 $crit = ($stats[3] / 35);
 $crit = int($crit*10000);
 print "Crit Chance = $crit\n";
}

sub calcExpBonus {
 ## Based on Presense(5)
 $exp_bonus = int($stats[5] * (((($BASE_LEVEL*$BASE_LEVEL) / (sqrt($BASE_LEVEL)) / $BASE_LEVEL))) + $BASE_LEVEL) / 25;
 if ($exp_bonus > 3.99) { $exp_bonus = 4; } 
 $exp_bonus = int($exp_bonus*100);
 print "Exp Bonus = $exp_bonus\n";
}



