void RandomPlayerbotMgr::RandomTeleportForLevel(Player* bot) { vector<WorldLocation> locs; QueryResult* results = WorldDatabase.PQuery("select map, position_x, position_y, position_z " "from (select map, position_x, position_y, position_z, avg(t.maxlevel), avg(t.minlevel), " "%u - (avg(t.maxlevel) + avg(t.minlevel)) / 2 delta " "from creature c inner join creature_template t on c.id = t.entry group by t.entry) q " "where delta >= 0 and delta <= %u and map in (%s)", bot->getLevel(), sPlayerbotAIConfig.randomBotTeleLevel, sPlayerbotAIConfig.randomBotMapsAsString.c_str()); if (results) { do { Field* fields = results->Fetch(); uint32 mapId = fields[0].GetUInt32(); float x = fields[1].GetFloat(); float y = fields[2].GetFloat(); float z = fields[3].GetFloat(); WorldLocation loc(mapId, x, y, z, 0); locs.push_back(loc); } while (results->NextRow()); delete results; } RandomTeleport(bot, locs); }
void RandomPlayerbotMgr::RandomTeleportForLevel(Player* bot) { vector<WorldLocation> locs; QueryResult results = WorldDatabase.PQuery("select map, position_x, position_y, position_z " "from (select map, position_x, position_y, position_z, avg(t.maxlevel), avg(t.minlevel), " "%u - (avg(t.maxlevel) + avg(t.minlevel)) / 2 delta " "from creature c inner join creature_template t on c.id = t.entry group by t.entry) q " "where delta >= 0 and delta <= %u and map in (%s) and not exists ( " "select map, position_x, position_y, position_z from " "(" "select map, c.position_x, c.position_y, c.position_z, avg(t.maxlevel), avg(t.minlevel), " "%u - (avg(t.maxlevel) + avg(t.minlevel)) / 2 delta " "from creature c " "inner join creature_template t on c.id = t.entry group by t.entry " ") q1 " "where delta > %u and q1.map = q.map " "and sqrt(" "(q1.position_x - q.position_x)*(q1.position_x - q.position_x) +" "(q1.position_y - q.position_y)*(q1.position_y - q.position_y) +" "(q1.position_z - q.position_z)*(q1.position_z - q.position_z)" ") < %u)", bot->getLevel(), sPlayerbotAIConfig.randomBotTeleLevel, sPlayerbotAIConfig.randomBotMapsAsString.c_str(), bot->getLevel(), sPlayerbotAIConfig.randomBotTeleLevel, sPlayerbotAIConfig.sightDistance ); if (results) { do { Field* fields = results->Fetch(); uint16 mapId = fields[0].GetUInt16(); float x = fields[1].GetFloat(); float y = fields[2].GetFloat(); float z = fields[3].GetFloat(); WorldLocation loc(mapId, x, y, z, 0); locs.push_back(loc); } while (results->NextRow()); } RandomTeleport(bot, locs); }
void RandomPlayerbotMgr::RandomizeFirst(Player* bot) { uint32 maxLevel = sPlayerbotAIConfig.randomBotMaxLevel; if (maxLevel > sWorld.getConfig(CONFIG_UINT32_MAX_PLAYER_LEVEL)) maxLevel = sWorld.getConfig(CONFIG_UINT32_MAX_PLAYER_LEVEL); for (int attempt = 0; attempt < 100; ++attempt) { int index = urand(0, sPlayerbotAIConfig.randomBotMaps.size() - 1); uint32 mapId = sPlayerbotAIConfig.randomBotMaps[index]; vector<GameTele const*> locs; GameTeleMap const & teleMap = sObjectMgr.GetGameTeleMap(); for(GameTeleMap::const_iterator itr = teleMap.begin(); itr != teleMap.end(); ++itr) { GameTele const* tele = &itr->second; if (tele->mapId == mapId) locs.push_back(tele); } index = urand(0, locs.size() - 1); if (index >= locs.size()) return; GameTele const* tele = locs[index]; uint32 level = GetZoneLevel(tele->mapId, tele->position_x, tele->position_y, tele->position_z); if (level > maxLevel + 5) continue; level = min(level, maxLevel); if (!level) level = 1; if (urand(0, 100) < 100 * sPlayerbotAIConfig.randomBotMaxLevelChance) level = maxLevel; if (level < sPlayerbotAIConfig.randomBotMinLevel) continue; PlayerbotFactory factory(bot, level); factory.CleanRandomize(); RandomTeleport(bot, tele->mapId, tele->position_x, tele->position_y, tele->position_z); break; } }
void RandomPlayerbotMgr::RandomTeleport(Player* bot, uint16 mapId, float teleX, float teleY, float teleZ) { vector<WorldLocation> locs; QueryResult results = WorldDatabase.PQuery("select position_x, position_y, position_z from creature where map = '%u' and abs(position_x - '%f') < '%u' and abs(position_y - '%f') < '%u'", mapId, teleX, sPlayerbotAIConfig.randomBotTeleportDistance / 2, teleY, sPlayerbotAIConfig.randomBotTeleportDistance / 2); if (results) { do { Field* fields = results->Fetch(); float x = fields[0].GetFloat(); float y = fields[1].GetFloat(); float z = fields[2].GetFloat(); WorldLocation loc(mapId, x, y, z, 0); locs.push_back(loc); } while (results->NextRow()); } RandomTeleport(bot, locs); Refresh(bot); }
bool RandomPlayerbotMgr::ProcessBot(uint32 bot) { uint32 isValid = GetEventValue(bot, "add"); if (!isValid) { Player* player = GetPlayerBot(bot); if (!player || !player->GetGroup()) { sLog.outDetail("Bot %d expired", bot); SetEventValue(bot, "add", 0, 0); } return true; } if (!GetPlayerBot(bot)) { sLog.outDetail("Bot %d logged in", bot); AddPlayerBot(bot, 0); if (!GetEventValue(bot, "online")) { SetEventValue(bot, "online", 1, sPlayerbotAIConfig.minRandomBotInWorldTime); } return true; } Player* player = GetPlayerBot(bot); if (!player) return false; PlayerbotAI* ai = player->GetPlayerbotAI(); if (!ai) return false; if (player->GetGroup()) { sLog.outDetail("Skipping bot %d as it is in group", bot); return false; } if (player->IsDead()) { if (!GetEventValue(bot, "dead")) { sLog.outDetail("Setting dead flag for bot %d", bot); uint32 randomTime = urand(sPlayerbotAIConfig.minRandomBotReviveTime, sPlayerbotAIConfig.maxRandomBotReviveTime); SetEventValue(bot, "dead", 1, randomTime); SetEventValue(bot, "revive", 1, randomTime - 60); return false; } if (!GetEventValue(bot, "revive")) { sLog.outDetail("Reviving dead bot %d", bot); SetEventValue(bot, "dead", 0, 0); SetEventValue(bot, "revive", 0, 0); RandomTeleport(player, player->GetMapId(), player->GetPositionX(), player->GetPositionY(), player->GetPositionZ()); return true; } return false; } uint32 randomize = GetEventValue(bot, "randomize"); if (!randomize) { sLog.outDetail("Randomizing bot %d", bot); Randomize(player); uint32 randomTime = urand(sPlayerbotAIConfig.minRandomBotRandomizeTime, sPlayerbotAIConfig.maxRandomBotRandomizeTime); ScheduleRandomize(bot, randomTime); return true; } uint32 logout = GetEventValue(bot, "logout"); if (!logout) { sLog.outDetail("Logging out bot %d", bot); LogoutPlayerBot(bot); SetEventValue(bot, "logout", 1, sPlayerbotAIConfig.maxRandomBotInWorldTime); return true; } uint32 teleport = GetEventValue(bot, "teleport"); if (!teleport) { sLog.outDetail("Random teleporting bot %d", bot); RandomTeleportForLevel(ai->GetBot()); SetEventValue(bot, "teleport", 1, sPlayerbotAIConfig.maxRandomBotInWorldTime); return true; } return false; }
bool RandomPlayerbotMgr::ProcessBot(uint32 bot) { uint32 isValid = GetEventValue(bot, "add"); if (!isValid) { Player* player = GetPlayerBot(bot); if (!player || !player->GetGroup()) { sLog->outMessage("playerbot", LOG_LEVEL_INFO, "Bot %d expired", bot); SetEventValue(bot, "add", 0, 0); } return true; } if (!GetPlayerBot(bot)) { sLog->outMessage("playerbot", LOG_LEVEL_INFO, "Bot %d logged in", bot); AddPlayerBot(bot, 0); if (!GetEventValue(bot, "online")) { SetEventValue(bot, "online", 1, sPlayerbotAIConfig.minRandomBotInWorldTime); } return true; } Player* player = GetPlayerBot(bot); if (!player) return false; PlayerbotAI* ai = player->GetPlayerbotAI(); if (!ai) return false; if (player->GetGroup()) { sLog->outMessage("playerbot", LOG_LEVEL_INFO, "Skipping bot %d as it is in group", bot); return false; } if (player->isDead()) { if (!GetEventValue(bot, "dead")) { sLog->outMessage("playerbot", LOG_LEVEL_INFO, "Setting dead flag for bot %d", bot); uint32 randomTime = urand(sPlayerbotAIConfig.minRandomBotReviveTime, sPlayerbotAIConfig.maxRandomBotReviveTime); SetEventValue(bot, "dead", 1, randomTime); SetEventValue(bot, "revive", 1, randomTime - 60); return false; } if (!GetEventValue(bot, "revive")) { sLog->outMessage("playerbot", LOG_LEVEL_INFO, "Reviving dead bot %d", bot); SetEventValue(bot, "dead", 0, 0); SetEventValue(bot, "revive", 0, 0); RandomTeleport(player, player->GetMapId(), player->GetPositionX(), player->GetPositionY(), player->GetPositionZ()); return true; } return false; } if (player->GetGuild() && player->GetGuild()->GetLeaderGUID() == player->GetGUID()) { for (vector<Player*>::iterator i = players.begin(); i != players.end(); ++i) sGuildTaskMgr.Update(*i, player); } uint32 randomize = GetEventValue(bot, "randomize"); if (!randomize) { sLog->outMessage("playerbot", LOG_LEVEL_INFO, "Randomizing bot %d", bot); Randomize(player); uint32 randomTime = urand(sPlayerbotAIConfig.minRandomBotRandomizeTime, sPlayerbotAIConfig.maxRandomBotRandomizeTime); ScheduleRandomize(bot, randomTime); return true; } uint32 logout = GetEventValue(bot, "logout"); if (!logout) { sLog->outMessage("playerbot", LOG_LEVEL_INFO, "Logging out bot %d", bot); LogoutPlayerBot(bot); SetEventValue(bot, "logout", 1, sPlayerbotAIConfig.maxRandomBotInWorldTime); return true; } uint32 teleport = GetEventValue(bot, "teleport"); if (!teleport) { sLog->outMessage("playerbot", LOG_LEVEL_INFO, "Random teleporting bot %d", bot); RandomTeleportForLevel(ai->GetBot()); SetEventValue(bot, "teleport", 1, sPlayerbotAIConfig.maxRandomBotInWorldTime); return true; } return false; }