Item/ExtendedCost

* display a "sells" entry for every combination of currencies the vendor accepts per item
 * display every cost combination in the quick infos on the item detail page
This commit is contained in:
Sarjuuk
2018-05-10 19:20:07 +02:00
parent 761da59ee9
commit 3bbd7f97da
4 changed files with 198 additions and 154 deletions

View File

@@ -17,6 +17,8 @@ abstract class BaseType
protected $queryBase = ''; protected $queryBase = '';
protected $queryOpts = []; protected $queryOpts = [];
private $itrStack = [];
public static $contribute = CONTRIBUTE_ANY; public static $contribute = CONTRIBUTE_ANY;
/* /*
@@ -287,7 +289,7 @@ abstract class BaseType
public function &iterate() public function &iterate()
{ {
$oldIdx = $this->id; $this->itrStack[] = $this->id;
// reset on __construct // reset on __construct
$this->reset(); $this->reset();
@@ -304,6 +306,7 @@ abstract class BaseType
// fforward to old index // fforward to old index
$this->reset(); $this->reset();
$oldIdx = array_pop($this->itrStack);
do do
{ {
if (key($this->templates) != $oldIdx) if (key($this->templates) != $oldIdx)
@@ -311,6 +314,7 @@ abstract class BaseType
$this->curTpl = current($this->templates); $this->curTpl = current($this->templates);
$this->id = key($this->templates); $this->id = key($this->templates);
next($this->templates);
break; break;
} }
while (next($this->templates)); while (next($this->templates));

View File

@@ -90,31 +90,42 @@ class ItemList extends BaseType
if (empty($this->vendors)) if (empty($this->vendors))
{ {
$itemz = DB::World()->select(' $itemz = [];
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) $xCostData = [];
$rawEntries = DB::World()->select('
SELECT nv.item, nv.entry, 0 AS eventId, nv.maxcount, nv.extendedCost FROM npc_vendor nv WHERE {nv.entry IN (?a) AND} nv.item IN (?a)
UNION 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)', SELECT genv.item, c.id AS `entry`, 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], empty($filter[TYPE_NPC]) || !is_array($filter[TYPE_NPC]) ? DBSIMPLE_SKIP : $filter[TYPE_NPC],
array_keys($this->templates), array_keys($this->templates),
empty($filter[TYPE_NPC]) || !is_array($filter[TYPE_NPC]) ? DBSIMPLE_SKIP : $filter[TYPE_NPC], empty($filter[TYPE_NPC]) || !is_array($filter[TYPE_NPC]) ? DBSIMPLE_SKIP : $filter[TYPE_NPC],
array_keys($this->templates) array_keys($this->templates)
); );
$xCosts = []; foreach ($rawEntries as $costEntry)
foreach ($itemz as $i => $vendors) {
$xCosts = array_merge($xCosts, array_column($vendors, 'extendedCost')); if ($costEntry['extendedCost'])
$xCostData[] = $costEntry['extendedCost'];
if ($xCosts) if (!isset($itemz[$costEntry['item']][$costEntry['entry']]))
$xCosts = DB::Aowow()->select('SELECT *, id AS ARRAY_KEY FROM ?_itemextendedcost WHERE id IN (?a)', $xCosts); $itemz[$costEntry['item']][$costEntry['entry']] = [$costEntry];
else
$itemz[$costEntry['item']][$costEntry['entry']][] = $costEntry;
}
if ($xCostData)
$xCostData = DB::Aowow()->select('SELECT *, id AS ARRAY_KEY FROM ?_itemextendedcost WHERE id IN (?a)', $xCostData);
$cItems = []; $cItems = [];
foreach ($itemz as $k => $vendors) foreach ($itemz as $k => $vendors)
{ {
foreach ($vendors as $l => $vInfo) foreach ($vendors as $l => $vendor)
{
foreach ($vendor as $m => $vInfo)
{ {
$costs = []; $costs = [];
if (!empty($xCosts[$vInfo['extendedCost']])) if (!empty($xCostData[$vInfo['extendedCost']]))
$costs = $xCosts[$vInfo['extendedCost']]; $costs = $xCostData[$vInfo['extendedCost']];
$data = array( $data = array(
'stock' => $vInfo['maxcount'] ?: -1, 'stock' => $vInfo['maxcount'] ?: -1,
@@ -153,7 +164,9 @@ class ItemList extends BaseType
$data[0] = $_; $data[0] = $_;
} }
$vendors[$l] = $data; $vendor[$m] = $data;
}
$vendors[$l] = $vendor;
} }
$itemz[$k] = $vendors; $itemz[$k] = $vendors;
@@ -167,11 +180,13 @@ class ItemList extends BaseType
foreach ($jsData as $k => $v) foreach ($jsData as $k => $v)
$this->jsGlobals[$type][$k] = $v; $this->jsGlobals[$type][$k] = $v;
foreach ($itemz as $id => $vendors) foreach ($itemz as $itemId => $vendors)
{ {
foreach ($vendors as $l => $costs) foreach ($vendors as $npcId => $costData)
{ {
foreach ($costs as $k => $v) foreach ($costData as $itr => $cost)
{
foreach ($cost as $k => $v)
{ {
if (in_array($k, $cItems)) if (in_array($k, $cItems))
{ {
@@ -180,8 +195,8 @@ class ItemList extends BaseType
{ {
if ($moneyItems->getField('itemId') == $k) if ($moneyItems->getField('itemId') == $k)
{ {
unset($costs[$k]); unset($cost[$k]);
$costs[-$moneyItems->id] = $v; $cost[-$moneyItems->id] = $v;
$found = true; $found = true;
break; break;
} }
@@ -191,9 +206,11 @@ class ItemList extends BaseType
$this->jsGlobals[TYPE_ITEM][$k] = $k; $this->jsGlobals[TYPE_ITEM][$k] = $k;
} }
} }
$vendors[$l] = $costs; $costData[$itr] = $cost;
} }
$itemz[$id] = $vendors; $vendors[$npcId] = $costData;
}
$itemz[$itemId] = $vendors;
} }
} }
@@ -209,7 +226,9 @@ class ItemList extends BaseType
foreach ($result as $itemId => &$data) foreach ($result as $itemId => &$data)
{ {
$reqRating = []; $reqRating = [];
foreach ($data as $npcId => $costs) foreach ($data as $npcId => $entries)
{
foreach ($entries as $costs)
{ {
if ($tok || $cur) // bought with specific token or currency if ($tok || $cur) // bought with specific token or currency
{ {
@@ -232,6 +251,7 @@ class ItemList extends BaseType
if (isset($data[$npcId]) && $costs['reqRating'] && (!$reqRating || $reqRating[0] < $costs['reqRating'])) if (isset($data[$npcId]) && $costs['reqRating'] && (!$reqRating || $reqRating[0] < $costs['reqRating']))
$reqRating = [$costs['reqRating'], $costs['reqBracket']]; $reqRating = [$costs['reqRating'], $costs['reqBracket']];
} }
}
if ($reqRating) if ($reqRating)
$data['reqRating'] = $reqRating[0]; $data['reqRating'] = $reqRating[0];
@@ -266,6 +286,7 @@ class ItemList extends BaseType
if ($addInfoMask & ITEMINFO_VENDOR) if ($addInfoMask & ITEMINFO_VENDOR)
$extCosts = $this->getExtendedCost($miscData); $extCosts = $this->getExtendedCost($miscData);
$extCostOther = [];
foreach ($this->iterate() as $__) foreach ($this->iterate() as $__)
{ {
foreach ($this->json[$this->id] as $k => $v) foreach ($this->json[$this->id] as $k => $v)
@@ -300,14 +321,17 @@ class ItemList extends BaseType
if ($addInfoMask & ITEMINFO_VENDOR) if ($addInfoMask & ITEMINFO_VENDOR)
{ {
// just use the first results // just use the first results
// todo (med): dont use first result; search for the right one // todo (med): dont use first vendor; search for the right one
if (!empty($extCosts[$this->id])) if (!empty($extCosts[$this->id]))
{ {
$cost = reset($extCosts[$this->id]); $cost = reset($extCosts[$this->id]);
foreach ($cost as $itr => $entries)
{
$currency = []; $currency = [];
$tokens = []; $tokens = [];
$costArr = [];
foreach ($cost as $k => $qty) foreach ($entries as $k => $qty)
{ {
if (is_string($k)) if (is_string($k))
continue; continue;
@@ -318,24 +342,30 @@ class ItemList extends BaseType
$currency[] = [-$k, $qty]; $currency[] = [-$k, $qty];
} }
$data[$this->id]['stock'] = $cost['stock']; // display as column in lv $costArr['stock'] = $entries['stock'];// display as column in lv
$data[$this->id]['avail'] = $cost['stock']; // display as number on icon $costArr['avail'] = $entries['stock'];// display as number on icon
$data[$this->id]['cost'] = [empty($cost[0]) ? 0 : $cost[0]]; $costArr['cost'] = [empty($entries[0]) ? 0 : $entries[0]];
if ($cost['event']) if ($entries['event'])
{ {
$this->jsGlobals[TYPE_WORLDEVENT][$cost['event']] = $cost['event']; $this->jsGlobals[TYPE_WORLDEVENT][$entries['event']] = $entries['event'];
$row['condition'][0][$this->id][] = [[CND_ACTIVE_EVENT, $cost['event']]]; $costArr['condition'][0][$this->id][] = [[CND_ACTIVE_EVENT, $entries['event']]];
} }
if ($currency || $tokens) // fill idx:3 if required if ($currency || $tokens) // fill idx:3 if required
$data[$this->id]['cost'][] = $currency; $costArr['cost'][] = $currency;
if ($tokens) if ($tokens)
$data[$this->id]['cost'][] = $tokens; $costArr['cost'][] = $tokens;
if (!empty($cost['reqRating'])) if (!empty($entries['reqRating']))
$data[$this->id]['reqarenartng'] = $cost['reqRating']; $costArr['reqarenartng'] = $entries['reqRating'];
if ($itr > 0)
$extCostOther[$this->id][] = $costArr;
else
$data[$this->id] = array_merge($data[$this->id], $costArr);
}
} }
if ($x = $this->curTpl['buyPrice']) if ($x = $this->curTpl['buyPrice'])
@@ -397,6 +427,10 @@ class ItemList extends BaseType
$data[$this->id]['cooldown'] = $this->curTpl['cooldown'] / 1000; $data[$this->id]['cooldown'] = $this->curTpl['cooldown'] / 1000;
} }
foreach ($extCostOther as $itemId => $duplicates)
foreach ($duplicates as $d)
$data[] = array_merge($data[$itemId], $d); // we dont really use keys on data, but this may cause errors in future
/* even more complicated crap /* even more complicated crap
modelviewer {type:X, displayid:Y, slot:z} .. not sure, when to set modelviewer {type:X, displayid:Y, slot:z} .. not sure, when to set
*/ */

