iterate() as $__) $enchIds[] = $enchantSpells->getField('effect1MiscValue'); $enchMisc = []; $enchJSON = Util::parseItemEnchantment($enchIds, false, $enchMisc); foreach ($locales as $lId) { set_time_limit(120); User::useLocale($lId); Lang::load(Util::$localeStrings[$lId]); $enchantsOut = []; foreach ($enchantSpells->iterate() as $__) { // slots have to be recalculated $slot = 0; if ($enchantSpells->getField('equippedItemClass') == 4) // armor { 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) // 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)); } } } $eId = $enchantSpells->getField('effect1MiscValue'); // 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' => [], // determined per spell but set per item 'enchantment' => Util::localizedString($enchMisc[$eId]['text'], 'text'), 'jsonequip' => @$enchJSON[$eId] ?: [], 'temp' => 0, // always 0 'classes' => 0, // modified by item ); if (isset($enchMisc[$eId]['reqskill'])) $ench['jsonequip']['reqskill'] = $enchMisc[$eId]['reqskill']; if (isset($enchMisc[$eId]['reqskillrank'])) $ench['jsonequip']['reqskill'] = $enchMisc[$eId]['reqskillrank']; if (isset($enchMisc[$eId]['requiredLevel'])) $ench['jsonequip']['requiredLevel'] = $enchMisc[$eId]['requiredLevel']; // check if the spell has an entry in skill_line_ability -> Source:Profession if ($skill = DB::Aowow()->SelectCell('SELECT skillLineId FROM dbc.skilllineability WHERE spellId = ?d', $enchantSpells->id)) { $ench['name'][] = $enchantSpells->getField('name', true); $ench['source'][] = $enchantSpells->id; $ench['skill'] = $skill; $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])) // already found, append data { foreach ($enchantsOut[$eId] as $k => $v) { if (is_array($v)) { while ($pop = array_pop($ench[$k])) $enchantsOut[$eId][$k][] = $pop; } else { if ($k == 'quality') // quality:-1 if spells and items are mixed { 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 = "; $toFile .= json_encode($enchantsOut, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_NUMERIC_CHECK); $toFile .= ";"; $file = 'datasets/'.User::$localeString.'/enchants'; if (!writeFile($file, $toFile, $log)) $success = false; } return $successs; } ?>