Refactored db_scripts

The unity! - Based on the original work of H0zen for Zero.
This commit is contained in:
Antz 2017-01-20 00:10:08 +00:00 committed by Antz
parent a92011c6bf
commit 695651324c
15 changed files with 415 additions and 482 deletions

View file

@ -905,12 +905,12 @@ bool ChatHandler::HandleReloadDBScriptsOnGossipCommand(char* args)
} }
if (*args != 'a') if (*args != 'a')
sLog.outString("Re-Loading Scripts from `dbscripts_on_gossip`..."); { sLog.outString("Re-Loading Scripts from `db_scripts [type = DBS_ON_GOSSIP]`..."); }
sScriptMgr.LoadGossipScripts(); sScriptMgr.LoadDbScripts(DBS_ON_GOSSIP);
if (*args != 'a') if (*args != 'a')
SendGlobalSysMessage("DB table `dbscripts_on_gossip` reloaded."); SendGlobalSysMessage("DB table `db_scripts [type = DBS_ON_GOSSIP]` reloaded.");
return true; return true;
} }
@ -925,12 +925,12 @@ bool ChatHandler::HandleReloadDBScriptsOnSpellCommand(char* args)
} }
if (*args != 'a') if (*args != 'a')
sLog.outString("Re-Loading Scripts from `dbscripts_on_spell`..."); { sLog.outString("Re-Loading Scripts from `db_scripts [type = DBS_ON_SPELL]`..."); }
sScriptMgr.LoadSpellScripts(); sScriptMgr.LoadDbScripts(DBS_ON_SPELL);
if (*args != 'a') if (*args != 'a')
SendGlobalSysMessage("DB table `dbscripts_on_spell` reloaded."); SendGlobalSysMessage("DB table `db_scripts [type = DBS_ON_SPELL]` reloaded.");
return true; return true;
} }
@ -945,12 +945,12 @@ bool ChatHandler::HandleReloadDBScriptsOnQuestStartCommand(char* args)
} }
if (*args != 'a') if (*args != 'a')
sLog.outString("Re-Loading Scripts from `dbscripts_on_quest_start`..."); { sLog.outString("Re-Loading Scripts from `db_scripts [type = DBS_ON_QUEST_START]`..."); }
sScriptMgr.LoadQuestStartScripts(); sScriptMgr.LoadDbScripts(DBS_ON_QUEST_START);
if (*args != 'a') if (*args != 'a')
SendGlobalSysMessage("DB table `dbscripts_on_quest_start` reloaded."); SendGlobalSysMessage("DB table `db_scripts [type = DBS_ON_QUEST_START]` reloaded.");
return true; return true;
} }
@ -965,12 +965,12 @@ bool ChatHandler::HandleReloadDBScriptsOnQuestEndCommand(char* args)
} }
if (*args != 'a') if (*args != 'a')
sLog.outString("Re-Loading Scripts from `dbscripts_on_quest_end`..."); { sLog.outString("Re-Loading Scripts from `db_scripts [type = DBS_ON_QUEST_END]`..."); }
sScriptMgr.LoadQuestEndScripts(); sScriptMgr.LoadDbScripts(DBS_ON_QUEST_END);
if (*args != 'a') if (*args != 'a')
SendGlobalSysMessage("DB table `dbscripts_on_quest_end` reloaded."); SendGlobalSysMessage("DB table `db_scripts [type = DBS_ON_QUEST_END]` reloaded.");
return true; return true;
} }
@ -985,12 +985,12 @@ bool ChatHandler::HandleReloadDBScriptsOnEventCommand(char* args)
} }
if (*args != 'a') if (*args != 'a')
sLog.outString("Re-Loading Scripts from `dbscripts_on_event`..."); { sLog.outString("Re-Loading Scripts from `db_scripts [type = DBS_ON_EVENT]`..."); }
sScriptMgr.LoadEventScripts(); sScriptMgr.LoadDbScripts(DBS_ON_EVENT);
if (*args != 'a') if (*args != 'a')
SendGlobalSysMessage("DB table `dbscripts_on_event` reloaded."); SendGlobalSysMessage("DB table `db_scripts [type = DBS_ON_EVENT]` reloaded.");
return true; return true;
} }
@ -1005,13 +1005,13 @@ bool ChatHandler::HandleReloadDBScriptsOnGoUseCommand(char* args)
} }
if (*args != 'a') if (*args != 'a')
sLog.outString("Re-Loading Scripts from `dbscripts_on_go[_template]_use`..."); { sLog.outString("Re-Loading Scripts from `db_scripts [type = DBS_ON_GO[_TEMPLATE]_USE]`..."); }
sScriptMgr.LoadGameObjectScripts(); sScriptMgr.LoadDbScripts(DBS_ON_GO_USE);
sScriptMgr.LoadGameObjectTemplateScripts(); sScriptMgr.LoadDbScripts(DBS_ON_GOT_USE);
if (*args != 'a') if (*args != 'a')
SendGlobalSysMessage("DB table `dbscripts_on_go[_template]_use` reloaded."); SendGlobalSysMessage("DB table `db_scripts [type = DBS_ON_GO[_TEMPLATE]_USE]` reloaded.");
return true; return true;
} }
@ -1026,12 +1026,12 @@ bool ChatHandler::HandleReloadDBScriptsOnCreatureDeathCommand(char* args)
} }
if (*args != 'a') if (*args != 'a')
sLog.outString("Re-Loading Scripts from `dbscripts_on_creature_death`..."); { sLog.outString("Re-Loading Scripts from `db_scripts [type = DBS_ON_CREATURE_DEATH]`..."); }
sScriptMgr.LoadCreatureDeathScripts(); sScriptMgr.LoadDbScripts(DBS_ON_CREATURE_DEATH);
if (*args != 'a') if (*args != 'a')
SendGlobalSysMessage("DB table `dbscripts_on_creature_death` reloaded."); SendGlobalSysMessage("DB table `db_scripts [type = DBS_ON_CREATURE_DEATH]` reloaded.");
return true; return true;
} }

View file

@ -124,7 +124,7 @@ void WaypointMovementGenerator<Creature>::OnArrived(Creature& creature)
if (node.script_id) if (node.script_id)
{ {
DEBUG_FILTER_LOG(LOG_FILTER_AI_AND_MOVEGENSS, "Creature movement start script %u at point %u for %s.", node.script_id, i_currentNode, creature.GetGuidStr().c_str()); DEBUG_FILTER_LOG(LOG_FILTER_AI_AND_MOVEGENSS, "Creature movement start script %u at point %u for %s.", node.script_id, i_currentNode, creature.GetGuidStr().c_str());
creature.GetMap()->ScriptsStart(sCreatureMovementScripts, node.script_id, &creature, &creature); creature.GetMap()->ScriptsStart(DBS_ON_CREATURE_MOVEMENT, node.script_id, &creature, &creature);
} }
// We have reached the destination and can process behavior // We have reached the destination and can process behavior

View file

@ -1116,7 +1116,7 @@ void GameObject::Use(Unit* user)
bool scriptReturnValue = user->GetTypeId() == TYPEID_PLAYER && sScriptMgr.OnGameObjectUse((Player*)user, this); bool scriptReturnValue = user->GetTypeId() == TYPEID_PLAYER && sScriptMgr.OnGameObjectUse((Player*)user, this);
if (!scriptReturnValue) if (!scriptReturnValue)
{ GetMap()->ScriptsStart(sGameObjectTemplateScripts, GetEntry(), spellCaster, this); } { GetMap()->ScriptsStart(DBS_ON_GOT_USE, GetEntry(), spellCaster, this); }
switch (GetGoType()) switch (GetGoType())
{ {
@ -1127,7 +1127,7 @@ void GameObject::Use(Unit* user)
// activate script // activate script
if (!scriptReturnValue) if (!scriptReturnValue)
{ GetMap()->ScriptsStart(sGameObjectScripts, GetGUIDLow(), spellCaster, this); } { GetMap()->ScriptsStart(DBS_ON_GO_USE, GetGUIDLow(), spellCaster, this); }
return; return;
} }
case GAMEOBJECT_TYPE_BUTTON: // 1 case GAMEOBJECT_TYPE_BUTTON: // 1
@ -1139,7 +1139,7 @@ void GameObject::Use(Unit* user)
// activate script // activate script
if (!scriptReturnValue) if (!scriptReturnValue)
{ GetMap()->ScriptsStart(sGameObjectScripts, GetGUIDLow(), spellCaster, this); } { GetMap()->ScriptsStart(DBS_ON_GO_USE, GetGUIDLow(), spellCaster, this); }
return; return;
} }
@ -1353,7 +1353,7 @@ void GameObject::Use(Unit* user)
// activate script // activate script
if (!scriptReturnValue) if (!scriptReturnValue)
GetMap()->ScriptsStart(sGameObjectScripts, GetGUIDLow(), spellCaster, this); { GetMap()->ScriptsStart(DBS_ON_GO_USE, GetGUIDLow(), spellCaster, this); }
else else
return; return;

