d3hog/libs/diabloclass.php
Andrew Tomaka 4124cd55f3 Abstract Stats Collection
Abstract the stats collection portions of DPClass so that additional
providers might easily be substituted in the future.  Initial abstract
is weak and can expand when an additional provider is actually found.
2013-03-05 00:22:17 -05:00

88 lines
2.4 KiB
PHP

<?php
class DiabloClassFactory {
function createClassObject($class, $stats) {
if(!DiabloClassFactory::isValidClass($class)) {
return false;
}
include_once(__DIR__ . "/$class.php");
return new $class($stats);
}
private
function isValidClass($class) {
$classes = array(
'barbarian',
'demonhunter'
);
return in_array($class, $classes);
}
}
class DiabloClass {
var $class;
var $stats = array();
function __construct($stats) {
$this->stats = $stats;
}
function hallScore() {
return $this->DPSScore() * $this->EHPScore() * $this->sustainScore()
* $this->moveScore() * $this->paragonScore() * $this->miscScore();
}
function DPSScore() {
return $this->stats->getStat('DPS Unbuffed') / 1000;
}
function EHPScore() {
$ehp = $this->stats->getStat('EHP Unbuffed');
if($ehp < 1000000) {
return $ehp / 10000;
} elseif(1000000 <= $ehp && $ehp <= 2000000) {
return 100 + ($ehp - 1000000) / 20000;
} elseif(2000000 <= $ehp && $ehp <= 5000000) {
return 150 + ($ehp - 2000000) / 40000;
} elseif($ehp >= 5000000) {
return 225 + ($ehp - 5000000) / 100000;
}
}
function sustainScore() {
$effectiveLS = $this->stats->getStat('DPS Unbuffed') *
$this->stats->getStat('Life Steal') * .5;
$mitigation = $this->stats->getStat('EHP Unbuffed') / $this->stats->getStat('Life');
$rawSustainScore = 1 + $mitigation * ($this->stats->getStat('Life on Hit') *
(1 + ($this->stats->getStat('Attacks per Second') - 1) / 2) +
$effectiveLS + $this->stats->getStat('Life per Second')) /
($this->stats->getStat('Life') * $this->EHPScore() * 10000 /
$this->stats->getStat('EHP Unbuffed'));
if($rawSustainScore <= 1.5) {
return $rawSustainScore;
} elseif(1.5 < $rawSustainScore && $rawSustainScore <= 2) {
return 1.5 + ($rawSustainScore - 1.5) / 2;
} elseif(2 < $rawSustainScore && $rawSustainScore <= 3) {
return 1.75 + ($rawSustainScore - 2) / 4;
} else {
return 2 + ($rawSustainScore - 3) / 10;
}
}
function moveScore() {
return ($this->stats->getStat('Movement Speed') > .25) ? 1.25 : 1 + $this->stats->getStat('Movement Speed');
}
function paragonScore() {
return 1 + $this->stats->getStat('Paragon Level') / 2 / 100;
}
function miscScore() {
return 1;
}
}