crash fix trial

This commit is contained in:
Yunfan Li
2023-12-17 00:50:46 +08:00
parent c5f883f762
commit 4007ce2692
6 changed files with 107 additions and 67 deletions

View File

@@ -16,6 +16,9 @@ void FleeManager::calculateDistanceToCreatures(FleePoint *point)
point->minDistance = -1.0f;
point->sumDistance = 0.0f;
PlayerbotAI* botAI = GET_PLAYERBOT_AI(bot);
if (!botAI) {
return;
}
GuidVector units = *botAI->GetAiObjectContext()->GetValue<GuidVector>("possible targets no los");
for (GuidVector::iterator i = units.begin(); i != units.end(); ++i)
{
@@ -45,6 +48,9 @@ bool intersectsOri(float angle, std::vector<float>& angles, float angleIncrement
void FleeManager::calculatePossibleDestinations(std::vector<FleePoint*> &points)
{
PlayerbotAI* botAI = GET_PLAYERBOT_AI(bot);
if (!botAI) {
return;
}
Unit* target = *botAI->GetAiObjectContext()->GetValue<Unit*>("current target");
float botPosX = startPosition.getX();
@@ -153,6 +159,9 @@ bool FleeManager::CalculateDestination(float* rx, float* ry, float* rz)
bool FleeManager::isUseful()
{
PlayerbotAI* botAI = GET_PLAYERBOT_AI(bot);
if (!botAI) {
return false;
}
GuidVector units = *botAI->GetAiObjectContext()->GetValue<GuidVector>("possible targets no los");
for (GuidVector::iterator i = units.begin(); i != units.end(); ++i)
{

View File

@@ -59,6 +59,9 @@ void LootObject::Refresh(Player* bot, ObjectGuid lootGUID)
guid.Clear();
PlayerbotAI* botAI = GET_PLAYERBOT_AI(bot);
if (!botAI) {
return;
}
Creature* creature = botAI->GetCreature(lootGUID);
if (creature && creature->getDeathState() == DeathState::Corpse)
{
@@ -175,7 +178,9 @@ WorldObject* LootObject::GetWorldObject(Player* bot)
Refresh(bot, guid);
PlayerbotAI* botAI = GET_PLAYERBOT_AI(bot);
if (!botAI) {
return nullptr;
}
Creature* creature = botAI->GetCreature(guid);
if (creature && creature->getDeathState() == DeathState::Corpse)
return creature;
@@ -201,7 +206,9 @@ bool LootObject::IsLootPossible(Player* bot)
return false;
PlayerbotAI* botAI = GET_PLAYERBOT_AI(bot);
if (!botAI) {
return false;
}
if (reqItem && !bot->HasItemCount(reqItem, 1))
return false;

View File

@@ -204,10 +204,7 @@ void PlayerbotAI::UpdateAI(uint32 elapsed, bool minimal)
}
// cancel logout in combat
if (!bot->GetSession()) {
return;
}
if (bot->GetSession()->isLogingOut())
if (!bot->GetSession() || bot->GetSession()->isLogingOut())
{
// if (bot->IsInCombat() || (master && master->IsInCombat() && sServerFacade->GetDistance2d(bot, master) < 30.0f))
// {
@@ -1047,7 +1044,9 @@ void PlayerbotAI::DoNextAction(bool min)
if ((!master || (masterBotAI && !masterBotAI->IsRealPlayer())) && group)
{
PlayerbotAI* botAI = GET_PLAYERBOT_AI(bot);
if (!botAI) {
return;
}
// Ideally we want to have the leader as master.
Player* newMaster = botAI->GetGroupMaster();
Player* playerMaster = nullptr;

View File

@@ -84,7 +84,7 @@ void PlayerbotHolder::HandlePlayerBotLoginCallback(PlayerbotLoginQueryHolder con
if (!bot)
{
LogoutPlayerBot(holder.GetGuid());
LOG_ERROR("playerbots", "Error logging in bot {}, please try to reset all random bots", holder.GetGuid().ToString().c_str());
// LOG_ERROR("playerbots", "Error logging in bot {}, please try to reset all random bots", holder.GetGuid().ToString().c_str());
return;
}
@@ -114,7 +114,7 @@ void PlayerbotHolder::HandlePlayerBotLoginCallback(PlayerbotLoginQueryHolder con
OnBotLogin(bot);
LogoutPlayerBot(bot->GetGUID());
LOG_ERROR("playerbots", "Attempt to add not allowed bot {}, please try to reset all random bots", bot->GetName());
// LOG_ERROR("playerbots", "Attempt to add not allowed bot {}, please try to reset all random bots", bot->GetName());
}
}
@@ -125,7 +125,10 @@ void PlayerbotHolder::UpdateSessions()
Player* const bot = itr->second;
if (bot->IsBeingTeleported())
{
GET_PLAYERBOT_AI(bot)->HandleTeleportAck();
PlayerbotAI* botAI = GET_PLAYERBOT_AI(bot);
if (botAI) {
botAI->HandleTeleportAck();
}
}
else if (bot->IsInWorld())
{
@@ -315,6 +318,9 @@ void PlayerbotHolder::DisablePlayerBot(ObjectGuid guid)
if (Player* bot = GetPlayerBot(guid))
{
PlayerbotAI* botAI = GET_PLAYERBOT_AI(bot);
if (!botAI) {
return;
}
botAI->TellMaster("Goodbye!");
bot->StopMoving();
bot->GetMotionMaster()->Clear();
@@ -363,6 +369,9 @@ void PlayerbotHolder::OnBotLogin(Player* const bot)
playerBots[bot->GetGUID()] = bot;
PlayerbotAI* botAI = GET_PLAYERBOT_AI(bot);
if (!botAI) {
return;
}
Player* master = botAI->GetMaster();
if (master)
{
@@ -546,6 +555,7 @@ std::string const PlayerbotHolder::ProcessBotCommand(std::string const cmd, Obje
return "ERROR: You can not use this command on non-summoned random bot.";
}
if (GET_PLAYERBOT_AI(bot)) {
if (Player* master = GET_PLAYERBOT_AI(bot)->GetMaster())
{
if (master->GetSession()->GetSecurity() <= SEC_PLAYER && sPlayerbotAIConfig->autoInitOnly && cmd != "init=auto") {
@@ -596,6 +606,7 @@ std::string const PlayerbotHolder::ProcessBotCommand(std::string const cmd, Obje
return "ok, gear score limit: " + std::to_string(gs / (ITEM_QUALITY_EPIC + 1)) + "(for epic)";
}
}
}
if (cmd == "levelup" || cmd == "level")
{
@@ -1147,14 +1158,16 @@ void PlayerbotMgr::HandleCommand(uint32 type, std::string const text)
for (PlayerBotMap::const_iterator it = GetPlayerBotsBegin(); it != GetPlayerBotsEnd(); ++it)
{
Player* const bot = it->second;
GET_PLAYERBOT_AI(bot)->HandleCommand(type, text, master);
PlayerbotAI* botAI = GET_PLAYERBOT_AI(bot);
if (botAI)
botAI->HandleCommand(type, text, master);
}
for (PlayerBotMap::const_iterator it = sRandomPlayerbotMgr->GetPlayerBotsBegin(); it != sRandomPlayerbotMgr->GetPlayerBotsEnd(); ++it)
{
Player* const bot = it->second;
PlayerbotAI* botAI = GET_PLAYERBOT_AI(bot);
if (botAI->GetMaster() == master)
if (botAI && botAI->GetMaster() == master)
botAI->HandleCommand(type, text, master);
}
}
@@ -1166,8 +1179,9 @@ void PlayerbotMgr::HandleMasterIncomingPacket(WorldPacket const& packet)
Player* const bot = it->second;
if (!bot)
continue;
GET_PLAYERBOT_AI(bot)->HandleMasterIncomingPacket(packet);
PlayerbotAI* botAI = GET_PLAYERBOT_AI(bot);
if (botAI)
botAI->HandleMasterIncomingPacket(packet);
}
for (PlayerBotMap::const_iterator it = sRandomPlayerbotMgr->GetPlayerBotsBegin(); it != sRandomPlayerbotMgr->GetPlayerBotsEnd(); ++it)
@@ -1200,7 +1214,9 @@ void PlayerbotMgr::HandleMasterOutgoingPacket(WorldPacket const& packet)
for (PlayerBotMap::const_iterator it = GetPlayerBotsBegin(); it != GetPlayerBotsEnd(); ++it)
{
Player* const bot = it->second;
GET_PLAYERBOT_AI(bot)->HandleMasterOutgoingPacket(packet);
PlayerbotAI* botAI = GET_PLAYERBOT_AI(bot);
if (botAI)
botAI->HandleMasterOutgoingPacket(packet);
}
for (PlayerBotMap::const_iterator it = sRandomPlayerbotMgr->GetPlayerBotsBegin(); it != sRandomPlayerbotMgr->GetPlayerBotsEnd(); ++it)
@@ -1223,7 +1239,7 @@ void PlayerbotMgr::SaveToDB()
for (PlayerBotMap::const_iterator it = sRandomPlayerbotMgr->GetPlayerBotsBegin(); it != sRandomPlayerbotMgr->GetPlayerBotsEnd(); ++it)
{
Player* const bot = it->second;
if (GET_PLAYERBOT_AI(bot)->GetMaster() == GetMaster())
if (GET_PLAYERBOT_AI(bot) && GET_PLAYERBOT_AI(bot)->GetMaster() == GetMaster())
bot->SaveToDB(false, false);
}
}
@@ -1231,6 +1247,9 @@ void PlayerbotMgr::SaveToDB()
void PlayerbotMgr::OnBotLoginInternal(Player * const bot)
{
PlayerbotAI* botAI = GET_PLAYERBOT_AI(bot);
if (!botAI) {
return;
}
botAI->SetMaster(master);
botAI->ResetStrategies();

View File

@@ -19,6 +19,9 @@ PlayerbotSecurityLevel PlayerbotSecurity::LevelFor(Player* from, DenyReason* rea
return PLAYERBOT_SECURITY_ALLOW_ALL;
PlayerbotAI* botAI = GET_PLAYERBOT_AI(bot);
if (!botAI) {
return PLAYERBOT_SECURITY_DENY_ALL;
}
if (botAI->IsOpposing(from))
{
if (reason)

View File

@@ -1399,6 +1399,7 @@ void RandomPlayerbotMgr::RandomizeFirst(Player* bot)
PlayerbotsDatabase.Execute(stmt);
// teleport to a random inn for bot level
if (GET_PLAYERBOT_AI(bot))
GET_PLAYERBOT_AI(bot)->Reset(true);
if (bot->GetGroup())
@@ -1435,7 +1436,9 @@ void RandomPlayerbotMgr::RandomizeMin(Player* bot)
PlayerbotsDatabase.Execute(stmt);
// teleport to a random inn for bot level
if (GET_PLAYERBOT_AI(bot))
GET_PLAYERBOT_AI(bot)->Reset(true);
if (bot->GetGroup())
bot->RemoveFromGroup();
@@ -1862,7 +1865,7 @@ void RandomPlayerbotMgr::OnPlayerLogout(Player* player)
{
Player* const bot = it->second;
PlayerbotAI* botAI = GET_PLAYERBOT_AI(bot);
if (player == botAI->GetMaster())
if (botAI && player == botAI->GetMaster())
{
botAI->SetMaster(nullptr);
if (!bot->InBattleground())
@@ -1906,7 +1909,7 @@ void RandomPlayerbotMgr::OnPlayerLogin(Player* player)
{
Player* member = gref->GetSource();
PlayerbotAI* botAI = GET_PLAYERBOT_AI(bot);
if (member == player && (!botAI->GetMaster() || GET_PLAYERBOT_AI(botAI->GetMaster())))
if (botAI && member == player && (!botAI->GetMaster() || GET_PLAYERBOT_AI(botAI->GetMaster())))
{
if (!bot->InBattleground())
{