diff --git a/src/Playerbots.cpp b/src/Playerbots.cpp index 51865e34..4d492e69 100644 --- a/src/Playerbots.cpp +++ b/src/Playerbots.cpp @@ -239,44 +239,39 @@ public: void OnPlayerGiveXP(Player* player, uint32& amount, Unit* /*victim*/, uint8 /*xpSource*/) override { - // no XP multiplier, when player is no bot. - if (!player || !player->GetSession()->IsBot()) + if (sPlayerbotAIConfig->randomBotXPRate == 1.0f || !player || !player->IsInWorld()) return; - // no XP gain, if master is not a bot and has xp gain disabled. - if (const Player* master = GET_PLAYERBOT_AI(player)->GetMaster()) + PlayerbotAI* botAI = GET_PLAYERBOT_AI(player); + if (!botAI || !sRandomPlayerbotMgr->IsRandomBot(player)) + return; + + // No XP gain if master is a real player with XP gain disabled + if (const Player* master = botAI->GetMaster()) { - if (!master->GetSession()->IsBot() && master->HasPlayerFlag(PLAYER_FLAGS_NO_XP_GAIN)) + if (WorldSession* masterSession = master->GetSession(); + masterSession && !masterSession->IsBot() && master->HasPlayerFlag(PLAYER_FLAGS_NO_XP_GAIN)) { - amount = 0; + amount = 0; // disable XP multiplier return; } } - // early return - if (sPlayerbotAIConfig->randomBotXPRate == 1.0 || !sRandomPlayerbotMgr->IsRandomBot(player)) - return; - - // no XP multiplier, when bot is in a group with a real player. + // No XP multiplier if bot is in a group with at least one real player if (Group* group = player->GetGroup()) { for (GroupReference* gref = group->GetFirstMember(); gref; gref = gref->next()) { - Player* member = gref->GetSource(); - if (!member) + if (Player* member = gref->GetSource()) { - continue; - } - - if (!member->GetSession()->IsBot()) - { - return; + if (!member->GetSession()->IsBot()) + return; } } } - // otherwise apply bot XP multiplier. - amount = static_cast(std::round(static_cast(amount) * sPlayerbotAIConfig->randomBotXPRate)); + // Otherwise apply XP multiplier + amount = static_cast(std::round(amount * sPlayerbotAIConfig->randomBotXPRate)); } }; diff --git a/src/RandomPlayerbotMgr.cpp b/src/RandomPlayerbotMgr.cpp index 1f94e35e..49851f8c 100644 --- a/src/RandomPlayerbotMgr.cpp +++ b/src/RandomPlayerbotMgr.cpp @@ -2594,17 +2594,14 @@ void RandomPlayerbotMgr::Refresh(Player* bot) bool RandomPlayerbotMgr::IsRandomBot(Player* bot) { - if (bot && GET_PLAYERBOT_AI(bot)) - { - if (GET_PLAYERBOT_AI(bot)->IsRealPlayer()) - return false; - } - if (bot) - { - return IsRandomBot(bot->GetGUID().GetCounter()); - } + if (!bot) + return false; - return false; + PlayerbotAI* botAI = GET_PLAYERBOT_AI(bot); + if (!botAI || botAI->IsRealPlayer()) + return false; + + return IsRandomBot(bot->GetGUID().GetCounter()); } bool RandomPlayerbotMgr::IsRandomBot(ObjectGuid::LowType bot)