mirror of
https://github.com/mod-playerbots/mod-playerbots.git
synced 2026-01-13 00:58:33 +00:00
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:
@@ -239,24 +239,32 @@ public:
|
|||||||
|
|
||||||
void OnPlayerGiveXP(Player* player, uint32& amount, Unit* /*victim*/, uint8 /*xpSource*/) override
|
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;
|
return;
|
||||||
|
|
||||||
PlayerbotAI* botAI = GET_PLAYERBOT_AI(player);
|
PlayerbotAI* botAI = GET_PLAYERBOT_AI(player);
|
||||||
if (!botAI || !sRandomPlayerbotMgr->IsRandomBot(player))
|
if (!botAI)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// No XP gain if master is a real player with XP gain disabled
|
// No XP gain if master is a real player with XP gain disabled
|
||||||
if (const Player* master = botAI->GetMaster())
|
if (const Player* master = botAI->GetMaster())
|
||||||
{
|
{
|
||||||
if (WorldSession* masterSession = master->GetSession();
|
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
|
amount = 0; // disable XP multiplier
|
||||||
return;
|
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 if bot is in a group with at least one real player
|
||||||
if (Group* group = player->GetGroup())
|
if (Group* group = player->GetGroup())
|
||||||
{
|
{
|
||||||
@@ -264,14 +272,14 @@ public:
|
|||||||
{
|
{
|
||||||
if (Player* member = gref->GetSource())
|
if (Player* member = gref->GetSource())
|
||||||
{
|
{
|
||||||
if (!member->GetSession()->IsBot())
|
if (WorldSession* session = member->GetSession();session && !session->IsBot())
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Otherwise apply XP multiplier
|
// 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));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user