View file

@ -9672,9 +9672,13 @@ void ObjectMgr::LoadGossipMenu(std::set<uint32>& gossipScriptSet)
// Check script-id // Check script-id
if (gMenu.script_id) if (gMenu.script_id)
{ {
if (sGossipScripts.second.find(gMenu.script_id) == sGossipScripts.second.end()) ScriptChainMap const* scm = sScriptMgr.GetScriptChainMap(DBS_ON_GOSSIP);
if (!scm)
continue;
if (scm->find(gMenu.script_id) == scm->end())
{ {
sLog.outErrorDb("Table gossip_menu for menu %u, text-id %u have script_id %u that does not exist in `dbscripts_on_gossip`, ignoring", gMenu.entry, gMenu.text_id, gMenu.script_id); sLog.outErrorDb("Table gossip_menu for menu %u, text-id %u have script_id %u that does not exist in `db_scripts [type = %d]`, ignoring", gMenu.entry, gMenu.text_id, gMenu.script_id, DBS_ON_GOSSIP);
continue; continue;
} }
@ -9853,9 +9857,13 @@ void ObjectMgr::LoadGossipMenuItems(std::set<uint32>& gossipScriptSet)
if (gMenuItem.action_script_id) if (gMenuItem.action_script_id)
{ {
if (sGossipScripts.second.find(gMenuItem.action_script_id) == sGossipScripts.second.end()) ScriptChainMap const* scm = sScriptMgr.GetScriptChainMap(DBS_ON_GOSSIP);
if (!scm)
continue;
if (scm->find(gMenuItem.action_script_id) == scm->end())
{ {
sLog.outErrorDb("Table gossip_menu_option for menu %u, id %u have action_script_id %u that does not exist in `dbscripts_on_gossip`, ignoring", gMenuItem.menu_id, gMenuItem.id, gMenuItem.action_script_id); sLog.outErrorDb("Table gossip_menu_option for menu %u, id %u have action_script_id %u that does not exist in `db_scripts [type = %d]`, ignoring", gMenuItem.menu_id, gMenuItem.id, gMenuItem.action_script_id, DBS_ON_GOSSIP);
continue; continue;
} }
@ -9893,10 +9901,14 @@ void ObjectMgr::LoadGossipMenuItems(std::set<uint32>& gossipScriptSet)
void ObjectMgr::LoadGossipMenus() void ObjectMgr::LoadGossipMenus()
{ {
// Check which script-ids in dbscripts_on_gossip are not used ScriptChainMap const* scm = sScriptMgr.GetScriptChainMap(DBS_ON_GOSSIP);
if (!scm)
return;
// Check which script-ids in db_scripts type DBS_ON_GOSSIP are not used
std::set<uint32> gossipScriptSet; std::set<uint32> gossipScriptSet;
for (ScriptMapMap::const_iterator itr = sGossipScripts.second.begin(); itr != sGossipScripts.second.end(); ++itr) for (ScriptChainMap::const_iterator itr = scm->begin(); itr != scm->end(); ++itr)
gossipScriptSet.insert(itr->first); { gossipScriptSet.insert(itr->first); }
// Load gossip_menu and gossip_menu_option data // Load gossip_menu and gossip_menu_option data
sLog.outString("(Re)Loading Gossip menus..."); sLog.outString("(Re)Loading Gossip menus...");
@ -9905,7 +9917,7 @@ void ObjectMgr::LoadGossipMenus()
LoadGossipMenuItems(gossipScriptSet); LoadGossipMenuItems(gossipScriptSet);
for (std::set<uint32>::const_iterator itr = gossipScriptSet.begin(); itr != gossipScriptSet.end(); ++itr) for (std::set<uint32>::const_iterator itr = gossipScriptSet.begin(); itr != gossipScriptSet.end(); ++itr)
sLog.outErrorDb("Table `dbscripts_on_gossip` contains unused script, id %u.", *itr); { sLog.outErrorDb("Table `db_scripts [type = %d]` contains unused script, id %u.", DBS_ON_GOSSIP, *itr); }
} }
void ObjectMgr::AddVendorItem(uint32 entry, uint32 item, uint8 type, uint32 maxcount, uint32 incrtime, uint32 extendedcost) void ObjectMgr::AddVendorItem(uint32 entry, uint32 item, uint8 type, uint32 maxcount, uint32 incrtime, uint32 extendedcost)

View file

@ -13103,9 +13103,9 @@ void Player::OnGossipSelect(WorldObject* pSource, uint32 gossipListId, uint32 me
if (pMenuData.m_gAction_script) if (pMenuData.m_gAction_script)
{ {
if (pSource->GetTypeId() == TYPEID_UNIT) if (pSource->GetTypeId() == TYPEID_UNIT)
GetMap()->ScriptsStart(sGossipScripts, pMenuData.m_gAction_script, pSource, this, Map::SCRIPT_EXEC_PARAM_UNIQUE_BY_SOURCE); { GetMap()->ScriptsStart(DBS_ON_GOSSIP, pMenuData.m_gAction_script, pSource, this, Map::SCRIPT_EXEC_PARAM_UNIQUE_BY_SOURCE); }
else if (pSource->GetTypeId() == TYPEID_GAMEOBJECT) else if (pSource->GetTypeId() == TYPEID_GAMEOBJECT)
GetMap()->ScriptsStart(sGossipScripts, pMenuData.m_gAction_script, this, pSource, Map::SCRIPT_EXEC_PARAM_UNIQUE_BY_TARGET); { GetMap()->ScriptsStart(DBS_ON_GOSSIP, pMenuData.m_gAction_script, this, pSource, Map::SCRIPT_EXEC_PARAM_UNIQUE_BY_TARGET); }
} }
} }
@ -13146,7 +13146,7 @@ uint32 Player::GetGossipTextId(uint32 menuId, WorldObject* pSource)
// Start related script // Start related script
if (scriptId) if (scriptId)
GetMap()->ScriptsStart(sGossipScripts, scriptId, this, pSource, Map::SCRIPT_EXEC_PARAM_UNIQUE_BY_TARGET); { GetMap()->ScriptsStart(DBS_ON_GOSSIP, scriptId, this, pSource, Map::SCRIPT_EXEC_PARAM_UNIQUE_BY_TARGET); }
return textId; return textId;
} }
@ -13690,7 +13690,7 @@ void Player::AddQuest(Quest const* pQuest, Object* questGiver)
// starting initial DB quest script // starting initial DB quest script
if (pQuest->GetQuestStartScript() != 0) if (pQuest->GetQuestStartScript() != 0)
GetMap()->ScriptsStart(sQuestStartScripts, pQuest->GetQuestStartScript(), questGiver, this, Map::SCRIPT_EXEC_PARAM_UNIQUE_BY_SOURCE); { GetMap()->ScriptsStart(DBS_ON_QUEST_START, pQuest->GetQuestStartScript(), questGiver, this, Map::SCRIPT_EXEC_PARAM_UNIQUE_BY_SOURCE); }
} }
// remove start item if not need // remove start item if not need
@ -13913,7 +13913,7 @@ void Player::RewardQuest(Quest const* pQuest, uint32 reward, Object* questGiver,
} }
if (!handled && pQuest->GetQuestCompleteScript() != 0) if (!handled && pQuest->GetQuestCompleteScript() != 0)
GetMap()->ScriptsStart(sQuestEndScripts, pQuest->GetQuestCompleteScript(), questGiver, this, Map::SCRIPT_EXEC_PARAM_UNIQUE_BY_SOURCE); { GetMap()->ScriptsStart(DBS_ON_QUEST_END, pQuest->GetQuestCompleteScript(), questGiver, this, Map::SCRIPT_EXEC_PARAM_UNIQUE_BY_SOURCE); }
// cast spells after mark quest complete (some spells have quest completed state reqyurements in spell_area data) // cast spells after mark quest complete (some spells have quest completed state reqyurements in spell_area data)
if (pQuest->GetRewSpellCast() > 0) if (pQuest->GetRewSpellCast() > 0)

