diff --git a/includes/classes/class.items.php b/includes/classes/class.items.php index fc4975c2a..52a79385d 100644 --- a/includes/classes/class.items.php +++ b/includes/classes/class.items.php @@ -3,7 +3,7 @@ /** * @package World of Warcraft Armory * @version Release Candidate 1 - * @revision 409 + * @revision 414 * @copyright (c) 2009-2010 Shadez * @license http://opensource.org/licenses/gpl-license.php GNU Public License * @@ -290,13 +290,13 @@ public function GetItemSetBonusInfo($itemsetdata) { * @category Items class * @access public * @param int $item - * @param int $vendor + * @param int $type * @param array $data = false * @return array **/ - public function BuildLootTable($item, $vendor, $data=false) { + public function BuildLootTable($item, $type, $data=false) { $lootTable = array(); - switch($vendor) { + switch($type) { case 'vendor': $VendorLoot = $this->armory->wDB->select("SELECT `entry`, `ExtendedCost` FROM `npc_vendor` WHERE `item`=%d", $item); if(!is_array($VendorLoot)) { @@ -312,55 +312,59 @@ public function BuildLootTable($item, $vendor, $data=false) { $i++; } break; - case 'boss': - $BossLoot = $this->armory->wDB->select("SELECT `entry` FROM `creature_loot_template` WHERE `item`=%d", $item); - if(!is_array($BossLoot)) { + case 'creature': + $CreatureLoot = $this->armory->wDB->select("SELECT `entry` FROM `creature_loot_template` WHERE `item`=%d", $item); + if(!is_array($CreatureLoot)) { return false; } $i = 0; - foreach($BossLoot as $bItem) { - $lootTable[$i] = $this->armory->wDB->selectRow("SELECT `entry` AS `id`, `name`, `minlevel` AS `minLevel`, `maxlevel` AS `maxLevel`, `rank` AS `classification` FROM `creature_template` WHERE `entry`=%d", $bItem['entry']); - if($this->armory->GetLocale() != 'en_gb' || $this->armory->GetLocale() != 'en_us') { - $lootTable[$i]['name'] = Mangos::GetNpcName($bItem['entry']); - } - if(Mangos::GetNpcInfo($bItem['entry'], 'isBoss')) { - $areaData = self::GetImprovedItemSource($item, $bItem['entry'], true); + foreach($CreatureLoot as $cItem) { + $lootTable[$i] = $this->armory->wDB->selectRow("SELECT `entry` AS `id`, `name`, `minlevel` AS `minLevel`, `maxlevel` AS `maxLevel`, `rank` AS `classification` FROM `creature_template` WHERE `entry`=%d", $cItem['entry']); + $isBoss = Mangos::GetNpcInfo($cItem['entry'], 'isBoss'); + if($isBoss) { + $npc_data = Mangos::GetNpcName($cItem['entry'], true); + $lootTable[$i]['name'] = $npc_data['name']; + $lootTable[$i]['id'] = $npc_data['id']; + $areaData = self::GetImprovedItemSource($item, $cItem['entry'], true); $lootTable[$i]['area'] = $areaData['areaName']; $lootTable[$i]['areaUrl'] = $areaData['areaUrl']; } else { - $lootTable[$i]['area'] = Mangos::GetNpcInfo($bItem['entry'], 'map'); - $lootTable[$i]['areaUrl'] = Mangos::GetNpcInfo($bItem['entry'], 'areaUrl'); + if($this->armory->GetLocale() != 'en_gb' || $this->armory->GetLocale() != 'en_us') { + $lootTable[$i]['name'] = Mangos::GetNpcName($cItem['entry']); + } + $lootTable[$i]['area'] = Mangos::GetNpcInfo($cItem['entry'], 'map'); + $lootTable[$i]['areaUrl'] = Mangos::GetNpcInfo($cItem['entry'], 'areaUrl'); } - $drop_percent = Mangos::GenerateLootPercent($bItem['entry'], 'creature_loot_template', $item); + $drop_percent = Mangos::GenerateLootPercent($cItem['entry'], 'creature_loot_template', $item); $lootTable[$i]['dropRate'] = Mangos::GetDropRate($drop_percent); - if($lootTable[$i]['areaUrl'] && Mangos::GetNpcInfo($bItem['entry'], 'isBoss')) { - $lootTable[$i]['url'] = str_replace('boss=all', 'boss='.$bItem['entry'], $lootTable[$i]['areaUrl']); + if($lootTable[$i]['areaUrl'] && $isBoss) { + $lootTable[$i]['url'] = str_replace('boss=all', 'boss=' . $lootTable[$i]['id'], $lootTable[$i]['areaUrl']); } $i++; } break; - case 'chest': - $ChestLoot = $this->armory->wDB->select("SELECT `entry` FROM `gameobject_loot_template` WHERE `item`=%d", $item); - if(!is_array($ChestLoot)) { + case 'gameobject': + $GameObjectLoot = $this->armory->wDB->select("SELECT `entry` FROM `gameobject_loot_template` WHERE `item`=%d", $item); + if(!is_array($GameObjectLoot)) { return false; } $i = 0; - foreach($ChestLoot as $cItem) { - $drop_percent = Mangos::GenerateLootPercent($cItem['entry'], 'gameobject_loot_template', $item); + foreach($GameObjectLoot as $gItem) { + $drop_percent = Mangos::GenerateLootPercent($gItem['entry'], 'gameobject_loot_template', $item); $lootTable[$i] = array( - 'name' => Mangos::GetGameObjectInfo($cItem['entry'], 'name'), - 'id' => $cItem['entry'], + 'name' => Mangos::GetGameObjectInfo($gItem['entry'], 'name'), + 'id' => $gItem['entry'], 'dropRate' => Mangos::GetDropRate($drop_percent) ); - if(Mangos::GetGameObjectInfo($cItem['entry'], 'isInInstance')) { - $areaData = self::GetImprovedItemSource($item, $cItem['entry'], true); + if(Mangos::GetGameObjectInfo($gItem['entry'], 'isInInstance')) { + $areaData = self::GetImprovedItemSource($item, $gItem['entry'], true); $lootTable[$i]['area'] = $areaData['areaName']; $lootTable[$i]['areaUrl'] = $areaData['areaUrl']; } else { - $lootTable[$i]['area'] = Mangos::GetGameObjectInfo($cItem['entry'], 'map'); - $lootTable[$i]['areaUrl'] = Mangos::GetGameObjectInfo($cItem['entry'], 'areaUrl'); + $lootTable[$i]['area'] = Mangos::GetGameObjectInfo($gItem['entry'], 'map'); + $lootTable[$i]['areaUrl'] = Mangos::GetGameObjectInfo($gItem['entry'], 'areaUrl'); } $i++; } @@ -519,7 +523,10 @@ public function BuildLootTable($item, $vendor, $data=false) { $CostIDs = array('pos' => array(), 'neg' => array()); foreach($exCostIds as $tmp_cost) { $CostIDs['pos'][] = $tmp_cost['id']; - $CostIDs['neg'][] = '-'.$tmp_cost['id']; + $CostIDs['neg'][] = -$tmp_cost['id']; + } + if(!isset($CostIDs['pos'][0]) || !$CostIDs['pos'][0]) { + return false; } $itemsData = $this->armory->wDB->select(" SELECT diff --git a/includes/classes/class.mangos.php b/includes/classes/class.mangos.php index a554e17b6..230d6839e 100644 --- a/includes/classes/class.mangos.php +++ b/includes/classes/class.mangos.php @@ -3,7 +3,7 @@ /** * @package World of Warcraft Armory * @version Release Candidate 1 - * @revision 398 + * @revision 414 * @copyright (c) 2009-2010 Shadez * @license http://opensource.org/licenses/gpl-license.php GNU Public License * @@ -220,36 +220,41 @@ public function GetGameObjectInfo($entry, $infoType) { * @category Mangos class * @access public * @param int $npc + * @param bool $isBoss = false * @return string **/ - public function GetNPCName($npc) { - if($this->armory->GetLocale() == 'en_gb' || $this->armory->GetLocale() == 'en_us') { - return $this->armory->wDB->selectCell("SELECT `name` FROM `creature_template` WHERE `entry`=%d LIMIT 1", $npc); + public function GetNPCName($npc, $isBoss = false) { + $creature_id = $npc; + // If npc is boss we need to find him/her original ID (to prevent names like "Bronjahm (1)", etc.) + if($isBoss) { + $KillCreditInfo = $this->armory->wDB->selectRow("SELECT `KillCredit1`, `KillCredit2` FROM `creature_template` WHERE `entry` = %d LIMIT 1", $npc); + if(!$KillCreditInfo) { + // return name for current ID + return $this->armory->wDB->selectCell("SELECT `name` FROM `creature_template` WHERE `entry`=%d LIMIT 1", $npc); + } + if($KillCreditInfo['KillCredit1'] > 0) { + $creature_id = $KillCreditInfo['KillCredit1']; + } + elseif($KillCreditInfo['KillCredit2'] > 0) { + $creature_id = $KillCreditInfo['KillCredit']; + } + } + if($this->armory->GetLoc() == 0) { + $name = $this->armory->wDB->selectCell("SELECT `name` FROM `creature_template` WHERE `entry`=%d LIMIT 1", $creature_id); } else { - $name = $this->armory->wDB->selectCell("SELECT `name_loc%d` FROM `locales_creature` WHERE `entry`=%d LIMIT 1", $this->armory->GetLoc(), $npc); + $name = $this->armory->wDB->selectCell("SELECT `name_loc%d` FROM `locales_creature` WHERE `entry` = %d LIMIT 1", $this->armory->GetLoc(), $creature_id); if(!$name) { - // Check KillCredit - $kc_entry = false; - $KillCredit = $this->armory->wDB->selectRow("SELECT `KillCredit1`, `KillCredit2` FROM `creature_template` WHERE `entry`=%d", $npc); - if($KillCredit['KillCredit1'] > 0) { - $kc_entry = $KillCredit['KillCredit1']; - } - elseif($KillCredit['KillCredit2'] > 0) { - $kc_entry = $KillCredit['KillCredit2']; - } - if($kc_entry > 0) { - $name = $this->armory->wDB->selectCell("SELECT `name_loc%d` FROM `locales_creature` WHERE `entry`=%d LIMIT 1", $this->armory->GetLoc(), $kc_entry); - if(!$name) { - $name = $this->armory->wDB->selectCell("SELECT `name` FROM `creature_template` WHERE `entry`=%d LIMIT 1", $npc); - } - } - else { + $name = $this->armory->wDB->selectCell("SELECT `name_loc%d` FROM `locales_creature` WHERE `entry` = %d LIMIT 1", $this->armory->GetLoc(), $npc); + if(!$name) { $name = $this->armory->wDB->selectCell("SELECT `name` FROM `creature_template` WHERE `entry`=%d LIMIT 1", $npc); } } } - if($name) { + if($name && $isBoss) { + return array('id' => $creature_id, 'name' => $name); + } + elseif($name && !$isBoss) { return $name; } $this->armory->Log()->writeError('%s : unable to find NPC name (id: %d, KillCredit1: %d, KillCredit2: %d)', __METHOD__, $npc, (isset($KillCredit['KillCredit1'])) ? $KillCredit['KillCredit1'] : 0, (isset($KillCredit['KillCredit2'])) ? $KillCredit['KillCredit2'] : 0); diff --git a/includes/revision_nr.php b/includes/revision_nr.php index 0e03ef66a..feb682c85 100644 --- a/includes/revision_nr.php +++ b/includes/revision_nr.php @@ -1,5 +1,5 @@ \ No newline at end of file diff --git a/item-info.php b/item-info.php index 9bd4e1ff9..99d13294e 100644 --- a/item-info.php +++ b/item-info.php @@ -3,7 +3,7 @@ /** * @package World of Warcraft Armory * @version Release Candidate 1 - * @revision 365 + * @revision 414 * @copyright (c) 2009-2010 Shadez * @license http://opensource.org/licenses/gpl-license.php GNU Public License * @@ -83,7 +83,7 @@ $xml->XMLWriter()->writeAttribute($pvp_cost_key, $pvp_cost_value); } } - $xml->XMLWriter()->writeAttribute('factionId', ($data['Flags2']&ITEM_FLAGS2_HORDE_ONLY) ? 0 : 1); + $xml->XMLWriter()->writeAttribute('factionId', ($data['Flags2']&ITEM_FLAGS2_HORDE_ONLY) ? FACTION_ALLIANCE : FACTION_HORDE); } if(is_array($cost_info)) { foreach($cost_info as $cost) { @@ -143,7 +143,7 @@ } $xml->XMLWriter()->endElement(); //currencyFor } -if($creature_loot = $items->BuildLootTable($itemID, 'boss')) { +if($creature_loot = $items->BuildLootTable($itemID, 'creature')) { $xml->XMLWriter()->startElement('dropCreatures'); foreach($creature_loot as $creature_item) { $xml->XMLWriter()->startElement('creature'); @@ -154,7 +154,7 @@ } $xml->XMLWriter()->endElement(); //dropCreatures } -if($gameobject_loot = $items->BuildLootTable($itemID, 'chest')) { +if($gameobject_loot = $items->BuildLootTable($itemID, 'gameobject')) { $xml->XMLWriter()->startElement('containerObjects'); foreach($gameobject_loot as $gameobject_item) { $xml->XMLWriter()->startElement('object');