diff --git a/includes/game/chrstatistics.php b/includes/game/chrstatistics.php index 4dc83619..fc1cb193 100644 --- a/includes/game/chrstatistics.php +++ b/includes/game/chrstatistics.php @@ -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 */ diff --git a/includes/types/enchantment.class.php b/includes/types/enchantment.class.php index 76331e5a..c4c7b1f0 100644 --- a/includes/types/enchantment.class.php +++ b/includes/types/enchantment.class.php @@ -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 diff --git a/includes/types/item.class.php b/includes/types/item.class.php index 3043cd34..a935c371 100644 --- a/includes/types/item.class.php +++ b/includes/types/item.class.php @@ -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 = []; diff --git a/pages/compare.php b/pages/compare.php index bc9e13e5..c1d8beb2 100644 --- a/pages/compare.php +++ b/pages/compare.php @@ -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),