コード例 #1
0
ファイル: enchantment.php プロジェクト: TrinityCore/aowow
 protected function generateContent()
 {
     /***********/
     /* Infobox */
     /***********/
     $infobox = Lang::getInfoBoxForFlags($this->subject->getField('cuFlags'));
     // reqLevel
     if ($_ = $this->subject->getField('requiredLevel')) {
         $infobox[] = sprintf(Lang::game('reqLevel'), $_);
     }
     // reqskill
     if ($_ = $this->subject->getField('skillLine')) {
         $this->extendGlobalIds(TYPE_SKILL, $_);
         $foo = sprintf(Lang::game('requires'), ' [skill=' . $_ . ']');
         if ($_ = $this->subject->getField('skillLevel')) {
             $foo .= ' (' . $_ . ')';
         }
         $infobox[] = $foo;
     }
     /****************/
     /* Main Content */
     /****************/
     $this->infobox = $infobox ? '[ul][li]' . implode('[/li][li]', $infobox) . '[/li][/ul]' : null;
     $this->effects = [];
     // 3 effects
     for ($i = 1; $i < 4; $i++) {
         $_ty = $this->subject->getField('type' . $i);
         $_qty = $this->subject->getField('amount' . $i);
         $_obj = $this->subject->getField('object' . $i);
         switch ($_ty) {
             case 1:
             case 3:
             case 7:
                 $sArr = $this->subject->getField('spells')[$i];
                 $spl = $this->subject->getRelSpell($sArr[0]);
                 $this->effects[$i]['name'] = User::isInGroup(U_GROUP_EMPLOYEE) ? sprintf(Util::$dfnString, 'Type: ' . $_ty, Lang::item('trigger', $sArr[1])) : Lang::item('trigger', $sArr[1]);
                 $this->effects[$i]['proc'] = $sArr[3];
                 $this->effects[$i]['value'] = $_qty ?: null;
                 $this->effects[$i]['icon'] = array('name' => !$spl ? Util::ucFirst(Lang::game('spell')) . ' #' . $sArr[0] : Util::localizedString($spl, 'name'), 'id' => $sArr[0], 'count' => $sArr[2]);
                 break;
             case 5:
                 if ($_obj < 2) {
                     // [mana, health] are on [0, 1] respectively and are expected on [1, 2] ..
                     $_obj++;
                 }
                 // 0 is weaponDmg .. ehh .. i messed up somewhere
                 $this->effects[$i]['tip'] = [$_obj, Util::$itemMods[$_obj]];
                 // DO NOT BREAK!
             // DO NOT BREAK!
             case 2:
             case 6:
             case 8:
             case 4:
                 $this->effects[$i]['name'] = User::isInGroup(U_GROUP_EMPLOYEE) ? sprintf(Util::$dfnString, 'Type: ' . $_ty, Lang::enchantment('types', $_ty)) : Lang::enchantment('types', $_ty);
                 $this->effects[$i]['value'] = $_qty;
                 if ($_ty == 4) {
                     $this->effects[$i]['name'] .= Lang::main('colon') . '(' . (User::isInGroup(U_GROUP_EMPLOYEE) ? sprintf(Util::$dfnString, 'Object: ' . $_obj, Lang::getMagicSchools(1 << $_obj)) : Lang::getMagicSchools(1 << $_obj)) . ')';
                 }
         }
     }
     // activation conditions
     if ($_ = $this->subject->getField('conditionId')) {
         $x = '';
         if ($gemCnd = DB::Aowow()->selectRow('SELECT * FROM ?_itemenchantmentcondition WHERE id = ?d', $_)) {
             for ($i = 1; $i < 6; $i++) {
                 if (!$gemCnd['color' . $i]) {
                     continue;
                 }
                 $fiColors = function ($idx) {
                     $foo = '';
                     switch ($idx) {
                         case 2:
                             $foo = '0:3:5';
                             break;
                             // red
                         // red
                         case 3:
                             $foo = '2:4:5';
                             break;
                             // yellow
                         // yellow
                         case 4:
                             $foo = '1:3:4';
                             break;
                             // blue
                     }
                     return $foo;
                 };
                 $bLink = $gemCnd['color' . $i] ? '<a href="?items=3&filter=ty=' . $fiColors($gemCnd['color' . $i]) . '">' . Lang::item('gemColors', $gemCnd['color' . $i] - 1) . '</a>' : '';
                 $cLink = $gemCnd['cmpColor' . $i] ? '<a href="?items=3&filter=ty=' . $fiColors($gemCnd['cmpColor' . $i]) . '">' . Lang::item('gemColors', $gemCnd['cmpColor' . $i] - 1) . '</a>' : '';
                 switch ($gemCnd['comparator' . $i]) {
                     case 2:
                         // requires less <color> than (<value> || <comparecolor>) gems
                     // requires less <color> than (<value> || <comparecolor>) gems
                     case 5:
                         // requires at least <color> than (<value> || <comparecolor>) gems
                         $sp = (int) $gemCnd['value' . $i] > 1;
                         $x .= '<span class="q0">' . Lang::achievement('reqNumCrt') . ' ' . sprintf(Lang::item('gemConditions', $gemCnd['comparator' . $i], $sp), $gemCnd['value' . $i], $bLink) . '</span><br />';
                         break;
                     case 3:
                         // requires more <color> than (<value> || <comparecolor>) gems
                         $link = '<a href="?items=3&filter=ty=' . $fiColors($gemCnd['cmpColor' . $i]) . '">' . Lang::item('gemColors', $gemCnd['cmpColor' . $i] - 1) . '</a>';
                         $x .= '<span class="q0">' . Lang::achievement('reqNumCrt') . ' ' . sprintf(Lang::item('gemConditions', 3), $bLink, $cLink) . '</span><br />';
                         break;
                 }
             }
         }
         $this->activateCondition = $x;
     }
     /**************/
     /* Extra Tabs */
     /**************/
     // used by gem
     $gemList = new ItemList(array(['gemEnchantmentId', $this->typeId]));
     if (!$gemList->error) {
         $this->lvTabs[] = ['item', array('data' => array_values($gemList->getListviewData()), 'name' => '$LANG.tab_usedby + \' \' + LANG.gems', 'id' => 'used-by-gem')];
         $this->extendGlobalData($gemList->getJsGlobals());
     }
     // used by socket bonus
     $socketsList = new ItemList(array(['socketBonus', $this->typeId]));
     if (!$socketsList->error) {
         $this->lvTabs[] = ['item', array('data' => array_values($socketsList->getListviewData()), 'name' => '$LANG.tab_usedby + \' \' + \'' . Lang::item('socketBonus') . '\'', 'id' => 'used-by-socketbonus')];
         $this->extendGlobalData($socketsList->getJsGlobals());
     }
     // used by spell
     // used by useItem
     $cnd = array('OR', ['AND', ['effect1Id', [53, 54, 156, 92]], ['effect1MiscValue', $this->typeId]], ['AND', ['effect2Id', [53, 54, 156, 92]], ['effect2MiscValue', $this->typeId]], ['AND', ['effect3Id', [53, 54, 156, 92]], ['effect3MiscValue', $this->typeId]]);
     $spellList = new SpellList($cnd);
     if (!$spellList->error) {
         $spellData = $spellList->getListviewData();
         $this->extendGlobalData($spellList->getJsGlobals());
         $spellIds = $spellList->getFoundIDs();
         $conditions = array('OR', ['AND', ['spellTrigger1', [0, 5]], ['spellId1', $spellIds]], ['AND', ['spellTrigger2', [0, 5]], ['spellId2', $spellIds]], ['AND', ['spellTrigger3', [0, 5]], ['spellId3', $spellIds]], ['AND', ['spellTrigger4', [0, 5]], ['spellId4', $spellIds]], ['AND', ['spellTrigger5', [0, 5]], ['spellId5', $spellIds]]);
         $ubItems = new ItemList($conditions);
         if (!$ubItems->error) {
             $this->lvTabs[] = ['item', array('data' => array_values($ubItems->getListviewData()), 'name' => '$LANG.tab_usedby + \' \' + LANG.types[3][0]', 'id' => 'used-by-item')];
             $this->extendGlobalData($ubItems->getJSGlobals(GLOBALINFO_SELF));
         }
         // remove found spells if they are used by an item
         if (!$ubItems->error) {
             foreach ($spellList->iterate() as $sId => $__) {
                 // if Perm. Enchantment has a createItem its a Scroll of Enchantment (display both)
                 for ($i = 1; $i < 4; $i++) {
                     if ($spellList->getField('effect' . $i . 'Id') == 53 && $spellList->getField('effect' . $i . 'CreateItemId')) {
                         continue 2;
                     }
                 }
                 foreach ($ubItems->iterate() as $__) {
                     for ($i = 1; $i < 6; $i++) {
                         if ($ubItems->getField('spellId' . $i) == $sId) {
                             unset($spellData[$sId]);
                             break 2;
                         }
                     }
                 }
             }
         }
         $this->lvTabs[] = ['spell', array('data' => array_values($spellData), 'name' => '$LANG.tab_usedby + \' \' + LANG.types[6][0]', 'id' => 'used-by-spell')];
     }
     // used by randomAttrItem
     $ire = DB::Aowow()->select('SELECT *, ABS(id) AS ARRAY_KEY FROM ?_itemrandomenchant WHERE enchantId1 = ?d OR enchantId2 = ?d OR enchantId3 = ?d OR enchantId4 = ?d OR enchantId5 = ?d', $this->typeId, $this->typeId, $this->typeId, $this->typeId, $this->typeId);
     if ($ire) {
         if ($iet = DB::World()->select('SELECT entry AS ARRAY_KEY, ench, chance FROM item_enchantment_template WHERE ench IN (?a)', array_keys($ire))) {
             $randIds = [];
             // transform back to signed format
             foreach ($iet as $tplId => $data) {
                 $randIds[$ire[$data['ench']]['id'] > 0 ? $tplId : -$tplId] = $ire[$data['ench']]['id'];
             }
             $randItems = new ItemList(array(CFG_SQL_LIMIT_NONE, ['randomEnchant', array_keys($randIds)]));
             if (!$randItems->error) {
                 $data = $randItems->getListviewData();
                 foreach ($randItems->iterate() as $iId => $__) {
                     $re = $randItems->getField('randomEnchant');
                     $data[$iId]['percent'] = $iet[abs($re)]['chance'];
                     $data[$iId]['count'] = 1;
                     // expected by js or the pct-col becomes unsortable
                     $data[$iId]['rel'] = 'rand=' . $ire[$iet[abs($re)]['ench']]['id'];
                     $data[$iId]['name'] .= ' ' . Util::localizedString($ire[$iet[abs($re)]['ench']], 'name');
                 }
                 $this->lvTabs[] = ['item', array('data' => array_values($data), 'id' => 'used-by-rand', 'name' => '$LANG.tab_usedby + \' \' + \'' . Lang::item('_rndEnchants') . '\'', 'extraCols' => ['$Listview.extraCols.percent'])];
                 $this->extendGlobalData($randItems->getJSGlobals(GLOBALINFO_SELF));
             }
         }
     }
 }