Re-enable no-xp-feature with better checks (#1935)

The feature `Disable bot XP gain when master has XP turned off` (#1910)
was unintentionally disabled in #1929.
This PR re-enables it with better checks in order to prevent crashes
when playing together with the individual progression module.
This commit is contained in:
HennyWilly
2025-12-21 21:28:39 +01:00
committed by GitHub
parent cafbd4681e
commit 66f5f597bb

View File

@@ -239,24 +239,32 @@ public:
void OnPlayerGiveXP(Player* player, uint32& amount, Unit* /*victim*/, uint8 /*xpSource*/) override
{
if (sPlayerbotAIConfig->randomBotXPRate == 1.0f || !player || !player->IsInWorld())
if (!player || !player->IsInWorld())
return;
if (WorldSession* session = player->GetSession(); !session || !session->IsBot())
return;
PlayerbotAI* botAI = GET_PLAYERBOT_AI(player);
if (!botAI || !sRandomPlayerbotMgr->IsRandomBot(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))
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
if (Group* group = player->GetGroup())
{
@@ -264,14 +272,14 @@ public:
{
if (Player* member = gref->GetSource())
{
if (!member->GetSession()->IsBot())
if (WorldSession* session = member->GetSession();session && !session->IsBot())
return;
}
}
}
// Otherwise apply XP multiplier
amount = static_cast<uint32>(std::round(amount * sPlayerbotAIConfig->randomBotXPRate));
amount = static_cast<uint32>(std::round(static_cast<float>(amount) * sPlayerbotAIConfig->randomBotXPRate));
}
};