Skip to content

Commit

Permalink
Teleport: Bots now set their hs to a nearby inn after random teleport
Browse files Browse the repository at this point in the history
  • Loading branch information
mostlikely4r committed Feb 7, 2025
1 parent 4c6edac commit cd6d2f9
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 3 deletions.
41 changes: 38 additions & 3 deletions playerbot/RandomPlayerbotMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2579,6 +2579,7 @@ void RandomPlayerbotMgr::PrepareTeleportCache()
}

std::vector<std::pair<std::pair<uint32, uint32>, WorldPosition>> newPoints;
std::vector<std::pair<std::pair<uint32, uint32>, GuidPosition>> innPoints;

//Static portals.
for (auto& goData : WorldPosition().getGameObjectsNear(0, 0))
Expand Down Expand Up @@ -2631,22 +2632,34 @@ void RandomPlayerbotMgr::PrepareTeleportCache()
allowedNpcFlags.push_back(UNIT_NPC_FLAG_TRAINER);
allowedNpcFlags.push_back(UNIT_NPC_FLAG_VENDOR);
allowedNpcFlags.push_back(UNIT_NPC_FLAG_REPAIR);
allowedNpcFlags.push_back(UNIT_NPC_FLAG_INNKEEPER);

for (auto flag : allowedNpcFlags)
{
{
if ((cInfo->NpcFlags & flag) != 0)
{
std::vector<std::pair<uint32, uint32>> ranges = RpgLocationsNear(WorldPosition(creatureData), areaNames);

for (auto& range : ranges)
newPoints.push_back(std::make_pair(std::make_pair(range.first, range.second), creatureData));
if (cInfo->NpcFlags & UNIT_NPC_FLAG_INNKEEPER)
{
for (auto& range : ranges)
innPoints.push_back(std::make_pair(std::make_pair(range.first, range.second), creatureData));
}
else
{
for (auto& range : ranges)
newPoints.push_back(std::make_pair(std::make_pair(range.first, range.second), creatureData));
}
break;
}
}
}

for (auto newPoint : newPoints)
rpgLocsCacheLevel[newPoint.first.first][newPoint.first.second].push_back(newPoint.second);

for (auto innPoint : innPoints)
innCacheLevel[innPoint.first.first][innPoint.first.second].push_back(std::make_pair(innPoint.second, innPoint.second));
}

void RandomPlayerbotMgr::PrintTeleportCache()
Expand Down Expand Up @@ -2692,6 +2705,28 @@ void RandomPlayerbotMgr::RandomTeleportForLevel(Player* bot, bool activeOnly)
sLog.outDetail("Preparing location to random teleporting bot %s for level %u", bot->GetName(), bot->GetLevel());
RandomTeleport(bot, locsPerLevelCache[bot->GetLevel()], false, activeOnly);
Refresh(bot);

WorldPosition botPos(bot);

ObjectGuid closestInn;
float minDistance = -1.0f;
for (auto& [innGuid, innPosition] : innCacheLevel[bot->getRace()][bot->GetLevel()])
{
float distance = botPos.sqDistance(innPosition);
if (minDistance > 0 || distance >= minDistance)
continue;

minDistance = distance;
closestInn = innGuid;
}

if (closestInn)
{
WorldPacket data(SMSG_TRAINER_BUY_SUCCEEDED, (8 + 4));
data << closestInn;
data << uint32(3286); // Bind
bot->GetSession()->SendPacket(data);
}
}

void RandomPlayerbotMgr::RandomTeleport(Player* bot)
Expand Down
1 change: 1 addition & 0 deletions playerbot/RandomPlayerbotMgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ class RandomPlayerbotMgr : public PlayerbotHolder
std::map<uint8, std::vector<WorldLocation> > locsPerLevelCache;
std::map<uint32, std::vector<WorldLocation> > rpgLocsCache;
std::map<uint32, std::map<uint32, std::vector<WorldLocation> > > rpgLocsCacheLevel;
std::map<uint32, std::map<uint32, std::vector<std::pair<ObjectGuid, WorldLocation>> > > innCacheLevel;
std::map<Team, std::map<BattleGroundTypeId, std::list<uint32> > > BattleMastersCache;
std::map<uint32, std::map<std::string, CachedEvent> > eventCache;
BarGoLink* loginProgressBar;
Expand Down

0 comments on commit cd6d2f9

Please sign in to comment.