diff options
| -rw-r--r-- | src/server/game/Globals/ObjectMgr.cpp | 164 | ||||
| -rw-r--r-- | src/server/game/Globals/ObjectMgr.h | 22 | ||||
| -rw-r--r-- | src/server/game/Maps/Map.cpp | 29 | ||||
| -rw-r--r-- | src/server/game/World/World.h | 2 |
4 files changed, 134 insertions, 83 deletions
diff --git a/src/server/game/Globals/ObjectMgr.cpp b/src/server/game/Globals/ObjectMgr.cpp index 7a54f49e2b9..65f7b3575d7 100644 --- a/src/server/game/Globals/ObjectMgr.cpp +++ b/src/server/game/Globals/ObjectMgr.cpp @@ -57,6 +57,38 @@ ScriptMapMap sEventScripts; ScriptMapMap sGossipScripts; 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) { if (name.empty()) @@ -4487,18 +4519,26 @@ void ObjectMgr::LoadQuestLocales() 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. 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]; - 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); + sprintf(buff, "SELECT id,delay,command,datalong,datalong2,dataint,x,y,z,o%s FROM %s", isSpellScriptTable ? ",effIndex" : "", tableName.c_str()); QueryResult_AutoPtr result = WorldDatabase.Query(buff); uint32 count = 0; @@ -4523,7 +4563,7 @@ void ObjectMgr::LoadScripts(ScriptMapMap& scripts, char const* tablename) ScriptInfo tmp; tmp.id = fields[0].GetUInt32(); if (isSpellScriptTable) - tmp.id |= fields[10].GetUInt32() << 16; + tmp.id |= fields[10].GetUInt8() << 24; tmp.delay = fields[1].GetUInt32(); tmp.command = fields[2].GetUInt32(); tmp.datalong = fields[3].GetUInt32(); @@ -4541,17 +4581,20 @@ void ObjectMgr::LoadScripts(ScriptMapMap& scripts, char const* tablename) { 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; } 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; } 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; } @@ -4562,7 +4605,8 @@ void ObjectMgr::LoadScripts(ScriptMapMap& scripts, char const* tablename) { 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; } break; @@ -4572,13 +4616,15 @@ void ObjectMgr::LoadScripts(ScriptMapMap& scripts, char const* tablename) { 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; } 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; } break; @@ -4588,7 +4634,8 @@ void ObjectMgr::LoadScripts(ScriptMapMap& scripts, char const* tablename) { 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; } break; @@ -4598,13 +4645,15 @@ void ObjectMgr::LoadScripts(ScriptMapMap& scripts, char const* tablename) { 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; } 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; } break; @@ -4615,14 +4664,16 @@ void ObjectMgr::LoadScripts(ScriptMapMap& scripts, char const* tablename) GameObjectData const* data = GetGOData(tmp.datalong); 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; } GameObjectInfo const* info = GetGameObjectInfo(data->id); 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; } @@ -4632,7 +4683,8 @@ void ObjectMgr::LoadScripts(ScriptMapMap& scripts, char const* tablename) info->type == GAMEOBJECT_TYPE_BUTTON || 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; } break; @@ -4643,20 +4695,22 @@ void ObjectMgr::LoadScripts(ScriptMapMap& scripts, char const* tablename) GameObjectData const* data = GetGOData(tmp.datalong); 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; } GameObjectInfo const* info = GetGameObjectInfo(data->id); 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; } 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; } @@ -4667,13 +4721,15 @@ void ObjectMgr::LoadScripts(ScriptMapMap& scripts, char const* tablename) Quest const* quest = GetQuestTemplate(tmp.datalong); 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; } 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 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) { 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; } 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", - tablename,tmp.datalong2,tmp.id,DEFAULT_VISIBILITY_DISTANCE); + tableName.c_str(),tmp.datalong2,tmp.id,DEFAULT_VISIBILITY_DISTANCE); continue; } 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", - tablename,tmp.datalong2,tmp.id,INTERACTION_DISTANCE); + tableName.c_str(),tmp.datalong2,tmp.id,INTERACTION_DISTANCE); continue; } @@ -4710,13 +4766,13 @@ void ObjectMgr::LoadScripts(ScriptMapMap& scripts, char const* tablename) if (!sSpellStore.LookupEntry(tmp.datalong)) { 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; } 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", - tablename,tmp.datalong2,tmp.id); + tableName.c_str(),tmp.datalong2,tmp.id); continue; } break; @@ -4726,25 +4782,25 @@ void ObjectMgr::LoadScripts(ScriptMapMap& scripts, char const* tablename) if (!sSpellStore.LookupEntry(tmp.datalong)) { 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; } 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", - tablename,tmp.datalong2,tmp.id); + tableName.c_str(),tmp.datalong2,tmp.id); continue; } 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", - tablename,tmp.dataint,tmp.id); + tableName.c_str(),tmp.dataint,tmp.id); continue; } 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", - tablename,tmp.dataint,tmp.id); + tableName.c_str(),tmp.dataint,tmp.id); continue; } break; @@ -4755,25 +4811,25 @@ void ObjectMgr::LoadScripts(ScriptMapMap& scripts, char const* tablename) if (!GetItemPrototype(tmp.datalong)) { 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; } if (!tmp.datalong2) { 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; } break; } } - if (scripts.find(tmp.id) == scripts.end()) + if (scripts->find(tmp.id) == scripts->end()) { 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; } while (result->NextRow()); @@ -4784,7 +4840,7 @@ void ObjectMgr::LoadScripts(ScriptMapMap& scripts, char const* tablename) void ObjectMgr::LoadGameObjectScripts() { - LoadScripts(sGameObjectScripts, "gameobject_scripts"); + LoadScripts(SCRIPTS_GAMEOBJECT); // check ids for (ScriptMapMap::const_iterator itr = sGameObjectScripts.begin(); itr != sGameObjectScripts.end(); ++itr) @@ -4796,7 +4852,7 @@ void ObjectMgr::LoadGameObjectScripts() void ObjectMgr::LoadQuestEndScripts() { - LoadScripts(sQuestEndScripts, "quest_end_scripts"); + LoadScripts(SCRIPTS_QUEST_END); // check ids for (ScriptMapMap::const_iterator itr = sQuestEndScripts.begin(); itr != sQuestEndScripts.end(); ++itr) @@ -4808,7 +4864,7 @@ void ObjectMgr::LoadQuestEndScripts() void ObjectMgr::LoadQuestStartScripts() { - LoadScripts(sQuestStartScripts,"quest_start_scripts"); + LoadScripts(SCRIPTS_QUEST_START); // check ids for (ScriptMapMap::const_iterator itr = sQuestStartScripts.begin(); itr != sQuestStartScripts.end(); ++itr) @@ -4820,12 +4876,12 @@ void ObjectMgr::LoadQuestStartScripts() void ObjectMgr::LoadSpellScripts() { - LoadScripts(sSpellScripts, "spell_scripts"); + LoadScripts(SCRIPTS_SPELL); // check ids 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); if (!spellInfo) @@ -4834,7 +4890,7 @@ void ObjectMgr::LoadSpellScripts() continue; } - uint32 i = PAIR32_HIPART(itr->first); + uint8 i = (uint8)((uint32(itr->first) >> 24) & 0x000000FF); //check for correct spellEffect 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); @@ -4843,7 +4899,7 @@ void ObjectMgr::LoadSpellScripts() void ObjectMgr::LoadEventScripts() { - LoadScripts(sEventScripts, "event_scripts"); + LoadScripts(SCRIPTS_EVENT); std::set<uint32> evt_scripts; // Load all possible script entries from gameobjects @@ -4897,7 +4953,7 @@ void ObjectMgr::LoadEventScripts() //Load WP Scripts void ObjectMgr::LoadWaypointScripts() { - LoadScripts(sWaypointScripts, "waypoint_scripts"); + LoadScripts(SCRIPTS_WAYPOINT); for (ScriptMapMap::const_iterator itr = sWaypointScripts.begin(); itr != sWaypointScripts.end(); ++itr) { @@ -5009,7 +5065,7 @@ void ObjectMgr::ValidateSpellScripts() void ObjectMgr::LoadGossipScripts() { - LoadScripts(sGossipScripts, "gossip_scripts"); + LoadScripts(SCRIPTS_GOSSIP); // checks are done in LoadGossipMenuItems } @@ -8749,9 +8805,12 @@ uint32 ObjectMgr::GetScriptId(const char *name) 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) { @@ -8780,13 +8839,8 @@ void ObjectMgr::LoadDbScriptStrings() if (GetTrinityStringLocale(i)) ids.insert(i); - CheckScripts(sQuestEndScripts,ids); - CheckScripts(sQuestStartScripts,ids); - CheckScripts(sSpellScripts,ids); - CheckScripts(sGameObjectScripts,ids); - CheckScripts(sEventScripts,ids); - - CheckScripts(sWaypointScripts,ids); + for (int type = SCRIPTS_FIRST; type < SCRIPTS_LAST; ++type) + CheckScripts(ScriptsType(type), ids); 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); diff --git a/src/server/game/Globals/ObjectMgr.h b/src/server/game/Globals/ObjectMgr.h index b59dad0d71c..649e21dad71 100644 --- a/src/server/game/Globals/ObjectMgr.h +++ b/src/server/game/Globals/ObjectMgr.h @@ -88,6 +88,21 @@ struct ScriptInfo 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::map<uint32, ScriptMap > ScriptMapMap; typedef std::multimap<uint32, uint32> SpellScriptsMap; @@ -100,6 +115,9 @@ extern ScriptMapMap sEventScripts; extern ScriptMapMap sGossipScripts; extern ScriptMapMap sWaypointScripts; +std::string GetScriptsTableNameByType(ScriptsType type); +ScriptMapMap* GetScriptsMapByType(ScriptsType type); + struct SpellClickInfo { uint32 spellId; @@ -1041,8 +1059,8 @@ class ObjectMgr int DBCLocaleIndex; private: - void LoadScripts(ScriptMapMap& scripts, char const* tablename); - void CheckScripts(ScriptMapMap const& scripts,std::set<int32>& ids); + void LoadScripts(ScriptsType type); + void CheckScripts(ScriptsType type, std::set<int32>& ids); void LoadCreatureAddons(SQLStorage& creatureaddons, char const* entryName, char const* comment); void ConvertCreatureAddonAuras(CreatureDataAddon* addon, char const* table, char const* guidEntryStr); void LoadQuestRelationsHelper(QuestRelations& map,char const* table); diff --git a/src/server/game/Maps/Map.cpp b/src/server/game/Maps/Map.cpp index e5d6e36d269..fb9419210e7 100644 --- a/src/server/game/Maps/Map.cpp +++ b/src/server/game/Maps/Map.cpp @@ -3440,34 +3440,13 @@ void Map::ScriptsProcess() } //Lets choose our ScriptMap map - ScriptMapMap *datamap = NULL; - switch (step.script->dataint) - { - 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); - break; - } + ScriptMapMap *datamap = GetScriptsMapByType(ScriptsType(step.script->dataint)); //if no scriptmap present... if (!datamap) + { + sLog.outError("SCRIPT_COMMAND_CALLSCRIPT (script id: %u) unknown scriptmap (%u) specified, skipping.", step.script->id, step.script->dataint); break; + } // Insert script into schedule but do not start it ScriptsStart(*datamap, step.script->datalong2, cTarget, NULL); diff --git a/src/server/game/World/World.h b/src/server/game/World/World.h index 74993e6b30a..27afbf9ab32 100644 --- a/src/server/game/World/World.h +++ b/src/server/game/World/World.h @@ -460,7 +460,7 @@ enum ScriptCommands 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_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 // TrinityCore only |
