diff --git a/endpoints/account/weightscales.php b/endpoints/account/weightscales.php index 13bba67e..d4bf016c 100644 --- a/endpoints/account/weightscales.php +++ b/endpoints/account/weightscales.php @@ -88,7 +88,7 @@ class AccountWeightscalesResponse extends TextResponse return false; foreach ($this->_post['scale'] as [$k, $v]) - if (in_array($k, Util::$weightScales)) // $v is known to be a positive int due to regex check + if (Stat::getWeightJson($k)) // $v is known to be a positive int due to regex check if (!is_int(DB::Aowow()->query('INSERT INTO ?_account_weightscale_data VALUES (?d, ?, ?d)', $scaleId, $k, $v))) return false; diff --git a/endpoints/admin/weight-presets_save.php b/endpoints/admin/weight-presets_save.php index 50038a54..8001cd4b 100644 --- a/endpoints/admin/weight-presets_save.php +++ b/endpoints/admin/weight-presets_save.php @@ -37,7 +37,7 @@ class AdminWeightpresetsActionSaveResponse extends TextResponse { [$k, $v] = explode(':', $s); - if (!in_array($k, Util::$weightScales) || $v < 1) + if (!Stat::getWeightJson($k) || $v < 1) continue; if (DB::Aowow()->query('INSERT INTO ?_account_weightscale_data VALUES (?d, ?, ?d)', $this->_post['id'], $k, $v) === null) diff --git a/includes/dbtypes/item.class.php b/includes/dbtypes/item.class.php index 01dd9b46..21336935 100644 --- a/includes/dbtypes/item.class.php +++ b/includes/dbtypes/item.class.php @@ -2018,9 +2018,8 @@ class ItemListFilter extends Filter foreach ($this->values['wt'] as $k => $v) { - if ($idx = Stat::getIndexFrom(Stat::IDX_FILTER_CR_ID, $v)) + if ($str = Stat::getWeightJson($v)) { - $str = Stat::getJsonString($idx); $qty = intVal($this->values['wtv'][$k]); $select[] = '(IFNULL(`is`.`'.$str.'`, 0) * '.$qty.')'; diff --git a/includes/game/chrstatistics.php b/includes/game/chrstatistics.php index 15aba20e..48703152 100644 --- a/includes/game/chrstatistics.php +++ b/includes/game/chrstatistics.php @@ -116,6 +116,7 @@ abstract class Stat // based on g_statTo public const FLAG_PROFILER = 0x04; // stat used in profiler only public const FLAG_LVL_SCALING = 0x08; // rating effectivenes scales with level public const FLAG_FLOAT_VALUE = 0x10; // not an int + public const FLAG_NO_WEIGHT = 0x20; // for item summary and filter .. basically any fi_filters.items of type: num thats not excluded by noweights: 1 is weightable public const IDX_JSON_STR = 0; public const IDX_ITEM_MOD = 1; // granted by items @@ -123,7 +124,7 @@ abstract class Stat // based on g_statTo public const IDX_FILTER_CR_ID = 3; // also references listview cols public const IDX_FLAGS = 4; - private static /* array */ $data = array( + private static array $data = array( self::HEALTH => ['health', ITEM_MOD_HEALTH, null, 115, self::FLAG_ITEM], self::MANA => ['mana', ITEM_MOD_MANA, null, 116, self::FLAG_ITEM], self::AGILITY => ['agi', ITEM_MOD_AGILITY, null, 21, self::FLAG_ITEM], @@ -188,7 +189,7 @@ abstract class Stat // based on g_statTo self::ARCANE_SPELL_POWER => ['arcsplpwr', null, null, 52, self::FLAG_ITEM], // v not part of g_statToJson v self::WEAPON_DAMAGE => ['dmg', null, null, null, self::FLAG_SERVERSIDE | self::FLAG_FLOAT_VALUE], - self::WEAPON_DAMAGE_TYPE => ['damagetype', null, null, 35, self::FLAG_SERVERSIDE], + self::WEAPON_DAMAGE_TYPE => ['damagetype', null, null, 35, self::FLAG_SERVERSIDE | self::FLAG_NO_WEIGHT], self::WEAPON_DAMAGE_MIN => ['dmgmin1', null, null, 33, self::FLAG_SERVERSIDE], self::WEAPON_DAMAGE_MAX => ['dmgmax1', null, null, 34, self::FLAG_SERVERSIDE], self::WEAPON_SPEED => ['speed', null, null, 36, self::FLAG_SERVERSIDE | self::FLAG_FLOAT_VALUE], @@ -201,7 +202,7 @@ abstract class Stat // based on g_statTo self::RANGED_DAMAGE_MAX => ['rgddmgmax', null, null, 140, self::FLAG_SERVERSIDE], self::RANGED_SPEED => ['rgdspeed', null, null, 141, self::FLAG_SERVERSIDE | self::FLAG_FLOAT_VALUE], self::RANGED_DPS => ['rgddps', null, null, 138, self::FLAG_SERVERSIDE | self::FLAG_FLOAT_VALUE | self::FLAG_PROFILER], - self::EXTRA_SOCKETS => ['nsockets', null, null, 100, self::FLAG_SERVERSIDE], + self::EXTRA_SOCKETS => ['nsockets', null, null, 100, self::FLAG_SERVERSIDE | self::FLAG_NO_WEIGHT], self::ARMOR_BONUS => ['armorbonus', null, null, 109, self::FLAG_SERVERSIDE], self::MELEE_ATTACK_POWER => ['mleatkpwr', null, null, 37, self::FLAG_SERVERSIDE | self::FLAG_PROFILER], // v Profiler only v @@ -248,6 +249,16 @@ abstract class Stat // based on g_statTo return !(self::$data[$stat][self::IDX_FLAGS] & self::FLAG_LVL_SCALING); } + public static function getWeightJson(string|int $jsonOrCriteriaId) : string + { + if (is_numeric($jsonOrCriteriaId)) + $row = array_find(self::$data, fn($x) => $x[self::IDX_FILTER_CR_ID] == $jsonOrCriteriaId); + else + $row = array_find(self::$data, fn($x) => $x[self::IDX_JSON_STR] == $jsonOrCriteriaId); + + return $row && $row[self::IDX_FILTER_CR_ID] && !($row[self::IDX_FLAGS] & self::FLAG_NO_WEIGHT) ? $row[self::IDX_JSON_STR] : ''; + } + public static function getRatingPctFactor(int $stat) : float { // Note: this makes the weapon skill related combat ratings inaccessible. Is this relevant..? @@ -315,13 +326,9 @@ abstract class Stat // based on g_statTo return $x; } - public static function getIndexFrom(int $idx, string $match) : int + public static function getIndexFrom(int $idx, string $search) : int { - $i = array_search($match, array_column(self::$data, $idx)); - if ($i === false) - return 0; - - return array_keys(self::$data)[$i]; + return array_find_key(self::$data, fn($x) => $x[$idx] == $search) ?: 0; } } diff --git a/includes/utilities.php b/includes/utilities.php index fd9e8789..0857a4f0 100644 --- a/includes/utilities.php +++ b/includes/utilities.php @@ -69,18 +69,6 @@ abstract class Util 'clothChestArmor', 'leatherChestArmor', 'mailChestArmor', 'plateChestArmor' ); - public static $weightScales = array( - 'agi', 'int', 'sta', 'spi', 'str', 'health', 'mana', 'healthrgn', 'manargn', - 'armor', 'blockrtng', 'block', 'defrtng', 'dodgertng', 'parryrtng', 'resirtng', - 'atkpwr', 'feratkpwr', 'armorpenrtng', 'critstrkrtng', 'exprtng', 'hastertng', 'hitrtng', 'splpen', - 'splpwr', 'arcsplpwr', 'firsplpwr', 'frosplpwr', 'holsplpwr', 'natsplpwr', 'shasplpwr', - 'dmg', 'mledps', 'rgddps', 'mledmgmin', 'rgddmgmin', 'mledmgmax', 'rgddmgmax', 'mlespeed', 'rgdspeed', - 'arcres', 'firres', 'frores', 'holres', 'natres', 'shares', - 'mleatkpwr', 'mlecritstrkrtng', 'mlehastertng', 'mlehitrtng', 'rgdatkpwr', 'rgdcritstrkrtng', 'rgdhastertng', 'rgdhitrtng', - 'splcritstrkrtng', 'splhastertng', 'splhitrtng', 'spldmg', 'splheal', - 'nsockets' - ); - public static $dateFormatInternal = "Y/m/d H:i:s"; public static $changeLevelString = '%s';