Merge pull request #105 from H0zen/develop21

Refactoring db_scripts
This commit is contained in:
Antz 2016-03-25 00:55:36 +00:00
commit 2423af36c1
14 changed files with 335 additions and 362 deletions

View File

@ -835,12 +835,12 @@ bool ChatHandler::HandleReloadDBScriptsOnGossipCommand(char* args)
}
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')
SendGlobalSysMessage("DB table `dbscripts_on_gossip` reloaded.", SEC_MODERATOR);
SendGlobalSysMessage("DB table `db_scripts [type = DBS_ON_GOSSIP]` reloaded.", SEC_MODERATOR);
return true;
}
@ -855,12 +855,12 @@ bool ChatHandler::HandleReloadDBScriptsOnSpellCommand(char* args)
}
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')
SendGlobalSysMessage("DB table `dbscripts_on_spell` reloaded.", SEC_MODERATOR);
SendGlobalSysMessage("DB table `db_scripts [type = DBS_ON_SPELL]` reloaded.", SEC_MODERATOR);
return true;
}
@ -875,12 +875,12 @@ bool ChatHandler::HandleReloadDBScriptsOnQuestStartCommand(char* args)
}
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')
SendGlobalSysMessage("DB table `dbscripts_on_quest_start` reloaded.", SEC_MODERATOR);
SendGlobalSysMessage("DB table `db_scripts [type = DBS_ON_QUEST_START]` reloaded.", SEC_MODERATOR);
return true;
}
@ -895,12 +895,12 @@ bool ChatHandler::HandleReloadDBScriptsOnQuestEndCommand(char* args)
}
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')
SendGlobalSysMessage("DB table `dbscripts_on_quest_end` reloaded.", SEC_MODERATOR);
SendGlobalSysMessage("DB table `db_scripts [type = DBS_ON_QUEST_END]` reloaded.", SEC_MODERATOR);
return true;
}
@ -915,12 +915,12 @@ bool ChatHandler::HandleReloadDBScriptsOnEventCommand(char* args)
}
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')
SendGlobalSysMessage("DB table `dbscripts_on_event` reloaded.", SEC_MODERATOR);
SendGlobalSysMessage("DB table `db_scripts [type = DBS_ON_EVENT]` reloaded.", SEC_MODERATOR);
return true;
}
@ -935,13 +935,13 @@ bool ChatHandler::HandleReloadDBScriptsOnGoUseCommand(char* args)
}
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.LoadGameObjectTemplateScripts();
sScriptMgr.LoadDbScripts(DBS_ON_GO_USE);
sScriptMgr.LoadDbScripts(DBS_ON_GOT_USE);
if (*args != 'a')
SendGlobalSysMessage("DB table `dbscripts_on_go[_template]_use` reloaded.", SEC_MODERATOR);
SendGlobalSysMessage("DB table `db_scripts [type = DBS_ON_GO[_TEMPLATE]_USE]` reloaded.", SEC_MODERATOR);
return true;
}
@ -956,12 +956,12 @@ bool ChatHandler::HandleReloadDBScriptsOnCreatureDeathCommand(char* args)
}
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')
SendGlobalSysMessage("DB table `dbscripts_on_creature_death` reloaded.", SEC_MODERATOR);
SendGlobalSysMessage("DB table `db_scripts [type = DBS_ON_CREATURE_DEATH]` reloaded.", SEC_MODERATOR);
return true;
}

View File

@ -124,7 +124,7 @@ void WaypointMovementGenerator<Creature>::OnArrived(Creature& creature)
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());
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

View File

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

View File

@ -8238,9 +8238,13 @@ void ObjectMgr::LoadGossipMenu(std::set<uint32>& gossipScriptSet)
// Check 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;
}
@ -8419,9 +8423,13 @@ void ObjectMgr::LoadGossipMenuItems(std::set<uint32>& gossipScriptSet)
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;
}
@ -8459,9 +8467,13 @@ void ObjectMgr::LoadGossipMenuItems(std::set<uint32>& gossipScriptSet)
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;
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); }
// Load gossip_menu and gossip_menu_option data
@ -8471,7 +8483,7 @@ void ObjectMgr::LoadGossipMenus()
LoadGossipMenuItems(gossipScriptSet);
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, uint32 maxcount, uint32 incrtime)

View File

@ -11771,9 +11771,9 @@ void Player::OnGossipSelect(WorldObject* pSource, uint32 gossipListId)
if (pMenuData.m_gAction_script)
{
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)
{ 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); }
}
}
@ -11815,7 +11815,7 @@ uint32 Player::GetGossipTextId(uint32 menuId, WorldObject* pSource)
// Start related script
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;
}
@ -12325,7 +12325,7 @@ void Player::AddQuest(Quest const* pQuest, Object* questGiver)
// starting initial DB quest script
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
@ -12495,7 +12495,7 @@ void Player::RewardQuest(Quest const* pQuest, uint32 reward, Object* questGiver,
}
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)
if (pQuest->GetRewSpellCast() > 0)

