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

@ -98,7 +98,7 @@ Map::Map(uint32 id, time_t expiry, uint32 InstanceId, uint8 SpawnMode)
m_VisibleDistance(DEFAULT_VISIBILITY_DISTANCE), m_persistentState(NULL),
m_activeNonPlayersIter(m_activeNonPlayers.end()),
i_gridExpiry(expiry), m_TerrainData(sTerrainMgr.LoadTerrain(id)),
i_data(NULL), i_script_id(0)
i_data(NULL)
{
m_CreatureGuids.Set(sObjectMgr.GetFirstTemporaryCreatureLowGuid());
m_GameObjectGuids.Set(sObjectMgr.GetFirstTemporaryGameObjectLowGuid());
@ -1743,13 +1743,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
@ -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)
{
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();
}
@ -1794,7 +1798,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));
@ -1815,7 +1819,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();
@ -1823,7 +1827,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();