Items/Stats

* fixed stats for random enchanted items with scaling enchantments
 * don't send unused 'chance' to Summary tool
This commit is contained in:
Sarjuuk
2025-07-27 15:14:53 +02:00
parent a99fff46aa
commit b35ab67360
4 changed files with 26 additions and 8 deletions

View File

@@ -325,7 +325,7 @@ abstract class Stat // based on g_statTo
}
}
class StatsContainer
class StatsContainer implements \Countable
{
private $store = [];
@@ -502,6 +502,16 @@ class StatsContainer
return $this->store;
}
public function filter(?callable $filterFn = null) : self
{
$this->store = array_filter($this->store, $filterFn, ARRAY_FILTER_USE_BOTH);
return $this;
}
public function count() : int
{
return count($this->store);
}
/****************/
/* internal use */

View File

@@ -57,7 +57,12 @@ class EnchantmentList extends BaseType
}
}
$this->jsonStats[$this->id] = (new StatsContainer)->fromJson($curTpl, true);
// issue with scaling stats enchantments
// stats are stored as NOT NULL to be usable by the search filters and such become indistinguishable from scaling enchantments that _actually_ use the value 0
// so filter the stats container and if it is empty, rebuild from self. .. there are no mixed scaling/static enchantments, right!?
$this->jsonStats[$this->id] = (new StatsContainer)->fromJson($curTpl, true)->filter();
if (!count($this->jsonStats[$this->id]))
$this->jsonStats[$this->id]->fromEnchantment($curTpl);
}
if ($relSpells)
@@ -67,7 +72,7 @@ class EnchantmentList extends BaseType
// use if you JUST need the name
public static function getName($id)
{
$n = DB::Aowow()->SelectRow('SELECT name_loc0, name_loc2, name_loc3, name_loc4, name_loc6, name_loc8 FROM ?_itemenchantment WHERE id = ?d', $id );
$n = DB::Aowow()->SelectRow('SELECT `name_loc0`, `name_loc2`, `name_loc3`, `name_loc4`, `name_loc6`, `name_loc8` FROM ?_itemenchantment WHERE `id` = ?d', $id );
return Util::localizedString($n, 'name');
}
// end static use

View File

@@ -1578,11 +1578,11 @@ class ItemList extends BaseType
return;
// remember: id < 0: randomSuffix; id > 0: randomProperty
$subItemTpls = DB::World()->select('
SELECT CAST( entry as SIGNED) AS ARRAY_KEY, CAST( ench as SIGNED) AS ARRAY_KEY2, chance FROM item_enchantment_template WHERE entry IN (?a) UNION
SELECT CAST(-entry as SIGNED) AS ARRAY_KEY, CAST(-ench as SIGNED) AS ARRAY_KEY2, chance FROM item_enchantment_template WHERE entry IN (?a)',
array_keys(array_filter($subItemIds, function ($v) { return $v > 0; })) ?: [0],
array_keys(array_filter($subItemIds, function ($v) { return $v < 0; })) ?: [0]
$subItemTpls = DB::World()->select(
'SELECT CAST( `entry` as SIGNED) AS ARRAY_KEY, CAST( `ench` as SIGNED) AS ARRAY_KEY2, `chance` FROM item_enchantment_template WHERE `entry` IN (?a) UNION
SELECT CAST(-`entry` as SIGNED) AS ARRAY_KEY, CAST(-`ench` as SIGNED) AS ARRAY_KEY2, `chance` FROM item_enchantment_template WHERE `entry` IN (?a)',
array_keys(array_filter($subItemIds, fn($v) => $v > 0)) ?: [0],
array_keys(array_filter($subItemIds, fn($v) => $v < 0)) ?: [0]
);
$randIds = [];

View File

@@ -86,7 +86,10 @@ class ComparePage extends GenericPage
if (!empty($data[$itemId]['subitems']))
foreach ($data[$itemId]['subitems'] as &$si)
{
$si['enchantment'] = implode(', ', $si['enchantment']);
unset($si['chance']);
}
$this->cmpItems[$itemId] = [
'name_'.Lang::getLocale()->json() => $iList->getField('name', true),