From 010d29d1eda5cc893be15e747b135b3ea7fc15c7 Mon Sep 17 00:00:00 2001 From: Schmoozerd Date: Sat, 21 Apr 2012 22:00:39 +0200 Subject: [PATCH] [11985] Implement support for go_template_scripts Add a new table `gameobject_template_scripts` to start scripts for any type gameobject. Scripts in this table are triggered for all gameobjects on GameObject::Use Note: The table `gameobject_scripts` is expected to not be required very much longer, and will most likely be removed someday --- sql/mangos.sql | 36 ++++++++++++++++++- ..._01_mangos_gameobject_template_scripts.sql | 35 ++++++++++++++++++ src/game/GameObject.cpp | 2 ++ src/game/Level3.cpp | 5 +-- src/game/ScriptMgr.cpp | 14 ++++++++ src/game/ScriptMgr.h | 2 ++ src/game/World.cpp | 1 + src/shared/revision_nr.h | 2 +- src/shared/revision_sql.h | 2 +- 9 files changed, 94 insertions(+), 5 deletions(-) create mode 100644 sql/updates/11985_01_mangos_gameobject_template_scripts.sql diff --git a/sql/mangos.sql b/sql/mangos.sql index 5e23a6e16..20a912ef5 100644 --- a/sql/mangos.sql +++ b/sql/mangos.sql @@ -24,7 +24,7 @@ CREATE TABLE `db_version` ( `version` varchar(120) default NULL, `creature_ai_version` varchar(120) default NULL, `cache_id` int(10) default '0', - `required_11968_01_mangos_creature_linking_template` bit(1) default NULL + `required_11985_01_mangos_gameobject_template_scripts` bit(1) default NULL ) ENGINE=MyISAM DEFAULT CHARSET=utf8 ROW_FORMAT=FIXED COMMENT='Used DB version notes'; -- @@ -2133,6 +2133,40 @@ LOCK TABLES `gameobject_template` WRITE; /*!40000 ALTER TABLE `gameobject_template` ENABLE KEYS */; UNLOCK TABLES; +-- +-- Table structure for table `gameobject_template_scripts` +-- + +DROP TABLE IF EXISTS `gameobject_template_scripts`; +CREATE TABLE `gameobject_template_scripts` ( + `id` mediumint(8) unsigned NOT NULL default '0', + `delay` int(10) unsigned NOT NULL default '0', + `command` mediumint(8) unsigned NOT NULL default '0', + `datalong` mediumint(8) unsigned NOT NULL default '0', + `datalong2` int(10) unsigned NOT NULL default '0', + `buddy_entry` int(10) unsigned NOT NULL default '0', + `search_radius` int(10) unsigned NOT NULL default '0', + `data_flags` tinyint(3) unsigned NOT NULL default '0', + `dataint` int(11) NOT NULL default '0', + `dataint2` int(11) NOT NULL default '0', + `dataint3` int(11) NOT NULL default '0', + `dataint4` int(11) NOT NULL default '0', + `x` float NOT NULL default '0', + `y` float NOT NULL default '0', + `z` float NOT NULL default '0', + `o` float NOT NULL default '0', + `comments` varchar(255) NOT NULL +) ENGINE=MyISAM DEFAULT CHARSET=utf8; + +-- +-- Dumping data for table `gameobject_template_scripts` +-- + +LOCK TABLES `gameobject_template_scripts` WRITE; +/*!40000 ALTER TABLE `gameobject_template_scripts` DISABLE KEYS */; +/*!40000 ALTER TABLE `gameobject_template_scripts` ENABLE KEYS */; +UNLOCK TABLES; + -- -- Table structure for table `gossip_menu` -- diff --git a/sql/updates/11985_01_mangos_gameobject_template_scripts.sql b/sql/updates/11985_01_mangos_gameobject_template_scripts.sql new file mode 100644 index 000000000..105f065af --- /dev/null +++ b/sql/updates/11985_01_mangos_gameobject_template_scripts.sql @@ -0,0 +1,35 @@ +ALTER TABLE db_version CHANGE COLUMN required_11968_01_mangos_creature_linking_template required_11985_01_mangos_gameobject_template_scripts bit; + +-- +-- Table structure for table `gameobject_template_scripts` +-- + +DROP TABLE IF EXISTS `gameobject_template_scripts`; +CREATE TABLE `gameobject_template_scripts` ( + `id` mediumint(8) unsigned NOT NULL default '0', + `delay` int(10) unsigned NOT NULL default '0', + `command` mediumint(8) unsigned NOT NULL default '0', + `datalong` mediumint(8) unsigned NOT NULL default '0', + `datalong2` int(10) unsigned NOT NULL default '0', + `buddy_entry` int(10) unsigned NOT NULL default '0', + `search_radius` int(10) unsigned NOT NULL default '0', + `data_flags` tinyint(3) unsigned NOT NULL default '0', + `dataint` int(11) NOT NULL default '0', + `dataint2` int(11) NOT NULL default '0', + `dataint3` int(11) NOT NULL default '0', + `dataint4` int(11) NOT NULL default '0', + `x` float NOT NULL default '0', + `y` float NOT NULL default '0', + `z` float NOT NULL default '0', + `o` float NOT NULL default '0', + `comments` varchar(255) NOT NULL +) ENGINE=MyISAM DEFAULT CHARSET=utf8; + +-- +-- Dumping data for table `gameobject_template_scripts` +-- + +LOCK TABLES `gameobject_template_scripts` WRITE; +/*!40000 ALTER TABLE `gameobject_template_scripts` DISABLE KEYS */; +/*!40000 ALTER TABLE `gameobject_template_scripts` ENABLE KEYS */; +UNLOCK TABLES; diff --git a/src/game/GameObject.cpp b/src/game/GameObject.cpp index fc29bf47f..b1b7b102a 100644 --- a/src/game/GameObject.cpp +++ b/src/game/GameObject.cpp @@ -961,6 +961,8 @@ void GameObject::Use(Unit* user) } bool scriptReturnValue = user->GetTypeId() == TYPEID_PLAYER && sScriptMgr.OnGameObjectUse((Player*)user, this); + if (!scriptReturnValue) + GetMap()->ScriptsStart(sGameObjectTemplateScripts, GetEntry(), spellCaster, this); switch (GetGoType()) { diff --git a/src/game/Level3.cpp b/src/game/Level3.cpp index 3a11d8e23..f8b242928 100644 --- a/src/game/Level3.cpp +++ b/src/game/Level3.cpp @@ -876,12 +876,13 @@ bool ChatHandler::HandleReloadGameObjectScriptsCommand(char* args) } if (*args!='a') - sLog.outString( "Re-Loading Scripts from `gameobject_scripts`..."); + sLog.outString( "Re-Loading Scripts from `gameobject_[template]_scripts`..."); sScriptMgr.LoadGameObjectScripts(); + sScriptMgr.LoadGameObjectTemplateScripts(); if (*args!='a') - SendGlobalSysMessage("DB table `gameobject_scripts` reloaded."); + SendGlobalSysMessage("DB table `gameobject_[template]_scripts` reloaded."); return true; } diff --git a/src/game/ScriptMgr.cpp b/src/game/ScriptMgr.cpp index 6f50860bd..811370b9e 100644 --- a/src/game/ScriptMgr.cpp +++ b/src/game/ScriptMgr.cpp @@ -34,6 +34,7 @@ ScriptMapMapName sQuestEndScripts; ScriptMapMapName sQuestStartScripts; ScriptMapMapName sSpellScripts; ScriptMapMapName sGameObjectScripts; +ScriptMapMapName sGameObjectTemplateScripts; ScriptMapMapName sEventScripts; ScriptMapMapName sGossipScripts; ScriptMapMapName sCreatureMovementScripts; @@ -598,6 +599,18 @@ void ScriptMgr::LoadGameObjectScripts() } } +void ScriptMgr::LoadGameObjectTemplateScripts() +{ + LoadScripts(sGameObjectTemplateScripts, "gameobject_template_scripts"); + + // check ids + for (ScriptMapMap::const_iterator itr = sGameObjectTemplateScripts.second.begin(); itr != sGameObjectTemplateScripts.second.end(); ++itr) + { + if (!sObjectMgr.GetGameObjectInfo(itr->first)) + sLog.outErrorDb("Table `gameobject_template_scripts` has not existing gameobject (Entry: %u) as script id", itr->first); + } +} + void ScriptMgr::LoadQuestEndScripts() { LoadScripts(sQuestEndScripts, "quest_end_scripts"); @@ -754,6 +767,7 @@ void ScriptMgr::LoadDbScriptStrings() CheckScriptTexts(sQuestStartScripts, ids); CheckScriptTexts(sSpellScripts, ids); CheckScriptTexts(sGameObjectScripts, ids); + CheckScriptTexts(sGameObjectTemplateScripts, ids); CheckScriptTexts(sEventScripts, ids); CheckScriptTexts(sGossipScripts, ids); CheckScriptTexts(sCreatureMovementScripts, ids); diff --git a/src/game/ScriptMgr.h b/src/game/ScriptMgr.h index ce9ee47ca..fd493ac57 100644 --- a/src/game/ScriptMgr.h +++ b/src/game/ScriptMgr.h @@ -388,6 +388,7 @@ extern ScriptMapMapName sQuestEndScripts; extern ScriptMapMapName sQuestStartScripts; extern ScriptMapMapName sSpellScripts; extern ScriptMapMapName sGameObjectScripts; +extern ScriptMapMapName sGameObjectTemplateScripts; extern ScriptMapMapName sEventScripts; extern ScriptMapMapName sGossipScripts; extern ScriptMapMapName sCreatureMovementScripts; @@ -407,6 +408,7 @@ class ScriptMgr ~ScriptMgr(); void LoadGameObjectScripts(); + void LoadGameObjectTemplateScripts(); void LoadQuestEndScripts(); void LoadQuestStartScripts(); void LoadEventScripts(); diff --git a/src/game/World.cpp b/src/game/World.cpp index 0ca3ed3c7..528b94050 100644 --- a/src/game/World.cpp +++ b/src/game/World.cpp @@ -1285,6 +1285,7 @@ void World::SetInitialWorldSettings() 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) sLog.outString( ">>> Scripts loaded" ); sLog.outString(); diff --git a/src/shared/revision_nr.h b/src/shared/revision_nr.h index 0df235bcb..f289d1bdf 100644 --- a/src/shared/revision_nr.h +++ b/src/shared/revision_nr.h @@ -1,4 +1,4 @@ #ifndef __REVISION_NR_H__ #define __REVISION_NR_H__ - #define REVISION_NR "11984" + #define REVISION_NR "11985" #endif // __REVISION_NR_H__ diff --git a/src/shared/revision_sql.h b/src/shared/revision_sql.h index 66d527389..0937cb464 100644 --- a/src/shared/revision_sql.h +++ b/src/shared/revision_sql.h @@ -1,6 +1,6 @@ #ifndef __REVISION_SQL_H__ #define __REVISION_SQL_H__ #define REVISION_DB_CHARACTERS "required_11785_02_characters_instance" - #define REVISION_DB_MANGOS "required_11968_01_mangos_creature_linking_template" + #define REVISION_DB_MANGOS "required_11985_01_mangos_gameobject_template_scripts" #define REVISION_DB_REALMD "required_10008_01_realmd_realmd_db_version" #endif // __REVISION_SQL_H__