View File

@ -1054,7 +1054,7 @@ void Unit::JustKilledCreature(Creature* victim, Player* responsiblePlayer)
{ outdoorPvP->HandleCreatureDeath(victim); }
// 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())
{ victim->GetMap()->GetCreatureLinkingHolder()->DoCreatureLinkingEvent(LINKING_EVENT_DIE, victim); }

View File

@ -1656,13 +1656,17 @@ bool Map::CanEnter(Player* player)
}
/// 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);
///- Find the script map
ScriptMapMap::const_iterator s = scripts.second.find(id);
if (s == scripts.second.end())
///- Find the script chain map
ScriptChainMap const *scm = sScriptMgr.GetScriptChainMap(type);
if (!scm)
{ return false; }
ScriptChainMap::const_iterator s = scm->find(id);
if (s == scm->end())
{ return false; }
// prepare static data
@ -1674,23 +1678,23 @@ bool Map::ScriptsStart(ScriptMapMapName const& scripts, uint32 id, Object* sourc
{
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_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;
}
}
}
///- Schedule script execution for all scripts in the script map
ScriptMap const* s2 = &(s->second);
for (ScriptMap::const_iterator iter = s2->begin(); iter != s2->end(); ++iter)
ScriptChain const* s2 = &(s->second);
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();
}
@ -1707,7 +1711,7 @@ void Map::ScriptCommandStart(ScriptInfo const& script, uint32 delay, Object* sou
ObjectGuid targetGuid = target ? target->GetObjectGuid() : 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));
@ -1728,7 +1732,7 @@ void Map::ScriptsProcess()
if (iter->second.HandleScriptStep())
{
// Terminate following script steps of this script
const char* tableName = iter->second.GetTableName();
DBScriptType type = iter->second.GetType();
uint32 id = iter->second.GetId();
ObjectGuid sourceGuid = iter->second.GetSourceGuid();
ObjectGuid targetGuid = iter->second.GetTargetGuid();
@ -1736,7 +1740,7 @@ void Map::ScriptsProcess()
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++);
sScriptMgr.DecreaseScheduledScriptCount();

View File

@ -214,7 +214,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_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);
// must called with AddToWorld

File diff suppressed because it is too large Load Diff

View File

@ -47,6 +47,22 @@ class SpellCastTargets;
class Unit;
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
{
SCRIPTED_UNIT = 0, //CreatureScript
@ -470,18 +486,22 @@ struct ScriptInfo
}
};
typedef std::vector < ScriptInfo > ScriptChain;
typedef std::map < uint32 /*id*/, ScriptChain > ScriptChainMap;
typedef std::vector < ScriptChainMap > DBScripts;
class ScriptAction
{
public:
ScriptAction(const char* _table, 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)
ScriptAction(DBScriptType _type, Map* _map, ObjectGuid _sourceGuid, ObjectGuid _targetGuid, ObjectGuid _ownerGuid, ScriptInfo const* _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
const char* GetTableName() const
DBScriptType GetType() const
{
return m_table;
return m_type;
}
uint32 GetId() const
{
@ -500,16 +520,16 @@ class ScriptAction
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) &&
(targetGuid == m_targetGuid || !targetGuid) &&
(ownerGuid == m_ownerGuid || !ownerGuid);
}
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
ObjectGuid m_sourceGuid;
ObjectGuid m_targetGuid;
@ -526,19 +546,6 @@ class ScriptAction
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
{
@ -556,16 +563,7 @@ class ScriptMgr
std::string GenerateNameToId(ScriptedObjectType sot, uint32 id);
void LoadGameObjectScripts();
void LoadGameObjectTemplateScripts();
void LoadQuestEndScripts();
void LoadQuestStartScripts();
void LoadEventScripts();
void LoadSpellScripts();
void LoadGossipScripts();
void LoadCreatureDeathScripts();
void LoadCreatureMovementScripts();
void LoadDbScripts(DBScriptType type);
void LoadDbScriptStrings();
void LoadScriptNames();
@ -576,15 +574,26 @@ class ScriptMgr
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
{
return id < m_scriptNames.size() ? m_scriptNames[id].c_str() : "";
}
uint32 GetScriptId(const char* name) const;
uint32 GetScriptIdsCount() const
{
return m_scriptNames.size();
}
uint32 GetBoundScriptId(ScriptedObjectType entity, int32 entry);
ScriptLoadResult LoadScriptLibrary(const char* libName);
@ -643,16 +652,16 @@ class ScriptMgr
private:
void CollectPossibleEventIds(std::set<uint32>& eventIds);
void LoadScripts(ScriptMapMapName& scripts, const char* tablename);
void CheckScriptTexts(ScriptMapMapName const& scripts, std::set<int32>& ids);
void LoadScripts(DBScriptType type);
void CheckScriptTexts(std::set<int32>& ids);
typedef std::vector<std::string> ScriptNameMap;
typedef UNORDERED_MAP<int32, uint32> EntryToScriptIdMap;
EntryToScriptIdMap m_scriptBind[SCRIPTED_MAX_TYPE];
ScriptNameMap m_scriptNames;
EntryToScriptIdMap m_scriptBind[SCRIPTED_MAX_TYPE];
ScriptNameMap m_scriptNames;
DBScripts m_dbScripts;
#ifdef _DEBUG
// mutex allowing to reload the script binding table
ACE_RW_Thread_Mutex m_bindMutex;

View File

@ -1331,7 +1331,7 @@ void Spell::EffectDummy(SpellEffectIndex eff_idx)
{ return; }
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::EffectTriggerSpell(SpellEffectIndex eff_idx)
@ -1469,7 +1469,7 @@ void Spell::EffectTriggerMissileSpell(SpellEffectIndex effect_idx)
if (unitTarget)
{
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
sLog.outError("EffectTriggerMissileSpell of spell %u (eff: %u): triggering unknown spell id %u",
@ -3829,7 +3829,7 @@ void Spell::EffectScriptEffect(SpellEffectIndex eff_idx)
{ return; }
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(SpellEffectIndex /*eff_idx*/)

View File

@ -61,9 +61,13 @@ void WaypointManager::Load()
uint32 total_nodes = 0;
uint32 total_behaviors = 0;
ScriptChainMap const* scm = sScriptMgr.GetScriptChainMap(DBS_ON_CREATURE_MOVEMENT);
if (!scm)
return;
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); }
// /////////////////////////////////////////////////////
@ -159,7 +163,7 @@ void WaypointManager::Load()
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);
continue;
@ -314,7 +318,7 @@ void WaypointManager::Load()
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);
continue;
@ -586,7 +590,11 @@ bool WaypointManager::SetNodeScriptId(uint32 entry, uint32 dbGuid, uint32 point,
if (find != path->end())
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)

