importing changes from callmephil repo

a special thanks to him
This commit is contained in:
Yehonal 2016-06-26 19:22:35 +02:00
parent 5bb70a86be
commit 52f305111c
49 changed files with 4333 additions and 3252 deletions

View file

@ -680,7 +680,19 @@ void World::LoadConfigSettings(bool reload)
m_int_configs[CONFIG_STRICT_CHARTER_NAMES] = sConfigMgr->GetIntDefault ("StrictCharterNames", 0);
m_int_configs[CONFIG_STRICT_CHANNEL_NAMES] = sConfigMgr->GetIntDefault ("StrictChannelNames", 0);
m_int_configs[CONFIG_STRICT_PET_NAMES] = sConfigMgr->GetIntDefault ("StrictPetNames", 0);
m_bool_configs[CONFIG_ALLOW_TWO_SIDE_ACCOUNTS] = sConfigMgr->GetBoolDefault("AllowTwoSide.Accounts", true);
m_bool_configs[CONFIG_ALLOW_TWO_SIDE_INTERACTION_CALENDAR]= sConfigMgr->GetBoolDefault("AllowTwoSide.Interaction.Calendar", false);
m_bool_configs[CONFIG_ALLOW_TWO_SIDE_INTERACTION_CHAT] = sConfigMgr->GetBoolDefault("AllowTwoSide.Interaction.Chat", false);
m_bool_configs[CONFIG_ALLOW_TWO_SIDE_INTERACTION_CHANNEL] = sConfigMgr->GetBoolDefault("AllowTwoSide.Interaction.Channel", false);
m_bool_configs[CONFIG_ALLOW_TWO_SIDE_INTERACTION_GROUP] = sConfigMgr->GetBoolDefault("AllowTwoSide.Interaction.Group", false);
m_bool_configs[CONFIG_ALLOW_TWO_SIDE_INTERACTION_GUILD] = sConfigMgr->GetBoolDefault("AllowTwoSide.Interaction.Guild", false);
m_bool_configs[CONFIG_ALLOW_TWO_SIDE_INTERACTION_AUCTION] = sConfigMgr->GetBoolDefault("AllowTwoSide.Interaction.Auction", false);
m_bool_configs[CONFIG_ALLOW_TWO_SIDE_INTERACTION_MAIL] = sConfigMgr->GetBoolDefault("AllowTwoSide.Interaction.Mail", false);
m_bool_configs[CONFIG_ALLOW_TWO_SIDE_WHO_LIST] = sConfigMgr->GetBoolDefault("AllowTwoSide.WhoList", false);
m_bool_configs[CONFIG_ALLOW_TWO_SIDE_ADD_FRIEND] = sConfigMgr->GetBoolDefault("AllowTwoSide.AddFriend", false);
m_bool_configs[CONFIG_ALLOW_TWO_SIDE_TRADE] = sConfigMgr->GetBoolDefault("AllowTwoSide.trade", false);
m_int_configs[CONFIG_MIN_PLAYER_NAME] = sConfigMgr->GetIntDefault ("MinPlayerName", 2);
if (m_int_configs[CONFIG_MIN_PLAYER_NAME] < 1 || m_int_configs[CONFIG_MIN_PLAYER_NAME] > MAX_PLAYER_NAME)
{
@ -1664,6 +1676,10 @@ void World::SetInitialWorldSettings()
///- Handle outdated emails (delete/return)
sLog->outString("Returning old mails...");
sObjectMgr->ReturnOrDeleteOldMails(false);
///- Load AutoBroadCast
sLog->outString("Loading Autobroadcasts...");
LoadAutobroadcasts();
///- Load and initialize scripts
sObjectMgr->LoadSpellScripts(); // must be after load Creature/Gameobject(Template/Data)
@ -1842,6 +1858,40 @@ void World::DetectDBCLang()
sLog->outString();
}
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);
stmt->setInt32(0, realmId);
PreparedQueryResult result = LoginDatabase.Query(stmt);
if (!result)
{
sLog->outString(">> Loaded 0 autobroadcasts definitions. DB table `autobroadcast` is empty for this realm!");
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();
++count;
} while (result->NextRow());
sLog->outString(">> Loaded %u autobroadcast definitions in %u ms", count, GetMSTimeDiffToNow(oldMSTime));
}
/// Update the World !
void World::Update(uint32 diff)
{
@ -2579,10 +2629,37 @@ void World::SendAutoBroadcast()
{
if (m_Autobroadcasts.empty())
return;
uint32 weight = 0;
AutobroadcastsWeightMap selectionWeights;
std::string msg;
msg = Trinity::Containers::SelectRandomContainerElement(m_Autobroadcasts);
for (AutobroadcastsWeightMap::const_iterator it = m_AutobroadcastsWeights.begin(); it != m_AutobroadcastsWeights.end(); ++it)
{
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())];
uint32 abcenter = sWorld->getIntConfig(CONFIG_AUTOBROADCAST_CENTER);