View file

@ -1424,7 +1424,7 @@ void Unit::JustKilledCreature(Creature* victim, Player* responsiblePlayer)
{ outdoorPvP->HandleCreatureDeath(victim); } { outdoorPvP->HandleCreatureDeath(victim); }
// Start creature death script // Start creature death script
GetMap()->ScriptsStart(sCreatureDeathScripts, victim->GetEntry(), victim, responsiblePlayer ? responsiblePlayer : this); GetMap()->ScriptsStart(DBS_ON_CREATURE_DEATH, victim->GetEntry(), victim, responsiblePlayer ? responsiblePlayer : this);
if (victim->IsLinkingEventTrigger()) if (victim->IsLinkingEventTrigger())
{ victim->GetMap()->GetCreatureLinkingHolder()->DoCreatureLinkingEvent(LINKING_EVENT_DIE, victim); } { victim->GetMap()->GetCreatureLinkingHolder()->DoCreatureLinkingEvent(LINKING_EVENT_DIE, victim); }

View file

@ -98,7 +98,7 @@ Map::Map(uint32 id, time_t expiry, uint32 InstanceId, uint8 SpawnMode)
m_VisibleDistance(DEFAULT_VISIBILITY_DISTANCE), m_persistentState(NULL), m_VisibleDistance(DEFAULT_VISIBILITY_DISTANCE), m_persistentState(NULL),
m_activeNonPlayersIter(m_activeNonPlayers.end()), m_activeNonPlayersIter(m_activeNonPlayers.end()),
i_gridExpiry(expiry), m_TerrainData(sTerrainMgr.LoadTerrain(id)), i_gridExpiry(expiry), m_TerrainData(sTerrainMgr.LoadTerrain(id)),
i_data(NULL), i_script_id(0) i_data(NULL)
{ {
m_CreatureGuids.Set(sObjectMgr.GetFirstTemporaryCreatureLowGuid()); m_CreatureGuids.Set(sObjectMgr.GetFirstTemporaryCreatureLowGuid());
m_GameObjectGuids.Set(sObjectMgr.GetFirstTemporaryGameObjectLowGuid()); m_GameObjectGuids.Set(sObjectMgr.GetFirstTemporaryGameObjectLowGuid());
@ -1743,13 +1743,17 @@ bool Map::CanEnter(Player* player)
} }
/// Put scripts in the execution queue /// Put scripts in the execution queue
bool Map::ScriptsStart(ScriptMapMapName const& scripts, uint32 id, Object* source, Object* target, ScriptExecutionParam execParams /*=SCRIPT_EXEC_PARAM_UNIQUE_BY_SOURCE_TARGET*/) bool Map::ScriptsStart(DBScriptType type, uint32 id, Object* source, Object* target, ScriptExecutionParam execParams /*=SCRIPT_EXEC_PARAM_UNIQUE_BY_SOURCE_TARGET*/)
{ {
MANGOS_ASSERT(source); MANGOS_ASSERT(source);
///- Find the script map ///- Find the script chain map
ScriptMapMap::const_iterator s = scripts.second.find(id); ScriptChainMap const *scm = sScriptMgr.GetScriptChainMap(type);
if (s == scripts.second.end()) if (!scm)
{ return false; }
ScriptChainMap::const_iterator s = scm->find(id);
if (s == scm->end())
{ return false; } { return false; }
// prepare static data // prepare static data
@ -1761,23 +1765,23 @@ bool Map::ScriptsStart(ScriptMapMapName const& scripts, uint32 id, Object* sourc
{ {
for (ScriptScheduleMap::const_iterator searchItr = m_scriptSchedule.begin(); searchItr != m_scriptSchedule.end(); ++searchItr) for (ScriptScheduleMap::const_iterator searchItr = m_scriptSchedule.begin(); searchItr != m_scriptSchedule.end(); ++searchItr)
{ {
if (searchItr->second.IsSameScript(scripts.first, id, if (searchItr->second.IsSameScript(type, id,
execParams & SCRIPT_EXEC_PARAM_UNIQUE_BY_SOURCE ? sourceGuid : ObjectGuid(), execParams & SCRIPT_EXEC_PARAM_UNIQUE_BY_SOURCE ? sourceGuid : ObjectGuid(),
execParams & SCRIPT_EXEC_PARAM_UNIQUE_BY_TARGET ? targetGuid : ObjectGuid(), ownerGuid)) execParams & SCRIPT_EXEC_PARAM_UNIQUE_BY_TARGET ? targetGuid : ObjectGuid(), ownerGuid))
{ {
DEBUG_LOG("DB-SCRIPTS: Process table `%s` id %u. Skip script as script already started for source %s, target %s - ScriptsStartParams %u", scripts.first, id, sourceGuid.GetString().c_str(), targetGuid.GetString().c_str(), execParams); DEBUG_LOG("DB-SCRIPTS: Process table `dbscripts [type=%d]` id %u. Skip script as script already started for source %s, target %s - ScriptsStartParams %u", type, id, sourceGuid.GetString().c_str(), targetGuid.GetString().c_str(), execParams);
return true; return true;
} }
} }
} }
///- Schedule script execution for all scripts in the script map ///- Schedule script execution for all scripts in the script map
ScriptMap const* s2 = &(s->second); ScriptChain const* s2 = &(s->second);
for (ScriptMap::const_iterator iter = s2->begin(); iter != s2->end(); ++iter) for (ScriptChain::const_iterator iter = s2->begin(); iter != s2->end(); ++iter)
{ {
ScriptAction sa(scripts.first, this, sourceGuid, targetGuid, ownerGuid, &iter->second); ScriptAction sa(type, this, sourceGuid, targetGuid, ownerGuid, &(*iter));
m_scriptSchedule.insert(ScriptScheduleMap::value_type(time_t(sWorld.GetGameTime() + iter->first), sa)); m_scriptSchedule.insert(ScriptScheduleMap::value_type(time_t(sWorld.GetGameTime() + iter->delay), sa));
sScriptMgr.IncreaseScheduledScriptsCount(); sScriptMgr.IncreaseScheduledScriptsCount();
} }
@ -1794,7 +1798,7 @@ void Map::ScriptCommandStart(ScriptInfo const& script, uint32 delay, Object* sou
ObjectGuid targetGuid = target ? target->GetObjectGuid() : ObjectGuid(); ObjectGuid targetGuid = target ? target->GetObjectGuid() : ObjectGuid();
ObjectGuid ownerGuid = source->isType(TYPEMASK_ITEM) ? ((Item*)source)->GetOwnerGuid() : ObjectGuid(); ObjectGuid ownerGuid = source->isType(TYPEMASK_ITEM) ? ((Item*)source)->GetOwnerGuid() : ObjectGuid();
ScriptAction sa("Internal Activate Command used for spell", this, sourceGuid, targetGuid, ownerGuid, &script); ScriptAction sa(DBS_INTERNAL, this, sourceGuid, targetGuid, ownerGuid, &script);
m_scriptSchedule.insert(ScriptScheduleMap::value_type(time_t(sWorld.GetGameTime() + delay), sa)); m_scriptSchedule.insert(ScriptScheduleMap::value_type(time_t(sWorld.GetGameTime() + delay), sa));
@ -1815,7 +1819,7 @@ void Map::ScriptsProcess()
if (iter->second.HandleScriptStep()) if (iter->second.HandleScriptStep())
{ {
// Terminate following script steps of this script // Terminate following script steps of this script
const char* tableName = iter->second.GetTableName(); DBScriptType type = iter->second.GetType();
uint32 id = iter->second.GetId(); uint32 id = iter->second.GetId();
ObjectGuid sourceGuid = iter->second.GetSourceGuid(); ObjectGuid sourceGuid = iter->second.GetSourceGuid();
ObjectGuid targetGuid = iter->second.GetTargetGuid(); ObjectGuid targetGuid = iter->second.GetTargetGuid();
@ -1823,7 +1827,7 @@ void Map::ScriptsProcess()
for (ScriptScheduleMap::iterator rmItr = m_scriptSchedule.begin(); rmItr != m_scriptSchedule.end();) for (ScriptScheduleMap::iterator rmItr = m_scriptSchedule.begin(); rmItr != m_scriptSchedule.end();)
{ {
if (rmItr->second.IsSameScript(tableName, id, sourceGuid, targetGuid, ownerGuid)) if (rmItr->second.IsSameScript(type, id, sourceGuid, targetGuid, ownerGuid))
{ {
m_scriptSchedule.erase(rmItr++); m_scriptSchedule.erase(rmItr++);
sScriptMgr.DecreaseScheduledScriptCount(); sScriptMgr.DecreaseScheduledScriptCount();

View file

@ -235,7 +235,7 @@ class Map : public GridRefManager<NGridType>
SCRIPT_EXEC_PARAM_UNIQUE_BY_TARGET = 0x02, // Start Script only if not yet started (uniqueness identified by id and target) SCRIPT_EXEC_PARAM_UNIQUE_BY_TARGET = 0x02, // Start Script only if not yet started (uniqueness identified by id and target)
SCRIPT_EXEC_PARAM_UNIQUE_BY_SOURCE_TARGET = 0x03, // Start Script only if not yet started (uniqueness identified by id, source and target) SCRIPT_EXEC_PARAM_UNIQUE_BY_SOURCE_TARGET = 0x03, // Start Script only if not yet started (uniqueness identified by id, source and target)
}; };
bool ScriptsStart(ScriptMapMapName const& scripts, uint32 id, Object* source, Object* target, ScriptExecutionParam execParams = SCRIPT_EXEC_PARAM_NONE); bool ScriptsStart(DBScriptType type, uint32 id, Object* source, Object* target, ScriptExecutionParam execParams = SCRIPT_EXEC_PARAM_NONE);
void ScriptCommandStart(ScriptInfo const& script, uint32 delay, Object* source, Object* target); void ScriptCommandStart(ScriptInfo const& script, uint32 delay, Object* source, Object* target);
// must called with AddToWorld // must called with AddToWorld
@ -296,6 +296,11 @@ class Map : public GridRefManager<NGridType>
// Teleport all players in that map to choosed location // Teleport all players in that map to choosed location
void TeleportAllPlayersTo(TeleportLocation loc); void TeleportAllPlayersTo(TeleportLocation loc);
// Random on map generation
bool GetReachableRandomPosition(Unit* unit, float& x, float& y, float& z, float radius);
bool GetReachableRandomPointOnGround(uint32 phaseMask, float& x, float& y, float& z, float radius);
bool GetRandomPointInTheAir(uint32 phaseMask, float& x, float& y, float& z, float radius);
bool GetRandomPointUnderWater(uint32 phaseMask, float& x, float& y, float& z, float radius, GridMapLiquidData& liquid_status);
// WeatherSystem // WeatherSystem
WeatherSystem* GetWeatherSystem() const { return m_weatherSystem; } WeatherSystem* GetWeatherSystem() const { return m_weatherSystem; }
@ -307,11 +312,6 @@ class Map : public GridRefManager<NGridType>
*/ */
void SetWeather(uint32 zoneId, WeatherType type, float grade, bool permanently); void SetWeather(uint32 zoneId, WeatherType type, float grade, bool permanently);
// Random on map generation
bool GetReachableRandomPosition(Unit* unit, float& x, float& y, float& z, float radius);
bool GetReachableRandomPointOnGround(uint32 phaseMask, float& x, float& y, float& z, float radius);
bool GetRandomPointInTheAir(uint32 phaseMask, float& x, float& y, float& z, float radius);
bool GetRandomPointUnderWater(uint32 phaseMask, float& x, float& y, float& z, float radius, GridMapLiquidData& liquid_status);
private: private:
void LoadMapAndVMap(int gx, int gy); void LoadMapAndVMap(int gx, int gy);
@ -385,7 +385,6 @@ class Map : public GridRefManager<NGridType>
ScriptScheduleMap m_scriptSchedule; ScriptScheduleMap m_scriptSchedule;
InstanceData* i_data; InstanceData* i_data;
uint32 i_script_id;
// Map local low guid counters // Map local low guid counters
ObjectGuidGenerator<HIGHGUID_UNIT> m_CreatureGuids; ObjectGuidGenerator<HIGHGUID_UNIT> m_CreatureGuids;

File diff suppressed because it is too large Load diff

View file

@ -48,6 +48,22 @@ class SpellCastTargets;
class Unit; class Unit;
class WorldObject; class WorldObject;
enum DBScriptType
{
DBS_INTERNAL = -1,
DBS_ON_QUEST_START = 0,
DBS_ON_QUEST_END = 1,
DBS_ON_GOSSIP = 2,
DBS_ON_CREATURE_MOVEMENT = 3,
DBS_ON_CREATURE_DEATH = 4,
DBS_ON_SPELL = 5,
DBS_ON_GO_USE = 6,
DBS_ON_GOT_USE = 7,
DBS_ON_EVENT = 8,
DBS_END = 9,
};
#define DBS_START DBS_ON_QUEST_START
enum ScriptedObjectType enum ScriptedObjectType
{ {
SCRIPTED_UNIT = 0, //CreatureScript SCRIPTED_UNIT = 0, //CreatureScript
@ -134,7 +150,7 @@ enum DBScriptCommand // resSource, resTar
SCRIPT_COMMAND_XP_USER = 33, // source or target with Player, datalong = bool (0=off, 1=on) SCRIPT_COMMAND_XP_USER = 33, // source or target with Player, datalong = bool (0=off, 1=on)
SCRIPT_COMMAND_TERMINATE_COND = 34, // datalong = condition_id, datalong2 = if != 0 then quest_id of quest that will be failed for player's group if the script is terminated SCRIPT_COMMAND_TERMINATE_COND = 34, // datalong = condition_id, datalong2 = if != 0 then quest_id of quest that will be failed for player's group if the script is terminated
// data_flags & SCRIPT_FLAG_COMMAND_ADDITIONAL terminate when condition is false ELSE terminate when condition is true // data_flags & SCRIPT_FLAG_COMMAND_ADDITIONAL terminate when condition is false ELSE terminate when condition is true
SCRIPT_COMMAND_SEND_AI_EVENT = 35, // resSource = Creature, resTarget = Unit SCRIPT_COMMAND_SEND_AI_EVENT_AROUND = 35, // resSource = Creature, resTarget = Unit
// datalong = AIEventType // datalong = AIEventType
// datalong2 = radius // datalong2 = radius
SCRIPT_COMMAND_TURN_TO = 36, // resSource = Unit, resTarget = Unit/none SCRIPT_COMMAND_TURN_TO = 36, // resSource = Unit, resTarget = Unit/none
@ -386,7 +402,7 @@ struct ScriptInfo
uint32 failQuest; // datalong2 uint32 failQuest; // datalong2
} terminateCond; } terminateCond;
struct // SCRIPT_COMMAND_SEND_AI_EVENT (35) struct // SCRIPT_COMMAND_SEND_AI_EVENT_AROUND (35)
{ {
uint32 eventType; // datalong uint32 eventType; // datalong
uint32 radius; // datalong2 uint32 radius; // datalong2
@ -512,18 +528,22 @@ struct ScriptInfo
} }
}; };
typedef std::vector < ScriptInfo > ScriptChain;
typedef std::map < uint32 /*id*/, ScriptChain > ScriptChainMap;
typedef std::vector < ScriptChainMap > DBScripts;
class ScriptAction class ScriptAction
{ {
public: public:
ScriptAction(const char* _table, Map* _map, ObjectGuid _sourceGuid, ObjectGuid _targetGuid, ObjectGuid _ownerGuid, ScriptInfo const* _script) : ScriptAction(DBScriptType _type, Map* _map, ObjectGuid _sourceGuid, ObjectGuid _targetGuid, ObjectGuid _ownerGuid, ScriptInfo const* _script) :
m_table(_table), m_map(_map), m_sourceGuid(_sourceGuid), m_targetGuid(_targetGuid), m_ownerGuid(_ownerGuid), m_script(_script) m_type(_type), m_map(_map), m_sourceGuid(_sourceGuid), m_targetGuid(_targetGuid), m_ownerGuid(_ownerGuid), m_script(_script)
{} {}
bool HandleScriptStep(); // return true IF AND ONLY IF the script should be terminated bool HandleScriptStep(); // return true IF AND ONLY IF the script should be terminated
const char* GetTableName() const DBScriptType GetType() const
{ {
return m_table; return m_type;
} }
uint32 GetId() const uint32 GetId() const
{ {
@ -542,16 +562,16 @@ class ScriptAction
return m_ownerGuid; return m_ownerGuid;
} }
bool IsSameScript(const char* table, uint32 id, ObjectGuid sourceGuid, ObjectGuid targetGuid, ObjectGuid ownerGuid) const bool IsSameScript(DBScriptType type, uint32 id, ObjectGuid sourceGuid, ObjectGuid targetGuid, ObjectGuid ownerGuid) const
{ {
return table == m_table && id == GetId() && return type == m_type && id == GetId() &&
(sourceGuid == m_sourceGuid || !sourceGuid) && (sourceGuid == m_sourceGuid || !sourceGuid) &&
(targetGuid == m_targetGuid || !targetGuid) && (targetGuid == m_targetGuid || !targetGuid) &&
(ownerGuid == m_ownerGuid || !ownerGuid); (ownerGuid == m_ownerGuid || !ownerGuid);
} }
private: private:
const char* m_table; // of which table the script was started DBScriptType m_type; // which type has the script was started
Map* m_map; // Map on which the action will be executed Map* m_map; // Map on which the action will be executed
ObjectGuid m_sourceGuid; ObjectGuid m_sourceGuid;
ObjectGuid m_targetGuid; ObjectGuid m_targetGuid;
@ -568,19 +588,6 @@ class ScriptAction
Player* GetPlayerTargetOrSourceAndLog(WorldObject* pSource, WorldObject* pTarget); Player* GetPlayerTargetOrSourceAndLog(WorldObject* pSource, WorldObject* pTarget);
}; };
typedef std::multimap < uint32 /*delay*/, ScriptInfo > ScriptMap;
typedef std::map < uint32 /*id*/, ScriptMap > ScriptMapMap;
typedef std::pair<const char*, ScriptMapMap> ScriptMapMapName;
extern ScriptMapMapName sQuestEndScripts;
extern ScriptMapMapName sQuestStartScripts;
extern ScriptMapMapName sSpellScripts;
extern ScriptMapMapName sGameObjectScripts;
extern ScriptMapMapName sGameObjectTemplateScripts;
extern ScriptMapMapName sEventScripts;
extern ScriptMapMapName sGossipScripts;
extern ScriptMapMapName sCreatureDeathScripts;
extern ScriptMapMapName sCreatureMovementScripts;
enum ScriptLoadResult enum ScriptLoadResult
{ {
@ -598,16 +605,7 @@ class ScriptMgr
std::string GenerateNameToId(ScriptedObjectType sot, uint32 id); std::string GenerateNameToId(ScriptedObjectType sot, uint32 id);
void LoadGameObjectScripts(); void LoadDbScripts(DBScriptType type);
void LoadGameObjectTemplateScripts();
void LoadQuestEndScripts();
void LoadQuestStartScripts();
void LoadEventScripts();
void LoadSpellScripts();
void LoadGossipScripts();
void LoadCreatureDeathScripts();
void LoadCreatureMovementScripts();
void LoadDbScriptStrings(); void LoadDbScriptStrings();
void LoadScriptNames(); void LoadScriptNames();
@ -621,15 +619,26 @@ class ScriptMgr
bool ReloadScriptBinding(); bool ReloadScriptBinding();
ScriptChainMap const* GetScriptChainMap(DBScriptType type)
{
if ((type != DBS_INTERNAL) && type < DBS_END)
return &m_dbScripts[type];
return NULL;
}
const char* GetScriptName(uint32 id) const const char* GetScriptName(uint32 id) const
{ {
return id < m_scriptNames.size() ? m_scriptNames[id].c_str() : ""; return id < m_scriptNames.size() ? m_scriptNames[id].c_str() : "";
} }
uint32 GetScriptId(const char* name) const; uint32 GetScriptId(const char* name) const;
uint32 GetScriptIdsCount() const uint32 GetScriptIdsCount() const
{ {
return m_scriptNames.size(); return m_scriptNames.size();
} }
uint32 GetBoundScriptId(ScriptedObjectType entity, int32 entry); uint32 GetBoundScriptId(ScriptedObjectType entity, int32 entry);
ScriptLoadResult LoadScriptLibrary(const char* libName); ScriptLoadResult LoadScriptLibrary(const char* libName);
@ -689,16 +698,16 @@ class ScriptMgr
private: private:
void CollectPossibleEventIds(std::set<uint32>& eventIds); void CollectPossibleEventIds(std::set<uint32>& eventIds);
void LoadScripts(ScriptMapMapName& scripts, const char* tablename); void LoadScripts(DBScriptType type);
void CheckScriptTexts(ScriptMapMapName const& scripts, std::set<int32>& ids); void CheckScriptTexts(std::set<int32>& ids);
typedef std::vector<std::string> ScriptNameMap; typedef std::vector<std::string> ScriptNameMap;
typedef UNORDERED_MAP<int32, uint32> EntryToScriptIdMap; typedef UNORDERED_MAP<int32, uint32> EntryToScriptIdMap;
EntryToScriptIdMap m_scriptBind[SCRIPTED_MAX_TYPE]; EntryToScriptIdMap m_scriptBind[SCRIPTED_MAX_TYPE];
ScriptNameMap m_scriptNames;
ScriptNameMap m_scriptNames;
DBScripts m_dbScripts;
#ifdef _DEBUG #ifdef _DEBUG
// mutex allowing to reload the script binding table; TODO just do it AWAY from any map update, e.g. right after sessions update // mutex allowing to reload the script binding table; TODO just do it AWAY from any map update, e.g. right after sessions update
ACE_RW_Thread_Mutex m_bindMutex; ACE_RW_Thread_Mutex m_bindMutex;
@ -712,16 +721,13 @@ bool StartEvents_Event(Map* map, uint32 id, Object* source, Object* target, bool
#define sScriptMgr MaNGOS::Singleton<ScriptMgr>::Instance() #define sScriptMgr MaNGOS::Singleton<ScriptMgr>::Instance()
MANGOS_DLL_SPEC uint32 GetAreaTriggerScriptId(uint32 triggerId);
MANGOS_DLL_SPEC uint32 GetEventIdScriptId(uint32 eventId);
MANGOS_DLL_SPEC uint32 GetScriptId(const char* name);
MANGOS_DLL_SPEC char const* GetScriptName(uint32 id);
MANGOS_DLL_SPEC uint32 GetScriptIdsCount();
MANGOS_DLL_SPEC void SetExternalWaypointTable(char const* tableName);
MANGOS_DLL_SPEC bool AddWaypointFromExternal(uint32 entry, int32 pathId, uint32 pointId, float x, float y, float z, float o, uint32 waittime);
uint32 GetScriptId(const char* name); uint32 GetScriptId(const char* name);
char const* GetScriptName(uint32 id); char const* GetScriptName(uint32 id);
uint32 GetScriptIdsCount(); uint32 GetScriptIdsCount();
uint32 GetAreaTriggerScriptId(uint32 triggerId);
uint32 GetEventIdScriptId(uint32 eventId);
uint32 GetScriptIdsCount();
void SetExternalWaypointTable(char const* tableName);
bool AddWaypointFromExternal(uint32 entry, int32 pathId, uint32 pointId, float x, float y, float z, float o, uint32 waittime);
#endif #endif

View file

@ -4039,7 +4039,7 @@ void Spell::EffectDummy(SpellEffectEntry const* effect)
return; return;
DEBUG_FILTER_LOG(LOG_FILTER_SPELL_CAST, "Spell ScriptStart spellid %u in EffectDummy", m_spellInfo->Id); DEBUG_FILTER_LOG(LOG_FILTER_SPELL_CAST, "Spell ScriptStart spellid %u in EffectDummy", m_spellInfo->Id);
m_caster->GetMap()->ScriptsStart(sSpellScripts, m_spellInfo->Id, m_caster, unitTarget); m_caster->GetMap()->ScriptsStart(DBS_ON_SPELL, m_spellInfo->Id, m_caster, unitTarget);
} }
void Spell::EffectTriggerSpellWithValue(SpellEffectEntry const* effect) void Spell::EffectTriggerSpellWithValue(SpellEffectEntry const* effect)
@ -4112,32 +4112,8 @@ void Spell::EffectForceCast(SpellEffectEntry const* effect)
if (!unitTarget) if (!unitTarget)
return; return;
uint32 triggered_spell_id = effect->EffectTriggerSpell; DEBUG_FILTER_LOG(LOG_FILTER_SPELL_CAST, "Spell ScriptStart spellid %u in EffectDummy", m_spellInfo->Id);
m_caster->GetMap()->ScriptsStart(DBS_ON_SPELL, m_spellInfo->Id, m_caster, unitTarget);
// normal case
SpellEntry const* spellInfo = sSpellStore.LookupEntry(triggered_spell_id);
if (!spellInfo)
{
sLog.outError("EffectForceCast of spell %u: triggering unknown spell id %i", m_spellInfo->Id, triggered_spell_id);
return;
}
int32 basePoints = damage;
// forced cast spells by vehicle on master always unboard the master
if (m_caster->IsVehicle() && m_caster->GetVehicleInfo()->HasOnBoard(unitTarget) &&
effect->EffectImplicitTargetA == TARGET_MASTER)
{
if (sSpellStore.LookupEntry(basePoints))
m_caster->RemoveAurasDueToSpell(basePoints);
}
// spell effect 141 needs to be cast as custom with basePoints
if (effect->Effect == SPELL_EFFECT_FORCE_CAST_WITH_VALUE)
unitTarget->CastCustomSpell(unitTarget, spellInfo, &basePoints, &basePoints, &basePoints, true, NULL , NULL, m_originalCasterGUID, m_spellInfo);
else
unitTarget->CastSpell(unitTarget, spellInfo, true, NULL, NULL, m_originalCasterGUID, m_spellInfo);
} }
void Spell::EffectTriggerSpell(SpellEffectEntry const* effect) void Spell::EffectTriggerSpell(SpellEffectEntry const* effect)
@ -4220,16 +4196,7 @@ void Spell::EffectTriggerSpell(SpellEffectEntry const* effect)
SpellEntry const* spellInfo = sSpellStore.LookupEntry(triggered_spell_id); SpellEntry const* spellInfo = sSpellStore.LookupEntry(triggered_spell_id);
if (!spellInfo) if (!spellInfo)
{ {
// No previous Effect might have started a script sLog.outError("EffectTriggerSpell of spell %u: triggering unknown spell id %i", m_spellInfo->Id, triggered_spell_id);
bool startDBScript = unitTarget && ScriptMgr::CanSpellEffectStartDBScript(m_spellInfo, SpellEffectIndex(effect->EffectIndex));
if (startDBScript)
{
DEBUG_FILTER_LOG(LOG_FILTER_SPELL_CAST, "Spell ScriptStart spellid %u in EffectTriggerSpell", m_spellInfo->Id);
startDBScript = m_caster->GetMap()->ScriptsStart(sSpellScripts, m_spellInfo->Id, m_caster, unitTarget);
}
if (!startDBScript)
sLog.outError("EffectTriggerSpell of spell %u: triggering unknown spell id %i", m_spellInfo->Id, triggered_spell_id);
return; return;
} }
@ -4289,7 +4256,7 @@ void Spell::EffectTriggerMissileSpell(SpellEffectEntry const* effect)
if (unitTarget) if (unitTarget)
{ {
DEBUG_FILTER_LOG(LOG_FILTER_SPELL_CAST, "Spell ScriptStart spellid %u in EffectTriggerMissileSpell", m_spellInfo->Id); DEBUG_FILTER_LOG(LOG_FILTER_SPELL_CAST, "Spell ScriptStart spellid %u in EffectTriggerMissileSpell", m_spellInfo->Id);
m_caster->GetMap()->ScriptsStart(sSpellScripts, m_spellInfo->Id, m_caster, unitTarget); m_caster->GetMap()->ScriptsStart(DBS_ON_SPELL, m_spellInfo->Id, m_caster, unitTarget);
} }
else else
sLog.outError("EffectTriggerMissileSpell of spell %u (eff: %u): triggering unknown spell id %u", sLog.outError("EffectTriggerMissileSpell of spell %u (eff: %u): triggering unknown spell id %u",
@ -10119,7 +10086,7 @@ void Spell::EffectScriptEffect(SpellEffectEntry const* effect)
return; return;
DEBUG_FILTER_LOG(LOG_FILTER_SPELL_CAST, "Spell ScriptStart spellid %u in EffectScriptEffect", m_spellInfo->Id); DEBUG_FILTER_LOG(LOG_FILTER_SPELL_CAST, "Spell ScriptStart spellid %u in EffectScriptEffect", m_spellInfo->Id);
m_caster->GetMap()->ScriptsStart(sSpellScripts, m_spellInfo->Id, m_caster, unitTarget); m_caster->GetMap()->ScriptsStart(DBS_ON_SPELL, m_spellInfo->Id, m_caster, unitTarget);
} }
void Spell::EffectSanctuary(SpellEffectEntry const* /*effect*/) void Spell::EffectSanctuary(SpellEffectEntry const* /*effect*/)

View file

@ -601,6 +601,6 @@ void Transport::DoEventIfAny(WayPointMap::value_type const& node, bool departure
DEBUG_FILTER_LOG(LOG_FILTER_TRANSPORT_MOVES, "Taxi %s event %u of node %u of %s \"%s\") path", departure ? "departure" : "arrival", eventid, node.first, GetGuidStr().c_str(), GetName()); DEBUG_FILTER_LOG(LOG_FILTER_TRANSPORT_MOVES, "Taxi %s event %u of node %u of %s \"%s\") path", departure ? "departure" : "arrival", eventid, node.first, GetGuidStr().c_str(), GetName());
if (!sScriptMgr.OnProcessEvent(eventid, this, this, departure)) if (!sScriptMgr.OnProcessEvent(eventid, this, this, departure))
GetMap()->ScriptsStart(sEventScripts, eventid, this, this); GetMap()->ScriptsStart(DBS_ON_EVENT, eventid, this, this);
} }
} }

View file

@ -61,12 +61,19 @@ void WaypointManager::Load()
uint32 total_nodes = 0; uint32 total_nodes = 0;
uint32 total_behaviors = 0; uint32 total_behaviors = 0;
ScriptChainMap const* scm = sScriptMgr.GetScriptChainMap(DBS_ON_CREATURE_MOVEMENT);
if (!scm)
return;
std::set<uint32> movementScriptSet; std::set<uint32> movementScriptSet;
for (ScriptMapMap::const_iterator itr = sCreatureMovementScripts.second.begin(); itr != sCreatureMovementScripts.second.end(); ++itr) for (ScriptChainMap::const_iterator itr = scm->begin(); itr != scm->end(); ++itr)
movementScriptSet.insert(itr->first); { movementScriptSet.insert(itr->first); }
// /////////////////////////////////////////////////////
// creature_movement // creature_movement
// /////////////////////////////////////////////////////
QueryResult* result = WorldDatabase.Query("SELECT id, COUNT(point) FROM creature_movement GROUP BY id"); QueryResult* result = WorldDatabase.Query("SELECT id, COUNT(point) FROM creature_movement GROUP BY id");
if (!result) if (!result)
@ -162,7 +169,7 @@ void WaypointManager::Load()
if (node.script_id) if (node.script_id)
{ {
if (sCreatureMovementScripts.second.find(node.script_id) == sCreatureMovementScripts.second.end()) if (scm->find(node.script_id) == scm->end())
{ {
sLog.outErrorDb("Table creature_movement for id %u, point %u have script_id %u that does not exist in `dbscripts_on_creature_movement`, ignoring", id, point, node.script_id); sLog.outErrorDb("Table creature_movement for id %u, point %u have script_id %u that does not exist in `dbscripts_on_creature_movement`, ignoring", id, point, node.script_id);
continue; continue;
@ -238,7 +245,10 @@ void WaypointManager::Load()
delete result; delete result;
} }
// /////////////////////////////////////////////////////
// creature_movement_template // creature_movement_template
// /////////////////////////////////////////////////////
result = WorldDatabase.Query("SELECT entry, COUNT(point) FROM creature_movement_template GROUP BY entry"); result = WorldDatabase.Query("SELECT entry, COUNT(point) FROM creature_movement_template GROUP BY entry");
if (!result) if (!result)
@ -322,7 +332,7 @@ void WaypointManager::Load()
if (node.script_id) if (node.script_id)
{ {
if (sCreatureMovementScripts.second.find(node.script_id) == sCreatureMovementScripts.second.end()) if (scm->find(node.script_id) == scm->end())
{ {
sLog.outErrorDb("Table creature_movement_template for entry %u, point %u have script_id %u that does not exist in `dbscripts_on_creature_movement`, ignoring", entry, point, node.script_id); sLog.outErrorDb("Table creature_movement_template for entry %u, point %u have script_id %u that does not exist in `dbscripts_on_creature_movement`, ignoring", entry, point, node.script_id);
continue; continue;
@ -594,7 +604,11 @@ bool WaypointManager::SetNodeScriptId(uint32 entry, uint32 dbGuid, uint32 point,
if (find != path->end()) if (find != path->end())
find->second.script_id = scriptId; find->second.script_id = scriptId;
return sCreatureMovementScripts.second.find(scriptId) != sCreatureMovementScripts.second.end(); ScriptChainMap const* scm = sScriptMgr.GetScriptChainMap(DBS_ON_CREATURE_MOVEMENT);
if (!scm)
return false;
return scm->find(scriptId) != scm->end();
} }
inline void CheckWPText(bool isTemplate, uint32 entryOrGuid, uint32 point, WaypointBehavior* be, std::set<int32>& ids) inline void CheckWPText(bool isTemplate, uint32 entryOrGuid, uint32 point, WaypointBehavior* be, std::set<int32>& ids)

View file

@ -76,11 +76,12 @@
#include "Calendar.h" #include "Calendar.h"
#include "Weather.h" #include "Weather.h"
#include "LFGMgr.h" #include "LFGMgr.h"
#ifdef ENABLE_ELUNA #ifdef ENABLE_ELUNA
#include "LuaEngine.h" #include "LuaEngine.h"
#endif /*ENABLE_ELUNA*/ #endif /* ENABLE_ELUNA */
// Warden // WARDEN
#include "WardenCheckMgr.h" #include "WardenCheckMgr.h"
#include <iostream> #include <iostream>
@ -932,14 +933,15 @@ void World::LoadConfigSettings(bool reload)
setConfig(CONFIG_BOOL_MMAP_ENABLED, "mmap.enabled", true); setConfig(CONFIG_BOOL_MMAP_ENABLED, "mmap.enabled", true);
std::string ignoreMapIds = sConfig.GetStringDefault("mmap.ignoreMapIds", ""); std::string ignoreMapIds = sConfig.GetStringDefault("mmap.ignoreMapIds", "");
MMAP::MMapFactory::preventPathfindingOnMaps(ignoreMapIds.c_str()); MMAP::MMapFactory::preventPathfindingOnMaps(ignoreMapIds.c_str());
sLog.outString("WORLD: mmap pathfinding %sabled", getConfig(CONFIG_BOOL_MMAP_ENABLED) ? "en" : "dis"); sLog.outString("WORLD: MMap pathfinding %sabled", getConfig(CONFIG_BOOL_MMAP_ENABLED) ? "en" : "dis");
setConfig(CONFIG_BOOL_ELUNA_ENABLED, "Eluna.Enabled", true); setConfig(CONFIG_BOOL_ELUNA_ENABLED, "Eluna.Enabled", true);
#ifdef ENABLE_ELUNA #ifdef ENABLE_ELUNA
if (reload) if (reload)
sEluna->OnConfigLoad(reload); sEluna->OnConfigLoad(reload);
#endif /* ENABLE_ELUNA */ #endif /* ENABLE_ELUNA */
sLog.outString();
} }
/// Initialize the World /// Initialize the World
@ -1095,7 +1097,7 @@ void World::SetInitialWorldSettings()
sLog.outString("Loading Creature Stats..."); sLog.outString("Loading Creature Stats...");
sObjectMgr.LoadCreatureClassLvlStats(); sObjectMgr.LoadCreatureClassLvlStats();
sLog.outErrorDb("Loading Creature templates..."); sLog.outString("Loading Creature templates...");
sObjectMgr.LoadCreatureTemplates(); sObjectMgr.LoadCreatureTemplates();
sLog.outString("Loading Creature template spells..."); sLog.outString("Loading Creature template spells...");
@ -1179,6 +1181,7 @@ void World::SetInitialWorldSettings()
sLog.outString("Creating map persistent states for non-instanceable maps..."); // must be after PackInstances(), LoadCreatures(), sPoolMgr.LoadFromDB(), sGameEventMgr.LoadFromDB(); sLog.outString("Creating map persistent states for non-instanceable maps..."); // must be after PackInstances(), LoadCreatures(), sPoolMgr.LoadFromDB(), sGameEventMgr.LoadFromDB();
sMapPersistentStateMgr.InitWorldMaps(); sMapPersistentStateMgr.InitWorldMaps();
sLog.outString();
sLog.outString("Loading Creature Respawn Data..."); // must be after LoadCreatures(), and sMapPersistentStateMgr.InitWorldMaps() sLog.outString("Loading Creature Respawn Data..."); // must be after LoadCreatures(), and sMapPersistentStateMgr.InitWorldMaps()
sMapPersistentStateMgr.LoadCreatureRespawnTimes(); sMapPersistentStateMgr.LoadCreatureRespawnTimes();
@ -1228,6 +1231,7 @@ void World::SetInitialWorldSettings()
sObjectMgr.LoadPetNames(); sObjectMgr.LoadPetNames();
CharacterDatabaseCleaner::CleanDatabase(); CharacterDatabaseCleaner::CleanDatabase();
sLog.outString();
sLog.outString("Loading the max pet number..."); sLog.outString("Loading the max pet number...");
sObjectMgr.LoadPetNumber(); sObjectMgr.LoadPetNumber();
@ -1274,7 +1278,7 @@ void World::SetInitialWorldSettings()
sObjectMgr.LoadNpcGossips(); // must be after load Creature and LoadGossipText sObjectMgr.LoadNpcGossips(); // must be after load Creature and LoadGossipText
sLog.outString("Loading Gossip scripts..."); sLog.outString("Loading Gossip scripts...");
sScriptMgr.LoadGossipScripts(); // must be before gossip menu options sScriptMgr.LoadDbScripts(DBS_ON_GOSSIP); // must be before gossip menu options
sObjectMgr.LoadGossipMenus(); sObjectMgr.LoadGossipMenus();
@ -1287,7 +1291,7 @@ void World::SetInitialWorldSettings()
sObjectMgr.LoadTrainers(); // must be after load CreatureTemplate, TrainerTemplate sObjectMgr.LoadTrainers(); // must be after load CreatureTemplate, TrainerTemplate
sLog.outString("Loading Waypoint scripts..."); // before loading from creature_movement sLog.outString("Loading Waypoint scripts..."); // before loading from creature_movement
sScriptMgr.LoadCreatureMovementScripts(); sScriptMgr.LoadDbScripts(DBS_ON_CREATURE_MOVEMENT);
sLog.outString("Loading Waypoints..."); sLog.outString("Loading Waypoints...");
sLog.outString(); sLog.outString();
@ -1356,22 +1360,22 @@ void World::SetInitialWorldSettings()
sLog.outString("Returning old mails..."); sLog.outString("Returning old mails...");
sObjectMgr.ReturnOrDeleteOldMails(false); sObjectMgr.ReturnOrDeleteOldMails(false);
///- Load and initialize scripts ///- Load and initialize DBScripts Engine
sLog.outString("Loading Scripts..."); sLog.outString("Loading DB-Scripts Engine...");
sLog.outString(); sScriptMgr.LoadDbScripts(DBS_ON_QUEST_START); // must be after load Creature/Gameobject(Template/Data) and QuestTemplate
sScriptMgr.LoadQuestStartScripts(); // must be after load Creature/Gameobject(Template/Data) and QuestTemplate sScriptMgr.LoadDbScripts(DBS_ON_QUEST_END); // must be after load Creature/Gameobject(Template/Data) and QuestTemplate
sScriptMgr.LoadQuestEndScripts(); // must be after load Creature/Gameobject(Template/Data) and QuestTemplate sScriptMgr.LoadDbScripts(DBS_ON_SPELL); // must be after load Creature/Gameobject(Template/Data)
sScriptMgr.LoadSpellScripts(); // must be after load Creature/Gameobject(Template/Data) sScriptMgr.LoadDbScripts(DBS_ON_GO_USE); // must be after load Creature/Gameobject(Template/Data)
sScriptMgr.LoadGameObjectScripts(); // must be after load Creature/Gameobject(Template/Data) sScriptMgr.LoadDbScripts(DBS_ON_GOT_USE); // must be after load Creature/Gameobject(Template/Data)
sScriptMgr.LoadGameObjectTemplateScripts(); // must be after load Creature/Gameobject(Template/Data) sScriptMgr.LoadDbScripts(DBS_ON_EVENT); // must be after load Creature/Gameobject(Template/Data)
sScriptMgr.LoadEventScripts(); // must be after load Creature/Gameobject(Template/Data) sScriptMgr.LoadDbScripts(DBS_ON_CREATURE_DEATH); // must be after load Creature/Gameobject(Template/Data)
sScriptMgr.LoadCreatureDeathScripts(); // must be after load Creature/Gameobject(Template/Data) sLog.outString(">>> DB Scripts loaded");
sLog.outString(">>> Scripts loaded");
sLog.outString(); sLog.outString();
sLog.outString("Loading Scripts text locales..."); // must be after Load*Scripts calls sLog.outString("Loading Scripts text locales..."); // must be after Load*Scripts calls
sScriptMgr.LoadDbScriptStrings(); sScriptMgr.LoadDbScriptStrings();
///- Load and initialize EventAI Scripts
sLog.outString("Loading CreatureEventAI Texts..."); sLog.outString("Loading CreatureEventAI Texts...");
sEventAIMgr.LoadCreatureEventAI_Texts(false); // false, will checked in LoadCreatureEventAI_Scripts sEventAIMgr.LoadCreatureEventAI_Texts(false); // false, will checked in LoadCreatureEventAI_Scripts
@ -1385,25 +1389,26 @@ void World::SetInitialWorldSettings()
#ifdef ENABLE_SD3 #ifdef ENABLE_SD3
switch (sScriptMgr.LoadScriptLibrary(MANGOS_SCRIPT_NAME)) switch (sScriptMgr.LoadScriptLibrary(MANGOS_SCRIPT_NAME))
{ {
case SCRIPT_LOAD_OK: case SCRIPT_LOAD_OK:
sLog.outString("Scripting library loaded."); sLog.outString("Scripting library loaded.");
break; break;
case SCRIPT_LOAD_ERR_NOT_FOUND: case SCRIPT_LOAD_ERR_NOT_FOUND:
sLog.outError("Scripting library not found or not accessible."); sLog.outError("Scripting library not found or not accessible.");
break; break;
case SCRIPT_LOAD_ERR_WRONG_API: case SCRIPT_LOAD_ERR_WRONG_API:
sLog.outError("Scripting library has wrong list functions (outdated?)."); sLog.outError("Scripting library has wrong list functions (outdated?).");
break; break;
case SCRIPT_LOAD_ERR_OUTDATED: case SCRIPT_LOAD_ERR_OUTDATED:
sLog.outError("Scripting library build for old mangosd revision. You need rebuild it."); sLog.outError("Scripting library build for old mangosd revision. You need rebuild it.");
break; break;
} }
#else /* ENABLE_SD3 */ #else /* ENABLE_SD3 */
sLog.outError("SD3 was not included in compilation, not using it."); sLog.outError("SD3 was not included in compilation, not using it.");
#endif /* ENABLE_SD3 */ #endif /* ENABLE_SD3 */
sLog.outString();
///- Initialize game time and timers ///- Initialize game time and timers
sLog.outString("DEBUG:: Initialize game time and timers"); sLog.outString("Initialize game time and timers");
m_gameTime = time(NULL); m_gameTime = time(NULL);
m_startTime = m_gameTime; m_startTime = m_gameTime;
@ -1413,10 +1418,10 @@ void World::SetInitialWorldSettings()
local = *(localtime(&curr)); // dereference and assign local = *(localtime(&curr)); // dereference and assign
char isoDate[128]; char isoDate[128];
sprintf(isoDate, "%04d-%02d-%02d %02d:%02d:%02d", sprintf(isoDate, "%04d-%02d-%02d %02d:%02d:%02d",
local.tm_year + 1900, local.tm_mon + 1, local.tm_mday, local.tm_hour, local.tm_min, local.tm_sec); local.tm_year + 1900, local.tm_mon + 1, local.tm_mday, local.tm_hour, local.tm_min, local.tm_sec);
LoginDatabase.PExecute("INSERT INTO uptime (realmid, starttime, startstring, uptime) VALUES('%u', " UI64FMTD ", '%s', 0)", LoginDatabase.PExecute("INSERT INTO uptime (realmid, starttime, startstring, uptime) VALUES('%u', " UI64FMTD ", '%s', 0)",
realmID, uint64(m_startTime), isoDate); realmID, uint64(m_startTime), isoDate);
m_timers[WUPDATE_AUCTIONS].SetInterval(MINUTE * IN_MILLISECONDS); m_timers[WUPDATE_AUCTIONS].SetInterval(MINUTE * IN_MILLISECONDS);
m_timers[WUPDATE_UPTIME].SetInterval(getConfig(CONFIG_UINT32_UPTIME_UPDATE)*MINUTE * IN_MILLISECONDS); m_timers[WUPDATE_UPTIME].SetInterval(getConfig(CONFIG_UINT32_UPTIME_UPDATE)*MINUTE * IN_MILLISECONDS);
@ -1445,6 +1450,7 @@ void World::SetInitialWorldSettings()
///- Initialize MapManager ///- Initialize MapManager
sLog.outString("Starting Map System"); sLog.outString("Starting Map System");
sMapMgr.Initialize(); sMapMgr.Initialize();
sLog.outString();
///- Initialize Battlegrounds ///- Initialize Battlegrounds
sLog.outString("Starting BattleGround System"); sLog.outString("Starting BattleGround System");
@ -1470,6 +1476,7 @@ void World::SetInitialWorldSettings()
sLog.outString("Deleting expired bans..."); sLog.outString("Deleting expired bans...");
LoginDatabase.Execute("DELETE FROM ip_banned WHERE unbandate<=UNIX_TIMESTAMP() AND unbandate<>bandate"); LoginDatabase.Execute("DELETE FROM ip_banned WHERE unbandate<=UNIX_TIMESTAMP() AND unbandate<>bandate");
sLog.outString();
sLog.outString("Calculate next daily quest and dungeon reset time..."); sLog.outString("Calculate next daily quest and dungeon reset time...");
InitDailyQuestResetTime(); InitDailyQuestResetTime();
@ -1497,7 +1504,7 @@ void World::SetInitialWorldSettings()
sLog.outString("Initialize AuctionHouseBot..."); sLog.outString("Initialize AuctionHouseBot...");
sAuctionBot.Initialize(); sAuctionBot.Initialize();
sLog.outString();
#ifdef ENABLE_ELUNA #ifdef ENABLE_ELUNA
///- Run eluna scripts. ///- Run eluna scripts.
// in multithread foreach: run scripts // in multithread foreach: run scripts
@ -1505,10 +1512,14 @@ void World::SetInitialWorldSettings()
sEluna->OnConfigLoad(false); // Must be done after Eluna is initialized and scripts have run. sEluna->OnConfigLoad(false); // Must be done after Eluna is initialized and scripts have run.
#endif #endif
sLog.outString("------------------------");
sLog.outString("WORLD: World initialized"); sLog.outString("WORLD: World initialized");
sLog.outString("------------------------");
sLog.outString();
uint32 uStartInterval = WorldTimer::getMSTimeDiff(uStartTime, WorldTimer::getMSTime()); uint32 uStartInterval = WorldTimer::getMSTimeDiff(uStartTime, WorldTimer::getMSTime());
sLog.outString("SERVER STARTUP TIME: %i minutes %i seconds", uStartInterval / 60000, (uStartInterval % 60000) / 1000); sLog.outString("SERVER STARTUP TIME: %i minutes %i seconds", uStartInterval / 60000, (uStartInterval % 60000) / 1000);
sLog.outString();
} }
void World::DetectDBCLang() void World::DetectDBCLang()

View file

@ -37,7 +37,7 @@
#define CHAR_DB_UPDATE_DESCRIPTION "characters_pvpstats" #define CHAR_DB_UPDATE_DESCRIPTION "characters_pvpstats"
#define WORLD_DB_VERSION_NR 21 #define WORLD_DB_VERSION_NR 21
#define WORLD_DB_STRUCTURE_NR 4 #define WORLD_DB_STRUCTURE_NR 5
#define WORLD_DB_CONTENT_NR 8 #define WORLD_DB_CONTENT_NR 1
#define WORLD_DB_UPDATE_DESCRIPTION "NPC text corrections" #define WORLD_DB_UPDATE_DESCRIPTION "dbscripts_refactor"
#endif // __REVISION_H__ #endif // __REVISION_H__