View File

@@ -109,7 +109,8 @@ class CurrencyPage extends GenericPage
{ {
$items = []; $items = [];
$tokens = []; $tokens = [];
foreach ($vendors[$k] as $id => $qty) // note: can only display one entry per row, so only use first entry of each vendor
foreach ($vendors[$k][0] as $id => $qty)
{ {
if (is_string($id)) if (is_string($id))
continue; continue;
@@ -120,16 +121,16 @@ class CurrencyPage extends GenericPage
$items[] = [-$id, $qty]; $items[] = [-$id, $qty];
} }
if ($vendors[$k]['event']) if ($vendors[$k][0]['event'])
{ {
if (count($extraCols) == 3) // not already pushed if (count($extraCols) == 3) // not already pushed
$extraCols[] = '$Listview.extraCols.condition'; $extraCols[] = '$Listview.extraCols.condition';
$this->extendGlobalIds(TYPE_WORLDEVENT, $vendors[$k]['event']); $this->extendGlobalIds(TYPE_WORLDEVENT, $vendors[$k][0]['event']);
$row['condition'][0][$this->typeId][] = [[CND_ACTIVE_EVENT, $vendors[$k]['event']]]; $row['condition'][0][$this->typeId][] = [[CND_ACTIVE_EVENT, $vendors[$k][0]['event']]];
} }
$row['stock'] = $vendors[$k]['stock']; $row['stock'] = $vendors[$k][0]['stock'];
$row['stack'] = $itemObj->getField('buyCount'); $row['stack'] = $itemObj->getField('buyCount');
$row['cost'] = array( $row['cost'] = array(
$itemObj->getField('buyPrice'), $itemObj->getField('buyPrice'),

View File

@@ -185,7 +185,9 @@ class ItemPage extends genericPage
$each = $this->subject->getField('stackable') > 1 ? '[color=q0] ('.Lang::item('each').')[/color]' : null; $each = $this->subject->getField('stackable') > 1 ? '[color=q0] ('.Lang::item('each').')[/color]' : null;
$handled = []; $handled = [];
$costList = []; $costList = [];
foreach ($vendors as $npcId => $data) foreach ($vendors as $npcId => $entries)
{
foreach ($entries as $data)
{ {
$tokens = []; $tokens = [];
$currency = []; $currency = [];
@@ -202,9 +204,15 @@ class ItemPage extends genericPage
} }
if ($c < 0) // currency items (and honor or arena) if ($c < 0) // currency items (and honor or arena)
{
$currency[] = -$c.','.$qty; $currency[] = -$c.','.$qty;
$this->extendGlobalIds(TYPE_CURRENCY, -$c);
}
else if ($c > 0) // plain items (item1,count1,item2,count2,...) else if ($c > 0) // plain items (item1,count1,item2,count2,...)
{
$tokens[$c] = $c.','.$qty; $tokens[$c] = $c.','.$qty;
$this->extendGlobalIds(TYPE_ITEM, $c);
}
} }
// display every cost-combination only once // display every cost-combination only once
@@ -225,6 +233,7 @@ class ItemPage extends genericPage
$costList[] = $cost; $costList[] = $cost;
} }
}
if (count($costList) == 1) if (count($costList) == 1)
$infobox[] = Lang::item('cost').Lang::main('colon').$costList[0].$each; $infobox[] = Lang::item('cost').Lang::main('colon').$costList[0].$each;
@@ -760,7 +769,9 @@ class ItemPage extends genericPage
{ {
$currency = []; $currency = [];
$tokens = []; $tokens = [];
foreach ($vendors[$k] as $id => $qty)
// note: can only display one entry per row, so only use first entry of each vendor
foreach ($vendors[$k][0] as $id => $qty)
{ {
if (is_string($id)) if (is_string($id))
continue; continue;
@@ -771,16 +782,10 @@ class ItemPage extends genericPage
$currency[] = [-$id, $qty]; $currency[] = [-$id, $qty];
} }
if ($currency) $row['stock'] = $vendors[$k][0]['stock'];
$this->extendGlobalIds(TYPE_CURRENCY, array_column($currency, 0)); $row['cost'] = [empty($vendors[$k][0][0]) ? 0 : $vendors[$k][0][0]];
if ($tokens) if ($e = $vendors[$k][0]['event'])
$this->extendGlobalIds(TYPE_ITEM, array_column($tokens, 0));
$row['stock'] = $vendors[$k]['stock'];
$row['cost'] = [empty($vendors[$k][0]) ? 0 : $vendors[$k][0]];
if ($e = $vendors[$k]['event'])
{ {
if (count($extraCols) == 3) if (count($extraCols) == 3)
$extraCols[] = '$Listview.extraCols.condition'; $extraCols[] = '$Listview.extraCols.condition';