feat: track UNIT_FIELD_STAT0-4 from server update fields for accurate character stats

Add UNIT_FIELD_STAT0-4 (STR/AGI/STA/INT/SPI) to the UF enum and wire up
per-expansion indices in all four expansion JSON files (WotLK: 84-88,
Classic/Turtle: 138-142, TBC: 159-163). Read the values in both CREATE
and VALUES player update handlers and store in playerStats_[5].

renderStatsPanel now uses the server-authoritative totals when available,
falling back to the previous 20+level estimate only if the server hasn't
sent UNIT_FIELD_STAT* yet. Item-query bonuses are still shown as (+N)
alongside the server total for both paths.
This commit is contained in:
Kelsi 2026-03-10 23:08:15 -07:00
parent d95abfb607
commit 99de1fa3e5
10 changed files with 115 additions and 30 deletions

View file

@ -295,6 +295,13 @@ public:
// Server-authoritative armor (UNIT_FIELD_RESISTANCES[0])
int32_t getArmorRating() const { return playerArmorRating_; }
// Server-authoritative primary stats (UNIT_FIELD_STAT0-4: STR, AGI, STA, INT, SPI).
// Returns -1 if the server hasn't sent the value yet.
int32_t getPlayerStat(int idx) const {
if (idx < 0 || idx > 4) return -1;
return playerStats_[idx];
}
// Inventory
Inventory& getInventory() { return inventory; }
const Inventory& getInventory() const { return inventory; }
@ -2109,6 +2116,8 @@ private:
std::unordered_map<uint64_t, float> recentLootMoneyAnnounceCooldowns_;
uint64_t playerMoneyCopper_ = 0;
int32_t playerArmorRating_ = 0;
// Server-authoritative primary stats: [0]=STR [1]=AGI [2]=STA [3]=INT [4]=SPI; -1 = not received yet
int32_t playerStats_[5] = {-1, -1, -1, -1, -1};
// Some servers/custom clients shift update field indices. We can auto-detect coinage by correlating
// money-notify deltas with update-field diffs and then overriding UF::PLAYER_FIELD_COINAGE at runtime.
uint32_t pendingMoneyDelta_ = 0;

View file

@ -34,6 +34,11 @@ enum class UF : uint16_t {
UNIT_NPC_FLAGS,
UNIT_DYNAMIC_FLAGS,
UNIT_FIELD_RESISTANCES, // Physical armor (index 0 of the resistance array)
UNIT_FIELD_STAT0, // Strength (effective base, includes items)
UNIT_FIELD_STAT1, // Agility
UNIT_FIELD_STAT2, // Stamina
UNIT_FIELD_STAT3, // Intellect
UNIT_FIELD_STAT4, // Spirit
UNIT_END,
// Player fields