示例#1
0
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;
}
示例#2
0
 private static function getSubjects()
 {
     foreach (self::$subjCache as $type => $ids) {
         $_ = array_filter(array_keys($ids), 'is_numeric');
         if (!$_) {
             continue;
         }
         $cnd = [CFG_SQL_LIMIT_NONE, ['id', $_]];
         switch ($type) {
             case TYPE_NPC:
                 $obj = new CreatureList($cnd);
                 break;
             case TYPE_OBJECT:
                 $obj = new GameobjectList($cnd);
                 break;
             case TYPE_ITEM:
                 $obj = new ItemList($cnd);
                 break;
             case TYPE_ITEMSET:
                 $obj = new ItemsetList($cnd);
                 break;
             case TYPE_QUEST:
                 $obj = new QuestList($cnd);
                 break;
             case TYPE_SPELL:
                 $obj = new SpellList($cnd);
                 break;
             case TYPE_ZONE:
                 $obj = new ZoneList($cnd);
                 break;
             case TYPE_FACTION:
                 $obj = new FactionList($cnd);
                 break;
             case TYPE_PET:
                 $obj = new PetList($cnd);
                 break;
             case TYPE_ACHIEVEMENT:
                 $obj = new AchievementList($cnd);
                 break;
             case TYPE_TITLE:
                 $obj = new TitleList($cnd);
                 break;
             case TYPE_WORLDEVENT:
                 $obj = new WorldEventList($cnd);
                 break;
             case TYPE_CLASS:
                 $obj = new CharClassList($cnd);
                 break;
             case TYPE_RACE:
                 $obj = new CharRaceList($cnd);
                 break;
             case TYPE_SKILL:
                 $obj = new SkillList($cnd);
                 break;
             case TYPE_CURRENCY:
                 $obj = new CurrencyList($cnd);
                 break;
             case TYPE_EMOTE:
                 $obj = new EmoteList($cnd);
                 break;
             case TYPE_ENCHANTMENT:
                 $obj = new EnchantmentList($cnd);
                 break;
             default:
                 continue;
         }
         foreach ($obj->iterate() as $id => $__) {
             self::$subjCache[$type][$id] = $obj->getField('name', true);
         }
     }
 }
示例#3
0
 public function initSubItems()
 {
     if (!array_keys($this->templates)) {
         return;
     }
     $subItemIds = [];
     foreach ($this->iterate() as $__) {
         if ($_ = $this->getField('randomEnchant')) {
             $subItemIds[abs($_)] = $_;
         }
     }
     if (!$subItemIds) {
         return;
     }
     // remember: id < 0: randomSuffix; id > 0: randomProperty
     $subItemTpls = DB::World()->select('
         SELECT CAST( entry as SIGNED) AS ARRAY_KEY, CAST( ench as SIGNED) AS ARRAY_KEY2, chance FROM item_enchantment_template WHERE entry IN (?a) UNION
         SELECT CAST(-entry as SIGNED) AS ARRAY_KEY, CAST(-ench as SIGNED) AS ARRAY_KEY2, chance FROM item_enchantment_template WHERE entry IN (?a)', array_keys(array_filter($subItemIds, function ($v) {
         return $v > 0;
     })) ?: [0], array_keys(array_filter($subItemIds, function ($v) {
         return $v < 0;
     })) ?: [0]);
     $randIds = [];
     foreach ($subItemTpls as $tpl) {
         $randIds = array_merge($randIds, array_keys($tpl));
     }
     if (!$randIds) {
         return;
     }
     $randEnchants = DB::Aowow()->select('SELECT *, id AS ARRAY_KEY FROM ?_itemrandomenchant WHERE id IN (?a)', $randIds);
     $enchIds = array_unique(array_merge(array_column($randEnchants, 'enchantId1'), array_column($randEnchants, 'enchantId2'), array_column($randEnchants, 'enchantId3'), array_column($randEnchants, 'enchantId4'), array_column($randEnchants, 'enchantId5')));
     $enchants = new EnchantmentList(array(['id', $enchIds], CFG_SQL_LIMIT_NONE));
     foreach ($enchants->iterate() as $eId => $_) {
         $this->rndEnchIds[$eId] = array('text' => $enchants->getField('name', true), 'stats' => $enchants->getStatGain());
     }
     foreach ($this->iterate() as $mstItem => $__) {
         if (!$this->getField('randomEnchant')) {
             continue;
         }
         if (empty($subItemTpls[$this->getField('randomEnchant')])) {
             continue;
         }
         foreach ($subItemTpls[$this->getField('randomEnchant')] as $subId => $data) {
             if (empty($randEnchants[$subId])) {
                 continue;
             }
             $data = array_merge($randEnchants[$subId], $data);
             $jsonEquip = [];
             $jsonText = [];
             for ($i = 1; $i < 6; $i++) {
                 $enchId = $data['enchantId' . $i];
                 if ($enchId <= 0 || empty($this->rndEnchIds[$enchId])) {
                     continue;
                 }
                 if ($data['allocationPct' . $i] > 0) {
                     $qty = intVal($data['allocationPct' . $i] * $this->generateEnchSuffixFactor());
                     $stats = array_fill_keys(array_keys($this->rndEnchIds[$enchId]['stats']), $qty);
                     $jsonText[$enchId] = str_replace('$i', $qty, $this->rndEnchIds[$enchId]['text']);
                     Util::arraySumByKey($jsonEquip, $stats);
                 } else {
                     $jsonText[$enchId] = $this->rndEnchIds[$enchId]['text'];
                     Util::arraySumByKey($jsonEquip, $this->rndEnchIds[$enchId]['stats']);
                 }
             }
             $this->subItems[$mstItem][$subId] = array('name' => Util::localizedString($data, 'name'), 'enchantment' => $jsonText, 'jsonequip' => $jsonEquip, 'chance' => $data['chance']);
         }
         if (!empty($this->subItems[$mstItem])) {
             $this->json[$mstItem]['subitems'] = $this->subItems[$mstItem];
         }
     }
 }
示例#4
0
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;
}