From e7429d53d72c524a311cf0e17ab477283ed1098c Mon Sep 17 00:00:00 2001 From: Sarjuuk Date: Sun, 15 Dec 2013 20:57:34 +0100 Subject: [PATCH] expanded reagents for spells --- includes/types/item.class.php | 56 +++++----- includes/types/spell.class.php | 5 +- localization/locale_dede.php | 2 + localization/locale_enus.php | 4 +- localization/locale_eses.php | 2 + localization/locale_frfr.php | 2 + localization/locale_ruru.php | 2 + pages/item.php | 15 ++- pages/spell.php | 182 +++++++++++++++++++++++++----- template/bricks/reagentList.tpl | 191 ++++++++++++++++++++++++++++++++ template/spell.tpl | 2 +- 11 files changed, 395 insertions(+), 68 deletions(-) create mode 100644 template/bricks/reagentList.tpl diff --git a/includes/types/item.class.php b/includes/types/item.class.php index 48bf3b11..2cff4610 100644 --- a/includes/types/item.class.php +++ b/includes/types/item.class.php @@ -131,37 +131,40 @@ class ItemList extends BaseType } // convert items to currency if possible - $moneyItems = new CurrencyList(array(['itemId', $cItems])); - $moneyItems->addGlobalsToJscript(Util::$pageTemplate); - - foreach ($itemz as $id => &$vendors) + if ($cItems) { - foreach ($vendors as &$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; - } - } + $moneyItems = new CurrencyList(array(['itemId', $cItems])); + $moneyItems->addGlobalsToJscript(Util::$pageTemplate); - if (!$found) - Util::$pageTemplate->extendGlobalIds(TYPE_ITEM, $k); + foreach ($itemz as $id => &$vendors) + { + foreach ($vendors as &$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) + Util::$pageTemplate->extendGlobalIds(TYPE_ITEM, $k); + } } } } - - $this->vendors[$id] = $vendors; } + + $this->vendors = $itemz; } $result = $this->vendors; @@ -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; diff --git a/includes/types/spell.class.php b/includes/types/spell.class.php index 257fbfba..2ec064d6 100644 --- a/includes/types/spell.class.php +++ b/includes/types/spell.class.php @@ -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 - $_ .= '
'; + $_ .= empty($reagents) ? '
' : ', '; } $xTmp[] = $_.''; diff --git a/localization/locale_dede.php b/localization/locale_dede.php index 489f9b7b..f639ab7d 100644 --- a/localization/locale_dede.php +++ b/localization/locale_dede.php @@ -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", diff --git a/localization/locale_enus.php b/localization/locale_enus.php index 60378184..a72628d9 100644 --- a/localization/locale_enus.php +++ b/localization/locale_enus.php @@ -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", diff --git a/localization/locale_eses.php b/localization/locale_eses.php index 3d19b24f..9c808a78 100644 --- a/localization/locale_eses.php +++ b/localization/locale_eses.php @@ -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", diff --git a/localization/locale_frfr.php b/localization/locale_frfr.php index 53b7ba80..449a0b79 100644 --- a/localization/locale_frfr.php +++ b/localization/locale_frfr.php @@ -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", diff --git a/localization/locale_ruru.php b/localization/locale_ruru.php index b069cef7..12efb888 100644 --- a/localization/locale_ruru.php +++ b/localization/locale_ruru.php @@ -330,6 +330,8 @@ $lang = array( '_radius' => "Радиус действия", '_interval' => "Интервал", '_inSlot' => "в слот", + '_collapseAll' => "[Collapse All]", + '_expandAll' => "[Expand All]", 'ppm' => "Срабатывает %s раз в минуту", 'procChance' => "Шанс срабатывания", diff --git a/pages/item.php b/pages/item.php index 83e3400b..a52192cd 100644 --- a/pages/item.php +++ b/pages/item.php @@ -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); diff --git a/pages/spell.php b/pages/spell.php index 3ae931bb..4bdaf05c 100644 --- a/pages/spell.php +++ b/pages/spell.php @@ -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( @@ -908,7 +1035,7 @@ if (!$smarty->loadCache($cacheKeyPage, $pageData)) if (!$transform->error) { $pageData['view3D'] = $transform->getRandomModelId(); - $pageData['buttons'][BUTTON_VIEW3D] = ['type' => TYPE_NPC, 'displayId' => $transform->getRandomModelId()]; + $pageData['buttons'][BUTTON_VIEW3D] = ['type' => TYPE_NPC, 'displayId' => $transform->getRandomModelId()]; $bar = ' ('.$transform->getField('name', true).')'; } else @@ -941,7 +1068,6 @@ if (!$smarty->loadCache($cacheKeyPage, $pageData)) unset($foo); // clear reference - /**************/ /* Extra Tabs */ /**************/ diff --git a/template/bricks/reagentList.tpl b/template/bricks/reagentList.tpl new file mode 100644 index 00000000..032e040e --- /dev/null +++ b/template/bricks/reagentList.tpl @@ -0,0 +1,191 @@ +

{$lang.reagents}

+ +{if $enhanced} + + +{/if} + + +{if $enhanced} + + + + +{/if} +{foreach from=$reagents key='k' item='itr'} + {strip} + + +{if !empty($itr.final) && $enhanced} +
 
+{elseif $enhanced} +
 
+{/if} + {$itr.name}{if $itr.qty > 1} ({$itr.qty}){/if} + +
{/strip} +{/foreach} +
+ + +
+ + + +
diff --git a/template/spell.tpl b/template/spell.tpl index 9f060d62..07d5ea4a 100644 --- a/template/spell.tpl +++ b/template/spell.tpl @@ -26,7 +26,7 @@ {if $lvData.page.reagents} {if $lvData.page.tools}
{/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}
{/if} {/if}