View File

@ -1188,7 +1188,7 @@ void World::SetInitialWorldSettings()
sObjectMgr.LoadNpcGossips(); // must be after load Creature and LoadGossipText
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();
@ -1201,7 +1201,7 @@ void World::SetInitialWorldSettings()
sObjectMgr.LoadTrainers(); // must be after load CreatureTemplate, TrainerTemplate
sLog.outString("Loading Waypoint scripts..."); // before loading from creature_movement
sScriptMgr.LoadCreatureMovementScripts();
sScriptMgr.LoadDbScripts(DBS_ON_CREATURE_MOVEMENT);
sLog.outString("Loading Waypoints...");
sWaypointMgr.Load();
@ -1258,13 +1258,13 @@ void World::SetInitialWorldSettings()
///- Load and initialize DBScripts Engine
sLog.outString("Loading DB-Scripts Engine...");
sScriptMgr.LoadQuestStartScripts(); // must be after load Creature/Gameobject(Template/Data) and QuestTemplate
sScriptMgr.LoadQuestEndScripts(); // must be after load Creature/Gameobject(Template/Data) and QuestTemplate
sScriptMgr.LoadSpellScripts(); // must be after load Creature/Gameobject(Template/Data)
sScriptMgr.LoadGameObjectScripts(); // must be after load Creature/Gameobject(Template/Data)
sScriptMgr.LoadGameObjectTemplateScripts(); // must be after load Creature/Gameobject(Template/Data)
sScriptMgr.LoadEventScripts(); // must be after load Creature/Gameobject(Template/Data)
sScriptMgr.LoadCreatureDeathScripts(); // must be after load Creature/Gameobject(Template/Data)
sScriptMgr.LoadDbScripts(DBS_ON_QUEST_START); // 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.LoadDbScripts(DBS_ON_SPELL); // must be after load Creature/Gameobject(Template/Data)
sScriptMgr.LoadDbScripts(DBS_ON_GO_USE); // must be after load Creature/Gameobject(Template/Data)
sScriptMgr.LoadDbScripts(DBS_ON_GOT_USE); // must be after load Creature/Gameobject(Template/Data)
sScriptMgr.LoadDbScripts(DBS_ON_EVENT); // must be after load Creature/Gameobject(Template/Data)
sScriptMgr.LoadDbScripts(DBS_ON_CREATURE_DEATH); // must be after load Creature/Gameobject(Template/Data)
sLog.outString(">>> DB Scripts loaded");
sLog.outString();

View File

@ -37,7 +37,7 @@
#define CHAR_DB_UPDATE_DESCRIPTION "characters_pvpstats"
#define WORLD_DB_VERSION_NR 21
#define WORLD_DB_STRUCTURE_NR 6
#define WORLD_DB_STRUCTURE_NR 7
#define WORLD_DB_CONTENT_NR 1
#define WORLD_DB_UPDATE_DESCRIPTION "GM Ticket Additions"
#define WORLD_DB_UPDATE_DESCRIPTION "db_scripts refactor"
#endif // __REVISION_H__