\n";
foreach ($locales as $lId)
{
User::useLocale($lId);
$enchantsOut = [];
while ($enchantSpells->iterate())
{
$enchant = DB::Aowow()->SelectRow('SELECT * FROM ?_itemEnchantment WHERE Id = ?d', $enchantSpells->getField('effect1MiscValue'));
if (!$enchant) // 'shouldn't' happen
continue;
// slots have to be recalculated
$slot = 0;
if ($enchantSpells->getField('equippedItemClass') == 4) // armor
{
if ($invType = $enchantSpells->getField('equippedItemInventoryTypeMask'))
$slot = $enchantSpells->getField('equippedItemInventoryTypeMask') >> 1;
else /* if (equippedItemSubClassMask == 64) */ // shields have it their own way <_<
$slot = (1 << (14 - 1));
}
else if ($enchantSpells->getField('equippedItemClass') == 2) // weapon
{
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));
}
}
}
// costy and locale-independant -> cache
if (!isset($jsonEnchants[$enchant['id']]))
$jsonEnchants[$enchant['id']] = Util::parseItemEnchantment($enchant);
// defaults
$ench = array(
'name' => [], // set by skill or item
'quality' => -1, // modified if item
'icon' => strToLower($enchantSpells->getField('iconString')), // item over spell
'source' => [], // <0: item; >0:spell
'skill' => -1, // modified if skill
'slots' => [], // determied per spell but set per item
'enchantment' => Util::jsEscape(Util::localizedString($enchant, 'text')),
'jsonequip' => $jsonEnchants[$enchant['id']],
'temp' => 0, // always 0
'classes' => 0, // modified by item
);
if ($enchant['skillLine'] > 0)
$ench['jsonequip']['reqskill'] = $enchant['skillLine'];
if ($enchant['skillLevel'] > 0)
$ench['jsonequip']['reqskillrank'] = $enchant['skillLevel'];
if ($enchant['requiredLevel'] > 0)
$ench['jsonequip']['reqlevel'] = $enchant['requiredLevel'];
// check if the spell has an entry in skill_line_ability -> Source:Profession
if ($skill = DB::Aowow()->SelectCell('SELECT skillId FROM ?_skill_line_ability WHERE spellId = ?d', $enchantSpells->id))
{
$ench['name'][] = Util::jsEscape($enchantSpells->getField('name', true)));
$ench['source'][] = $enchantSpells->id;
$ench['skill'] = $skill;
$ench['slots'][] = $slot;
}
// check if this item can be cast via item -> Source:Item
if (!isset($castItems[$enchantSpells->id]))
$castItems[$enchantSpells->id] = new ItemList([['spellid_1', $enchantSpells->id], ['name', 'Scroll of Enchant%', '!']]); // do not reuse enchantment scrolls
$cI &= $castItems[$enchantSpells->id]; // this construct is a bit .. unwieldy
while ($cI->iterate())
{
$ench['name'][] = Util::jsEscape($cI->getField('name', true));
$ench['source'][] = -$cI->id;
$ench['icon'] = strTolower($cI->getField('icon'));
$ench['slots'][] = $slot;
if ($cI->getField('Quality') > $ench['quality'])
$ench['quality'] = $cI->getField('Quality');
if ($cI->getField('AllowableClass') > 0)
{
$ench['classes'] = $cI->getField('AllowableClass');
$ench['jsonequip']['classes'] = $cI->getField('AllowableClass');
}
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[$enchant['id']])) // already found, append data
{
foreach ($enchantsOut[$enchant['id']] as $k => $v)
{
if (is_array($v))
{
while ($pop = array_pop($ench[$k]))
$enchantsOut[$enchant['id']][$k][] = $pop;
}
else
{
if ($k == 'quality') // quality:-1 if spells and items are mixed
{
if ($enchantsOut[$enchant['id']]['source'][0] > 0 && $ench['source'][0] < 0)
$enchantsOut[$enchant['id']][$k] = -1;
else if ($enchantsOut[$enchant['id']]['source'][0] < 0 && $ench['source'][0] > 0)
$enchantsOut[$enchant['id']][$k] = -1;
else
$enchantsOut[$enchant['id']][$k] = $ench[$k];
}
else if ($enchantsOut[$enchant['id']][$k] <= 0)
$enchantsOut[$enchant['id']][$k] = $ench[$k];
}
}
}
else // nothing yet, create new
$enchantsOut[$enchant['id']] = $ench;
}
// walk over each entry and strip single-item arrays
foreach ($enchantsOut as $eId => $ench)
{
foreach ($ench as $k => $v)
if (is_array($v) && count($v) == 1 && $k != 'jsonequip')
$enchantsOut[$eId][$k] = $v[0];
}
ksort($enchantsOut);
$toFile = "var g_enchants = ";
$toFile .= json_encode($enchantsOut, JSON_PRETTY_PRINT | JSON_NUMERIC_CHECK);
$toFile .= ";";
$file = 'datasets\\'.User::$localeString.'\\enchants';
$handle = fOpen($file, "w");
fWrite($handle, $toFile);
fClose($handle);
echo "done enchants loc: ".$lId." in ".Util::execTime()."
\n";
}
echo "
\nall done";
User::useLocale(LOCALE_EN);
$stats = DB::Aowow()->getStatistics();
echo "
\n".$stats['count']." queries in: ".Util::formatTime($stats['time'] * 1000);
?>