mirror of
https://github.com/TrinityCore/TrinityCore.git
synced 2026-01-21 17:54:48 +01:00
Core/World: Fixed compile warning
This commit is contained in:
@@ -2183,7 +2183,6 @@ void World::LoadAutobroadcasts()
|
||||
uint32 oldMSTime = getMSTime();
|
||||
|
||||
m_Autobroadcasts.clear();
|
||||
m_AutobroadcastsWeights.clear();
|
||||
|
||||
uint32 realmId = sConfigMgr->GetIntDefault("RealmID", 0);
|
||||
PreparedStatement* stmt = LoginDatabase.GetPreparedStatement(LOGIN_SEL_AUTOBROADCAST);
|
||||
@@ -2196,20 +2195,16 @@ void World::LoadAutobroadcasts()
|
||||
return;
|
||||
}
|
||||
|
||||
uint32 count = 0;
|
||||
|
||||
do
|
||||
{
|
||||
Field* fields = result->Fetch();
|
||||
uint8 id = fields[0].GetUInt8();
|
||||
|
||||
m_Autobroadcasts[id] = fields[2].GetString();
|
||||
m_AutobroadcastsWeights[id] = fields[1].GetUInt8();
|
||||
m_Autobroadcasts[id] = { fields[2].GetString(), fields[1].GetUInt8() };
|
||||
|
||||
++count;
|
||||
} while (result->NextRow());
|
||||
|
||||
TC_LOG_INFO("server.loading", ">> Loaded %u autobroadcast definitions in %u ms", count, GetMSTimeDiffToNow(oldMSTime));
|
||||
TC_LOG_INFO("server.loading", ">> Loaded " SZFMTD " autobroadcast definitions in %u ms", m_Autobroadcasts.size(), GetMSTimeDiffToNow(oldMSTime));
|
||||
}
|
||||
|
||||
/// Update the World !
|
||||
@@ -3012,49 +3007,24 @@ void World::SendAutoBroadcast()
|
||||
if (m_Autobroadcasts.empty())
|
||||
return;
|
||||
|
||||
uint32 weight = 0;
|
||||
AutobroadcastsWeightMap selectionWeights;
|
||||
std::string msg;
|
||||
|
||||
for (AutobroadcastsWeightMap::const_iterator it = m_AutobroadcastsWeights.begin(); it != m_AutobroadcastsWeights.end(); ++it)
|
||||
auto itr = Trinity::Containers::SelectRandomWeightedContainerElement(m_Autobroadcasts, [](AutobroadcastContainer::value_type const& pair)
|
||||
{
|
||||
if (it->second)
|
||||
{
|
||||
weight += it->second;
|
||||
selectionWeights[it->first] = it->second;
|
||||
}
|
||||
}
|
||||
|
||||
if (weight)
|
||||
{
|
||||
uint32 selectedWeight = urand(0, weight - 1);
|
||||
weight = 0;
|
||||
for (AutobroadcastsWeightMap::const_iterator it = selectionWeights.begin(); it != selectionWeights.end(); ++it)
|
||||
{
|
||||
weight += it->second;
|
||||
if (selectedWeight < weight)
|
||||
{
|
||||
msg = m_Autobroadcasts[it->first];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
msg = m_Autobroadcasts[urand(0, m_Autobroadcasts.size())];
|
||||
return pair.second.Weight;
|
||||
});
|
||||
|
||||
uint32 abcenter = sWorld->getIntConfig(CONFIG_AUTOBROADCAST_CENTER);
|
||||
|
||||
if (abcenter == 0)
|
||||
sWorld->SendWorldText(LANG_AUTO_BROADCAST, msg.c_str());
|
||||
sWorld->SendWorldText(LANG_AUTO_BROADCAST, itr->second.Message.c_str());
|
||||
else if (abcenter == 1)
|
||||
sWorld->SendGlobalMessage(WorldPackets::Chat::PrintNotification(msg).Write());
|
||||
sWorld->SendGlobalMessage(WorldPackets::Chat::PrintNotification(itr->second.Message).Write());
|
||||
else if (abcenter == 2)
|
||||
{
|
||||
sWorld->SendWorldText(LANG_AUTO_BROADCAST, msg.c_str());
|
||||
sWorld->SendGlobalMessage(WorldPackets::Chat::PrintNotification(msg).Write());
|
||||
sWorld->SendWorldText(LANG_AUTO_BROADCAST, itr->second.Message.c_str());
|
||||
sWorld->SendGlobalMessage(WorldPackets::Chat::PrintNotification(itr->second.Message).Write());
|
||||
}
|
||||
|
||||
TC_LOG_DEBUG("misc", "AutoBroadcast: '%s'", msg.c_str());
|
||||
TC_LOG_DEBUG("misc", "AutoBroadcast: '%s'", itr->second.Message.c_str());
|
||||
}
|
||||
|
||||
void World::UpdateRealmCharCount(uint32 accountId)
|
||||
|
||||
@@ -902,11 +902,13 @@ class TC_GAME_API World
|
||||
// used versions
|
||||
std::string m_DBVersion;
|
||||
|
||||
typedef std::map<uint8, std::string> AutobroadcastsMap;
|
||||
AutobroadcastsMap m_Autobroadcasts;
|
||||
|
||||
typedef std::map<uint8, uint8> AutobroadcastsWeightMap;
|
||||
AutobroadcastsWeightMap m_AutobroadcastsWeights;
|
||||
struct Autobroadcast
|
||||
{
|
||||
std::string Message;
|
||||
uint8 Weight;
|
||||
};
|
||||
typedef std::unordered_map<uint8, Autobroadcast> AutobroadcastContainer;
|
||||
AutobroadcastContainer m_Autobroadcasts;
|
||||
|
||||
typedef std::map<ObjectGuid, CharacterInfo> CharacterInfoContainer;
|
||||
CharacterInfoContainer _characterInfoStore;
|
||||
|
||||
Reference in New Issue
Block a user