Setuo/enchants

* reduced overhead by directly querying for spells instead of wrapping them in a SpellList (that functions i didn't neeed)
 * skip enchantments from items without source
This commit is contained in:
Sarjuuk
2017-02-12 01:56:28 +01:00
parent a31e018959
commit 201f31b3ac

View File

@@ -59,16 +59,29 @@ if (!CLI)
$slotPointer = [13, 17, 26, 26, 13, 17, 17, 13, 17, null, 17, null, null, 13, null, 13, null, null, null, null, 17]; $slotPointer = [13, 17, 26, 26, 13, 17, 17, 13, 17, null, 17, null, null, 13, null, 13, null, null, null, null, 17];
$castItems = []; $castItems = [];
$successs = true; $successs = true;
$enchantSpells = new SpellList([['effect1Id', 53], ['name_loc0', 'QA%', '!'], CFG_SQL_LIMIT_NONE]); // enchantItemPermanent && !qualityAssurance $enchantSpells = DB::Aowow()->select('
SELECT
s.id AS ARRAY_KEY,
effect1MiscValue,
equippedItemClass, equippedItemInventoryTypeMask, equippedItemSubClassMask,
skillLine1,
IFNULL(i.iconString, "inv_misc_questionmark") AS iconString,
name_loc0, name_loc2, name_loc3, name_loc6, name_loc8
FROM
?_spell s
LEFT JOIN
?_icons i ON i.id = s.iconId
WHERE
effect1Id = ?d AND
name_loc0 NOT LIKE "QA%"'
, 53); // enchantItemPermanent && !qualityAssurance
// check directory-structure // check directory-structure
foreach (Util::$localeStrings as $dir) foreach (Util::$localeStrings as $dir)
if (!CLISetup::writeDir('datasets/'.$dir)) if (!CLISetup::writeDir('datasets/'.$dir))
$success = false; $success = false;
$enchIds = []; $enchIds = array_column($enchantSpells, 'effect1MiscValue');
foreach ($enchantSpells->iterate() as $__)
$enchIds[] = $enchantSpells->getField('effect1MiscValue');
$enchantments = new EnchantmentList(array(['id', $enchIds], CFG_SQL_LIMIT_NONE)); $enchantments = new EnchantmentList(array(['id', $enchIds], CFG_SQL_LIMIT_NONE));
if ($enchantments->error) if ($enchantments->error)
@@ -86,32 +99,32 @@ if (!CLI)
Lang::load(Util::$localeStrings[$lId]); Lang::load(Util::$localeStrings[$lId]);
$enchantsOut = []; $enchantsOut = [];
foreach ($enchantSpells->iterate() as $__) foreach ($enchantSpells as $esId => $es)
{ {
$eId = $enchantSpells->getField('effect1MiscValue'); $eId = $es['effect1MiscValue'];
if (!$enchantments->getEntry($eId)) if (!$enchantments->getEntry($eId))
{ {
CLISetup::log(' * could not find enchantment #'.$eId.' referenced by spell #'.$enchantSpells->id, CLISetup::LOG_WARN); CLISetup::log(' * could not find enchantment #'.$eId.' referenced by spell #'.$esId, CLISetup::LOG_WARN);
continue; continue;
} }
// slots have to be recalculated // slots have to be recalculated
$slot = 0; $slot = 0;
if ($enchantSpells->getField('equippedItemClass') == 4) // armor if ($es['equippedItemClass'] == 4) // armor
{ {
if ($invType = $enchantSpells->getField('equippedItemInventoryTypeMask')) if ($invType = $es['equippedItemInventoryTypeMask'])
$slot = $invType >> 1; $slot = $invType >> 1;
else /* if (equippedItemSubClassMask == 64) */ // shields have it their own way <_< else /* if (equippedItemSubClassMask == 64) */ // shields have it their own way <_<
$slot = (1 << (14 - 1)); $slot = (1 << (14 - 1));
} }
else if ($enchantSpells->getField('equippedItemClass') == 2) // weapon else if ($es['equippedItemClass'] == 2) // weapon
{ {
foreach ($slotPointer as $i => $sp) foreach ($slotPointer as $i => $sp)
{ {
if (!$sp) if (!$sp)
continue; continue;
if ((1 << $i) & $enchantSpells->getField('equippedItemSubClassMask')) if ((1 << $i) & $es['equippedItemSubClassMask'])
{ {
if ($sp == 13) // also mainHand & offHand *siiigh* if ($sp == 13) // also mainHand & offHand *siiigh*
$slot |= ((1 << (21 - 1)) | (1 << (22 - 1))); $slot |= ((1 << (21 - 1)) | (1 << (22 - 1)));
@@ -126,7 +139,7 @@ if (!CLI)
$ench = array( $ench = array(
'name' => [], // set by skill or item 'name' => [], // set by skill or item
'quality' => -1, // modified if item 'quality' => -1, // modified if item
'icon' => strToLower($enchantSpells->getField('iconString')), // item over spell 'icon' => strToLower($es['iconString']), // item over spell
'source' => [], // <0: item; >0:spell 'source' => [], // <0: item; >0:spell
'skill' => -1, // modified if skill 'skill' => -1, // modified if skill
'slots' => [], // determined per spell but set per item 'slots' => [], // determined per spell but set per item
@@ -146,19 +159,20 @@ if (!CLI)
$ench['jsonequip']['reqlevel'] = $_; $ench['jsonequip']['reqlevel'] = $_;
// check if the spell has an entry in skill_line_ability -> Source:Profession // check if the spell has an entry in skill_line_ability -> Source:Profession
if ($skills = $enchantSpells->getField('skillLines')) if ($es['skillLine1'])
{ {
$ench['name'][] = $enchantSpells->getField('name', true); $ench['name'][] = Util::localizedString($es, 'name');
$ench['source'][] = $enchantSpells->id; $ench['source'][] = $esId;
$ench['skill'] = $skills[0]; $ench['skill'] = $es['skillLine1'];
$ench['slots'][] = $slot; $ench['slots'][] = $slot;
} }
// check if this spell can be cast via item -> Source:Item // check if this spell can be cast via item -> Source:Item
if (!isset($castItems[$enchantSpells->id])) // do not reuse enchantment scrolls; do not use items without source
$castItems[$enchantSpells->id] = new ItemList([['spellId1', $enchantSpells->id], ['name_loc0', 'Scroll of Enchant%', '!']]); // do not reuse enchantment scrolls if (!isset($castItems[$esId]))
$castItems[$esId] = new ItemList([['spellId1', $esId], ['name_loc0', 'Scroll of Enchant%', '!'], ['src.typeId', null, '!']]);
$cI = &$castItems[$enchantSpells->id]; // this construct is a bit .. unwieldy $cI = &$castItems[$esId]; // this construct is a bit .. unwieldy
foreach ($cI->iterate() as $__) foreach ($cI->iterate() as $__)
{ {
$ench['name'][] = $cI->getField('name', true); $ench['name'][] = $cI->getField('name', true);