mirror of
https://github.com/Sarjuuk/aowow.git
synced 2025-11-29 15:58:16 +08:00
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:
@@ -17,6 +17,8 @@ abstract class BaseType
|
||||
protected $queryBase = '';
|
||||
protected $queryOpts = [];
|
||||
|
||||
private $itrStack = [];
|
||||
|
||||
public static $contribute = CONTRIBUTE_ANY;
|
||||
|
||||
/*
|
||||
@@ -287,7 +289,7 @@ abstract class BaseType
|
||||
|
||||
public function &iterate()
|
||||
{
|
||||
$oldIdx = $this->id;
|
||||
$this->itrStack[] = $this->id;
|
||||
|
||||
// reset on __construct
|
||||
$this->reset();
|
||||
@@ -304,6 +306,7 @@ abstract class BaseType
|
||||
|
||||
// fforward to old index
|
||||
$this->reset();
|
||||
$oldIdx = array_pop($this->itrStack);
|
||||
do
|
||||
{
|
||||
if (key($this->templates) != $oldIdx)
|
||||
@@ -311,6 +314,7 @@ abstract class BaseType
|
||||
|
||||
$this->curTpl = current($this->templates);
|
||||
$this->id = key($this->templates);
|
||||
next($this->templates);
|
||||
break;
|
||||
}
|
||||
while (next($this->templates));
|
||||
|
||||
@@ -90,31 +90,42 @@ class ItemList extends BaseType
|
||||
|
||||
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)
|
||||
$itemz = [];
|
||||
$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
|
||||
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],
|
||||
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'));
|
||||
foreach ($rawEntries as $costEntry)
|
||||
{
|
||||
if ($costEntry['extendedCost'])
|
||||
$xCostData[] = $costEntry['extendedCost'];
|
||||
|
||||
if ($xCosts)
|
||||
$xCosts = DB::Aowow()->select('SELECT *, id AS ARRAY_KEY FROM ?_itemextendedcost WHERE id IN (?a)', $xCosts);
|
||||
if (!isset($itemz[$costEntry['item']][$costEntry['entry']]))
|
||||
$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 = [];
|
||||
foreach ($itemz as $k => $vendors)
|
||||
{
|
||||
foreach ($vendors as $l => $vInfo)
|
||||
foreach ($vendors as $l => $vendor)
|
||||
{
|
||||
foreach ($vendor as $m => $vInfo)
|
||||
{
|
||||
$costs = [];
|
||||
if (!empty($xCosts[$vInfo['extendedCost']]))
|
||||
$costs = $xCosts[$vInfo['extendedCost']];
|
||||
if (!empty($xCostData[$vInfo['extendedCost']]))
|
||||
$costs = $xCostData[$vInfo['extendedCost']];
|
||||
|
||||
$data = array(
|
||||
'stock' => $vInfo['maxcount'] ?: -1,
|
||||
@@ -153,7 +164,9 @@ class ItemList extends BaseType
|
||||
$data[0] = $_;
|
||||
}
|
||||
|
||||
$vendors[$l] = $data;
|
||||
$vendor[$m] = $data;
|
||||
}
|
||||
$vendors[$l] = $vendor;
|
||||
}
|
||||
|
||||
$itemz[$k] = $vendors;
|
||||
@@ -167,11 +180,13 @@ class ItemList extends BaseType
|
||||
foreach ($jsData as $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))
|
||||
{
|
||||
@@ -180,8 +195,8 @@ class ItemList extends BaseType
|
||||
{
|
||||
if ($moneyItems->getField('itemId') == $k)
|
||||
{
|
||||
unset($costs[$k]);
|
||||
$costs[-$moneyItems->id] = $v;
|
||||
unset($cost[$k]);
|
||||
$cost[-$moneyItems->id] = $v;
|
||||
$found = true;
|
||||
break;
|
||||
}
|
||||
@@ -191,9 +206,11 @@ class ItemList extends BaseType
|
||||
$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)
|
||||
{
|
||||
$reqRating = [];
|
||||
foreach ($data as $npcId => $costs)
|
||||
foreach ($data as $npcId => $entries)
|
||||
{
|
||||
foreach ($entries as $costs)
|
||||
{
|
||||
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']))
|
||||
$reqRating = [$costs['reqRating'], $costs['reqBracket']];
|
||||
}
|
||||
}
|
||||
|
||||
if ($reqRating)
|
||||
$data['reqRating'] = $reqRating[0];
|
||||
@@ -266,6 +286,7 @@ class ItemList extends BaseType
|
||||
if ($addInfoMask & ITEMINFO_VENDOR)
|
||||
$extCosts = $this->getExtendedCost($miscData);
|
||||
|
||||
$extCostOther = [];
|
||||
foreach ($this->iterate() as $__)
|
||||
{
|
||||
foreach ($this->json[$this->id] as $k => $v)
|
||||
@@ -300,14 +321,17 @@ class ItemList extends BaseType
|
||||
if ($addInfoMask & ITEMINFO_VENDOR)
|
||||
{
|
||||
// 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]))
|
||||
{
|
||||
$cost = reset($extCosts[$this->id]);
|
||||
foreach ($cost as $itr => $entries)
|
||||
{
|
||||
$currency = [];
|
||||
$tokens = [];
|
||||
$costArr = [];
|
||||
|
||||
foreach ($cost as $k => $qty)
|
||||
foreach ($entries as $k => $qty)
|
||||
{
|
||||
if (is_string($k))
|
||||
continue;
|
||||
@@ -318,24 +342,30 @@ class ItemList extends BaseType
|
||||
$currency[] = [-$k, $qty];
|
||||
}
|
||||
|
||||
$data[$this->id]['stock'] = $cost['stock']; // display as column in lv
|
||||
$data[$this->id]['avail'] = $cost['stock']; // display as number on icon
|
||||
$data[$this->id]['cost'] = [empty($cost[0]) ? 0 : $cost[0]];
|
||||
$costArr['stock'] = $entries['stock'];// display as column in lv
|
||||
$costArr['avail'] = $entries['stock'];// display as number on icon
|
||||
$costArr['cost'] = [empty($entries[0]) ? 0 : $entries[0]];
|
||||
|
||||
if ($cost['event'])
|
||||
if ($entries['event'])
|
||||
{
|
||||
$this->jsGlobals[TYPE_WORLDEVENT][$cost['event']] = $cost['event'];
|
||||
$row['condition'][0][$this->id][] = [[CND_ACTIVE_EVENT, $cost['event']]];
|
||||
$this->jsGlobals[TYPE_WORLDEVENT][$entries['event']] = $entries['event'];
|
||||
$costArr['condition'][0][$this->id][] = [[CND_ACTIVE_EVENT, $entries['event']]];
|
||||
}
|
||||
|
||||
if ($currency || $tokens) // fill idx:3 if required
|
||||
$data[$this->id]['cost'][] = $currency;
|
||||
$costArr['cost'][] = $currency;
|
||||
|
||||
if ($tokens)
|
||||
$data[$this->id]['cost'][] = $tokens;
|
||||
$costArr['cost'][] = $tokens;
|
||||
|
||||
if (!empty($cost['reqRating']))
|
||||
$data[$this->id]['reqarenartng'] = $cost['reqRating'];
|
||||
if (!empty($entries['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'])
|
||||
@@ -397,6 +427,10 @@ class ItemList extends BaseType
|
||||
$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
|
||||
modelviewer {type:X, displayid:Y, slot:z} .. not sure, when to set
|
||||
*/
|
||||
|
||||
@@ -109,7 +109,8 @@ class CurrencyPage extends GenericPage
|
||||
{
|
||||
$items = [];
|
||||
$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))
|
||||
continue;
|
||||
@@ -120,16 +121,16 @@ class CurrencyPage extends GenericPage
|
||||
$items[] = [-$id, $qty];
|
||||
}
|
||||
|
||||
if ($vendors[$k]['event'])
|
||||
if ($vendors[$k][0]['event'])
|
||||
{
|
||||
if (count($extraCols) == 3) // not already pushed
|
||||
$extraCols[] = '$Listview.extraCols.condition';
|
||||
|
||||
$this->extendGlobalIds(TYPE_WORLDEVENT, $vendors[$k]['event']);
|
||||
$row['condition'][0][$this->typeId][] = [[CND_ACTIVE_EVENT, $vendors[$k]['event']]];
|
||||
$this->extendGlobalIds(TYPE_WORLDEVENT, $vendors[$k][0]['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['cost'] = array(
|
||||
$itemObj->getField('buyPrice'),
|
||||
|
||||
@@ -185,7 +185,9 @@ class ItemPage extends genericPage
|
||||
$each = $this->subject->getField('stackable') > 1 ? '[color=q0] ('.Lang::item('each').')[/color]' : null;
|
||||
$handled = [];
|
||||
$costList = [];
|
||||
foreach ($vendors as $npcId => $data)
|
||||
foreach ($vendors as $npcId => $entries)
|
||||
{
|
||||
foreach ($entries as $data)
|
||||
{
|
||||
$tokens = [];
|
||||
$currency = [];
|
||||
@@ -202,9 +204,15 @@ class ItemPage extends genericPage
|
||||
}
|
||||
|
||||
if ($c < 0) // currency items (and honor or arena)
|
||||
{
|
||||
$currency[] = -$c.','.$qty;
|
||||
$this->extendGlobalIds(TYPE_CURRENCY, -$c);
|
||||
}
|
||||
else if ($c > 0) // plain items (item1,count1,item2,count2,...)
|
||||
{
|
||||
$tokens[$c] = $c.','.$qty;
|
||||
$this->extendGlobalIds(TYPE_ITEM, $c);
|
||||
}
|
||||
}
|
||||
|
||||
// display every cost-combination only once
|
||||
@@ -225,6 +233,7 @@ class ItemPage extends genericPage
|
||||
|
||||
$costList[] = $cost;
|
||||
}
|
||||
}
|
||||
|
||||
if (count($costList) == 1)
|
||||
$infobox[] = Lang::item('cost').Lang::main('colon').$costList[0].$each;
|
||||
@@ -760,7 +769,9 @@ class ItemPage extends genericPage
|
||||
{
|
||||
$currency = [];
|
||||
$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))
|
||||
continue;
|
||||
@@ -771,16 +782,10 @@ class ItemPage extends genericPage
|
||||
$currency[] = [-$id, $qty];
|
||||
}
|
||||
|
||||
if ($currency)
|
||||
$this->extendGlobalIds(TYPE_CURRENCY, array_column($currency, 0));
|
||||
$row['stock'] = $vendors[$k][0]['stock'];
|
||||
$row['cost'] = [empty($vendors[$k][0][0]) ? 0 : $vendors[$k][0][0]];
|
||||
|
||||
if ($tokens)
|
||||
$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 ($e = $vendors[$k][0]['event'])
|
||||
{
|
||||
if (count($extraCols) == 3)
|
||||
$extraCols[] = '$Listview.extraCols.condition';
|
||||
|
||||
Reference in New Issue
Block a user