Exemplo n.º 1
0
 /**
  * Return array with loot info: dropped by, contained in, disenchating to, reagent for, etc.
  * @category Items class
  * @access   public
  * @param    int $item
  * @param    int $type
  * @param    array $data = false
  * @return   array
  **/
 public function BuildLootTable($item, $type, $data = false)
 {
     $lootTable = array();
     switch ($type) {
         case 'vendor':
             $VendorLoot = $this->armory->wDB->select("SELECT `entry`, `ExtendedCost` FROM `npc_vendor` WHERE `item`=%d", $item);
             if (!is_array($VendorLoot)) {
                 return false;
             }
             $i = 0;
             foreach ($VendorLoot as $vItem) {
                 $lootTable[$i] = $this->armory->wDB->selectRow("SELECT `entry` AS `id`, `minlevel` AS `minLevel`, `maxlevel` AS `maxLevel`, name FROM `creature_template` WHERE `entry`=%d", $vItem['entry']);
                 if ($this->armory->GetLocale() != 'en_gb' || $this->armory->GetLocale() != 'en_us') {
                     $lootTable[$i]['name'] = Mangos::GetNpcName($vItem['entry']);
                 }
                 $lootTable[$i]['area'] = Mangos::GetNpcInfo($vItem['entry'], 'map');
                 $i++;
             }
             break;
         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 ($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 {
                     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($cItem['entry'], 'creature_loot_template', $item);
                 $lootTable[$i]['dropRate'] = Mangos::GetDropRate($drop_percent);
                 if ($lootTable[$i]['areaUrl'] && $isBoss) {
                     $lootTable[$i]['url'] = str_replace('boss=all', 'boss=' . $lootTable[$i]['id'], $lootTable[$i]['areaUrl']);
                 }
                 $i++;
             }
             break;
         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 ($GameObjectLoot as $gItem) {
                 $drop_percent = Mangos::GenerateLootPercent($gItem['entry'], 'gameobject_loot_template', $item);
                 $lootTable[$i] = array('name' => Mangos::GetGameObjectInfo($gItem['entry'], 'name'), 'id' => $gItem['entry'], 'dropRate' => Mangos::GetDropRate($drop_percent));
                 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($gItem['entry'], 'map');
                     $lootTable[$i]['areaUrl'] = Mangos::GetGameObjectInfo($gItem['entry'], 'areaUrl');
                 }
                 $i++;
             }
             break;
         case 'questreward':
             $QuestLoot = $this->armory->wDB->select("\n                SELECT `entry` AS `id`, `Title` AS `name`, `QuestLevel` AS `level`, `MinLevel` AS `reqMinLevel`, `SuggestedPlayers` AS `suggestedPartySize`\n                    FROM `quest_template`\n                        WHERE `RewChoiceItemId1` = %d OR `RewChoiceItemId2` = %d OR `RewChoiceItemId3` = %d OR \n                            `RewChoiceItemId4` = %d OR `RewChoiceItemId5` = %d OR `RewChoiceItemId6` = %d", $item, $item, $item, $item, $item, $item);
             if (!is_array($QuestLoot)) {
                 return false;
             }
             $i = 0;
             foreach ($QuestLoot as $qItem) {
                 $lootTable[$i] = $qItem;
                 if ($this->armory->GetLocale() != 'en_gb' || $this->armory->GetLocale() != 'en_us') {
                     $lootTable[$i]['name'] = Mangos::GetQuestInfo($qItem['id'], 'title');
                 }
                 $lootTable[$i]['area'] = Mangos::GetQuestInfo($qItem['id'], 'map');
                 $i++;
             }
             break;
         case 'queststart':
             $QuestStart = $this->armory->wDB->selectCell("SELECT `startquest` FROM `item_template` WHERE `entry`=%d", $item);
             if (!is_array($QuestStart)) {
                 return false;
             }
             $lootTable = $this->armory->wDB->selectRow("SELECT `entry` AS `id`, `Title` AS `name`, `QuestLevel` AS `level`, `MinLevel` AS `reqMinLevel`, `SuggestedPlayers` AS `suggestedPartySize` FROM `quest_template` WHERE `entry`=%d", $QuestStart);
             if ($this->armory->GetLocale() != 'en_gb' || $this->armory->GetLocale() != 'en_us') {
                 $lootTable['name'] = Mangos::GetQuestInfo($QuestStart, 'title');
             }
             $lootTable['name'] = Mangos::GetQuestInfo($QuestStart, 'title');
             $lootTable['area'] = Mangos::GetQuestInfo($QuestStart, 'map');
             break;
         case 'providedfor':
             $QuestInfo = $this->armory->wDB->select("SELECT `entry` AS `id`, `QuestLevel` AS `level`, `Title` AS `name`, `MinLevel` AS `reqMinLevel`, `SuggestedPlayers` AS `suggestedPartySize` FROM `quest_template` WHERE `SrcItemId`=%d", $item);
             if (!is_array($QuestInfo)) {
                 return false;
             }
             $i = 0;
             foreach ($QuestInfo as $quest) {
                 $lootTable[$i] = $quest;
                 if ($this->armory->GetLocale() != 'en_gb' || $this->armory->GetLocale() != 'en_us') {
                     $lootTable[$i]['name'] = Mangos::GetQuestInfo($quest['id'], 'title');
                 }
                 $lootTable[$i]['area'] = Mangos::GetQuestInfo($quest['id'], 'map');
             }
             break;
         case 'objectiveof':
             $QuestInfo = $this->armory->wDB->select("\n                SELECT `entry` AS `id`, `QuestLevel` AS `level`, `Title` AS `name`, `MinLevel` AS `reqMinLevel`, `SuggestedPlayers` AS `suggestedPartySize`\n                    FROM `quest_template`\n                        WHERE `ReqItemId1`=%d OR `ReqItemId2`=%d OR `ReqItemId3`=%d OR `ReqItemId4`=%d OR `ReqItemId5`=%d", $item, $item, $item, $item, $item);
             if (!is_array($QuestInfo)) {
                 return false;
             }
             $i = 0;
             foreach ($QuestInfo as $quest) {
                 $lootTable[$i] = $quest;
                 if ($this->armory->GetLocale() != 'en_gb' || $this->armory->GetLocale() != 'en_us') {
                     $lootTable[$i]['name'] = Mangos::GetQuestInfo($quest['id'], 'title');
                 }
                 $lootTable[$i]['area'] = Mangos::GetQuestInfo($quest['id'], 'map');
             }
             break;
         case 'disenchant':
             $disenchantID = $this->armory->wDB->selectCell("SELECT `DisenchantID` FROM `item_template` WHERE `entry` = %d", $item);
             $DisenchantLoot = $this->armory->wDB->select("SELECT `item`, `maxcount`, `mincountOrRef`, `ChanceOrQuestChance` FROM `disenchant_loot_template` WHERE `entry` = %d", $disenchantID);
             if (!is_array($DisenchantLoot)) {
                 return false;
             }
             $i = 0;
             foreach ($DisenchantLoot as $dItem) {
                 $tmp_info = $this->armory->wDB->selectRow("SELECT `name`, `Quality`, `displayid` FROM `item_template` WHERE `entry`=%d LIMIT 1", $dItem['item']);
                 $drop_percent = Mangos::GenerateLootPercent($disenchantID, 'disenchant_loot_template', $dItem['item']);
                 $lootTable[$i] = array('id' => $dItem['item'], 'name' => $this->armory->GetLocale() == 'en_gb' || $this->armory->GetLocale() == 'en_us' ? $tmp_info['name'] : self::GetItemName($dItem['item']), 'dropRate' => Mangos::GetDropRate($drop_percent), 'maxCount' => $dItem['maxcount'], 'minCount' => $dItem['mincountOrRef'], 'icon' => self::GetItemIcon($dItem['item'], $tmp_info['displayid']), 'quality' => $tmp_info['Quality']);
                 $i++;
             }
             break;
         case 'craft':
             if ($this->armory->GetLocale() == 'en_gb' || $this->armory->GetLocale() == 'ru_ru') {
                 $CraftLoot = $this->armory->aDB->select("\n                    SELECT `Reagent_1`, `Reagent_2`, `Reagent_3`, `Reagent_4`, `Reagent_5`, `Reagent_6`, `Reagent_7`, `Reagent_8`,\n                        `ReagentCount_1`, `ReagentCount_2`, `ReagentCount_3`, `ReagentCount_4`, `ReagentCount_5`, `ReagentCount_6`, \n                        `ReagentCount_7`, `ReagentCount_8`, `EffectItemType_1`, `EffectItemType_2`, `EffectItemType_3`,\n                        `SpellName_%s` AS `SpellName`, `SpellIconID`\n                        FROM `ARMORYDBPREFIX_spell`\n                            WHERE `EffectItemType_1` =%d OR `EffectItemType_2`=%d OR `EffectItemType_3`=%d", $this->armory->GetLocale(), $item, $item, $item);
             } else {
                 $CraftLoot = $this->armory->aDB->select("\n                    SELECT `Reagent_1`, `Reagent_2`, `Reagent_3`, `Reagent_4`, `Reagent_5`, `Reagent_6`, `Reagent_7`, `Reagent_8`,\n                        `ReagentCount_1`, `ReagentCount_2`, `ReagentCount_3`, `ReagentCount_4`, `ReagentCount_5`, `ReagentCount_6`, \n                        `ReagentCount_7`, `ReagentCount_8`, `EffectItemType_1`, `EffectItemType_2`, `EffectItemType_3`,\n                        `SpellName_en_gb` AS `SpellName`, `SpellIconID`\n                        FROM `ARMORYDBPREFIX_spell`\n                            WHERE `EffectItemType_1` =%d OR `EffectItemType_2`=%d OR `EffectItemType_3`=%d", $item, $item, $item);
             }
             if (!is_array($CraftLoot)) {
                 return false;
             }
             $i = 0;
             foreach ($CraftLoot as $craftItem) {
                 $lootTable[$i] = array('spell' => array(), 'item' => array(), 'reagent' => array());
                 $lootTable[$i]['spell']['name'] = $craftItem['SpellName'];
                 for ($o = 1; $o < 9; $o++) {
                     if ($craftItem['Reagent_' . $o] > 0) {
                         $tmp_info = $this->armory->wDB->selectRow("SELECT `name`, `Quality`, `displayid` FROM `item_template` WHERE `entry`=%d LIMIT 1", $craftItem['Reagent_' . $o]);
                         if (!$tmp_info) {
                             continue;
                         }
                         $lootTable[$i]['reagent'][$o] = array('id' => $craftItem['Reagent_' . $o], 'name' => $this->armory->GetLocale() == 'en_gb' || $this->armory->GetLocale() == 'en_us' ? $tmp_info['name'] : self::GetItemName($craftItem['Reagent_' . $o]), 'icon' => self::GetItemIcon($craftItem['Reagent_' . $o], $tmp_info['displayid']), 'count' => $craftItem['ReagentCount_' . $o], 'quality' => $tmp_info['Quality']);
                     }
                 }
                 for ($j = 1; $j < 4; $j++) {
                     if ($craftItem['EffectItemType_' . $j] > 0) {
                         $tmp_info = $this->armory->wDB->selectRow("SELECT `name`, `Quality`, `displayid` FROM `item_template` WHERE `entry`=%d LIMIT 1", $craftItem['EffectItemType_' . $j]);
                         if (!$tmp_info) {
                             continue;
                         }
                         $lootTable[$i]['item'][$j] = array('id' => $craftItem['EffectItemType_' . $j], 'name' => $this->armory->GetLocale() == 'en_gb' || $this->armory->GetLocale() == 'en_us' ? $tmp_info['name'] : self::GetItemName($craftItem['EffectItemType_' . $j]), 'icon' => self::GetItemIcon($craftItem['EffectItemType_' . $j], $tmp_info['displayid']), 'quality' => $tmp_info['Quality']);
                     }
                 }
                 $i++;
             }
             break;
         case 'currencyfor':
             $exCostIds = $this->armory->aDB->select("SELECT `id` FROM `ARMORYDBPREFIX_extended_cost` WHERE `item1`=%d OR `item2`=%d OR `item3`=%d OR `item4`=%d OR `item5`=%d", $item, $item, $item, $item, $item);
             if (!is_array($exCostIds)) {
                 return false;
             }
             $CostIDs = array('pos' => array(), 'neg' => array());
             foreach ($exCostIds as $tmp_cost) {
                 $CostIDs['pos'][] = $tmp_cost['id'];
                 $CostIDs['neg'][] = -$tmp_cost['id'];
             }
             if (!isset($CostIDs['pos'][0]) || !$CostIDs['pos'][0]) {
                 return false;
             }
             $itemsData = $this->armory->wDB->select("\n                SELECT\n                `item_template`.`entry` AS `id`,\n                `item_template`.`name`,\n                `item_template`.`class`,\n                `item_template`.`subclass`,\n                `item_template`.`ItemLevel` AS `level`,\n                `item_template`.`Quality` AS `quality`,\n                `item_template`.`displayid`,\n                `npc_vendor`.`ExtendedCost`\n                FROM `item_template` AS `item_template`\n                LEFT JOIN `npc_vendor` AS `npc_vendor` ON `npc_vendor`.`item`=`item_template`.`entry`\n                WHERE `npc_vendor`.`ExtendedCost` IN (%s) OR `npc_vendor`.`ExtendedCost` IN (%s)", $CostIDs['pos'], $CostIDs['neg']);
             if (!is_array($itemsData)) {
                 return false;
             }
             $oldItems = array();
             $i = 0;
             foreach ($itemsData as $curItem) {
                 if (isset($oldItems[$curItem['id']])) {
                     // Do not add same items many times
                     continue;
                 }
                 $lootTable[$i]['data'] = array('icon' => self::GetItemIcon($curItem['id'], $curItem['displayid']), 'id' => $curItem['id'], 'level' => $curItem['level'], 'name' => $this->armory->GetLocale() == 'en_gb' || $this->armory->GetLocale() == 'en_us' ? $curItem['name'] : self::GetItemName($curItem['id']), 'quality' => $curItem['quality'], 'type' => $this->armory->aDB->selectCell("SELECT `subclass_name_%s` FROM `ARMORYDBPREFIX_itemsubclass` WHERE `class`=%d AND `subclass`=%d", $this->armory->GetLocale(), $curItem['class'], $curItem['subclass']));
                 $lootTable[$i]['tokens'] = Mangos::GetExtendedCost($curItem['ExtendedCost']);
                 $oldItems[$curItem['id']] = $curItem['id'];
                 $i++;
             }
             break;
         case 'reagent':
             if ($this->armory->GetLocale() == 'en_gb' || $this->armory->GetLocale() == 'ru_ru') {
                 $ReagentLoot = $this->armory->aDB->select("\n                    SELECT `Reagent_1`, `Reagent_2`, `Reagent_3`, `Reagent_4`, `Reagent_5`, `Reagent_6`, `Reagent_7`, `Reagent_8`,\n                        `ReagentCount_1`, `ReagentCount_2`, `ReagentCount_3`, `ReagentCount_4`, `ReagentCount_5`, `ReagentCount_6`, \n                        `ReagentCount_7`, `ReagentCount_8`, `EffectItemType_1`, `EffectItemType_2`, `EffectItemType_3`,\n                        `SpellName_%s` AS `SpellName`, `SpellIconID`\n                    FROM `ARMORYDBPREFIX_spell`\n                        WHERE `Reagent_1`=%d OR `Reagent_2`=%d OR `Reagent_3`=%d OR `Reagent_4`=%d OR\n                            `Reagent_5`=%d OR `Reagent_6`=%d OR `Reagent_7`=%d OR `Reagent_8`=%d", $this->armory->GetLocale(), $item, $item, $item, $item, $item, $item, $item, $item);
             } else {
                 $ReagentLoot = $this->armory->aDB->select("\n                    SELECT `Reagent_1`, `Reagent_2`, `Reagent_3`, `Reagent_4`, `Reagent_5`, `Reagent_6`, `Reagent_7`, `Reagent_8`,\n                        `ReagentCount_1`, `ReagentCount_2`, `ReagentCount_3`, `ReagentCount_4`, `ReagentCount_5`, `ReagentCount_6`, \n                        `ReagentCount_7`, `ReagentCount_8`, `EffectItemType_1`, `EffectItemType_2`, `EffectItemType_3`,\n                        `SpellName_en_gb` AS `SpellName`, `SpellIconID`\n                    FROM `ARMORYDBPREFIX_spell`\n                        WHERE `Reagent_1`=%d OR `Reagent_2`=%d OR `Reagent_3`=%d OR `Reagent_4`=%d OR\n                            `Reagent_5`=%d OR `Reagent_6`=%d OR `Reagent_7`=%d OR `Reagent_8`=%d", $item, $item, $item, $item, $item, $item, $item, $item);
             }
             if (!is_array($ReagentLoot)) {
                 return false;
             }
             $i = 0;
             foreach ($ReagentLoot as $ReagentItem) {
                 $lootTable[$i] = array('spell' => array(), 'item' => array(), 'reagent' => array());
                 $lootTable[$i]['spell']['name'] = $ReagentItem['SpellName'];
                 for ($j = 1; $j < 4; $j++) {
                     if ($ReagentItem['EffectItemType_' . $j] > 0) {
                         $tmp_info = $this->armory->wDB->selectRow("SELECT `name`, `Quality`, `displayid` FROM `item_template` WHERE `entry`=%d LIMIT 1", $ReagentItem['EffectItemType_' . $j]);
                         $lootTable[$i]['item'][$j] = array('id' => $ReagentItem['EffectItemType_' . $j], 'name' => $this->armory->GetLocale() == 'en_gb' || $this->armory->GetLocale() == 'en_us' ? $tmp_info['name'] : self::GetItemName($ReagentItem['EffectItemType_' . $j]), 'icon' => self::GetItemIcon($ReagentItem['EffectItemType_' . $j], $tmp_info['displayid']), 'quality' => $tmp_info['Quality']);
                     }
                 }
                 for ($o = 1; $o < 9; $o++) {
                     if ($ReagentItem['Reagent_' . $o] > 0) {
                         $tmp_info = $this->armory->wDB->selectRow("SELECT `name`, `Quality`, `displayid` FROM `item_template` WHERE `entry`=%d LIMIT 1", $ReagentItem['Reagent_' . $o]);
                         $lootTable[$i]['reagent'][$o] = array('id' => $ReagentItem['Reagent_' . $o], 'icon' => self::GetItemIcon($ReagentItem['Reagent_' . $o], $tmp_info['displayid']), 'count' => $ReagentItem['ReagentCount_' . $o], 'name' => $this->armory->GetLocale() == 'en_gb' || $this->armory->GetLocale() == 'en_us' ? $tmp_info['name'] : self::GetItemName($ReagentItem['Reagent_' . $o]));
                     }
                 }
                 $i++;
             }
             break;
         case 'randomProperty':
             $itemProperty = $this->armory->wDB->selectRow("SELECT `RandomProperty`, `RandomSuffix` FROM `item_template` WHERE `entry`=%d LIMIT 1", $item);
             if (!is_array($itemProperty) || $itemProperty['RandomProperty'] == 0 && $itemProperty['RandomSuffix'] == 0) {
                 return false;
             }
             $type = false;
             if ($itemProperty['RandomProperty'] > 0) {
                 $itemPropertyId = $itemProperty['RandomProperty'];
                 $type = 'property';
             } elseif ($itemProperty['RandomSuffix'] > 0) {
                 $itemPropertyId = $itemProperty['RandomSuffix'];
                 $type = 'suffix';
             }
             $enchants_entries = $this->armory->wDB->select("SELECT * FROM `item_enchantment_template` WHERE `entry`=%d", $itemPropertyId);
             if (!$enchants_entries) {
                 return false;
             }
             $count = count($enchants_entries);
             $ids = array();
             for ($i = 0; $i < $count; $i++) {
                 $ids[$enchants_entries[$i]['ench']] = $enchants_entries[$i]['ench'];
             }
             if ($type == 'property') {
                 $enchants = $this->armory->aDB->select("SELECT `id`, `name_%s` AS `name`, `ench_1`, `ench_2`, `ench_3` FROM `ARMORYDBPREFIX_randomproperties` WHERE `id` IN (%s)", $this->armory->GetLocale(), $ids);
             } elseif ($type == 'suffix') {
                 $enchants = $this->armory->aDB->select("SELECT `id`, `name_%s` AS `name`, `ench_1`, `ench_2`, `ench_3`, `ench_4`, `ench_5`, `pref_1`, `pref_2`, `pref_3`, `pref_4`, `pref_5` FROM `ARMORYDBPREFIX_randomsuffix` WHERE `id` IN (%s)", $this->armory->GetLocale(), $ids);
             }
             if (!$enchants) {
                 return false;
             }
             $i = 0;
             $item_data = $this->armory->wDB->selectRow("SELECT `InventoryType`, `ItemLevel`, `Quality` FROM `item_template` WHERE `entry`=%d", $item);
             $points = self::GetRandomPropertiesPoints($item_data['ItemLevel'], $item_data['InventoryType'], $item_data['Quality']);
             foreach ($enchants as $entry) {
                 $str_tmp = array();
                 $lootTable[$i]['name'] = $entry['name'];
                 $lootTable[$i]['data'] = array();
                 for ($j = 1; $j < 6; $j++) {
                     if (isset($entry['ench_' . $j]) && $entry['ench_' . $j] > 0) {
                         if ($type == 'property') {
                             $str_tmp[$entry['ench_' . $j]] = $entry['ench_' . $j];
                         } elseif ($type == 'suffix') {
                             $str_tmp[$entry['ench_' . $j]] = $entry['ench_' . $j];
                         }
                     }
                 }
                 $enchs = $this->armory->aDB->select("SELECT `id`, `text_%s` AS `text` FROM `ARMORYDBPREFIX_enchantment` WHERE `id` IN (%s)", $this->armory->GetLocale(), $str_tmp);
                 if (!$enchs) {
                     $i++;
                     continue;
                 }
                 $k = 0;
                 foreach ($enchs as $m_ench) {
                     if ($type == 'suffix') {
                         for ($l = 1; $l < 3; $l++) {
                             if (isset($entry['ench_' . $l]) && $entry['ench_' . $l] > 0) {
                                 $lootTable[$i]['data'][$k] = str_replace('$i', round($points * $entry['pref_' . $l] / 10000, 0), $m_ench['text']);
                             }
                         }
                     } else {
                         $lootTable[$i]['data'][$k] = $m_ench['text'];
                     }
                     $k++;
                 }
                 $i++;
             }
             break;
         default:
             return false;
             break;
     }
     return $lootTable;
 }