@@ -1004,6 +1004,16 @@ void RandomPlayerbotMgr::OnPlayerLogout(Player* player)
10041004 {
10051005 players.erase (i);
10061006 }
1007+
1008+ uint32 zone = player->GetZoneId ();
1009+ std::unordered_map<uint32, uint32>::iterator zi = m_playerZoneCounts.find (zone);
1010+ if (zi != m_playerZoneCounts.end ())
1011+ {
1012+ if (zi->second <= 1 )
1013+ m_playerZoneCounts.erase (zi);
1014+ else
1015+ zi->second --;
1016+ }
10071017 }
10081018}
10091019
@@ -1041,8 +1051,38 @@ void RandomPlayerbotMgr::OnPlayerLogin(Player* player)
10411051 if (!player->GetPlayerbotAI ())
10421052 {
10431053 players.push_back (player);
1044- sLog .outDebug (" Including non-random bot player %s into random bot update" , player->GetName ());
1054+ // do not add to m_playerZoneCounts, as OnPlayerZoneChange is called anyway
1055+ }
1056+ }
1057+
1058+ void RandomPlayerbotMgr::OnPlayerZoneChange (Player* player, uint32 newZone)
1059+ {
1060+ if (player->GetPlayerbotAI () ||
1061+ player->GetSession ()->GetRemoteAddress () == " bot" )
1062+ {
1063+ // PlayerbotAI is not set before calling this on entry, so remote address chk
1064+ return ;
10451065 }
1066+
1067+ uint32 oldZone = player->GetCachedZoneId ();
1068+ if (oldZone == newZone)
1069+ return ;
1070+
1071+ std::unordered_map<uint32, uint32>::iterator zi = m_playerZoneCounts.find (oldZone);
1072+ if (zi != m_playerZoneCounts.end ())
1073+ {
1074+ if (zi->second <= 1 )
1075+ m_playerZoneCounts.erase (zi);
1076+ else
1077+ zi->second --;
1078+ }
1079+ m_playerZoneCounts[newZone]++;
1080+ }
1081+
1082+ bool RandomPlayerbotMgr::HasRealPlayerInZone (uint32 zoneId) const
1083+ {
1084+ std::unordered_map<uint32, uint32>::const_iterator zi = m_playerZoneCounts.find (zoneId);
1085+ return zi != m_playerZoneCounts.end () && zi->second > 0 ;
10461086}
10471087
10481088Player* RandomPlayerbotMgr::GetRandomPlayer ()
0 commit comments