mirror of
https://github.com/mod-playerbots/mod-playerbots.git
synced 2026-01-13 00:58:33 +00:00
server_crash_fix: OnPlayerGiveXP (#1929)
[fef0ed4072c8_worldserver.exe_.18-12_23-30-44.txt](https://github.com/user-attachments/files/24258638/fef0ed4072c8_worldserver.exe_.18-12_23-30-44.txt) - Just added common logic and defense coding - Optimized isRandombot while at it Just for clarification i am aware the trigger of bug lies with the progression mod. Regardless it should not happen.
This commit is contained in:
@@ -239,44 +239,39 @@ public:
|
|||||||
|
|
||||||
void OnPlayerGiveXP(Player* player, uint32& amount, Unit* /*victim*/, uint8 /*xpSource*/) override
|
void OnPlayerGiveXP(Player* player, uint32& amount, Unit* /*victim*/, uint8 /*xpSource*/) override
|
||||||
{
|
{
|
||||||
// no XP multiplier, when player is no bot.
|
if (sPlayerbotAIConfig->randomBotXPRate == 1.0f || !player || !player->IsInWorld())
|
||||||
if (!player || !player->GetSession()->IsBot())
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// no XP gain, if master is not a bot and has xp gain disabled.
|
PlayerbotAI* botAI = GET_PLAYERBOT_AI(player);
|
||||||
if (const Player* master = GET_PLAYERBOT_AI(player)->GetMaster())
|
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;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// early return
|
// No XP multiplier if bot is in a group with at least one real player
|
||||||
if (sPlayerbotAIConfig->randomBotXPRate == 1.0 || !sRandomPlayerbotMgr->IsRandomBot(player))
|
|
||||||
return;
|
|
||||||
|
|
||||||
// no XP multiplier, when bot is in a group with a real player.
|
|
||||||
if (Group* group = player->GetGroup())
|
if (Group* group = player->GetGroup())
|
||||||
{
|
{
|
||||||
for (GroupReference* gref = group->GetFirstMember(); gref; gref = gref->next())
|
for (GroupReference* gref = group->GetFirstMember(); gref; gref = gref->next())
|
||||||
{
|
{
|
||||||
Player* member = gref->GetSource();
|
if (Player* member = gref->GetSource())
|
||||||
if (!member)
|
|
||||||
{
|
{
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!member->GetSession()->IsBot())
|
if (!member->GetSession()->IsBot())
|
||||||
{
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// otherwise apply bot XP multiplier.
|
// Otherwise apply XP multiplier
|
||||||
amount = static_cast<uint32>(std::round(static_cast<float>(amount) * sPlayerbotAIConfig->randomBotXPRate));
|
amount = static_cast<uint32>(std::round(amount * sPlayerbotAIConfig->randomBotXPRate));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -2594,17 +2594,14 @@ void RandomPlayerbotMgr::Refresh(Player* bot)
|
|||||||
|
|
||||||
bool RandomPlayerbotMgr::IsRandomBot(Player* bot)
|
bool RandomPlayerbotMgr::IsRandomBot(Player* bot)
|
||||||
{
|
{
|
||||||
if (bot && GET_PLAYERBOT_AI(bot))
|
if (!bot)
|
||||||
{
|
|
||||||
if (GET_PLAYERBOT_AI(bot)->IsRealPlayer())
|
|
||||||
return false;
|
return false;
|
||||||
}
|
|
||||||
if (bot)
|
|
||||||
{
|
|
||||||
return IsRandomBot(bot->GetGUID().GetCounter());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
PlayerbotAI* botAI = GET_PLAYERBOT_AI(bot);
|
||||||
|
if (!botAI || botAI->IsRealPlayer())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
return IsRandomBot(bot->GetGUID().GetCounter());
|
||||||
}
|
}
|
||||||
|
|
||||||
bool RandomPlayerbotMgr::IsRandomBot(ObjectGuid::LowType bot)
|
bool RandomPlayerbotMgr::IsRandomBot(ObjectGuid::LowType bot)
|
||||||
|
|||||||
Reference in New Issue
Block a user