Pages/Item

* fixed fractional buy price for items sold in stacks in infobox (fixes #362)
 * fixed filter criteria enums being generally invalid
This commit is contained in:
Sarjuuk
2024-06-07 16:37:55 +02:00
parent e873d8cbd0
commit fc86825b15
2 changed files with 36 additions and 7 deletions

View File

@@ -1254,7 +1254,7 @@ abstract class Filter
$unsetme = true;
break;
case FILTER_CR_ENUM:
if (!Util::checkNumeric($_crs[$i], NUM_REQ_INT))
if (!Util::checkNumeric($_crs[$i], NUM_CAST_INT))
$unsetme = true;
break;
}

View File

@@ -206,7 +206,8 @@ class ItemPage extends genericPage
{
$vendors = $this->subject->getExtendedCost()[$this->subject->id];
$stack = $this->subject->getField('buyCount');
$each = $this->subject->getField('stackable') > 1 ? '[color=q0] ('.Lang::item('each').')[/color]' : null;
$divisor = $stack;
$each = '';
$handled = [];
$costList = [];
foreach ($vendors as $npcId => $entries)
@@ -229,29 +230,52 @@ class ItemPage extends genericPage
if ($c < 0) // currency items (and honor or arena)
{
$currency[] = -$c.','.($qty / $stack);
if (is_float($qty / $stack))
$divisor = 1;
$currency[] = [-$c, $qty];
$this->extendGlobalIds(Type::CURRENCY, -$c);
}
else if ($c > 0) // plain items (item1,count1,item2,count2,...)
{
$tokens[$c] = $c.','.($qty / $stack);
if (is_float($qty / $stack))
$divisor = 1;
$tokens[] = [$c, $qty];
$this->extendGlobalIds(Type::ITEM, $c);
}
}
// display every cost-combination only once
if (in_array(md5(serialize($data)), $handled))
$hash = md5(serialize($data));
if (in_array($hash, $handled))
continue;
$handled[] = md5(serialize($data));
$handled[] = $hash;
$cost = isset($data[0]) ? '[money='.($data[0] / $stack) : '[money';
if (isset($data[0]))
{
if (is_float($data[0] / $stack))
$divisor = 1;
$cost = '[money='.($data[0] / $divisor);
}
else
$cost = '[money';
$stringify = function(&$v) use ($divisor) { return $v = $v[0] . ',' . ($v[1] / $divisor); };
if ($tokens)
{
array_walk($tokens, $stringify, $divisor);
$cost .= ' items='.implode(',', $tokens);
}
if ($currency)
{
array_walk($currency, $stringify, $divisor);
$cost .= ' currency='.implode(',', $currency);
}
$cost .= ']';
@@ -259,6 +283,11 @@ class ItemPage extends genericPage
}
}
if ($stack > 1 && $divisor > 1)
$each = '[color=q0] ('.Lang::item('each').')[/color]';
else if ($stack > 1)
$each = '[color=q0] ('.$stack.')[/color]';
if (count($costList) == 1)
$infobox[] = Lang::item('cost').Lang::main('colon').$costList[0].$each;
else if (count($costList) > 1)