* Cleanup in LoadScripts method and related stuff (use enum instead of string to differentiate between script maps)
* Fix creation of id and sanity checks for spell_scripts. Should fix warnings about missing spells with id > 65535

--HG--
branch : trunk
This commit is contained in:
azazel
2010-08-20 12:19:14 +06:00
parent acc43ea47d
commit a200de3b5f
4 changed files with 134 additions and 83 deletions
+109 -55
View File
@@ -57,6 +57,38 @@ ScriptMapMap sEventScripts;
ScriptMapMap sGossipScripts; ScriptMapMap sGossipScripts;
ScriptMapMap sWaypointScripts; ScriptMapMap sWaypointScripts;
std::string GetScriptsTableNameByType(ScriptsType type)
{
std::string res = "";
switch (type)
{
case SCRIPTS_QUEST_END: res = "quest_end_scripts"; break;
case SCRIPTS_QUEST_START: res = "quest_start_scripts";break;
case SCRIPTS_SPELL: res = "spell_scripts"; break;
case SCRIPTS_GAMEOBJECT: res = "gameobject_scripts"; break;
case SCRIPTS_EVENT: res = "event_scripts"; break;
case SCRIPTS_WAYPOINT: res = "waypoint_scripts"; break;
case SCRIPTS_GOSSIP: res = "gossip_scripts"; break;
}
return res;
}
ScriptMapMap* GetScriptsMapByType(ScriptsType type)
{
ScriptMapMap* res = NULL;
switch (type)
{
case SCRIPTS_QUEST_END: res = &sQuestEndScripts; break;
case SCRIPTS_QUEST_START: res = &sQuestStartScripts; break;
case SCRIPTS_SPELL: res = &sSpellScripts; break;
case SCRIPTS_GAMEOBJECT: res = &sGameObjectScripts; break;
case SCRIPTS_EVENT: res = &sEventScripts; break;
case SCRIPTS_WAYPOINT: res = &sWaypointScripts; break;
case SCRIPTS_GOSSIP: res = &sGossipScripts; break;
}
return res;
}
bool normalizePlayerName(std::string& name) bool normalizePlayerName(std::string& name)
{ {
if (name.empty()) if (name.empty())
@@ -4487,18 +4519,26 @@ void ObjectMgr::LoadQuestLocales()
sLog.outString(">> Loaded %lu Quest locale strings", (unsigned long)mQuestLocaleMap.size()); sLog.outString(">> Loaded %lu Quest locale strings", (unsigned long)mQuestLocaleMap.size());
} }
void ObjectMgr::LoadScripts(ScriptMapMap& scripts, char const* tablename) void ObjectMgr::LoadScripts(ScriptsType type)
{ {
ScriptMapMap *scripts = GetScriptsMapByType(type);
if (!scripts)
return;
std::string tableName = GetScriptsTableNameByType(type);
if (tableName.empty())
return;
if (sWorld.IsScriptScheduled()) // function don't must be called in time scripts use. if (sWorld.IsScriptScheduled()) // function don't must be called in time scripts use.
return; return;
sLog.outString("%s :", tablename); sLog.outString("%s :", tableName.c_str());
scripts.clear(); // need for reload support scripts->clear(); // need for reload support
bool isSpellScriptTable = (type == SCRIPTS_SPELL);
char buff[125]; char buff[125];
bool isSpellScriptTable = !strcmp(tablename, "spell_scripts"); sprintf(buff, "SELECT id,delay,command,datalong,datalong2,dataint,x,y,z,o%s FROM %s", isSpellScriptTable ? ",effIndex" : "", tableName.c_str());
sprintf(buff, "SELECT id,delay,command,datalong,datalong2,dataint,x,y,z,o%s FROM %s", isSpellScriptTable ? ",effIndex" : "", tablename);
QueryResult_AutoPtr result = WorldDatabase.Query(buff); QueryResult_AutoPtr result = WorldDatabase.Query(buff);
uint32 count = 0; uint32 count = 0;
@@ -4523,7 +4563,7 @@ void ObjectMgr::LoadScripts(ScriptMapMap& scripts, char const* tablename)
ScriptInfo tmp; ScriptInfo tmp;
tmp.id = fields[0].GetUInt32(); tmp.id = fields[0].GetUInt32();
if (isSpellScriptTable) if (isSpellScriptTable)
tmp.id |= fields[10].GetUInt32() << 16; tmp.id |= fields[10].GetUInt8() << 24;
tmp.delay = fields[1].GetUInt32(); tmp.delay = fields[1].GetUInt32();
tmp.command = fields[2].GetUInt32(); tmp.command = fields[2].GetUInt32();
tmp.datalong = fields[3].GetUInt32(); tmp.datalong = fields[3].GetUInt32();
@@ -4541,17 +4581,20 @@ void ObjectMgr::LoadScripts(ScriptMapMap& scripts, char const* tablename)
{ {
if (tmp.datalong > CHAT_TYPE_WHISPER) if (tmp.datalong > CHAT_TYPE_WHISPER)
{ {
sLog.outErrorDb("Table `%s` has invalid talk type (datalong = %u) in SCRIPT_COMMAND_TALK for script id %u",tablename,tmp.datalong,tmp.id); sLog.outErrorDb("Table `%s` has invalid talk type (datalong = %u) in SCRIPT_COMMAND_TALK for script id %u",
tableName.c_str(),tmp.datalong,tmp.id);
continue; continue;
} }
if (tmp.dataint == 0) if (tmp.dataint == 0)
{ {
sLog.outErrorDb("Table `%s` has invalid talk text id (dataint = %i) in SCRIPT_COMMAND_TALK for script id %u",tablename,tmp.dataint,tmp.id); sLog.outErrorDb("Table `%s` has invalid talk text id (dataint = %i) in SCRIPT_COMMAND_TALK for script id %u",
tableName.c_str(),tmp.dataint,tmp.id);
continue; continue;
} }
if (tmp.dataint < MIN_DB_SCRIPT_STRING_ID || tmp.dataint >= MAX_DB_SCRIPT_STRING_ID) if (tmp.dataint < MIN_DB_SCRIPT_STRING_ID || tmp.dataint >= MAX_DB_SCRIPT_STRING_ID)
{ {
sLog.outErrorDb("Table `%s` has out of range text id (dataint = %i expected %u-%u) in SCRIPT_COMMAND_TALK for script id %u",tablename,tmp.dataint,MIN_DB_SCRIPT_STRING_ID,MAX_DB_SCRIPT_STRING_ID,tmp.id); sLog.outErrorDb("Table `%s` has out of range text id (dataint = %i expected %u-%u) in SCRIPT_COMMAND_TALK for script id %u",
tableName.c_str(),tmp.dataint,MIN_DB_SCRIPT_STRING_ID,MAX_DB_SCRIPT_STRING_ID,tmp.id);
continue; continue;
} }
@@ -4562,7 +4605,8 @@ void ObjectMgr::LoadScripts(ScriptMapMap& scripts, char const* tablename)
{ {
if (!sEmotesStore.LookupEntry(tmp.datalong)) if (!sEmotesStore.LookupEntry(tmp.datalong))
{ {
sLog.outErrorDb("Table `%s` has invalid emote id (datalong = %u) in SCRIPT_COMMAND_EMOTE for script id %u",tablename,tmp.datalong,tmp.id); sLog.outErrorDb("Table `%s` has invalid emote id (datalong = %u) in SCRIPT_COMMAND_EMOTE for script id %u",
tableName.c_str(),tmp.datalong,tmp.id);
continue; continue;
} }
break; break;
@@ -4572,13 +4616,15 @@ void ObjectMgr::LoadScripts(ScriptMapMap& scripts, char const* tablename)
{ {
if (!sMapStore.LookupEntry(tmp.datalong)) if (!sMapStore.LookupEntry(tmp.datalong))
{ {
sLog.outErrorDb("Table `%s` has invalid map (Id: %u) in SCRIPT_COMMAND_TELEPORT_TO for script id %u",tablename,tmp.datalong,tmp.id); sLog.outErrorDb("Table `%s` has invalid map (Id: %u) in SCRIPT_COMMAND_TELEPORT_TO for script id %u",
tableName.c_str(),tmp.datalong,tmp.id);
continue; continue;
} }
if (!Trinity::IsValidMapCoord(tmp.x,tmp.y,tmp.z,tmp.o)) if (!Trinity::IsValidMapCoord(tmp.x,tmp.y,tmp.z,tmp.o))
{ {
sLog.outErrorDb("Table `%s` has invalid coordinates (X: %f Y: %f) in SCRIPT_COMMAND_TELEPORT_TO for script id %u",tablename,tmp.x,tmp.y,tmp.id); sLog.outErrorDb("Table `%s` has invalid coordinates (X: %f Y: %f) in SCRIPT_COMMAND_TELEPORT_TO for script id %u",
tableName.c_str(),tmp.x,tmp.y,tmp.id);
continue; continue;
} }
break; break;
@@ -4588,7 +4634,8 @@ void ObjectMgr::LoadScripts(ScriptMapMap& scripts, char const* tablename)
{ {
if (!GetCreatureTemplate(tmp.datalong)) if (!GetCreatureTemplate(tmp.datalong))
{ {
sLog.outErrorDb("Table `%s` has invalid creature (Entry: %u) in SCRIPT_COMMAND_KILL_CREDIT for script id %u",tablename,tmp.datalong,tmp.id); sLog.outErrorDb("Table `%s` has invalid creature (Entry: %u) in SCRIPT_COMMAND_KILL_CREDIT for script id %u",
tableName.c_str(),tmp.datalong,tmp.id);
continue; continue;
} }
break; break;
@@ -4598,13 +4645,15 @@ void ObjectMgr::LoadScripts(ScriptMapMap& scripts, char const* tablename)
{ {
if (!Trinity::IsValidMapCoord(tmp.x,tmp.y,tmp.z,tmp.o)) if (!Trinity::IsValidMapCoord(tmp.x,tmp.y,tmp.z,tmp.o))
{ {
sLog.outErrorDb("Table `%s` has invalid coordinates (X: %f Y: %f) in SCRIPT_COMMAND_TEMP_SUMMON_CREATURE for script id %u",tablename,tmp.x,tmp.y,tmp.id); sLog.outErrorDb("Table `%s` has invalid coordinates (X: %f Y: %f) in SCRIPT_COMMAND_TEMP_SUMMON_CREATURE for script id %u",
tableName.c_str(),tmp.x,tmp.y,tmp.id);
continue; continue;
} }
if (!GetCreatureTemplate(tmp.datalong)) if (!GetCreatureTemplate(tmp.datalong))
{ {
sLog.outErrorDb("Table `%s` has invalid creature (Entry: %u) in SCRIPT_COMMAND_TEMP_SUMMON_CREATURE for script id %u",tablename,tmp.datalong,tmp.id); sLog.outErrorDb("Table `%s` has invalid creature (Entry: %u) in SCRIPT_COMMAND_TEMP_SUMMON_CREATURE for script id %u",
tableName.c_str(),tmp.datalong,tmp.id);
continue; continue;
} }
break; break;
@@ -4615,14 +4664,16 @@ void ObjectMgr::LoadScripts(ScriptMapMap& scripts, char const* tablename)
GameObjectData const* data = GetGOData(tmp.datalong); GameObjectData const* data = GetGOData(tmp.datalong);
if (!data) if (!data)
{ {
sLog.outErrorDb("Table `%s` has invalid gameobject (GUID: %u) in SCRIPT_COMMAND_RESPAWN_GAMEOBJECT for script id %u",tablename,tmp.datalong,tmp.id); sLog.outErrorDb("Table `%s` has invalid gameobject (GUID: %u) in SCRIPT_COMMAND_RESPAWN_GAMEOBJECT for script id %u",
tableName.c_str(),tmp.datalong,tmp.id);
continue; continue;
} }
GameObjectInfo const* info = GetGameObjectInfo(data->id); GameObjectInfo const* info = GetGameObjectInfo(data->id);
if (!info) if (!info)
{ {
sLog.outErrorDb("Table `%s` has gameobject with invalid entry (GUID: %u Entry: %u) in SCRIPT_COMMAND_RESPAWN_GAMEOBJECT for script id %u",tablename,tmp.datalong,data->id,tmp.id); sLog.outErrorDb("Table `%s` has gameobject with invalid entry (GUID: %u Entry: %u) in SCRIPT_COMMAND_RESPAWN_GAMEOBJECT for script id %u",
tableName.c_str(),tmp.datalong,data->id,tmp.id);
continue; continue;
} }
@@ -4632,7 +4683,8 @@ void ObjectMgr::LoadScripts(ScriptMapMap& scripts, char const* tablename)
info->type == GAMEOBJECT_TYPE_BUTTON || info->type == GAMEOBJECT_TYPE_BUTTON ||
info->type == GAMEOBJECT_TYPE_TRAP) info->type == GAMEOBJECT_TYPE_TRAP)
{ {
sLog.outErrorDb("Table `%s` have gameobject type (%u) unsupported by command SCRIPT_COMMAND_RESPAWN_GAMEOBJECT for script id %u",tablename,info->id,tmp.id); sLog.outErrorDb("Table `%s` have gameobject type (%u) unsupported by command SCRIPT_COMMAND_RESPAWN_GAMEOBJECT for script id %u",
tableName.c_str(),info->id,tmp.id);
continue; continue;
} }
break; break;
@@ -4643,20 +4695,22 @@ void ObjectMgr::LoadScripts(ScriptMapMap& scripts, char const* tablename)
GameObjectData const* data = GetGOData(tmp.datalong); GameObjectData const* data = GetGOData(tmp.datalong);
if (!data) if (!data)
{ {
sLog.outErrorDb("Table `%s` has invalid gameobject (GUID: %u) in %s for script id %u",tablename,tmp.datalong,(tmp.command == SCRIPT_COMMAND_OPEN_DOOR ? "SCRIPT_COMMAND_OPEN_DOOR" : "SCRIPT_COMMAND_CLOSE_DOOR"),tmp.id); sLog.outErrorDb("Table `%s` has invalid gameobject (GUID: %u) in %s for script id %u",
tableName.c_str(),tmp.datalong,(tmp.command == SCRIPT_COMMAND_OPEN_DOOR ? "SCRIPT_COMMAND_OPEN_DOOR" : "SCRIPT_COMMAND_CLOSE_DOOR"),tmp.id);
continue; continue;
} }
GameObjectInfo const* info = GetGameObjectInfo(data->id); GameObjectInfo const* info = GetGameObjectInfo(data->id);
if (!info) if (!info)
{ {
sLog.outErrorDb("Table `%s` has gameobject with invalid entry (GUID: %u Entry: %u) in %s for script id %u",tablename,tmp.datalong,data->id,(tmp.command == SCRIPT_COMMAND_OPEN_DOOR ? "SCRIPT_COMMAND_OPEN_DOOR" : "SCRIPT_COMMAND_CLOSE_DOOR"),tmp.id); sLog.outErrorDb("Table `%s` has gameobject with invalid entry (GUID: %u Entry: %u) in %s for script id %u",
tableName.c_str(),tmp.datalong,data->id,(tmp.command == SCRIPT_COMMAND_OPEN_DOOR ? "SCRIPT_COMMAND_OPEN_DOOR" : "SCRIPT_COMMAND_CLOSE_DOOR"),tmp.id);
continue; continue;
} }
if (info->type != GAMEOBJECT_TYPE_DOOR) if (info->type != GAMEOBJECT_TYPE_DOOR)
{ {
sLog.outErrorDb("Table `%s` has gameobject type (%u) non supported by command %s for script id %u",tablename,info->id,(tmp.command == SCRIPT_COMMAND_OPEN_DOOR ? "SCRIPT_COMMAND_OPEN_DOOR" : "SCRIPT_COMMAND_CLOSE_DOOR"),tmp.id); sLog.outErrorDb("Table `%s` has gameobject type (%u) non supported by command %s for script id %u",tableName.c_str(),info->id,(tmp.command == SCRIPT_COMMAND_OPEN_DOOR ? "SCRIPT_COMMAND_OPEN_DOOR" : "SCRIPT_COMMAND_CLOSE_DOOR"),tmp.id);
continue; continue;
} }
@@ -4667,13 +4721,15 @@ void ObjectMgr::LoadScripts(ScriptMapMap& scripts, char const* tablename)
Quest const* quest = GetQuestTemplate(tmp.datalong); Quest const* quest = GetQuestTemplate(tmp.datalong);
if (!quest) if (!quest)
{ {
sLog.outErrorDb("Table `%s` has invalid quest (ID: %u) in SCRIPT_COMMAND_QUEST_EXPLORED in `datalong` for script id %u",tablename,tmp.datalong,tmp.id); sLog.outErrorDb("Table `%s` has invalid quest (ID: %u) in SCRIPT_COMMAND_QUEST_EXPLORED in `datalong` for script id %u",
tableName.c_str(),tmp.datalong,tmp.id);
continue; continue;
} }
if (!quest->HasFlag(QUEST_TRINITY_FLAGS_EXPLORATION_OR_EVENT)) if (!quest->HasFlag(QUEST_TRINITY_FLAGS_EXPLORATION_OR_EVENT))
{ {
sLog.outErrorDb("Table `%s` has quest (ID: %u) in SCRIPT_COMMAND_QUEST_EXPLORED in `datalong` for script id %u, but quest not have flag QUEST_TRINITY_FLAGS_EXPLORATION_OR_EVENT in quest flags. Script command or quest flags wrong. Quest modified to require objective.",tablename,tmp.datalong,tmp.id); sLog.outErrorDb("Table `%s` has quest (ID: %u) in SCRIPT_COMMAND_QUEST_EXPLORED in `datalong` for script id %u, but quest not have flag QUEST_TRINITY_FLAGS_EXPLORATION_OR_EVENT in quest flags. Script command or quest flags wrong. Quest modified to require objective.",
tableName.c_str(),tmp.datalong,tmp.id);
// this will prevent quest completing without objective // this will prevent quest completing without objective
const_cast<Quest*>(quest)->SetFlag(QUEST_TRINITY_FLAGS_EXPLORATION_OR_EVENT); const_cast<Quest*>(quest)->SetFlag(QUEST_TRINITY_FLAGS_EXPLORATION_OR_EVENT);
@@ -4684,21 +4740,21 @@ void ObjectMgr::LoadScripts(ScriptMapMap& scripts, char const* tablename)
if (float(tmp.datalong2) > DEFAULT_VISIBILITY_DISTANCE) if (float(tmp.datalong2) > DEFAULT_VISIBILITY_DISTANCE)
{ {
sLog.outErrorDb("Table `%s` has too large distance (%u) for exploring objective complete in `datalong2` in SCRIPT_COMMAND_QUEST_EXPLORED in `datalong` for script id %u", sLog.outErrorDb("Table `%s` has too large distance (%u) for exploring objective complete in `datalong2` in SCRIPT_COMMAND_QUEST_EXPLORED in `datalong` for script id %u",
tablename,tmp.datalong2,tmp.id); tableName.c_str(),tmp.datalong2,tmp.id);
continue; continue;
} }
if (tmp.datalong2 && float(tmp.datalong2) > DEFAULT_VISIBILITY_DISTANCE) if (tmp.datalong2 && float(tmp.datalong2) > DEFAULT_VISIBILITY_DISTANCE)
{ {
sLog.outErrorDb("Table `%s` has too large distance (%u) for exploring objective complete in `datalong2` in SCRIPT_COMMAND_QUEST_EXPLORED in `datalong` for script id %u, max distance is %f or 0 for disable distance check", sLog.outErrorDb("Table `%s` has too large distance (%u) for exploring objective complete in `datalong2` in SCRIPT_COMMAND_QUEST_EXPLORED in `datalong` for script id %u, max distance is %f or 0 for disable distance check",
tablename,tmp.datalong2,tmp.id,DEFAULT_VISIBILITY_DISTANCE); tableName.c_str(),tmp.datalong2,tmp.id,DEFAULT_VISIBILITY_DISTANCE);
continue; continue;
} }
if (tmp.datalong2 && float(tmp.datalong2) < INTERACTION_DISTANCE) if (tmp.datalong2 && float(tmp.datalong2) < INTERACTION_DISTANCE)
{ {
sLog.outErrorDb("Table `%s` has too small distance (%u) for exploring objective complete in `datalong2` in SCRIPT_COMMAND_QUEST_EXPLORED in `datalong` for script id %u, min distance is %f or 0 for disable distance check", sLog.outErrorDb("Table `%s` has too small distance (%u) for exploring objective complete in `datalong2` in SCRIPT_COMMAND_QUEST_EXPLORED in `datalong` for script id %u, min distance is %f or 0 for disable distance check",
tablename,tmp.datalong2,tmp.id,INTERACTION_DISTANCE); tableName.c_str(),tmp.datalong2,tmp.id,INTERACTION_DISTANCE);
continue; continue;
} }
@@ -4710,13 +4766,13 @@ void ObjectMgr::LoadScripts(ScriptMapMap& scripts, char const* tablename)
if (!sSpellStore.LookupEntry(tmp.datalong)) if (!sSpellStore.LookupEntry(tmp.datalong))
{ {
sLog.outErrorDb("Table `%s` using non-existent spell (id: %u) in SCRIPT_COMMAND_REMOVE_AURA for script id %u", sLog.outErrorDb("Table `%s` using non-existent spell (id: %u) in SCRIPT_COMMAND_REMOVE_AURA for script id %u",
tablename,tmp.datalong,tmp.id); tableName.c_str(),tmp.datalong,tmp.id);
continue; continue;
} }
if (tmp.datalong2 & ~0x1) // 1 bits (0,1) if (tmp.datalong2 & ~0x1) // 1 bits (0,1)
{ {
sLog.outErrorDb("Table `%s` using unknown flags in datalong2 (%u) in SCRIPT_COMMAND_REMOVE_AURA for script id %u", sLog.outErrorDb("Table `%s` using unknown flags in datalong2 (%u) in SCRIPT_COMMAND_REMOVE_AURA for script id %u",
tablename,tmp.datalong2,tmp.id); tableName.c_str(),tmp.datalong2,tmp.id);
continue; continue;
} }
break; break;
@@ -4726,25 +4782,25 @@ void ObjectMgr::LoadScripts(ScriptMapMap& scripts, char const* tablename)
if (!sSpellStore.LookupEntry(tmp.datalong)) if (!sSpellStore.LookupEntry(tmp.datalong))
{ {
sLog.outErrorDb("Table `%s` using non-existent spell (id: %u) in SCRIPT_COMMAND_CAST_SPELL for script id %u", sLog.outErrorDb("Table `%s` using non-existent spell (id: %u) in SCRIPT_COMMAND_CAST_SPELL for script id %u",
tablename,tmp.datalong,tmp.id); tableName.c_str(),tmp.datalong,tmp.id);
continue; continue;
} }
if (tmp.datalong2 > 4) // targeting type if (tmp.datalong2 > 4) // targeting type
{ {
sLog.outErrorDb("Table `%s` using unknown target in datalong2 (%u) in SCRIPT_COMMAND_CAST_SPELL for script id %u", sLog.outErrorDb("Table `%s` using unknown target in datalong2 (%u) in SCRIPT_COMMAND_CAST_SPELL for script id %u",
tablename,tmp.datalong2,tmp.id); tableName.c_str(),tmp.datalong2,tmp.id);
continue; continue;
} }
if (tmp.datalong2 != 4 && tmp.dataint & ~0x1) // 1 bit (0,1) if (tmp.datalong2 != 4 && tmp.dataint & ~0x1) // 1 bit (0,1)
{ {
sLog.outErrorDb("Table `%s` using unknown flags in dataint (%u) in SCRIPT_COMMAND_CAST_SPELL for script id %u", sLog.outErrorDb("Table `%s` using unknown flags in dataint (%u) in SCRIPT_COMMAND_CAST_SPELL for script id %u",
tablename,tmp.dataint,tmp.id); tableName.c_str(),tmp.dataint,tmp.id);
continue; continue;
} }
else if (tmp.datalong2 == 4 && !GetCreatureTemplate(tmp.dataint)) else if (tmp.datalong2 == 4 && !GetCreatureTemplate(tmp.dataint))
{ {
sLog.outErrorDb("Table `%s` using invalid creature entry in dataint (%u) in SCRIPT_COMMAND_CAST_SPELL for script id %u", sLog.outErrorDb("Table `%s` using invalid creature entry in dataint (%u) in SCRIPT_COMMAND_CAST_SPELL for script id %u",
tablename,tmp.dataint,tmp.id); tableName.c_str(),tmp.dataint,tmp.id);
continue; continue;
} }
break; break;
@@ -4755,25 +4811,25 @@ void ObjectMgr::LoadScripts(ScriptMapMap& scripts, char const* tablename)
if (!GetItemPrototype(tmp.datalong)) if (!GetItemPrototype(tmp.datalong))
{ {
sLog.outErrorDb("Table `%s` has nonexistent item (entry: %u) in SCRIPT_COMMAND_CREATE_ITEM for script id %u", sLog.outErrorDb("Table `%s` has nonexistent item (entry: %u) in SCRIPT_COMMAND_CREATE_ITEM for script id %u",
tablename, tmp.datalong, tmp.id); tableName.c_str(), tmp.datalong, tmp.id);
continue; continue;
} }
if (!tmp.datalong2) if (!tmp.datalong2)
{ {
sLog.outErrorDb("Table `%s` SCRIPT_COMMAND_CREATE_ITEM but amount is %u for script id %u", sLog.outErrorDb("Table `%s` SCRIPT_COMMAND_CREATE_ITEM but amount is %u for script id %u",
tablename, tmp.datalong2, tmp.id); tableName.c_str(), tmp.datalong2, tmp.id);
continue; continue;
} }
break; break;
} }
} }
if (scripts.find(tmp.id) == scripts.end()) if (scripts->find(tmp.id) == scripts->end())
{ {
ScriptMap emptyMap; ScriptMap emptyMap;
scripts[tmp.id] = emptyMap; (*scripts)[tmp.id] = emptyMap;
} }
scripts[tmp.id].insert(std::pair<uint32, ScriptInfo>(tmp.delay, tmp)); (*scripts)[tmp.id].insert(std::pair<uint32, ScriptInfo>(tmp.delay, tmp));
++count; ++count;
} while (result->NextRow()); } while (result->NextRow());
@@ -4784,7 +4840,7 @@ void ObjectMgr::LoadScripts(ScriptMapMap& scripts, char const* tablename)
void ObjectMgr::LoadGameObjectScripts() void ObjectMgr::LoadGameObjectScripts()
{ {
LoadScripts(sGameObjectScripts, "gameobject_scripts"); LoadScripts(SCRIPTS_GAMEOBJECT);
// check ids // check ids
for (ScriptMapMap::const_iterator itr = sGameObjectScripts.begin(); itr != sGameObjectScripts.end(); ++itr) for (ScriptMapMap::const_iterator itr = sGameObjectScripts.begin(); itr != sGameObjectScripts.end(); ++itr)
@@ -4796,7 +4852,7 @@ void ObjectMgr::LoadGameObjectScripts()
void ObjectMgr::LoadQuestEndScripts() void ObjectMgr::LoadQuestEndScripts()
{ {
LoadScripts(sQuestEndScripts, "quest_end_scripts"); LoadScripts(SCRIPTS_QUEST_END);
// check ids // check ids
for (ScriptMapMap::const_iterator itr = sQuestEndScripts.begin(); itr != sQuestEndScripts.end(); ++itr) for (ScriptMapMap::const_iterator itr = sQuestEndScripts.begin(); itr != sQuestEndScripts.end(); ++itr)
@@ -4808,7 +4864,7 @@ void ObjectMgr::LoadQuestEndScripts()
void ObjectMgr::LoadQuestStartScripts() void ObjectMgr::LoadQuestStartScripts()
{ {
LoadScripts(sQuestStartScripts,"quest_start_scripts"); LoadScripts(SCRIPTS_QUEST_START);
// check ids // check ids
for (ScriptMapMap::const_iterator itr = sQuestStartScripts.begin(); itr != sQuestStartScripts.end(); ++itr) for (ScriptMapMap::const_iterator itr = sQuestStartScripts.begin(); itr != sQuestStartScripts.end(); ++itr)
@@ -4820,12 +4876,12 @@ void ObjectMgr::LoadQuestStartScripts()
void ObjectMgr::LoadSpellScripts() void ObjectMgr::LoadSpellScripts()
{ {
LoadScripts(sSpellScripts, "spell_scripts"); LoadScripts(SCRIPTS_SPELL);
// check ids // check ids
for (ScriptMapMap::const_iterator itr = sSpellScripts.begin(); itr != sSpellScripts.end(); ++itr) for (ScriptMapMap::const_iterator itr = sSpellScripts.begin(); itr != sSpellScripts.end(); ++itr)
{ {
uint32 spellId = PAIR32_LOPART(itr->first); uint32 spellId = uint32(itr->first) & 0x00FFFFFF;
SpellEntry const* spellInfo = sSpellStore.LookupEntry(spellId); SpellEntry const* spellInfo = sSpellStore.LookupEntry(spellId);
if (!spellInfo) if (!spellInfo)
@@ -4834,7 +4890,7 @@ void ObjectMgr::LoadSpellScripts()
continue; continue;
} }
uint32 i = PAIR32_HIPART(itr->first); uint8 i = (uint8)((uint32(itr->first) >> 24) & 0x000000FF);
//check for correct spellEffect //check for correct spellEffect
if (!spellInfo->Effect[i] || (spellInfo->Effect[i] != SPELL_EFFECT_SCRIPT_EFFECT && spellInfo->Effect[i] != SPELL_EFFECT_DUMMY)) if (!spellInfo->Effect[i] || (spellInfo->Effect[i] != SPELL_EFFECT_SCRIPT_EFFECT && spellInfo->Effect[i] != SPELL_EFFECT_DUMMY))
sLog.outErrorDb("Table `spell_scripts` - spell %u effect %u is not SPELL_EFFECT_SCRIPT_EFFECT or SPELL_EFFECT_DUMMY", spellId, i); sLog.outErrorDb("Table `spell_scripts` - spell %u effect %u is not SPELL_EFFECT_SCRIPT_EFFECT or SPELL_EFFECT_DUMMY", spellId, i);
@@ -4843,7 +4899,7 @@ void ObjectMgr::LoadSpellScripts()
void ObjectMgr::LoadEventScripts() void ObjectMgr::LoadEventScripts()
{ {
LoadScripts(sEventScripts, "event_scripts"); LoadScripts(SCRIPTS_EVENT);
std::set<uint32> evt_scripts; std::set<uint32> evt_scripts;
// Load all possible script entries from gameobjects // Load all possible script entries from gameobjects
@@ -4897,7 +4953,7 @@ void ObjectMgr::LoadEventScripts()
//Load WP Scripts //Load WP Scripts
void ObjectMgr::LoadWaypointScripts() void ObjectMgr::LoadWaypointScripts()
{ {
LoadScripts(sWaypointScripts, "waypoint_scripts"); LoadScripts(SCRIPTS_WAYPOINT);
for (ScriptMapMap::const_iterator itr = sWaypointScripts.begin(); itr != sWaypointScripts.end(); ++itr) for (ScriptMapMap::const_iterator itr = sWaypointScripts.begin(); itr != sWaypointScripts.end(); ++itr)
{ {
@@ -5009,7 +5065,7 @@ void ObjectMgr::ValidateSpellScripts()
void ObjectMgr::LoadGossipScripts() void ObjectMgr::LoadGossipScripts()
{ {
LoadScripts(sGossipScripts, "gossip_scripts"); LoadScripts(SCRIPTS_GOSSIP);
// checks are done in LoadGossipMenuItems // checks are done in LoadGossipMenuItems
} }
@@ -8749,9 +8805,12 @@ uint32 ObjectMgr::GetScriptId(const char *name)
return itr - m_scriptNames.begin(); return itr - m_scriptNames.begin();
} }
void ObjectMgr::CheckScripts(ScriptMapMap const& scripts,std::set<int32>& ids) void ObjectMgr::CheckScripts(ScriptsType type, std::set<int32>& ids)
{ {
for (ScriptMapMap::const_iterator itrMM = scripts.begin(); itrMM != scripts.end(); ++itrMM) ScriptMapMap *scripts = GetScriptsMapByType(type);
if (!scripts)
return;
for (ScriptMapMap::const_iterator itrMM = scripts->begin(); itrMM != scripts->end(); ++itrMM)
{ {
for (ScriptMap::const_iterator itrM = itrMM->second.begin(); itrM != itrMM->second.end(); ++itrM) for (ScriptMap::const_iterator itrM = itrMM->second.begin(); itrM != itrMM->second.end(); ++itrM)
{ {
@@ -8780,13 +8839,8 @@ void ObjectMgr::LoadDbScriptStrings()
if (GetTrinityStringLocale(i)) if (GetTrinityStringLocale(i))
ids.insert(i); ids.insert(i);
CheckScripts(sQuestEndScripts,ids); for (int type = SCRIPTS_FIRST; type < SCRIPTS_LAST; ++type)
CheckScripts(sQuestStartScripts,ids); CheckScripts(ScriptsType(type), ids);
CheckScripts(sSpellScripts,ids);
CheckScripts(sGameObjectScripts,ids);
CheckScripts(sEventScripts,ids);
CheckScripts(sWaypointScripts,ids);
for (std::set<int32>::const_iterator itr = ids.begin(); itr != ids.end(); ++itr) for (std::set<int32>::const_iterator itr = ids.begin(); itr != ids.end(); ++itr)
sLog.outErrorDb("Table `db_script_string` has unused string id %u", *itr); sLog.outErrorDb("Table `db_script_string` has unused string id %u", *itr);
+20 -2
View File
@@ -88,6 +88,21 @@ struct ScriptInfo
float o; float o;
}; };
enum ScriptsType
{
SCRIPTS_FIRST = 1,
SCRIPTS_QUEST_END = SCRIPTS_FIRST,
SCRIPTS_QUEST_START,
SCRIPTS_SPELL,
SCRIPTS_GAMEOBJECT,
SCRIPTS_EVENT,
SCRIPTS_WAYPOINT,
SCRIPTS_GOSSIP,
SCRIPTS_LAST
};
typedef std::multimap<uint32, ScriptInfo> ScriptMap; typedef std::multimap<uint32, ScriptInfo> ScriptMap;
typedef std::map<uint32, ScriptMap > ScriptMapMap; typedef std::map<uint32, ScriptMap > ScriptMapMap;
typedef std::multimap<uint32, uint32> SpellScriptsMap; typedef std::multimap<uint32, uint32> SpellScriptsMap;
@@ -100,6 +115,9 @@ extern ScriptMapMap sEventScripts;
extern ScriptMapMap sGossipScripts; extern ScriptMapMap sGossipScripts;
extern ScriptMapMap sWaypointScripts; extern ScriptMapMap sWaypointScripts;
std::string GetScriptsTableNameByType(ScriptsType type);
ScriptMapMap* GetScriptsMapByType(ScriptsType type);
struct SpellClickInfo struct SpellClickInfo
{ {
uint32 spellId; uint32 spellId;
@@ -1041,8 +1059,8 @@ class ObjectMgr
int DBCLocaleIndex; int DBCLocaleIndex;
private: private:
void LoadScripts(ScriptMapMap& scripts, char const* tablename); void LoadScripts(ScriptsType type);
void CheckScripts(ScriptMapMap const& scripts,std::set<int32>& ids); void CheckScripts(ScriptsType type, std::set<int32>& ids);
void LoadCreatureAddons(SQLStorage& creatureaddons, char const* entryName, char const* comment); void LoadCreatureAddons(SQLStorage& creatureaddons, char const* entryName, char const* comment);
void ConvertCreatureAddonAuras(CreatureDataAddon* addon, char const* table, char const* guidEntryStr); void ConvertCreatureAddonAuras(CreatureDataAddon* addon, char const* table, char const* guidEntryStr);
void LoadQuestRelationsHelper(QuestRelations& map,char const* table); void LoadQuestRelationsHelper(QuestRelations& map,char const* table);
+3 -24
View File
@@ -3440,34 +3440,13 @@ void Map::ScriptsProcess()
} }
//Lets choose our ScriptMap map //Lets choose our ScriptMap map
ScriptMapMap *datamap = NULL; ScriptMapMap *datamap = GetScriptsMapByType(ScriptsType(step.script->dataint));
switch (step.script->dataint) //if no scriptmap present...
if (!datamap)
{ {
case 1: //QUEST END SCRIPTMAP
datamap = &sQuestEndScripts;
break;
case 2: //QUEST START SCRIPTMAP
datamap = &sQuestStartScripts;
break;
case 3: //SPELLS SCRIPTMAP
datamap = &sSpellScripts;
break;
case 4: //GAMEOBJECTS SCRIPTMAP
datamap = &sGameObjectScripts;
break;
case 5: //EVENTS SCRIPTMAP
datamap = &sEventScripts;
break;
case 6: //WAYPOINTS SCRIPTMAP
datamap = &sWaypointScripts;
break;
default:
sLog.outError("SCRIPT_COMMAND_CALLSCRIPT (script id: %u) unknown scriptmap (%u) specified, skipping.", step.script->id, step.script->dataint); sLog.outError("SCRIPT_COMMAND_CALLSCRIPT (script id: %u) unknown scriptmap (%u) specified, skipping.", step.script->id, step.script->dataint);
break; break;
} }
//if no scriptmap present...
if (!datamap)
break;
// Insert script into schedule but do not start it // Insert script into schedule but do not start it
ScriptsStart(*datamap, step.script->datalong2, cTarget, NULL); ScriptsStart(*datamap, step.script->datalong2, cTarget, NULL);
+1 -1
View File
@@ -460,7 +460,7 @@ enum ScriptCommands
SCRIPT_COMMAND_DESPAWN_SELF = 18, // target/source = Creature, datalong = despawn delay SCRIPT_COMMAND_DESPAWN_SELF = 18, // target/source = Creature, datalong = despawn delay
SCRIPT_COMMAND_LOAD_PATH = 20, // source = Unit, datalong = path id, datalong2 = is repeatable SCRIPT_COMMAND_LOAD_PATH = 20, // source = Unit, datalong = path id, datalong2 = is repeatable
SCRIPT_COMMAND_CALLSCRIPT_TO_UNIT = 21, // source = WorldObject (if present used as a search center), datalong = script id, datalong2 = unit lowguid, dataint = script table to use SCRIPT_COMMAND_CALLSCRIPT_TO_UNIT = 21, // source = WorldObject (if present used as a search center), datalong = script id, datalong2 = unit lowguid, dataint = script table to use (see ScriptsType)
SCRIPT_COMMAND_KILL = 22, // source/target = Creature, dataint = remove corpse attribute SCRIPT_COMMAND_KILL = 22, // source/target = Creature, dataint = remove corpse attribute
// TrinityCore only // TrinityCore only