Compare commits

...

2 Commits

Author SHA1 Message Date
bashermens
2317652d72 Full revert: no xp bot when master has xp disabled (#1948)
Will reimplement the feature later in time.
2025-12-25 03:00:21 +01:00
bashermens
1fcd6c5cda Quickfix: performance problems (XP gain when master has XP turned off) (#1947)
Disable bot XP gain when master has XP turned off feature has a big
performance impact.

Instead of reverting placed back to original code before the feature
PR's for now as quickfix
2025-12-25 02:07:59 +01:00
2 changed files with 24 additions and 34 deletions

View File

@@ -264,46 +264,33 @@ public:
void OnPlayerGiveXP(Player* player, uint32& amount, Unit* /*victim*/, uint8 /*xpSource*/) override
{
if (!player || !player->IsInWorld())
// early return
if (sPlayerbotAIConfig->randomBotXPRate == 1.0 || !player)
return;
if (WorldSession* session = player->GetSession(); !session || !session->IsBot())
// no XP multiplier, when player is no bot.
if (!player->GetSession()->IsBot() || !sRandomPlayerbotMgr->IsRandomBot(player))
return;
PlayerbotAI* botAI = GET_PLAYERBOT_AI(player);
if (!botAI)
return;
// No XP gain if master is a real player with XP gain disabled
if (const Player* master = botAI->GetMaster())
{
if (WorldSession* masterSession = master->GetSession();
masterSession && !masterSession->IsBot() &&
master->HasPlayerFlag(PLAYER_FLAGS_NO_XP_GAIN))
{
amount = 0; // disable XP multiplier
return;
}
}
// From here on we only care about random bots
if (sPlayerbotAIConfig->randomBotXPRate == 1.0f || !sRandomPlayerbotMgr->IsRandomBot(player))
return;
// No XP multiplier if bot is in a group with at least one real player
// no XP multiplier, when bot is in a group with a real player.
if (Group* group = player->GetGroup())
{
for (GroupReference* gref = group->GetFirstMember(); gref; gref = gref->next())
{
if (Player* member = gref->GetSource())
Player* member = gref->GetSource();
if (!member)
{
if (WorldSession* session = member->GetSession();session && !session->IsBot())
return;
continue;
}
if (!member->GetSession()->IsBot())
{
return;
}
}
}
// Otherwise apply XP multiplier
// otherwise apply bot XP multiplier.
amount = static_cast<uint32>(std::round(static_cast<float>(amount) * sPlayerbotAIConfig->randomBotXPRate));
}
};

View File

@@ -2593,14 +2593,17 @@ void RandomPlayerbotMgr::Refresh(Player* bot)
bool RandomPlayerbotMgr::IsRandomBot(Player* bot)
{
if (!bot)
return false;
if (bot && GET_PLAYERBOT_AI(bot))
{
if (GET_PLAYERBOT_AI(bot)->IsRealPlayer())
return false;
}
if (bot)
{
return IsRandomBot(bot->GetGUID().GetCounter());
}
PlayerbotAI* botAI = GET_PLAYERBOT_AI(bot);
if (!botAI || botAI->IsRealPlayer())
return false;
return IsRandomBot(bot->GetGUID().GetCounter());
return false;
}
bool RandomPlayerbotMgr::IsRandomBot(ObjectGuid::LowType bot)