Skip to content

Commit

Permalink
[11985] Implement support for go_template_scripts
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Schmoozerd committed May 4, 2012
1 parent 11d92a9 commit 62a00dc
Show file tree
Hide file tree
Showing 9 changed files with 94 additions and 5 deletions.
36 changes: 35 additions & 1 deletion sql/mangos.sql
Expand Up @@ -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';

--
Expand Down Expand Up @@ -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`
--
Expand Down
35 changes: 35 additions & 0 deletions 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;
2 changes: 2 additions & 0 deletions src/game/GameObject.cpp
Expand Up @@ -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())
{
Expand Down
5 changes: 3 additions & 2 deletions src/game/Level3.cpp
Expand Up @@ -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;
}
Expand Down
14 changes: 14 additions & 0 deletions src/game/ScriptMgr.cpp
Expand Up @@ -34,6 +34,7 @@ ScriptMapMapName sQuestEndScripts;
ScriptMapMapName sQuestStartScripts;
ScriptMapMapName sSpellScripts;
ScriptMapMapName sGameObjectScripts;
ScriptMapMapName sGameObjectTemplateScripts;
ScriptMapMapName sEventScripts;
ScriptMapMapName sGossipScripts;
ScriptMapMapName sCreatureMovementScripts;
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions src/game/ScriptMgr.h
Expand Up @@ -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;
Expand All @@ -407,6 +408,7 @@ class ScriptMgr
~ScriptMgr();

void LoadGameObjectScripts();
void LoadGameObjectTemplateScripts();
void LoadQuestEndScripts();
void LoadQuestStartScripts();
void LoadEventScripts();
Expand Down
1 change: 1 addition & 0 deletions src/game/World.cpp
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion 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__
2 changes: 1 addition & 1 deletion 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__

1 comment on commit 62a00dc

@KiriX
Copy link

@KiriX KiriX commented on 62a00dc May 5, 2012

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Шикарные коммиты последнее время, спасибо! =)
Very interesting commits last time, I'm happy - thx! =)

Please sign in to comment.