Merge branch 'feature-weapon_elemental'

This commit is contained in:
Andrew Tomaka 2012-11-26 03:14:08 -05:00
commit bbf58e4d31
2 changed files with 15 additions and 8 deletions

View file

@ -6,6 +6,7 @@ include_once(__DIR__ . '/libs/dpclass.php');
if($_POST['submit']) { if($_POST['submit']) {
$diabloProgressUrl = trim($_POST['url']); $diabloProgressUrl = trim($_POST['url']);
$elementalOnWeapon = isset($_POST['elemental']['elemental']) ? true : false;
if(preg_match('{^http://www.diabloprogress.com/hero/[\w]+\-[\d]+/[\w]+/[\d]+$}', $diabloProgressUrl) != 1) { if(preg_match('{^http://www.diabloprogress.com/hero/[\w]+\-[\d]+/[\w]+/[\d]+$}', $diabloProgressUrl) != 1) {
die('Bad URL. Please enter the entire diablo progress URL.<br/><br/>Example: http://www.diabloprogress.com/hero/celanian-1548/HsuMing/21706367'); die('Bad URL. Please enter the entire diablo progress URL.<br/><br/>Example: http://www.diabloprogress.com/hero/celanian-1548/HsuMing/21706367');
} }
@ -18,7 +19,7 @@ if($_POST['submit']) {
$contents = curl_exec($curl); $contents = curl_exec($curl);
curl_close($curl); curl_close($curl);
$character = DPClassFactory::createClassObject($contents); $character = DPClassFactory::createClassObject($contents, $elementalOnWeapon);
if($character === FALSE) { if($character === FALSE) {
die('Bad class. Either your class could not be detected or we do not support your class at this time.'); die('Bad class. Either your class could not be detected or we do not support your class at this time.');
@ -38,5 +39,6 @@ Paragon Score: <?php echo number_format($character->paragonScore(), 2, '.', ',')
?> ?>
<form method="POST"> <form method="POST">
D3 Progress URL: <input type="text" name="url" style="width:500px;" value="<?php echo $diabloProgressUrl ?>" /><br /> D3 Progress URL: <input type="text" name="url" style="width:500px;" value="<?php echo $diabloProgressUrl ?>" /><br />
Elemental Damage on Weapon: <input type="checkbox" name="elemental" value="elemental" <?php echo $elementalOnWeapon ? 'checked="checked"' : '' ?> /><br/>
<input type="submit" name="submit" /> <input type="submit" name="submit" />
</form> </form>

View file

@ -1,16 +1,16 @@
<?php <?php
class DPClassFactory { class DPClassFactory {
function createClassObject($characterPage) { function createClassObject($characterPage, $elementalOnWeapon) {
$class = DPClassFactory::findClass($characterPage); $class = DPClassFactory::findClass($characterPage);
include_once(__DIR__ . "/$class.php"); include_once(__DIR__ . "/$class.php");
switch($class) { switch($class) {
case 'barbarian': case 'barbarian':
return new Barbarian($characterPage); return new Barbarian($characterPage, $elementalOnWeapon);
case 'wizard': case 'wizard':
return new Wizard($characterPage); return new Wizard($characterPage, $elementalOnWeapon);
default: default:
return false; return false;
} }
@ -30,10 +30,11 @@ class DPClass {
var $stats = array(); var $stats = array();
var $items = array(); var $items = array();
function __construct($characterPage) { function __construct($characterPage, $elementalOnWeapon) {
$this->dpHTML = $characterPage; $this->dpHTML = $characterPage;
$this->class = get_class($this); $this->class = get_class($this);
$this->elementalOnWeapon = $elementalOnWeapon;
$this->parseStats(); $this->parseStats();
} }
@ -61,14 +62,18 @@ class DPClass {
} }
function elementalDamage() { function elementalDamage() {
$totalElemental = 0; $totalElemental = 1;
foreach($this->stats as $stat => $value) { foreach($this->stats as $stat => $value) {
if(preg_match('/\+DPS \(.*\)/', $stat) > 0) { if(preg_match('/\+DPS \(.*\)/', $stat) > 0) {
$totalElemental += $value; $totalElemental += $value;
} }
} }
return ($totalElemental > 0) ? $totalElemental + 1 : 0; if($this->elementalOnWeapon && $totalElemental != 1) {
$totalElemental *= .5;
}
return ($totalElemental > 0) ? $totalElemental : 0;
} }
function calculateGemLife() { function calculateGemLife() {
@ -93,7 +98,7 @@ class DPClass {
function modifyDPSUnbuffed() { function modifyDPSUnbuffed() {
$this->stats['DPS Unbuffed'] = $this->getStat('DPS Unbuffed') * $this->stats['DPS Unbuffed'] = $this->getStat('DPS Unbuffed') *
max(1, 1 + ($this->getStat('All Elemental Damage') / 2)) * $this->getStat('All Elemental Damage') *
max(1, 1 + ($this->getStat('+DPS Against Elites') / 2)); max(1, 1 + ($this->getStat('+DPS Against Elites') / 2));
} }