function gems() { // sketchy, but should work // Id < 36'000 || ilevel < 70 ? BC : WOTLK $gems = DB::Aowow()->Select('SELECT i.id AS itemId, i.name_loc0, i.name_loc2, i.name_loc3, i.name_loc4, i.name_loc6, i.name_loc8, IF (i.id < 36000 OR i.itemLevel < 70, 1 , 2) AS expansion, i.quality, ic.iconString AS icon, i.gemEnchantmentId AS enchId, i.gemColorMask AS colors FROM ?_items i JOIN ?_icons ic ON ic.id = -i.displayId WHERE i.gemEnchantmentId <> 0 ORDER BY i.id DESC'); $success = true; // check directory-structure foreach (Util::$localeStrings as $dir) { if (!CLISetup::writeDir('datasets/' . $dir)) { $success = false; } } $enchIds = []; foreach ($gems as $pop) { $enchIds[] = $pop['enchId']; } $enchantments = new EnchantmentList(array(['id', $enchIds], CFG_SQL_LIMIT_NONE)); if ($enchantments->error) { CLISetup::log('Required table ?_itemenchantment seems to be empty! Leaving gems()...', CLISetup::LOG_ERROR); CLISetup::log(); return false; } foreach (CLISetup::$localeIds as $lId) { set_time_limit(5); User::useLocale($lId); Lang::load(Util::$localeStrings[$lId]); $gemsOut = []; foreach ($gems as $pop) { if (!$enchantments->getEntry($pop['enchId'])) { CLISetup::log(' * could not find enchantment #' . $pop['enchId'] . ' referenced by item #' . $gem['itemId'], CLISetup::LOG_WARN); continue; } $gemsOut[$pop['itemId']] = array('name' => Util::localizedString($pop, 'name'), 'quality' => $pop['quality'], 'icon' => strToLower($pop['icon']), 'enchantment' => $enchantments->getField('name', true), 'jsonequip' => $enchantments->getStatGain(), 'colors' => $pop['colors'], 'expansion' => $pop['expansion']); } $toFile = "var g_gems = " . Util::toJSON($gemsOut) . ";"; $file = 'datasets/' . User::$localeString . '/gems'; if (!CLISetup::writeFile($file, $toFile)) { $success = false; } } return $success; }
function enchants() { // from g_item_slots: 13:"One-Hand", 26:"Ranged", 17:"Two-Hand", $slotPointer = [13, 17, 26, 26, 13, 17, 17, 13, 17, null, 17, null, null, 13, null, 13, null, null, null, null, 17]; $castItems = []; $successs = true; $enchantSpells = new SpellList([['effect1Id', 53], ['name_loc0', 'QA%', '!'], CFG_SQL_LIMIT_NONE]); // enchantItemPermanent && !qualityAssurance // check directory-structure foreach (Util::$localeStrings as $dir) { if (!CLISetup::writeDir('datasets/' . $dir)) { $success = false; } } $enchIds = []; foreach ($enchantSpells->iterate() as $__) { $enchIds[] = $enchantSpells->getField('effect1MiscValue'); } $enchantments = new EnchantmentList(array(['id', $enchIds], CFG_SQL_LIMIT_NONE)); if ($enchantments->error) { CLISetup::log('Required table ?_itemenchantment seems to be empty! Leaving enchants()...', CLISetup::LOG_ERROR); CLISetup::log(); return false; } foreach (CLISetup::$localeIds as $lId) { set_time_limit(120); User::useLocale($lId); Lang::load(Util::$localeStrings[$lId]); $enchantsOut = []; foreach ($enchantSpells->iterate() as $__) { $eId = $enchantSpells->getField('effect1MiscValue'); if (!$enchantments->getEntry($eId)) { CLISetup::log(' * could not find enchantment #' . $eId . ' referenced by spell #' . $enchantSpells->id, CLISetup::LOG_WARN); continue; } // slots have to be recalculated $slot = 0; if ($enchantSpells->getField('equippedItemClass') == 4) { if ($invType = $enchantSpells->getField('equippedItemInventoryTypeMask')) { $slot = $invType >> 1; } else { /* if (equippedItemSubClassMask == 64) */ // shields have it their own way <_< $slot = 1 << 14 - 1; } } else { if ($enchantSpells->getField('equippedItemClass') == 2) { foreach ($slotPointer as $i => $sp) { if (!$sp) { continue; } if (1 << $i & $enchantSpells->getField('equippedItemSubClassMask')) { if ($sp == 13) { // also mainHand & offHand *siiigh* $slot |= 1 << 21 - 1 | 1 << 22 - 1; } $slot |= 1 << $sp - 1; } } } } // defaults $ench = array('name' => [], 'quality' => -1, 'icon' => strToLower($enchantSpells->getField('iconString')), 'source' => [], 'skill' => -1, 'slots' => [], 'enchantment' => $enchantments->getField('name', true), 'jsonequip' => $enchantments->getStatGain(), 'temp' => 0, 'classes' => 0); if ($_ = $enchantments->getField('skillLine')) { $ench['jsonequip']['reqskill'] = $_; } if ($_ = $enchantments->getField('skillLevel')) { $ench['jsonequip']['reqskillrank'] = $_; } if (($_ = $enchantments->getField('requiredLevel')) && $_ > 1) { $ench['jsonequip']['reqlevel'] = $_; } // check if the spell has an entry in skill_line_ability -> Source:Profession if ($skills = $enchantSpells->getField('skillLines')) { $ench['name'][] = $enchantSpells->getField('name', true); $ench['source'][] = $enchantSpells->id; $ench['skill'] = $skills[0]; $ench['slots'][] = $slot; } // check if this spell can be cast via item -> Source:Item if (!isset($castItems[$enchantSpells->id])) { $castItems[$enchantSpells->id] = new ItemList([['spellId1', $enchantSpells->id], ['name_loc0', 'Scroll of Enchant%', '!']]); } // do not reuse enchantment scrolls $cI =& $castItems[$enchantSpells->id]; // this construct is a bit .. unwieldy foreach ($cI->iterate() as $__) { $ench['name'][] = $cI->getField('name', true); $ench['source'][] = -$cI->id; $ench['icon'] = strTolower($cI->getField('iconString')); $ench['slots'][] = $slot; if ($cI->getField('quality') > $ench['quality']) { $ench['quality'] = $cI->getField('quality'); } if ($cI->getField('requiredClass') > 0) { $ench['classes'] = $cI->getField('requiredClass'); $ench['jsonequip']['classes'] = $cI->getField('requiredClass'); } if (!isset($ench['jsonequip']['reqlevel'])) { if ($cI->getField('requiredLevel') > 0) { $ench['jsonequip']['reqlevel'] = $cI->getField('requiredLevel'); } } } // enchant spell not in use if (empty($ench['source'])) { continue; } // everything gathered if (isset($enchantsOut[$eId])) { foreach ($enchantsOut[$eId] as $k => $v) { if (is_array($v)) { while ($pop = array_pop($ench[$k])) { $enchantsOut[$eId][$k][] = $pop; } } else { if ($k == 'quality') { if ($enchantsOut[$eId]['source'][0] > 0 && $ench['source'][0] < 0) { $enchantsOut[$eId][$k] = -1; } else { if ($enchantsOut[$eId]['source'][0] < 0 && $ench['source'][0] > 0) { $enchantsOut[$eId][$k] = -1; } else { $enchantsOut[$eId][$k] = $ench[$k]; } } } else { if ($enchantsOut[$eId][$k] <= 0) { $enchantsOut[$eId][$k] = $ench[$k]; } } } } } else { // nothing yet, create new $enchantsOut[$eId] = $ench; } } // walk over each entry and strip single-item arrays foreach ($enchantsOut as &$ench) { foreach ($ench as $k => $v) { if (is_array($v) && count($v) == 1 && $k != 'jsonequip') { $ench[$k] = $v[0]; } } } $toFile = "var g_enchants = " . Util::toJSON($enchantsOut) . ";"; $file = 'datasets/' . User::$localeString . '/enchants'; if (!CLISetup::writeFile($file, $toFile)) { $success = false; } } return $successs; }