expanded reagents for spells

This commit is contained in:
Sarjuuk
2013-12-15 20:57:34 +01:00
parent 954352e17a
commit e7429d53d7
11 changed files with 395 additions and 68 deletions

View File

@@ -131,6 +131,8 @@ class ItemList extends BaseType
}
// convert items to currency if possible
if ($cItems)
{
$moneyItems = new CurrencyList(array(['itemId', $cItems]));
$moneyItems->addGlobalsToJscript(Util::$pageTemplate);
@@ -159,11 +161,12 @@ class ItemList extends BaseType
}
}
}
$this->vendors[$id] = $vendors;
}
}
$this->vendors = $itemz;
}
$result = $this->vendors;
// apply filter if given
@@ -178,7 +181,6 @@ class ItemList extends BaseType
{
if ($npc && $npcId != $npc)
{
unset($data[$npcId]);
continue;
}
@@ -188,8 +190,6 @@ class ItemList extends BaseType
$valid = false;
foreach ($costs as $k => $qty)
{
if ((!$tok || $k == $tok) && (!$cur || $k == -$cur))
{
$valid = true;

View File

@@ -1481,10 +1481,7 @@ Lasts 5 min. $?$gte($pl,68)[][Cannot be used on items level 138 and higher.]
if ($reagent[1] > 1)
$_ .= ' ('.$reagent[1].')';
if(!empty($reagents))
$_ .= ', ';
else
$_ .= '<br />';
$_ .= empty($reagents) ? '<br />' : ', ';
}
$xTmp[] = $_.'</div>';

View File

@@ -372,6 +372,8 @@ $lang = array(
'_radius' => "Radius",
'_interval' => "Interval",
'_inSlot' => "im Platz",
'_collapseAll' => "Alle einklappen",
'_expandAll' => "Alle ausklappen",
'ppm' => "%s Auslösungen pro Minute",
'procChance' => "Procchance",

View File

@@ -345,7 +345,7 @@ $lang = array(
'_spellDetails' => "Spell Details",
'_cost' => "Cost",
'_range' => "Range",
'_castTime' => "Cast Time",
'_castTime' => "Cast time",
'_cooldown' => "Cooldown",
'_distUnit' => "yards",
'_forms' => "Forms",
@@ -359,6 +359,8 @@ $lang = array(
'_radius' => "Radius",
'_interval' => "Interval",
'_inSlot' => "in slot",
'_collapseAll' => "Collapse All",
'_expandAll' => "Expand All",
'ppm' => "%s procs per minute",
'procChance' => "Proc chance",

View File

@@ -330,6 +330,8 @@ $lang = array(
'_radius' => "Radio",
'_interval' => "Intérvalo",
'_inSlot' => "en la casilla",
'_collapseAll' => "Contraer todo",
'_expandAll' => "Expandier todo",
'ppm' => "%s procs por minuto",
'procChance' => "Probabilidad de que accione",

View File

@@ -330,6 +330,8 @@ $lang = array(
'_radius' => "Rayon",
'_interval' => "Intervalle",
'_inSlot' => "dans l'emplacement",
'_collapseAll' => "Replier Tout",
'_expandAll' => "Déplier Tout",
'ppm' => "%s déclenchements par minute",
'procChance' => "Chance",

View File

@@ -330,6 +330,8 @@ $lang = array(
'_radius' => "Радиус действия",
'_interval' => "Интервал",
'_inSlot' => "в слот",
'_collapseAll' => "[Collapse All]",
'_expandAll' => "[Expand All]",
'ppm' => "Срабатывает %s раз в минуту",
'procChance' => "Шанс срабатывания",

View File

@@ -135,17 +135,15 @@ if (!$smarty->loadCache($cacheKeyPage, $item))
$costList = [];
foreach ($_ as $npcId => $data)
{
if (in_array(md5(serialize($data)), $handled)) // display every cost-combination only once
continue;
$handled[] = md5(serialize($data));
$tokens = [];
$currency = [];
foreach ($data as $c => $qty)
{
if (is_string($c))
{
unset($data[$c]); // unset miscData to prevent having two vendors /w the same cost being cached, because of different stock or rating-requirements
continue;
}
if ($c < 0) // currency items (and honor or arena)
$currency[] = -$c.','.$qty;
@@ -153,7 +151,12 @@ if (!$smarty->loadCache($cacheKeyPage, $item))
$tokens[$c] = $c.','.$qty;
}
$cost = isset($_[0]) ? '[money='.$_[0] : '[money';
if (in_array(md5(serialize($data)), $handled)) // display every cost-combination only once
continue;
$handled[] = md5(serialize($data));
$cost = isset($data[0]) ? '[money='.$data[0] : '[money';
if ($tokens)
$cost .= ' items='.implode(',', $tokens);

View File

@@ -241,6 +241,158 @@ if (!$smarty->loadCache($cacheKeyPage, $pageData))
/* Main Content */
/****************/
// chain reagents by method of accquisition
$reagentResult = [];
$enhanced = false;
$reagents = $spell->getReagentsForCurrent();
$appendReagentItem = function(&$reagentResult, $_iId, $_qty, $_mult, $_level, $_path, $alreadyUsed) use (&$appendCreateSpell)
{
if (in_array($_iId, $alreadyUsed))
return false;
$item = DB::Aowow()->selectRow('
SELECT name_loc0, name_loc2, name_loc3, name_loc6, name_loc8, id, iconString, quality,
IF ( (spellId1 > 0 AND spellCharges1 < 0) OR
(spellId2 > 0 AND spellCharges2 < 0) OR
(spellId3 > 0 AND spellCharges3 < 0) OR
(spellId4 > 0 AND spellCharges4 < 0) OR
(spellId5 > 0 AND spellCharges5 < 0), 1, 0) AS consumed
FROM ?_items
WHERE id = ?d',
$_iId
);
if (!$item)
return false;
Util::$pageTemplate->extendGlobalIds(TYPE_ITEM, $item['id']);
$_level++;
if ($item['consumed'])
$_qty++;
$data = array(
'type' => TYPE_ITEM,
'typeId' => $item['id'],
'typeStr' => Util::$typeStrings[TYPE_ITEM],
'quality' => $item['quality'],
'name' => Util::localizedString($item, 'name'),
'icon' => $item['iconString'],
'qty' => $_qty * $_mult,
'path' => $_path.'.'.TYPE_ITEM.'-'.$item['id'],
'level' => $_level
);
$idx = count($reagentResult);
$reagentResult[] = $data;
$alreadyUsed[] = $item['id'];
if (!$appendCreateSpell($reagentResult, $item['id'], $data['qty'], $data['level'], $data['path'], $alreadyUsed))
$reagentResult[$idx]['final'] = true;
return true;
};
$appendCreateSpell = function(&$reagentResult, $_iId, $_qty, $_level, $_path, $alreadyUsed) use (&$appendReagentItem)
{
$_level++;
// when results are found executes in <10ms
// when no results are found executes in ~0.35sec
// dafuque?!
// ""solution"": index effect1Id and effect1CreateItemId and pray, that tradeSpells only use the first index >.<
$spells = DB::Aowow()->select('
SELECT reagent1, reagent2, reagent3, reagent4, reagent5, reagent6, reagent7, reagent8,
reagentCount1, reagentCount2, reagentCount3, reagentCount4, reagentCount5, reagentCount6, reagentCount7, reagentCount8,
name_loc0, name_loc2, name_loc3, name_loc6, name_loc8,
id AS ARRAY_KEY, iconString
FROM ?_spell
WHERE (effect1CreateItemId = ?d AND effect1Id = 24)',// OR
// (effect2CreateItemId = ?d AND effect2Id = 24) OR
// (effect3CreateItemId = ?d AND effect3Id = 24)',
$_iId//, $_iId, $_iId
);
if (!$spells)
return false;
$didAppendSomething = false;
foreach ($spells as $sId => $row)
{
if (in_array(-$sId, $alreadyUsed))
continue;
Util::$pageTemplate->extendGlobalIds(TYPE_SPELL, $sId);
$data = array(
'type' => TYPE_SPELL,
'typeId' => $sId,
'typeStr' => Util::$typeStrings[TYPE_SPELL],
'name' => Util::localizedString($row, 'name'),
'icon' => $row['iconString'],
'qty' => $_qty,
'path' => $_path.'.'.TYPE_SPELL.'-'.$sId,
'level' => $_level,
);
$reagentResult[] = $data;
$_aU = $alreadyUsed;
$_aU[] = -$sId;
$hasUnusedReagents = false;
for ($i = 1; $i < 9; $i++)
{
if ($row['reagent'.$i] <= 0 || $row['reagentCount'.$i] <= 0)
continue;
if ($appendReagentItem($reagentResult, $row['reagent'.$i], $row['reagentCount'.$i], $data['qty'], $data['level'], $data['path'], $_aU))
{
$hasUnusedReagents = true;
$didAppendSomething = true;
}
}
if (!$hasUnusedReagents) // no reagents were added, remove spell from result set
array_pop($reagentResult);
}
return $didAppendSomething;
};
if ($reagents)
{
foreach ($spell->relItems->iterate() as $iId => $__)
{
if (!in_array($iId, array_keys($reagents)))
continue;
$data = array(
'type' => TYPE_ITEM,
'typeId' => $iId,
'typeStr' => Util::$typeStrings[TYPE_ITEM],
'quality' => $spell->relItems->getField('quality'),
'name' => $spell->relItems->getField('name', true),
'icon' => $spell->relItems->getField('iconString'),
'qty' => $reagents[$iId][1],
'path' => TYPE_ITEM.'-'.$iId, // id of the html-element
'level' => 0 // depths in array, used for indentation
);
$idx = count($reagentResult);
$reagentResult[] = $data;
// start with self and current original item in usedEntries (spell < 0; item > 0)
if ($appendCreateSpell($reagentResult, $iId, $data['qty'], 0, $data['path'], [-$_id, $iId]))
$enhanced = true;
else
$reagentResult[$idx]['final'] = true;
}
}
// increment all indizes (by prepending null and removing it again)
array_unshift($reagentResult, null);
unset($reagentResult[0]);
$pageData = array(
'title' => $spell->getField('name', true),
'path' => json_encode($path, JSON_NUMERIC_CHECK),
@@ -256,7 +408,7 @@ if (!$smarty->loadCache($cacheKeyPage, $pageData))
'powerCost' => $spell->createPowerCostForCurrent(),
'castTime' => $spell->createCastTimeForCurrent(false, false),
'tools' => $spell->getToolsForCurrent(),
'reagents' => $spell->getReagentsForCurrent(),
'reagents' => [$enhanced, $reagentResult],
'name' => $spell->getField('name', true),
'icon' => $spell->getField('iconString'),
'stack' => $spell->getField('stackAmount'),
@@ -334,31 +486,6 @@ if (!$smarty->loadCache($cacheKeyPage, $pageData))
}
}
// prepare Reagents
if ($pageData['page']['reagents'])
{
$_ = $pageData['page']['reagents'];
$pageData['page']['reagents'] = [];
foreach ($spell->relItems->iterate() as $itemId => $__)
{
if (empty($_[$itemId]))
continue;
$pageData['page']['reagents'][] = array(
'name' => $spell->relItems->getField('name', true),
'quality' => $spell->relItems->getField('quality'),
'entry' => $itemId,
'count' => $_[$itemId][1],
);
unset($_[$itemId]);
if (empty($_))
break;
}
}
// spell scaling
$scaling = array_merge(
array(
@@ -941,7 +1068,6 @@ if (!$smarty->loadCache($cacheKeyPage, $pageData))
unset($foo); // clear reference
/**************/
/* Extra Tabs */
/**************/

View File

@@ -0,0 +1,191 @@
<h3>{$lang.reagents}</h3>
{if $enhanced}
<style type="text/css">
.iconlist-col {ldelim} float: left; width: 31%; margin-right: 2%; {rdelim}
.iconlist {ldelim} border-collapse: collapse; margin-top: 4px; {rdelim}
.iconlist ul {ldelim} margin: 0!important; padding: 0!important; {rdelim}
.iconlist ul li {ldelim} list-style-position: inside; list-style-type: square; padding-left: 13px; {rdelim}
.iconlist th {ldelim} min-width: 18px; white-space: nowrap; {rdelim}
.iconlist td {ldelim} padding: 4px 0 6px 0; {rdelim}
.iconlist var {ldelim} font-size: 1px; {rdelim}
.iconlist .iconsmall {ldelim} margin-right: 4px; {rdelim}
.iconlist a.disclosure-on, .iconlist a.disclosure-off {ldelim} font-weight: normal; text-decoration: underline; {rdelim}
.iconlist .iconlist ul li {ldelim} padding-left: 10px; {rdelim}
.iconlist .iconlist th, .iconlist .iconlist td {ldelim} font-size: 11px; {rdelim}
.iconlist-col table th li {ldelim} list-style-position: outside; padding: 0; margin-left: 20px; {rdelim}
</style>
<script type="text/javascript">//<![CDATA[
function iconlist_showhide(spn) {ldelim}
var
tr,
table,
trs,
s;
tr = spn;
while ((tr.parentNode) && tr.tagName.toUpperCase() != 'TR') {ldelim}
tr = tr.parentNode;
{rdelim}
table = tr;
while ((table.parentNode) && table.tagName.toUpperCase() != 'TABLE') {ldelim}
table = table.parentNode;
{rdelim}
trs = table.getElementsByTagName('tr');
var opening = spn.className.indexOf('disclosure-off') >= 0;
var isSpell = tr.id.substr(tr.id.lastIndexOf('.')+1, 1) == '6';
var isItem = tr.id.substr(tr.id.lastIndexOf('.')+1, 1) == '3';
if (opening) {ldelim}
if (isSpell) {ldelim} //find any other open spells on this branch and close them
for (var x = 0; x < trs.length; x++)
if (trs[x].id.indexOf(tr.id.substr(0,tr.id.lastIndexOf('-'))) == 0) {ldelim} //sister spell
ns = trs[x].getElementsByTagName('div');
for (var y = 0; y < ns.length; y++)
if (ns[y].className == 'iconlist-tree disclosure-on')
iconlist_showhide(ns[y]);
{rdelim}
{rdelim}
if (isItem) {ldelim} //expanding item to spells, so cross out item
tr.style.textDecoration = 'line-through';
{rdelim}
for (var x = 0; x < trs.length; x++) {ldelim}
if ((trs[x].id.indexOf(tr.id) == 0) && (trs[x].id.substr(tr.id.length+1).indexOf('.') < 0)) {ldelim}
trs[x].style.display = '';
{rdelim}
{rdelim}
spn.className = 'iconlist-tree disclosure-on';
if (isItem) {ldelim} //check to see if there is one spell for this item.. if so, expand it
var spellCount = 0; var lastTr = 0;
for (var x = 0; x < trs.length; x++) {ldelim}
if ((trs[x].id.indexOf(tr.id+'.6') == 0) && (trs[x].id.lastIndexOf('-') == tr.id.length + 2)) {ldelim}
spellCount++;
lastTr = x;
{rdelim}
{rdelim}
if (spellCount == 1) {ldelim}
ns = trs[lastTr].getElementsByTagName('div');
for (var y = 0; y < ns.length; y++) {ldelim}
if (ns[y].className == 'iconlist-tree disclosure-off') {ldelim}
iconlist_showhide(ns[y]);
{rdelim}
{rdelim}
{rdelim}
{rdelim}
{rdelim}
else {ldelim}
for (var x = 0; x < trs.length; x++) {ldelim}
if ((trs[x].id.indexOf(tr.id) == 0) && (trs[x].id != tr.id)) {ldelim}
trs[x].style.display = 'none';
trs[x].style.textDecoration = '';
ns = trs[x].getElementsByTagName('div');
for (var y = 0; y < ns.length; y++) {ldelim}
if (ns[y].className == 'iconlist-tree disclosure-on') {ldelim}
ns[y].className = 'iconlist-tree disclosure-off';
{rdelim}
{rdelim}
{rdelim}
{rdelim}
spn.className = 'iconlist-tree disclosure-off';
tr.style.textDecoration = '';
{rdelim}
{rdelim}
function iconlist_expandall(tableid,doexpand) {ldelim}
var table = document.getElementById(tableid);
var trs = table.getElementsByTagName('tr');
if (doexpand) {ldelim}
iconlist_expandall(tableid,false);
var firstSpells = new Array();
for (var x = 0; x < trs.length; x++) {ldelim}
if (!trs[x].id) {ldelim}
continue;
{rdelim}
if (trs[x].style.display == 'none') {ldelim}
continue;
{rdelim}
if (trs[x].id.substr(trs[x].id.lastIndexOf('.')+1,1) == '6') {ldelim} //is spell
var skipOut = false;
var thisItem = trs[x].id.substr(0,trs[x].id.lastIndexOf('.'));
for (var y = 0; y < firstSpells.length; y++) {ldelim}
if (firstSpells[y] == thisItem) {ldelim}
skipOut = true;
break;
{rdelim}
{rdelim}
if (skipOut) {ldelim}
continue;
{rdelim}
firstSpells.push(thisItem);
{rdelim}
var spn = document.getElementById('spn.'+trs[x].id);
if (spn && spn.className.indexOf('disclosure-off') >= 0) {ldelim}
iconlist_showhide(spn);
{rdelim}
{rdelim}
{rdelim}
else {ldelim}
for (var x = 0; x < trs.length; x++) {ldelim}
if (!trs[x].id) {ldelim}
continue;
{rdelim}
if (trs[x].id.indexOf('.') != trs[x].id.lastIndexOf('.')) {ldelim}
continue;
{rdelim}
var spn = document.getElementById('spn.'+trs[x].id);
if (spn && spn.className.indexOf('disclosure-on') >= 0) {ldelim}
iconlist_showhide(spn);
{rdelim}
{rdelim}
{rdelim}
{rdelim}
//]]></script>
{/if}
<table class="iconlist" id="reagent-list-generic">
{if $enhanced}
<tr>
<th></th>
<th align="left">
<input type="button" style="font-size: 11px; margin-right: 0.5em" onclick="iconlist_expandall('reagent-list-generic',true);" value="{$lang._expandAll}">
<input type="button" style="font-size: 11px; margin-right: 0.5em" onclick="iconlist_expandall('reagent-list-generic',false);" value="{$lang._collapseAll}">
</th>
</tr>
{/if}
{foreach from=$reagents key='k' item='itr'}
{strip}<tr id="reagent-list-generic.{$itr.path}"{if $itr.level} style="display: none"{/if}>
<th align="right" id="iconlist-icon{$k}"></th>
<td{if $itr.level} style="padding-left: {$itr.level}em"{/if}>
{if !empty($itr.final) && $enhanced}
<div class="iconlist-tree" style="width: 15px; float: left">&nbsp;</div>
{elseif $enhanced}
<div class="iconlist-tree disclosure-off" onclick="iconlist_showhide(this);" style="padding-left: 0; cursor: pointer; width: 15px; float: left" id="spn.reagent-list-generic.{$itr.path}">&nbsp;</div>
{/if}
<span class="q{if $itr.type == $smarty.const.TYPE_ITEM}{$itr.quality}{/if}"><a href="?{$itr.typeStr}={$itr.typeId}">{$itr.name}</a></span>{if $itr.qty > 1}&nbsp;({$itr.qty}){/if}
</td>
</tr>{/strip}
{/foreach}
</table>
<script type="text/javascript">//<![CDATA[
{foreach from=$reagents key='k' item='itr'}
$WH.ge('iconlist-icon{$k}').appendChild(g_{$itr.typeStr}s.createIcon({$itr.typeId}, 0, {$itr.qty}));
{/foreach}
//]]></script>
<div class="clear"></div>

View File

@@ -26,7 +26,7 @@
{if $lvData.page.reagents}
{if $lvData.page.tools}<div style="float: left; margin-right: 75px">{/if}
{include file='bricks/reagentList.tpl' reagent=$lvData.page.reagents}
{include file='bricks/reagentList.tpl' reagents=$lvData.page.reagents[1] enhanced=$lvData.page.reagents[0]}
{if $lvData.page.tools}</div>{/if}
{/if}