From 750e176c333027fbd97493dc8b7eb2b3b004e037 Mon Sep 17 00:00:00 2001 From: Sarjuuk Date: Tue, 24 Feb 2026 13:12:40 +0100 Subject: [PATCH] Stats/Fixup * fix melee attack power from spells counting towards generic attack power * combine melee and ranged attack power from the same spell into generic attack power, if amounts are equal --- includes/game/chrstatistics.php | 37 ++++++++++++++++++++--------- includes/utilities.php | 2 +- setup/sql/updates/1771934998_01.sql | 1 + 3 files changed, 28 insertions(+), 12 deletions(-) create mode 100644 setup/sql/updates/1771934998_01.sql diff --git a/includes/game/chrstatistics.php b/includes/game/chrstatistics.php index 48703152..d0874f03 100644 --- a/includes/game/chrstatistics.php +++ b/includes/game/chrstatistics.php @@ -334,10 +334,19 @@ abstract class Stat // based on g_statTo class StatsContainer implements \Countable { - private $store = []; + private array $store = []; - private $relSpells = []; - private $relEnchantments = []; + private array $relSpells = []; + private array $relEnchantments = []; + + private static array $combinedSpellStats = array ( + Stat::ATTACK_POWER => [Stat::RANGED_ATTACK_POWER, Stat::MELEE_ATTACK_POWER], + Stat::SPELL_POWER => [Stat::DAMAGE_SPELL_POWER, Stat::HEALING_SPELL_POWER], + // combat ratings below could be merged like this, but easier to handle as they are already in the same bitmask of the same spell effect + // Stat::HIT_RTG => [Stat::MELEE_HIT_RTG, Stat::RANGED_HIT_RTG, Stat::SPELL_HIT_RTG], + // Stat::CRIT_RTG => [Stat::MELEE_CRIT_TAKEN_RTG, Stat::RANGED_CRIT_RTG, Stat::SPELL_CRIT_RTG], + // Stat::RESILIENCE_RTG => [Stat::MELEE_CRIT_RTG, Stat::RANGED_CRIT_TAKEN_RTG, Stat::SPELL_CRIT_TAKEN_RTG] + ); public function __construct(array $relSpells = [], array $relEnchantments = []) { @@ -415,8 +424,6 @@ class StatsContainer implements \Countable if ($onlyFoodBuff && !($spell['attributes2'] & SPELL_ATTR2_FOOD_BUFF)) return $this; - // if spells grant an equal, non-zero amount of SPELL_DAMAGE and SPELL_HEALING, combine them to SPELL_POWER - // this probably does not affect enchantments $tmpStore = []; for ($i = 1; $i <= 3; $i++) @@ -438,11 +445,20 @@ class StatsContainer implements \Countable Util::arraySumByKey($tmpStore, [$idx => $amt]); } - if (!empty($tmpStore[Stat::HEALING_SPELL_POWER]) && !empty($tmpStore[Stat::DAMAGE_SPELL_POWER]) && $tmpStore[Stat::HEALING_SPELL_POWER] == $tmpStore[Stat::DAMAGE_SPELL_POWER]) + foreach (self::$combinedSpellStats as $combined => $stats) { - Util::arraySumByKey($tmpStore, [Stat::SPELL_POWER => $tmpStore[Stat::HEALING_SPELL_POWER]]); - unset($tmpStore[Stat::HEALING_SPELL_POWER]); - unset($tmpStore[Stat::DAMAGE_SPELL_POWER]); + for ($i = 0; $i < count($stats); $i++) + { + if (empty($tmpStore[$stats[$i]])) + continue 2; + + if ($i && $tmpStore[$stats[$i]] != $tmpStore[$stats[$i - 1]]) + continue 2; + } + + Util::arraySumByKey($tmpStore, [$combined => $tmpStore[$stats[0]]]); + foreach ($stats as $stat) + unset($tmpStore[$stat]); } Util::arraySumByKey($this->store, $tmpStore); @@ -586,7 +602,6 @@ class StatsContainer implements \Countable if (($mask & $critMask) == $critMask) return [Stat::CRIT_RTG]; // generic crit rating - $takentMask = (1 << CR_CRIT_TAKEN_MELEE) | (1 << CR_CRIT_TAKEN_RANGED) | (1 << CR_CRIT_TAKEN_SPELL); if (($mask & $takentMask) == $takentMask) return [Stat::RESILIENCE_RTG]; // resilience @@ -689,7 +704,7 @@ class StatsContainer implements \Countable case SPELL_AURA_MOD_POWER_REGEN: // mp5 return [Stat::MANA_REGENERATION]; case SPELL_AURA_MOD_ATTACK_POWER: - return [Stat::ATTACK_POWER/*, Stat::RANGED_ATTACK_POWER*/]; + return [Stat::MELEE_ATTACK_POWER]; case SPELL_AURA_MOD_RANGED_ATTACK_POWER: return [Stat::RANGED_ATTACK_POWER]; case SPELL_AURA_MOD_SHIELD_BLOCKVALUE: diff --git a/includes/utilities.php b/includes/utilities.php index 61d8319a..d04d46c3 100644 --- a/includes/utilities.php +++ b/includes/utilities.php @@ -723,7 +723,7 @@ abstract class Util /* file handling */ /*****************/ - public static function writeFile($file, $content) + public static function writeFile(string $file, string $content) : bool { $success = false; diff --git a/setup/sql/updates/1771934998_01.sql b/setup/sql/updates/1771934998_01.sql new file mode 100644 index 00000000..9fa47c05 --- /dev/null +++ b/setup/sql/updates/1771934998_01.sql @@ -0,0 +1 @@ +UPDATE `aowow_dbversion` SET `sql` = CONCAT(IFNULL(`sql`, ''), ' stats');