topN GetMixedGearScore

This commit is contained in:
Yunfan Li
2023-10-05 01:37:47 +08:00
parent 2aa7ff5a72
commit e75a824a85
3 changed files with 38 additions and 18 deletions

View File

@@ -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<uint32> 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<uint32> 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<uint32>* gearScore, uint32& twoHandScore, bool mixed)

View File

@@ -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);

View File

@@ -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)";
}
}