Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed item attributes that are present in buff descriptions not being added to existing attributes. #135

Merged
merged 2 commits into from
Sep 17, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 22 additions & 17 deletions src/GW2Spidy/GW2API/APIItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -185,15 +185,14 @@ public function getAttributes() {
public function getFormattedAttributes() {
$html = "";

$this->cleanAttributes();
$this->addBuffsToAttributes();

foreach ($this->getAttributes() as $attr) {
$pct = ($attr['attribute'] == 'Critical Damage') ? '%' : null;
$html .= "<dd class=\"db-stat\">+{$attr['modifier']}{$pct} {$attr['attribute']}</dd>\n";
}

if (($buff = $this->getBuffDescription()) !== null) {
$html .= "<dd class=\"db-stat\">{$buff}</dd>\n";
}

return $html;
}

Expand Down Expand Up @@ -229,21 +228,27 @@ public function getBuffDescription() {
}

protected function addBuffsToAttributes() {
$buffs = explode("\n", $this->infix_upgrade['buff']['description']);

$attributes_exist = (count($this->infix_upgrade['attributes']) > 0);

foreach ($buffs as $buff) {
list($modifier_stage1, $attribute) = explode(" ", $buff, 2);
$modifier_stage2 = str_replace("+", "", $modifier_stage1);
$modifier = (int) str_replace("%", "", $modifier_stage2);
if (isset($this->infix_upgrade['buff']['description'])) {
$buffs = explode("\n", $this->infix_upgrade['buff']['description']);

$attributes_exist = array();

if (!$attributes_exist) {
$this->infix_upgrade['attributes'][] = array('attribute' => $attribute, 'modifier' => $modifier);
foreach ($this->infix_upgrade['attributes']as $attr) {
$attributes_exist[] = $attr['attribute'];
}
else {
foreach ($this->infix_upgrade['attributes'] as &$attr) {
$attr['modifier'] += ($attr['attribute'] == $attribute) ? $modifier : 0;

foreach ($buffs as $buff) {
list($modifier_stage1, $attribute) = explode(" ", $buff, 2);
$modifier_stage2 = str_replace("+", "", $modifier_stage1);
$modifier = (int) str_replace("%", "", $modifier_stage2);

if (!in_array($attribute, $attributes_exist)) {
$this->infix_upgrade['attributes'][] = array('attribute' => $attribute, 'modifier' => $modifier);
}
else {
foreach ($this->infix_upgrade['attributes'] as &$attr) {
$attr['modifier'] += ($attr['attribute'] == $attribute) ? $modifier : 0;
}
}
}
}
Expand Down
2 changes: 0 additions & 2 deletions src/GW2Spidy/GW2API/Armor.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ public function __construct($APIItem) {
$this->infusion_slots = $APIItem['armor']['infusion_slots'];
$this->infix_upgrade = isset($APIItem['armor']['infix_upgrade']) ? $APIItem['armor']['infix_upgrade'] : array();
$this->suffix_item_id = $APIItem['armor']['suffix_item_id'];

$this->cleanAttributes();
}

public function getDefense() {
Expand Down
2 changes: 0 additions & 2 deletions src/GW2Spidy/GW2API/Back.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ public function __construct($APIItem) {
$this->infusion_slots = $APIItem['back']['infusion_slots'];
$this->infix_upgrade = isset($APIItem['back']['infix_upgrade']) ? $APIItem['back']['infix_upgrade'] : array();
$this->suffix_item_id = $APIItem['back']['suffix_item_id'];

$this->cleanAttributes();
}

public function getTooltipDescription() {
Expand Down
7 changes: 0 additions & 7 deletions src/GW2Spidy/GW2API/Trinket.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,6 @@ public function __construct($APIItem) {
$this->infusion_slots = $APIItem['trinket']['infusion_slots'];
$this->infix_upgrade = (isset($APIItem['trinket']['infix_upgrade'])) ? $APIItem['trinket']['infix_upgrade'] : array();
$this->suffix_item_id = $APIItem['trinket']['suffix_item_id'];

$this->cleanAttributes();

//Some items have buff descriptions which are just added into the items attributes automatically in game
if (isset($this->infix_upgrade['buff']['description'])) {
$this->addBuffsToAttributes();
}
}

public function getTooltipDescription() {
Expand Down
7 changes: 0 additions & 7 deletions src/GW2Spidy/GW2API/UpgradeComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,6 @@ public function __construct($APIItem) {
$this->bonuses = isset($APIItem['upgrade_component']['bonuses']) ? $APIItem['upgrade_component']['bonuses'] : array();
$this->infix_upgrade = isset($APIItem['upgrade_component']['infix_upgrade']) ? $APIItem['upgrade_component']['infix_upgrade'] : array();
$this->suffix = $APIItem['upgrade_component']['suffix'];

$this->cleanAttributes();

//Some items have buff descriptions which are just added into the items attributes automatically in game
if (isset($this->infix_upgrade['buff']['description'])) {
$this->addBuffsToAttributes();
}
}

public function getBonuses() {
Expand Down
2 changes: 0 additions & 2 deletions src/GW2Spidy/GW2API/Weapon.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ public function __construct($APIItem) {
$this->infusion_slots = $APIItem['weapon']['infusion_slots'];
$this->infix_upgrade = isset($APIItem['weapon']['infix_upgrade']) ? $APIItem['weapon']['infix_upgrade'] : array();
$this->suffix_item_id = $APIItem['weapon']['suffix_item_id'];

$this->cleanAttributes();
}

public function getMinPower() {
Expand Down