protected function generateContent() { $conditions = []; if (!User::isInGroup(U_GROUP_EMPLOYEE)) { $conditions[] = [['cuFlags', CUSTOM_EXCLUDE_FOR_LISTVIEW, '&'], 0]; } if ($this->category) { $conditions[] = ['category', (int) $this->category[0]]; } $money = new CurrencyList($conditions); $this->lvTabs[] = array('file' => 'currency', 'data' => $money->getListviewData(), 'params' => []); }
private function _searchCurrency($cndBase) { $result = []; $cnd = array_merge($cndBase, [$this->createLookup()]); $money = new CurrencyList($cnd); if ($data = $money->getListviewData()) { if ($this->searchMask & SEARCH_TYPE_OPEN) { foreach ($money->iterate() as $__) { $data[$money->id]['param1'] = strToLower($money->getField('iconString')); } } $result = array('type' => TYPE_CURRENCY, 'appendix' => ' (Currency)', 'matches' => $money->getMatches(), 'file' => CurrencyList::$brickFile, 'data' => $data, 'params' => []); if ($money->getMatches() > $this->maxResults) { $result['params']['note'] = sprintf(Util::$tryNarrowingString, 'LANG.lvnote_currenciesfound', $money->getMatches(), $this->maxResults); $result['params']['_truncated'] = 1; } } return $result; }
public function getExtendedCost($filter = [], &$reqRating = []) { if ($this->error) { return []; } if (empty($this->vendors)) { $itemz = DB::World()->select(' SELECT nv.item AS ARRAY_KEY1, nv.entry AS ARRAY_KEY2, 0 AS eventId, nv.maxcount, nv.extendedCost FROM npc_vendor nv WHERE {nv.entry IN (?a) AND} nv.item IN (?a) UNION SELECT genv.item AS ARRAY_KEY1, c.id AS ARRAY_KEY2, ge.eventEntry AS eventId, genv.maxcount, genv.extendedCost FROM game_event_npc_vendor genv LEFT JOIN game_event ge ON genv.eventEntry = ge.eventEntry JOIN creature c ON c.guid = genv.guid WHERE {c.id IN (?a) AND} genv.item IN (?a)', empty($filter[TYPE_NPC]) || !is_array($filter[TYPE_NPC]) ? DBSIMPLE_SKIP : $filter[TYPE_NPC], array_keys($this->templates), empty($filter[TYPE_NPC]) || !is_array($filter[TYPE_NPC]) ? DBSIMPLE_SKIP : $filter[TYPE_NPC], array_keys($this->templates)); $xCosts = []; foreach ($itemz as $i => $vendors) { $xCosts = array_merge($xCosts, array_column($vendors, 'extendedCost')); } if ($xCosts) { $xCosts = DB::Aowow()->select('SELECT *, id AS ARRAY_KEY FROM ?_itemextendedcost WHERE id IN (?a)', $xCosts); } $cItems = []; foreach ($itemz as $k => $vendors) { foreach ($vendors as $l => $vInfo) { $costs = []; if (!empty($xCosts[$vInfo['extendedCost']])) { $costs = $xCosts[$vInfo['extendedCost']]; } $data = array('stock' => $vInfo['maxcount'] ?: -1, 'event' => $vInfo['eventId'], 'reqRating' => $costs ? $costs['reqPersonalRating'] : 0, 'reqBracket' => $costs ? $costs['reqArenaSlot'] : 0); // hardcode arena(103) & honor(104) if (!empty($costs['reqArenaPoints'])) { $data[-103] = $costs['reqArenaPoints']; $this->jsGlobals[TYPE_CURRENCY][103] = 103; } if (!empty($costs['reqHonorPoints'])) { $data[-104] = $costs['reqHonorPoints']; $this->jsGlobals[TYPE_CURRENCY][104] = 104; } for ($i = 1; $i < 6; $i++) { if (!empty($costs['reqItemId' . $i]) && $costs['itemCount' . $i] > 0) { $data[$costs['reqItemId' . $i]] = $costs['itemCount' . $i]; $cItems[] = $costs['reqItemId' . $i]; } } // no extended cost or additional gold required if (!$costs || $this->getField('flagsExtra') & 0x4) { if ($_ = $this->getField('buyPrice')) { $data[0] = $_; } } $vendors[$l] = $data; } $itemz[$k] = $vendors; } // convert items to currency if possible if ($cItems) { $moneyItems = new CurrencyList(array(['itemId', $cItems])); foreach ($moneyItems->getJSGlobals() as $type => $jsData) { foreach ($jsData as $k => $v) { $this->jsGlobals[$type][$k] = $v; } } foreach ($itemz as $id => $vendors) { foreach ($vendors as $l => $costs) { foreach ($costs as $k => $v) { if (in_array($k, $cItems)) { $found = false; foreach ($moneyItems->iterate() as $__) { if ($moneyItems->getField('itemId') == $k) { unset($costs[$k]); $costs[-$moneyItems->id] = $v; $found = true; break; } } if (!$found) { $this->jsGlobals[TYPE_ITEM][$k] = $k; } } } $vendors[$l] = $costs; } $itemz[$id] = $vendors; } } $this->vendors = $itemz; } $result = $this->vendors; // apply filter if given $tok = !empty($filter[TYPE_ITEM]) ? $filter[TYPE_ITEM] : null; $cur = !empty($filter[TYPE_CURRENCY]) ? $filter[TYPE_CURRENCY] : null; foreach ($result as $itemId => &$data) { $reqRating = []; foreach ($data as $npcId => $costs) { if ($tok || $cur) { $valid = false; foreach ($costs as $k => $qty) { if ((!$tok || $k == $tok) && (!$cur || $k == -$cur)) { $valid = true; break; } } if (!$valid) { unset($data[$npcId]); } } // reqRating ins't really a cost .. so pass it by ref instead of return // use highest total value if (isset($data[$npcId]) && $costs['reqRating'] && (!$reqRating || $reqRating[0] < $costs['reqRating'])) { $reqRating = [$costs['reqRating'], $costs['reqBracket']]; } } if ($reqRating) { $data['reqRating'] = $reqRating[0]; } if (empty($data)) { unset($result[$itemId]); } } return $result; }
private function createRewards() { $rewards = []; // moneyReward / maxLevelCompensation $comp = $this->subject->getField('rewardMoneyMaxLevel'); $questMoney = $this->subject->getField('rewardOrReqMoney'); if ($questMoney > 0) { $rewards['money'] = Util::formatMoney($questMoney); if ($comp > 0) { $rewards['money'] .= ' ' . sprintf(Lang::quest('expConvert'), Util::formatMoney($questMoney + $comp), MAX_LEVEL); } } else { if ($questMoney <= 0 && $questMoney + $comp > 0) { $rewards['money'] = sprintf(Lang::quest('expConvert2'), Util::formatMoney($questMoney + $comp), MAX_LEVEL); } } // itemChoices if (!empty($this->subject->choices[$this->typeId][TYPE_ITEM])) { $c = $this->subject->choices[$this->typeId][TYPE_ITEM]; $choiceItems = new ItemList(array(['id', array_keys($c)])); if (!$choiceItems->error) { $this->extendGlobalData($choiceItems->getJSGlobals()); foreach ($choiceItems->Iterate() as $id => $__) { $rewards['choice'][] = array('typeStr' => Util::$typeStrings[TYPE_ITEM], 'id' => $id, 'name' => $choiceItems->getField('name', true), 'quality' => $choiceItems->getField('quality'), 'qty' => $c[$id], 'globalStr' => 'g_items'); } } } // itemRewards if (!empty($this->subject->rewards[$this->typeId][TYPE_ITEM])) { $ri = $this->subject->rewards[$this->typeId][TYPE_ITEM]; $rewItems = new ItemList(array(['id', array_keys($ri)])); if (!$rewItems->error) { $this->extendGlobalData($rewItems->getJSGlobals()); foreach ($rewItems->Iterate() as $id => $__) { $rewards['items'][] = array('typeStr' => Util::$typeStrings[TYPE_ITEM], 'id' => $id, 'name' => $rewItems->getField('name', true), 'quality' => $rewItems->getField('quality'), 'qty' => $ri[$id], 'globalStr' => 'g_items'); } } } if (!empty($this->subject->rewards[$this->typeId][TYPE_ITEM][TYPE_CURRENCY])) { $rc = $this->subject->rewards[$this->typeId][TYPE_ITEM][TYPE_CURRENCY]; $rewCurr = new CurrencyList(array(['id', array_keys($rc)])); if (!$rewCurr->error) { $this->extendGlobalData($rewCurr->getJSGlobals()); foreach ($rewCurr->Iterate() as $id => $__) { $rewards['items'][] = array('typeStr' => Util::$typeStrings[TYPE_CURRENCY], 'id' => $id, 'name' => $rewCurr->getField('name', true), 'quality' => 1, 'qty' => $rc[$id] * ($_side == 2 ? -1 : 1), 'globalStr' => 'g_gatheredcurrencies'); } } } // spellRewards $displ = $this->subject->getField('rewardSpell'); $cast = $this->subject->getField('rewardSpellCast'); if (!$cast && $displ) { $cast = $displ; $displ = 0; } if ($cast || $displ) { $rewSpells = new SpellList(array(['id', [$displ, $cast]])); $this->extendGlobalData($rewSpells->getJSGlobals()); if (User::isInGroup(U_GROUP_EMPLOYEE)) { $extra = null; if ($_ = $rewSpells->getEntry($displ)) { $extra = sprintf(Lang::quest('spellDisplayed'), $displ, Util::localizedString($_, 'name')); } if ($_ = $rewSpells->getEntry($cast)) { $rewards['spells']['extra'] = $extra; $rewards['spells']['cast'][] = array('typeStr' => Util::$typeStrings[TYPE_SPELL], 'id' => $cast, 'name' => Util::localizedString($_, 'name'), 'globalStr' => 'g_spells'); } } else { $teach = []; foreach ($rewSpells->iterate() as $id => $__) { if ($_ = $rewSpells->canTeachSpell()) { foreach ($_ as $idx) { $teach[$rewSpells->getField('effect' . $idx . 'TriggerSpell')] = $id; } } } if ($_ = $rewSpells->getEntry($displ)) { $rewards['spells']['extra'] = null; $rewards['spells'][$teach ? 'learn' : 'cast'][] = array('typeStr' => Util::$typeStrings[TYPE_SPELL], 'id' => $displ, 'name' => Util::localizedString($_, 'name'), 'globalStr' => 'g_spells'); } else { if (($_ = $rewSpells->getEntry($cast)) && !$teach) { $rewards['spells']['extra'] = null; $rewards['spells']['cast'][] = array('typeStr' => Util::$typeStrings[TYPE_SPELL], 'id' => $cast, 'name' => Util::localizedString($_, 'name'), 'globalStr' => 'g_spells'); } else { $taught = new SpellList(array(['id', array_keys($teach)])); if (!$taught->error) { $this->extendGlobalData($taught->getJSGlobals()); $rewards['spells']['extra'] = null; foreach ($taught->iterate() as $id => $__) { $rewards['spells']['learn'][] = array('typeStr' => Util::$typeStrings[TYPE_SPELL], 'id' => $id, 'name' => $taught->getField('name', true), 'globalStr' => 'g_spells'); } } } } } } return $rewards; }
public function init($map = null, $prefix = '') { if ($map != null) { if (PPUtils::array_match_key($map, $prefix . "baseAmount.")) { $newPrefix = $prefix . "baseAmount."; $this->baseAmount = new CurrencyType(); $this->baseAmount->init($map, $newPrefix); } if (PPUtils::array_match_key($map, $prefix . "currencyList.")) { $newPrefix = $prefix . "currencyList."; $this->currencyList = new CurrencyList(); $this->currencyList->init($map, $newPrefix); } } }
function profiler() { $success = true; $scripts = []; /**********/ /* Quests */ /**********/ $scripts[] = function () { $success = true; $condition = [CFG_SQL_LIMIT_NONE, 'AND', [['cuFlags', CUSTOM_EXCLUDE_FOR_LISTVIEW], 0], [['flags', QUEST_FLAG_DAILY | QUEST_FLAG_WEEKLY | QUEST_FLAG_REPEATABLE | QUEST_FLAG_AUTO_REWARDED, '&'], 0], [['specialFlags', QUEST_FLAG_SPECIAL_REPEATABLE | QUEST_FLAG_SPECIAL_DUNGEON_FINDER | QUEST_FLAG_SPECIAL_MONTHLY, '&'], 0]]; $questz = new QuestList($condition); $_ = []; $currencies = array_column($questz->rewards, TYPE_CURRENCY); foreach ($currencies as $curr) { foreach ($curr as $cId => $qty) { $_[] = $cId; } } $relCurr = new CurrencyList(array(['id', $_])); foreach (CLISetup::$localeIds as $l) { set_time_limit(20); User::useLocale($l); Lang::load(Util::$localeStrings[$l]); $buff = "var _ = g_gatheredcurrencies;\n"; foreach ($relCurr->getListviewData() as $id => $data) { $buff .= '_[' . $id . '] = ' . Util::toJSON($data) . ";\n"; } $buff .= "\n\nvar _ = g_quests;\n"; foreach ($questz->getListviewData() as $id => $data) { $buff .= '_[' . $id . '] = ' . Util::toJSON($data) . ";\n"; } $buff .= "\ng_quest_catorder = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10];\n"; if (!CLISetup::writeFile('datasets/' . User::$localeString . '/p-quests', $buff)) { $success = false; } } return $success; }; /****************/ /* Achievements */ /****************/ $scripts[] = function () { $success = true; $condition = array(CFG_SQL_LIMIT_NONE, [['cuFlags', CUSTOM_EXCLUDE_FOR_LISTVIEW, '&'], 0], [['flags', 1, '&'], 0]); $achievez = new AchievementList($condition); foreach (CLISetup::$localeIds as $l) { set_time_limit(5); User::useLocale($l); Lang::load(Util::$localeStrings[$l]); $sumPoints = 0; $buff = "var _ = g_achievements;\n"; foreach ($achievez->getListviewData(ACHIEVEMENTINFO_PROFILE) as $id => $data) { $sumPoints += $data['points']; $buff .= '_[' . $id . '] = ' . Util::toJSON($data) . ";\n"; } // categories to sort by $buff .= "\ng_achievement_catorder = [92, 14863, 97, 169, 170, 171, 172, 14802, 14804, 14803, 14801, 95, 161, 156, 165, 14806, 14921, 96, 201, 160, 14923, 14808, 14805, 14778, 14865, 14777, 14779, 155, 14862, 14861, 14864, 14866, 158, 162, 14780, 168, 14881, 187, 14901, 163, 14922, 159, 14941, 14961, 14962, 14981, 15003, 15002, 15001, 15041, 15042, 81]"; // sum points $buff .= "\ng_achievement_points = [" . $sumPoints . "];\n"; if (!CLISetup::writeFile('datasets/' . User::$localeString . '/p-achievements', $buff)) { $success = false; } } return $success; }; /**********/ /* Titles */ /**********/ $scripts[] = function () { $success = true; $condition = array(CFG_SQL_LIMIT_NONE, [['cuFlags', CUSTOM_EXCLUDE_FOR_LISTVIEW, '&'], 0]); $titlez = new TitleList($condition); foreach (CLISetup::$localeIds as $l) { set_time_limit(5); User::useLocale($l); Lang::load(Util::$localeStrings[$l]); foreach ([0, 1] as $g) { $buff = "var _ = g_titles;\n"; foreach ($titlez->getListviewData() as $id => $data) { $data['name'] = Util::localizedString($titlez->getEntry($id), $g ? 'female' : 'male'); unset($data['namefemale']); $buff .= '_[' . $id . '] = ' . Util::toJSON($data) . ";\n"; } if (!CLISetup::writeFile('datasets/' . User::$localeString . '/p-titles-' . $g, $buff)) { $success = false; } } } return $success; }; /**********/ /* Mounts */ /**********/ $scripts[] = function () { $success = true; $condition = array(CFG_SQL_LIMIT_NONE, [['cuFlags', CUSTOM_EXCLUDE_FOR_LISTVIEW, '&'], 0], ['typeCat', -5]); $mountz = new SpellList($condition); foreach (CLISetup::$localeIds as $l) { set_time_limit(5); User::useLocale($l); Lang::load(Util::$localeStrings[$l]); $buff = "var _ = g_spells;\n"; foreach ($mountz->getListviewData(ITEMINFO_MODEL) as $id => $data) { $data['quality'] = $data['name'][0]; $data['name'] = mb_substr($data['name'], 1); $buff .= '_[' . $id . '] = ' . Util::toJSON($data) . ";\n"; } if (!CLISetup::writeFile('datasets/' . User::$localeString . '/p-mounts', $buff)) { $success = false; } } return $success; }; /**************/ /* Companions */ /**************/ $scripts[] = function () { $success = true; $condition = array(CFG_SQL_LIMIT_NONE, [['cuFlags', CUSTOM_EXCLUDE_FOR_LISTVIEW, '&'], 0], ['typeCat', -6]); $companionz = new SpellList($condition); foreach (CLISetup::$localeIds as $l) { set_time_limit(5); User::useLocale($l); Lang::load(Util::$localeStrings[$l]); $buff = "var _ = g_spells;\n"; foreach ($companionz->getListviewData(ITEMINFO_MODEL) as $id => $data) { $data['quality'] = $data['name'][0]; $data['name'] = mb_substr($data['name'], 1); $buff .= '_[' . $id . '] = ' . Util::toJSON($data) . ";\n"; } if (!CLISetup::writeFile('datasets/' . User::$localeString . '/p-companions', $buff)) { $success = false; } } return $success; }; /************/ /* Factions */ /************/ $scripts[] = function () { $success = true; $condition = array(CFG_SQL_LIMIT_NONE, [['cuFlags', CUSTOM_EXCLUDE_FOR_LISTVIEW, '&'], 0]); $factionz = new FactionList($condition); foreach (CLISetup::$localeIds as $l) { set_time_limit(5); User::useLocale($l); Lang::load(Util::$localeStrings[$l]); $buff = "var _ = g_factions;\n"; foreach ($factionz->getListviewData() as $id => $data) { $buff .= '_[' . $id . '] = ' . Util::toJSON($data) . ";\n"; } $buff .= "\ng_faction_order = [0, 469, 891, 1037, 1118, 67, 1052, 892, 936, 1117, 169, 980, 1097];\n"; if (!CLISetup::writeFile('datasets/' . User::$localeString . '/p-factions', $buff)) { $success = false; } } return $success; }; /***********/ /* Recipes */ /***********/ $scripts[] = function () { // special case: secondary skills are always requested, so put them in one single file (185, 129, 356); it also contains g_skill_order $skills = [171, 164, 333, 202, 182, 773, 755, 165, 186, 393, 197, [185, 129, 356]]; $success = true; $baseCnd = array(CFG_SQL_LIMIT_NONE, [['cuFlags', CUSTOM_EXCLUDE_FOR_LISTVIEW, '&'], 0], ['effect1Id', [6, 45, 57, 127, 33, 158, 99, 28, 95], '!'], ['effect2Id', [118, 60], '!'], ['OR', ['typeCat', 9], ['typeCat', 11]]); foreach ($skills as $s) { $file = is_array($s) ? 'sec' : (string) $s; $cnd = array_merge($baseCnd, [['skillLine1', $s]]); $recipez = new SpellList($cnd); $created = ''; foreach ($recipez->iterate() as $__) { foreach ($recipez->canCreateItem() as $idx) { $id = $recipez->getField('effect' . $idx . 'CreateItemId'); $created .= "g_items.add(" . $id . ", {'icon':'" . $recipez->relItems->getEntry($id)['iconString'] . "'});\n"; } } foreach (CLISetup::$localeIds as $l) { set_time_limit(10); User::useLocale($l); Lang::load(Util::$localeStrings[$l]); $buff = ''; foreach ($recipez->getListviewData() as $id => $data) { $buff .= '_[' . $id . '] = ' . Util::toJSON($data) . ";\n"; } if (!$buff) { // this behaviour is intended, do not create an error CLISetup::log('profiler - file datasets/' . User::$localeString . '/p-recipes-' . $file . ' has no content => skipping', CLISetup::LOG_WARN); continue; } $buff = $created . "\nvar _ = g_spells;\n" . $buff; if (is_array($s)) { $buff .= "\ng_skill_order = [171, 164, 333, 202, 182, 773, 755, 165, 186, 393, 197, 185, 129, 356];\n"; } if (!CLISetup::writeFile('datasets/' . User::$localeString . '/p-recipes-' . $file, $buff)) { $success = false; } } } return $success; }; // check directory-structure foreach (Util::$localeStrings as $dir) { if (!CLISetup::writeDir('datasets/' . $dir)) { $success = false; } } // run scripts foreach ($scripts as $func) { if (!$func()) { $success = false; } } return $success; }
private function _searchCurrency($cndBase) { $cnd = array_merge($cndBase, [$this->createLookup()]); $money = new CurrencyList($cnd); if ($data = $money->getListviewData()) { $result['data'] = array_values($data); $osInfo = [TYPE_CURRENCY, ' (Currency)', $money->getMatches()]; if ($this->searchMask & SEARCH_TYPE_OPEN) { foreach ($money->iterate() as $id => $__) { $osInfo[3][$id] = strToLower($money->getField('iconString')); } } if ($money->getMatches() > $this->maxResults) { $result['note'] = sprintf(Util::$tryNarrowingString, 'LANG.lvnote_currenciesfound', $money->getMatches(), $this->maxResults); $result['_truncated'] = 1; } return ['currency', $result, null, $osInfo]; } return false; }
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; default: continue; } foreach ($obj->iterate() as $id => $__) { self::$subjCache[$type][$id] = $obj->getField('name', true); } } }