diff --git a/src/PlayerbotAI.cpp b/src/PlayerbotAI.cpp index aa2d4d50..2b107e3d 100644 --- a/src/PlayerbotAI.cpp +++ b/src/PlayerbotAI.cpp @@ -3514,7 +3514,7 @@ uint32 PlayerbotAI::GetEquipGearScore(Player* player, bool withBags, bool withBa return 0; } -uint32 PlayerbotAI::GetMixedGearScore(Player* player, bool withBags, bool withBank) +uint32 PlayerbotAI::GetMixedGearScore(Player* player, bool withBags, bool withBank, uint32 topN) { std::vector gearScore(EQUIPMENT_SLOT_END); uint32 twoHandScore = 0; @@ -3572,30 +3572,50 @@ uint32 PlayerbotAI::GetMixedGearScore(Player* player, bool withBags, bool withBa } } } + if (!topN) { + uint8 count = EQUIPMENT_SLOT_END - 2; // ignore body and tabard slots + uint32 sum = 0; - uint8 count = EQUIPMENT_SLOT_END - 2; // ignore body and tabard slots - uint32 sum = 0; + // check if 2h hand is higher level than main hand + off hand + if (gearScore[EQUIPMENT_SLOT_MAINHAND] + gearScore[EQUIPMENT_SLOT_OFFHAND] < twoHandScore * 2) + { + gearScore[EQUIPMENT_SLOT_OFFHAND] = 0; // off hand is ignored in calculations if 2h weapon has higher score + --count; + gearScore[EQUIPMENT_SLOT_MAINHAND] = twoHandScore; + } - // check if 2h hand is higher level than main hand + off hand + for (uint8 i = EQUIPMENT_SLOT_START; i < EQUIPMENT_SLOT_END; ++i) + { + sum += gearScore[i]; + } + + if (count) + { + uint32 res = uint32(sum / count); + return res; + } + + return 0; + } + // topN != 0 if (gearScore[EQUIPMENT_SLOT_MAINHAND] + gearScore[EQUIPMENT_SLOT_OFFHAND] < twoHandScore * 2) { - gearScore[EQUIPMENT_SLOT_OFFHAND] = 0; // off hand is ignored in calculations if 2h weapon has higher score - --count; + gearScore[EQUIPMENT_SLOT_OFFHAND] = twoHandScore; gearScore[EQUIPMENT_SLOT_MAINHAND] = twoHandScore; } - + std::vector topGearScore; for (uint8 i = EQUIPMENT_SLOT_START; i < EQUIPMENT_SLOT_END; ++i) { - sum += gearScore[i]; + topGearScore.push_back(gearScore[i]); } - - if (count) - { - uint32 res = uint32(sum / count); - return res; + std::sort(topGearScore.begin(), topGearScore.end(), [&](const uint32 lhs, const uint32 rhs) { + return lhs > rhs; + }); + uint32 sum = 0; + for (int i = 0; i < std::min((uint32)topGearScore.size(), topN); i++) { + sum += topGearScore[i]; } - - return 0; + return sum / topN; } void PlayerbotAI::_fillGearScoreData(Player* player, Item* item, std::vector* gearScore, uint32& twoHandScore, bool mixed) diff --git a/src/PlayerbotAI.h b/src/PlayerbotAI.h index 7bdaadaa..0f618cfd 100644 --- a/src/PlayerbotAI.h +++ b/src/PlayerbotAI.h @@ -400,7 +400,7 @@ class PlayerbotAI : public PlayerbotAIBase bool IsInVehicle(bool canControl = false, bool canCast = false, bool canAttack = false, bool canTurn = false, bool fixed = false); uint32 GetEquipGearScore(Player* player, bool withBags, bool withBank); - static uint32 GetMixedGearScore(Player* player, bool withBags, bool withBank); + static uint32 GetMixedGearScore(Player* player, bool withBags, bool withBank, uint32 topN = 0); bool HasSkill(SkillType skill); bool IsAllowedCommand(std::string const text); float GetRange(std::string const type); diff --git a/src/PlayerbotMgr.cpp b/src/PlayerbotMgr.cpp index b88e9ddf..838200bb 100644 --- a/src/PlayerbotMgr.cpp +++ b/src/PlayerbotMgr.cpp @@ -573,10 +573,10 @@ std::string const PlayerbotHolder::ProcessBotCommand(std::string const cmd, Obje } else if (cmd == "init=auto") { - uint32 mixedGearScore = PlayerbotAI::GetMixedGearScore(master, true, true) * 1.1f; + uint32 mixedGearScore = PlayerbotAI::GetMixedGearScore(master, false, false, 10) * 1.1f; PlayerbotFactory factory(bot, master->getLevel(), ITEM_QUALITY_LEGENDARY, mixedGearScore); factory.Randomize(false); - return "ok, gear score limit: " + std::to_string(mixedGearScore); + return "ok, gear score limit: " + std::to_string(mixedGearScore / 5) + "(for epic)"; } }