From edc9241fa32f8f5e539d5b9dce3178da9126ff41 Mon Sep 17 00:00:00 2001 From: Alex Dcnh <140754794+Wishmaster117@users.noreply.github.com> Date: Thu, 3 Jul 2025 22:21:54 +0200 Subject: [PATCH 1/3] Update PlayerbotAI.cpp --- src/PlayerbotAI.cpp | 51 ++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 48 insertions(+), 3 deletions(-) diff --git a/src/PlayerbotAI.cpp b/src/PlayerbotAI.cpp index 8c22533c..3191b9c2 100644 --- a/src/PlayerbotAI.cpp +++ b/src/PlayerbotAI.cpp @@ -4430,9 +4430,54 @@ void PlayerbotAI::RemoveShapeshift() // RemoveAura("tree of life"); } +// Official‐style Average Item Level for display / Who command +uint32 PlayerbotAI::GetEquipGearScore(Player* player) +{ + const uint8 kTotalSlots = 16; // default divisor + const bool hasTitanGrip = + player->HasAura(SPELL_TITAN_GRIP); + + uint32 sum = 0; + uint8 divisor = kTotalSlots; + + bool mainHas2H = false; + + for (uint8 slot = EQUIPMENT_SLOT_START; slot < EQUIPMENT_SLOT_END; ++slot) + { + 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; + + if (slot == EQUIPMENT_SLOT_MAINHAND) + mainHas2H = (proto->InventoryType == INVTYPE_2HWEAPON); + + // 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, + // we use 17 slots just like the client API. + if (hasTitanGrip && mainHas2H) + ++divisor; + + return divisor ? sum / divisor : 0; +} + // NOTE : function rewritten as flags "withBags" and "withBank" not used, and _fillGearScoreData sometimes attribute // one-hand/2H Weapon in wrong slots -uint32 PlayerbotAI::GetEquipGearScore(Player* player) +/*uint32 PlayerbotAI::GetEquipGearScore(Player* player) { // This function aims to calculate the equipped gear score @@ -4454,11 +4499,11 @@ uint32 PlayerbotAI::GetEquipGearScore(Player* player) if (!player->HasAura(SPELL_TITAN_GRIP) && mh_type == INVTYPE_2HWEAPON && i == SLOT_MAIN_HAND) sum += item->GetTemplate()->ItemLevel; } - } + } uint32 gs = uint32(sum / count); return gs; -} +}*/ /*uint32 PlayerbotAI::GetEquipGearScore(Player* player, bool withBags, bool withBank) { From 326783ed4fd04bea2ae66dc4c71dc082808e8e28 Mon Sep 17 00:00:00 2001 From: Alex Dcnh <140754794+Wishmaster117@users.noreply.github.com> Date: Fri, 4 Jul 2025 10:23:37 +0200 Subject: [PATCH 2/3] =?UTF-8?q?PlayerbotAI=20=E2=80=93=20Fix=20GetEquipGea?= =?UTF-8?q?rScore=20to=20mirror=20Blizzard=E2=80=99s=20average-ilvl=20rule?= =?UTF-8?q?s?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/PlayerbotAI.cpp | 50 ++++++++++++++++++--------------------------- 1 file changed, 20 insertions(+), 30 deletions(-) diff --git a/src/PlayerbotAI.cpp b/src/PlayerbotAI.cpp index 3191b9c2..1078820d 100644 --- a/src/PlayerbotAI.cpp +++ b/src/PlayerbotAI.cpp @@ -4430,49 +4430,39 @@ void PlayerbotAI::RemoveShapeshift() // RemoveAura("tree of life"); } -// Official‐style Average Item Level for display / Who command +// Mirrors Blizzard’s GetAverageItemLevel rules : +// https://wowpedia.fandom.com/wiki/API_GetAverageItemLevel uint32 PlayerbotAI::GetEquipGearScore(Player* player) { - const uint8 kTotalSlots = 16; // default divisor - const bool hasTitanGrip = - player->HasAura(SPELL_TITAN_GRIP); + constexpr uint8 BASE_SLOTS = 17; // everything except Body & Tabard + uint32 sumLevel = 0; + uint8 divisor = BASE_SLOTS; - uint32 sum = 0; - uint8 divisor = kTotalSlots; + Item* main = player->GetItemByPos(INVENTORY_SLOT_BAG_0, EQUIPMENT_SLOT_MAINHAND); + 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) { 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; - if (slot == EQUIPMENT_SLOT_MAINHAND) - mainHas2H = (proto->InventoryType == INVTYPE_2HWEAPON); - - // 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 (Item* it = player->GetItemByPos(INVENTORY_SLOT_BAG_0, slot)) + sumLevel += it->GetTemplate()->ItemLevel; } - // If Titan Grip is active and two genuine 2-H weapons are equipped, - // we use 17 slots just like the client API. - if (hasTitanGrip && mainHas2H) - ++divisor; + /* ---------- 2. Adjust divisor -------------- */ + if ((twoHandMain && !player->HasAura(SPELL_TITAN_GRIP)) || // real 2-H weapon + (!main && !off)) // both hands empty + { + 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 From 8fd188ff3b522f515292ac8d89f1bdb419193b65 Mon Sep 17 00:00:00 2001 From: Alex Dcnh <140754794+Wishmaster117@users.noreply.github.com> Date: Fri, 4 Jul 2025 19:19:29 +0200 Subject: [PATCH 3/3] Update PlayerbotAI.cpp --- src/PlayerbotAI.cpp | 40 ++++++++++++++++++++++------------------ 1 file changed, 22 insertions(+), 18 deletions(-) diff --git a/src/PlayerbotAI.cpp b/src/PlayerbotAI.cpp index 1078820d..0d3f693b 100644 --- a/src/PlayerbotAI.cpp +++ b/src/PlayerbotAI.cpp @@ -4434,35 +4434,39 @@ void PlayerbotAI::RemoveShapeshift() // https://wowpedia.fandom.com/wiki/API_GetAverageItemLevel uint32 PlayerbotAI::GetEquipGearScore(Player* player) { - constexpr uint8 BASE_SLOTS = 17; // everything except Body & Tabard - uint32 sumLevel = 0; - uint8 divisor = BASE_SLOTS; + constexpr uint8 TOTAL_SLOTS = 17; // every slot except Body & Tabard + uint32 sumLevel = 0; - Item* main = player->GetItemByPos(INVENTORY_SLOT_BAG_0, EQUIPMENT_SLOT_MAINHAND); - Item* off = player->GetItemByPos(INVENTORY_SLOT_BAG_0, EQUIPMENT_SLOT_OFFHAND); + /* ---------- 0. Detect “ignore off-hand” situations --------- */ + Item* main = player->GetItemByPos(INVENTORY_SLOT_BAG_0, EQUIPMENT_SLOT_MAINHAND); + Item* off = player->GetItemByPos(INVENTORY_SLOT_BAG_0, EQUIPMENT_SLOT_OFFHAND); - bool twoHandMain = false; + bool ignoreOffhand = false; // true → divisor = 16 if (main) - twoHandMain = (main->GetTemplate()->InventoryType == INVTYPE_2HWEAPON); + { + bool twoHand = (main->GetTemplate()->InventoryType == INVTYPE_2HWEAPON); + if (twoHand && !player->HasAura(SPELL_TITAN_GRIP)) + ignoreOffhand = true; // classic 2-hander + } + else if (!off) // both hands empty + ignoreOffhand = true; - /* ---------- 1. Add up item-levels ---------- */ + /* ---------- 1. Sum up item-levels -------------------------- */ for (uint8 slot = EQUIPMENT_SLOT_START; slot < EQUIPMENT_SLOT_END; ++slot) { if (slot == EQUIPMENT_SLOT_BODY || slot == EQUIPMENT_SLOT_TABARD) - continue; + continue; // Blizzard never counts these + + if (ignoreOffhand && slot == EQUIPMENT_SLOT_OFFHAND) + continue; // skip off-hand in 2-H case if (Item* it = player->GetItemByPos(INVENTORY_SLOT_BAG_0, slot)) - sumLevel += it->GetTemplate()->ItemLevel; + sumLevel += it->GetTemplate()->ItemLevel; // missing items add 0 } - /* ---------- 2. Adjust divisor -------------- */ - if ((twoHandMain && !player->HasAura(SPELL_TITAN_GRIP)) || // real 2-H weapon - (!main && !off)) // both hands empty - { - divisor = BASE_SLOTS - 1; // use 16 - } - - return divisor ? sumLevel / divisor : 0; + /* ---------- 2. Divide by 17 or 16 -------------------------- */ + const uint8 divisor = ignoreOffhand ? TOTAL_SLOTS - 1 : TOTAL_SLOTS; // 16 or 17 + return sumLevel / divisor; } // NOTE : function rewritten as flags "withBags" and "withBank" not used, and _fillGearScoreData sometimes attribute