From a5d1d7579dcf358dcf3affef012d419c567fe43e Mon Sep 17 00:00:00 2001 From: Yunfan Li Date: Sat, 14 Dec 2024 21:46:33 +0800 Subject: [PATCH] EnableNewRpgStrategy switch for initialization --- src/PlayerbotAI.h | 2 +- src/PlayerbotAIConfig.cpp | 1 + src/RandomPlayerbotFactory.cpp | 2 +- src/RandomPlayerbotMgr.cpp | 180 +++++++++++++++--------------- src/strategy/rpg/NewRpgAction.cpp | 25 +++-- 5 files changed, 107 insertions(+), 103 deletions(-) diff --git a/src/PlayerbotAI.h b/src/PlayerbotAI.h index 603dd851..7c61d48b 100644 --- a/src/PlayerbotAI.h +++ b/src/PlayerbotAI.h @@ -433,7 +433,7 @@ public: std::vector GetPlayersInGroup(); const AreaTableEntry* GetCurrentArea(); const AreaTableEntry* GetCurrentZone(); - std::string GetLocalizedAreaName(const AreaTableEntry* entry); + static std::string GetLocalizedAreaName(const AreaTableEntry* entry); bool TellMaster(std::ostringstream& stream, PlayerbotSecurityLevel securityLevel = PLAYERBOT_SECURITY_ALLOW_ALL); bool TellMaster(std::string const text, PlayerbotSecurityLevel securityLevel = PLAYERBOT_SECURITY_ALLOW_ALL); diff --git a/src/PlayerbotAIConfig.cpp b/src/PlayerbotAIConfig.cpp index fa21ad5c..b3a7afc2 100644 --- a/src/PlayerbotAIConfig.cpp +++ b/src/PlayerbotAIConfig.cpp @@ -399,6 +399,7 @@ bool PlayerbotAIConfig::Initialize() worldBuffs.clear(); + LOG_INFO("playerbots", "Loading Worldbuff..."); for (uint32 factionId = 0; factionId < 3; factionId++) { for (uint32 classId = 0; classId < MAX_CLASSES; classId++) diff --git a/src/RandomPlayerbotFactory.cpp b/src/RandomPlayerbotFactory.cpp index 57b42bda..3241978e 100644 --- a/src/RandomPlayerbotFactory.cpp +++ b/src/RandomPlayerbotFactory.cpp @@ -556,7 +556,7 @@ void RandomPlayerbotFactory::CreateRandomBots() totalRandomBotChars += AccountMgr::GetCharactersCount(accountId); } - LOG_INFO("server.loading", "{} random bot accounts with {} characters available", + LOG_INFO("server.loading", ">> {} random bot accounts with {} characters available", sPlayerbotAIConfig->randomBotAccounts.size(), totalRandomBotChars); } diff --git a/src/RandomPlayerbotMgr.cpp b/src/RandomPlayerbotMgr.cpp index 486d7d5d..d135b55c 100644 --- a/src/RandomPlayerbotMgr.cpp +++ b/src/RandomPlayerbotMgr.cpp @@ -1433,6 +1433,7 @@ void RandomPlayerbotMgr::PrepareTeleportCache() "position_x, " "position_y, " "position_z, " + "t.minlevel, " "t.maxlevel " "FROM " "(SELECT " @@ -1476,7 +1477,9 @@ void RandomPlayerbotMgr::PrepareTeleportCache() float x = fields[1].Get(); float y = fields[2].Get(); float z = fields[3].Get(); - uint32 level = fields[4].Get(); + uint32 min_level = fields[4].Get(); + uint32 max_level = fields[5].Get(); + uint32 level = (min_level + max_level) / 2; WorldLocation loc(mapId, x, y, z, 0); collected_locs++; for (int32 l = (int32)level - (int32)sPlayerbotAIConfig->randomBotTeleHigherLevel; @@ -1490,9 +1493,12 @@ void RandomPlayerbotMgr::PrepareTeleportCache() } } while (results->NextRow()); } - LOG_INFO("playerbots", "{} locations for level collected.", collected_locs); + LOG_INFO("playerbots", ">> {} locations for level collected.", collected_locs); - results = WorldDatabase.Query( + LOG_INFO("playerbots", "Preparing innkeepers locations for level collected"); + if (sPlayerbotAIConfig->enableNewRpgStrategy) + { + results = WorldDatabase.Query( "SELECT " "map, " "position_x, " @@ -1510,106 +1516,90 @@ void RandomPlayerbotMgr::PrepareTeleportCache() "ORDER BY " "t.minlevel;", sPlayerbotAIConfig->randomBotMapsAsString.c_str()); - collected_locs = 0; - if (results) - { - do + collected_locs = 0; + if (results) { - Field* fields = results->Fetch(); - uint16 mapId = fields[0].Get(); - float x = fields[1].Get(); - float y = fields[2].Get(); - float z = fields[3].Get(); - float orient = fields[4].Get(); - uint32 faction = fields[5].Get(); - uint32 c_entry = fields[6].Get(); - const FactionTemplateEntry* entry = sFactionTemplateStore.LookupEntry(faction); - - WorldLocation loc(mapId, x + cos(orient) * 5.0f, y + sin(orient) * 5.0f, z + 0.5f, orient + M_PI); - collected_locs++; - Map* map = sMapMgr->FindMap(loc.GetMapId(), 0); - if (!map) - continue; - const AreaTableEntry* area = sAreaTableStore.LookupEntry(map->GetAreaId(1, x, y, z)); - uint32 level = area->area_level; - for (int i = 5; i <= maxLevel; i++) + do { - std::vector& locs = locsPerLevelCache[i]; - int counter = 0; - WorldLocation levelLoc; - for (auto& checkLoc : locs) + Field* fields = results->Fetch(); + uint16 mapId = fields[0].Get(); + float x = fields[1].Get(); + float y = fields[2].Get(); + float z = fields[3].Get(); + float orient = fields[4].Get(); + uint32 faction = fields[5].Get(); + uint32 c_entry = fields[6].Get(); + const FactionTemplateEntry* entry = sFactionTemplateStore.LookupEntry(faction); + + WorldLocation loc(mapId, x + cos(orient) * 5.0f, y + sin(orient) * 5.0f, z + 0.5f, orient + M_PI); + collected_locs++; + Map* map = sMapMgr->FindMap(loc.GetMapId(), 0); + if (!map) + continue; + const AreaTableEntry* area = sAreaTableStore.LookupEntry(map->GetAreaId(1, x, y, z)); + uint32 level = area->area_level; + for (int i = 5; i <= maxLevel; i++) { - if (loc.GetMapId() != checkLoc.GetMapId()) - continue; - - if (area->zone != - map->GetZoneId(1, checkLoc.GetPositionX(), checkLoc.GetPositionY(), checkLoc.GetPositionZ())) - continue; - - if (loc.GetExactDist(checkLoc) <= 1000.0f) + std::vector& locs = locsPerLevelCache[i]; + int counter = 0; + WorldLocation levelLoc; + for (auto& checkLoc : locs) { + if (loc.GetMapId() != checkLoc.GetMapId()) + continue; + if (loc.GetExactDist(checkLoc) > 1000.0f) + continue; + + if (area->zone != + map->GetZoneId(1, checkLoc.GetPositionX(), checkLoc.GetPositionY(), checkLoc.GetPositionZ())) + continue; + counter++; levelLoc = checkLoc; } + if (counter < 15) + continue; + + if (!(entry->hostileMask & 4)) + { + hordeStarterPerLevelCache[i].push_back(loc); + } + if (!(entry->hostileMask & 2)) + { + allianceStarterPerLevelCache[i].push_back(loc); + } + LOG_DEBUG("playerbots", "Area: {} Level: {} creature_entry: {} add to: {} {}({},{},{},{})", area->ID, + level, c_entry, i, counter, levelLoc.GetPositionX(), levelLoc.GetPositionY(), + levelLoc.GetPositionZ(), levelLoc.GetMapId()); } - if (counter < 15) + } while (results->NextRow()); + } + // add all initial position + for (uint32 i = 1; i < MAX_RACES; i++) + { + for (uint32 j = 1; j < MAX_CLASSES; j++) + { + PlayerInfo const* info = sObjectMgr->GetPlayerInfo(i, j); + + if (!info) continue; - if (!(entry->hostileMask & 4)) + WorldPosition pos(info->mapId, info->positionX, info->positionY, info->positionZ, info->orientation); + + for (int32 l = 1; l <= 5; l++) { - hordeStarterPerLevelCache[i].push_back(loc); + if ((1 << (i - 1)) & RACEMASK_ALLIANCE) + allianceStarterPerLevelCache[(uint8)l].push_back(pos); + else + hordeStarterPerLevelCache[(uint8)l].push_back(pos); } - if (!(entry->hostileMask & 2)) - { - allianceStarterPerLevelCache[i].push_back(loc); - } - LOG_DEBUG("playerbots", "Area: {} Level: {} creature_entry: {} add to: {} {}({},{},{},{})", area->ID, - level, c_entry, i, counter, levelLoc.GetPositionX(), levelLoc.GetPositionY(), - levelLoc.GetPositionZ(), levelLoc.GetMapId()); + break; } - // int range = level <= 10 ? 6 : 8; - // for (int32 l = (int32)level; l <= (int32)level + range; l++) - // { - // if (l < 1 || l > maxLevel) - // { - // continue; - // } - // if (!(entry->hostileMask & 4)) - // { - // hordeStarterPerLevelCache[(uint8)l].push_back(loc); - // } - // if (!(entry->hostileMask & 2)) - // { - // allianceStarterPerLevelCache[(uint8)l].push_back(loc); - // } - // } - } while (results->NextRow()); - } - // add all initial position - for (uint32 i = 1; i < MAX_RACES; i++) - { - for (uint32 j = 1; j < MAX_CLASSES; j++) - { - PlayerInfo const* info = sObjectMgr->GetPlayerInfo(i, j); - - if (!info) - continue; - - WorldPosition pos(info->mapId, info->positionX, info->positionY, info->positionZ, info->orientation); - - for (int32 l = 1; l <= 5; l++) - { - if ((1 << (i - 1)) & RACEMASK_ALLIANCE) - allianceStarterPerLevelCache[(uint8)l].push_back(pos); - else - hordeStarterPerLevelCache[(uint8)l].push_back(pos); - } - break; } + LOG_INFO("playerbots", ">> {} innkeepers locations for level collected.", collected_locs); } - LOG_INFO("playerbots", "{} innkeepers locations for level collected.", collected_locs); - + results = WorldDatabase.Query( "SELECT " "map, " @@ -1673,7 +1663,7 @@ void RandomPlayerbotMgr::PrepareTeleportCache() } } while (results->NextRow()); } - LOG_INFO("playerbots", "{} banker locations for level collected.", collected_locs); + LOG_INFO("playerbots", ">> {} banker locations for level collected.", collected_locs); } void RandomPlayerbotMgr::PrepareAddclassCache() @@ -1711,7 +1701,7 @@ void RandomPlayerbotMgr::PrepareAddclassCache() } while (results->NextRow()); } } - LOG_INFO("playerbots", "{} characters collected for addclass command.", collected); + LOG_INFO("playerbots", ">> {} characters collected for addclass command.", collected); } void RandomPlayerbotMgr::RandomTeleportForLevel(Player* bot) @@ -2565,6 +2555,7 @@ void RandomPlayerbotMgr::PrintStats() uint32 stateCount[MAX_TRAVEL_STATE + 1] = {0}; std::vector> questCount; std::unordered_map rpgStatusCount; + std::unordered_map zoneCount; uint8 maxBotLevel = 0; for (PlayerBotMap::iterator i = playerBots.begin(); i != playerBots.end(); ++i) { @@ -2634,6 +2625,8 @@ void RandomPlayerbotMgr::PrintStats() ++tank; else ++dps; + + zoneCount[bot->GetZoneId()]++; if (sPlayerbotAIConfig->enableNewRpgStrategy) rpgStatusCount[botAI->rpgInfo.status]++; @@ -2719,6 +2712,15 @@ void RandomPlayerbotMgr::PrintStats() LOG_INFO("playerbots", " In BG: {}", inBg); LOG_INFO("playerbots", " In Rest: {}", rest); LOG_INFO("playerbots", " Dead: {}", dead); + + // LOG_INFO("playerbots", "Bots zone:"); + // for (auto &[zond_id, counter] : zoneCount) + // { + // const AreaTableEntry* entry = sAreaTableStore.LookupEntry(zond_id); + // std::string name = PlayerbotAI::GetLocalizedAreaName(entry); + // LOG_INFO("playerbots", " {}: {}", name, counter); + // } + if (sPlayerbotAIConfig->enableNewRpgStrategy) { LOG_INFO("playerbots", "Bots rpg status:", dead); diff --git a/src/strategy/rpg/NewRpgAction.cpp b/src/strategy/rpg/NewRpgAction.cpp index 7fd6931f..94d8aeae 100644 --- a/src/strategy/rpg/NewRpgAction.cpp +++ b/src/strategy/rpg/NewRpgAction.cpp @@ -33,7 +33,7 @@ bool NewRpgStatusUpdateAction::Execute(Event event) uint32 roll = urand(1, 100); // IDLE -> NEAR_NPC // if ((!info.lastNearNpc || info.lastNearNpc + setNpcInterval < getMSTime()) && roll <= 30) - if (roll <= 40) + if (roll <= 30) { info.lastNearNpc = getMSTime(); GuidVector possibleTargets = AI_VALUE(GuidVector, "possible rpg targets"); @@ -44,7 +44,7 @@ bool NewRpgStatusUpdateAction::Execute(Event event) } } // IDLE -> GO_INNKEEPER - else if (bot->GetLevel() >= 6 && roll <= 55) + else if (bot->GetLevel() >= 6 && roll <= 45) { WorldPosition pos = SelectRandomInnKeeperPos(); if (pos != WorldPosition() && bot->GetExactDist(pos) > 50.0f) @@ -155,8 +155,8 @@ WorldPosition NewRpgStatusUpdateAction::SelectRandomGrindPos() { if (bot->GetMapId() != loc.GetMapId()) continue; - - if (bot->GetMap()->GetZoneId(bot->GetPhaseMask(), loc.GetPositionX(), loc.GetPositionY(), loc.GetPositionZ()) != + + if (bot->GetMap()->GetZoneId(bot->GetPhaseMask(), loc.GetPositionX(), loc.GetPositionY(), loc.GetPositionZ()) != bot->GetZoneId()) continue; @@ -182,8 +182,8 @@ WorldPosition NewRpgStatusUpdateAction::SelectRandomGrindPos() dest = lo_prepared_locs[idx]; } LOG_DEBUG("playerbots", "[New Rpg] Bot {} select random grind pos Map:{} X:{} Y:{} Z:{} ({}+{} available in {})", - bot->GetName(), dest.GetMapId(), dest.GetPositionX(), dest.GetPositionY(), dest.GetPositionZ(), - hi_prepared_locs.size(), lo_prepared_locs.size() - hi_prepared_locs.size(), locs.size()); + bot->GetName(), dest.GetMapId(), dest.GetPositionX(), dest.GetPositionY(), dest.GetPositionZ(), + hi_prepared_locs.size(), lo_prepared_locs.size() - hi_prepared_locs.size(), locs.size()); return dest; } @@ -197,7 +197,7 @@ WorldPosition NewRpgStatusUpdateAction::SelectRandomInnKeeperPos() { if (bot->GetMapId() != loc.GetMapId()) continue; - + float range = bot->GetLevel() <= 5 ? 500.0f : 2500.0f; if (bot->GetExactDist(loc) < range) { @@ -211,8 +211,8 @@ WorldPosition NewRpgStatusUpdateAction::SelectRandomInnKeeperPos() dest = prepared_locs[idx]; } LOG_DEBUG("playerbots", "[New Rpg] Bot {} select random inn keeper pos Map:{} X:{} Y:{} Z:{} ({} available in {})", - bot->GetName(), dest.GetMapId(), dest.GetPositionX(), dest.GetPositionY(), dest.GetPositionZ(), - prepared_locs.size(), locs.size()); + bot->GetName(), dest.GetMapId(), dest.GetPositionX(), dest.GetPositionY(), dest.GetPositionZ(), + prepared_locs.size(), locs.size()); return dest; } @@ -221,7 +221,8 @@ bool NewRpgGoFarAwayPosAction::MoveFarTo(WorldPosition dest) float dis = bot->GetExactDist(dest); if (dis < pathFinderDis) { - return MoveTo(dest.getMapId(), dest.GetPositionX(), dest.GetPositionY(), dest.GetPositionZ(), false, false, false, true); + return MoveTo(dest.getMapId(), dest.GetPositionX(), dest.GetPositionY(), dest.GetPositionZ(), false, false, + false, true); } // performance optimization @@ -250,13 +251,13 @@ bool NewRpgGoFarAwayPosAction::MoveFarTo(WorldPosition dest) PathGenerator path(bot); path.CalculatePath(dx, dy, dz); PathType type = path.GetPathType(); - + bool canReach = type == PATHFIND_INCOMPLETE || type == PATHFIND_NORMAL; if (canReach && fabs(delta) <= minDelta) { found = true; - const G3D::Vector3 &endPos = path.GetActualEndPosition(); + const G3D::Vector3& endPos = path.GetActualEndPosition(); rx = endPos.x; ry = endPos.y; rz = endPos.z;