PlayerbotAI – Fix GetEquipGearScore to mirror Blizzard’s average-ilvl rules

This commit is contained in:
Alex Dcnh
2025-07-04 10:23:37 +02:00
committed by GitHub
parent 9503d32d46
commit 326783ed4f

View File

@@ -4430,49 +4430,39 @@ void PlayerbotAI::RemoveShapeshift()
// RemoveAura("tree of life"); // RemoveAura("tree of life");
} }
// Officialstyle Average Item Level for display / Who command // Mirrors Blizzards GetAverageItemLevel rules :
// https://wowpedia.fandom.com/wiki/API_GetAverageItemLevel
uint32 PlayerbotAI::GetEquipGearScore(Player* player) uint32 PlayerbotAI::GetEquipGearScore(Player* player)
{ {
const uint8 kTotalSlots = 16; // default divisor constexpr uint8 BASE_SLOTS = 17; // everything except Body & Tabard
const bool hasTitanGrip = uint32 sumLevel = 0;
player->HasAura(SPELL_TITAN_GRIP); uint8 divisor = BASE_SLOTS;
uint32 sum = 0; Item* main = player->GetItemByPos(INVENTORY_SLOT_BAG_0, EQUIPMENT_SLOT_MAINHAND);
uint8 divisor = kTotalSlots; Item* off = player->GetItemByPos(INVENTORY_SLOT_BAG_0, EQUIPMENT_SLOT_OFFHAND);
bool mainHas2H = false; bool twoHandMain = false;
if (main)
twoHandMain = (main->GetTemplate()->InventoryType == INVTYPE_2HWEAPON);
/* ---------- 1. Add up item-levels ---------- */
for (uint8 slot = EQUIPMENT_SLOT_START; slot < EQUIPMENT_SLOT_END; ++slot) for (uint8 slot = EQUIPMENT_SLOT_START; slot < EQUIPMENT_SLOT_END; ++slot)
{ {
if (slot == EQUIPMENT_SLOT_BODY || slot == EQUIPMENT_SLOT_TABARD) if (slot == EQUIPMENT_SLOT_BODY || slot == EQUIPMENT_SLOT_TABARD)
continue; // never counted in AIL
Item* item = player->GetItemByPos(INVENTORY_SLOT_BAG_0, slot);
if (!item)
continue; // empty slot ⇒ contributes 0
ItemTemplate const* proto = item->GetTemplate();
if (!proto)
continue; continue;
if (slot == EQUIPMENT_SLOT_MAINHAND) if (Item* it = player->GetItemByPos(INVENTORY_SLOT_BAG_0, slot))
mainHas2H = (proto->InventoryType == INVTYPE_2HWEAPON); sumLevel += it->GetTemplate()->ItemLevel;
// Off-hand with real 2-H in main and no Titan Grip still counts as
// an *empty* slot, so we keep the divisor unchanged and add 0 here.
if (slot == EQUIPMENT_SLOT_OFFHAND &&
mainHas2H && !hasTitanGrip)
continue;
sum += proto->ItemLevel;
} }
// If Titan Grip is active and two genuine 2-H weapons are equipped, /* ---------- 2. Adjust divisor -------------- */
// we use 17 slots just like the client API. if ((twoHandMain && !player->HasAura(SPELL_TITAN_GRIP)) || // real 2-H weapon
if (hasTitanGrip && mainHas2H) (!main && !off)) // both hands empty
++divisor; {
divisor = BASE_SLOTS - 1; // use 16
}
return divisor ? sum / divisor : 0; return divisor ? sumLevel / divisor : 0;
} }
// NOTE : function rewritten as flags "withBags" and "withBank" not used, and _fillGearScoreData sometimes attribute // NOTE : function rewritten as flags "withBags" and "withBank" not used, and _fillGearScoreData sometimes attribute