[11852] Add support for db scripts assigned to gossip menus

This commit is contained in:
Schmoozerd 2011-11-14 01:36:07 +01:00
parent 83e85416f4
commit 4c82458874
13 changed files with 76 additions and 48 deletions

View file

@ -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_11851_01_mangos_string` bit(1) default NULL
`required_11852_01_mangos_gossip_menu` bit(1) default NULL
) ENGINE=MyISAM DEFAULT CHARSET=utf8 ROW_FORMAT=FIXED COMMENT='Used DB version notes';
--
@ -2115,13 +2115,14 @@ DROP TABLE IF EXISTS gossip_menu;
CREATE TABLE gossip_menu (
entry smallint(6) unsigned NOT NULL default '0',
text_id mediumint(8) unsigned NOT NULL default '0',
script_id mediumint(8) UNSIGNED NOT NULL DEFAULT 0 COMMENT 'script in `gossip_scripts` - will be executed on GossipHello'
cond_1 tinyint(3) unsigned NOT NULL default '0',
cond_1_val_1 mediumint(8) unsigned NOT NULL default '0',
cond_1_val_2 mediumint(8) unsigned NOT NULL default '0',
cond_2 tinyint(3) unsigned NOT NULL default '0',
cond_2_val_1 mediumint(8) unsigned NOT NULL default '0',
cond_2_val_2 mediumint(8) unsigned NOT NULL default '0',
PRIMARY KEY (entry, text_id)
PRIMARY KEY (entry, text_id, script_id)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
--

View file

@ -0,0 +1,10 @@
ALTER TABLE db_version CHANGE COLUMN required_11851_01_mangos_string required_11852_01_mangos_gossip_menu bit;
-- Add collumn `script_id` to table `gossip_menu`
ALTER TABLE gossip_menu ADD COLUMN script_id
mediumint(8) UNSIGNED NOT NULL DEFAULT 0 COMMENT 'script in `gossip_scripts` - will be executed on GossipHello'
AFTER text_id;
ALTER TABLE gossip_menu
DROP PRIMARY KEY,
ADD PRIMARY KEY (entry, text_id, script_id);

View file

@ -528,7 +528,7 @@ ChatCommand * ChatHandler::getCommandTable()
{ "gameobject_scripts", SEC_ADMINISTRATOR, true, &ChatHandler::HandleReloadGameObjectScriptsCommand, "", NULL },
{ "gameobject_battleground", SEC_ADMINISTRATOR, true, &ChatHandler::HandleReloadBattleEventCommand, "", NULL },
{ "gossip_menu", SEC_ADMINISTRATOR, true, &ChatHandler::HandleReloadGossipMenuCommand, "", NULL },
{ "gossip_menu_option", SEC_ADMINISTRATOR, true, &ChatHandler::HandleReloadGossipMenuOptionCommand, "", NULL },
{ "gossip_menu_option", SEC_ADMINISTRATOR, true, &ChatHandler::HandleReloadGossipMenuCommand, "", NULL },
{ "gossip_scripts", SEC_ADMINISTRATOR, true, &ChatHandler::HandleReloadGossipScriptsCommand, "", NULL },
{ "item_convert", SEC_ADMINISTRATOR, true, &ChatHandler::HandleReloadItemConvertCommand, "", NULL },
{ "item_enchantment_template", SEC_ADMINISTRATOR, true, &ChatHandler::HandleReloadItemEnchantementsCommand, "", NULL },

View file

@ -414,7 +414,6 @@ class MANGOS_DLL_SPEC ChatHandler
bool HandleReloadGameObjectScriptsCommand(char* args);
bool HandleReloadGameTeleCommand(char* args);
bool HandleReloadGossipMenuCommand(char* args);
bool HandleReloadGossipMenuOptionCommand(char* args);
bool HandleReloadGossipScriptsCommand(char* args);
bool HandleReloadGOQuestRelationsCommand(char* args);
bool HandleReloadGOQuestInvRelationsCommand(char* args);

View file

@ -342,10 +342,9 @@ bool ChatHandler::HandleReloadAllSpellCommand(char* /*args*/)
bool ChatHandler::HandleReloadAllGossipsCommand(char* args)
{
HandleReloadGossipMenuCommand((char*)"a");
HandleReloadGossipMenuOptionCommand((char*)"a");
if (*args!='a') // already reload from all_scripts
HandleReloadGossipScriptsCommand((char*)"a");
HandleReloadGossipMenuCommand((char*)"a");
HandleReloadNpcGossipCommand((char*)"a");
HandleReloadPointsOfInterestCommand((char*)"a");
return true;
@ -440,17 +439,8 @@ bool ChatHandler::HandleReloadCreatureQuestInvRelationsCommand(char* /*args*/)
bool ChatHandler::HandleReloadGossipMenuCommand(char* /*args*/)
{
sLog.outString( "Re-Loading `gossip_menu` Table!" );
sObjectMgr.LoadGossipMenu();
SendGlobalSysMessage("DB table `gossip_menu` reloaded.");
return true;
}
bool ChatHandler::HandleReloadGossipMenuOptionCommand(char* /*args*/)
{
sLog.outString( "Re-Loading `gossip_menu_option` Table!" );
sObjectMgr.LoadGossipMenuItems();
SendGlobalSysMessage("DB table `gossip_menu_option` reloaded.");
sObjectMgr.LoadGossipMenus();
SendGlobalSysMessage("DB tables `gossip_menu` and `gossip_menu_option` reloaded.");
return true;
}

View file

@ -8487,11 +8487,12 @@ void ObjectMgr::LoadNpcGossips()
sLog.outString( ">> Loaded %d NpcTextId ", count );
}
void ObjectMgr::LoadGossipMenu()
void ObjectMgr::LoadGossipMenu(std::set<uint32>& gossipScriptSet)
{
m_mGossipMenusMap.clear();
QueryResult* result = WorldDatabase.Query("SELECT entry, text_id, "
// 0 1 2
QueryResult* result = WorldDatabase.Query("SELECT entry, text_id, script_id, "
// 3 4 5 6 7 8
"cond_1, cond_1_val_1, cond_1_val_2, cond_2, cond_2_val_1, cond_2_val_2 FROM gossip_menu");
if (!result)
@ -8519,13 +8520,14 @@ void ObjectMgr::LoadGossipMenu()
gMenu.entry = fields[0].GetUInt32();
gMenu.text_id = fields[1].GetUInt32();
gMenu.script_id = fields[2].GetUInt32();
ConditionType cond_1 = (ConditionType)fields[2].GetUInt32();
uint32 cond_1_val_1 = fields[3].GetUInt32();
uint32 cond_1_val_2 = fields[4].GetUInt32();
ConditionType cond_2 = (ConditionType)fields[5].GetUInt32();
uint32 cond_2_val_1 = fields[6].GetUInt32();
uint32 cond_2_val_2 = fields[7].GetUInt32();
ConditionType cond_1 = (ConditionType)fields[3].GetUInt32();
uint32 cond_1_val_1 = fields[4].GetUInt32();
uint32 cond_1_val_2 = fields[5].GetUInt32();
ConditionType cond_2 = (ConditionType)fields[6].GetUInt32();
uint32 cond_2_val_1 = fields[7].GetUInt32();
uint32 cond_2_val_2 = fields[8].GetUInt32();
if (!GetGossipText(gMenu.text_id))
{
@ -8533,6 +8535,19 @@ void ObjectMgr::LoadGossipMenu()
continue;
}
// Check script-id
if (gMenu.script_id)
{
if (sGossipScripts.find(gMenu.script_id) == sGossipScripts.end())
{
sLog.outErrorDb("Table gossip_menu for menu %u, text-id %u have script_id %u that does not exist in `gossip_scripts`, ignoring", gMenu.entry, gMenu.text_id, gMenu.script_id);
continue;
}
// Remove used script id
gossipScriptSet.erase(gMenu.script_id);
}
if (!PlayerCondition::IsValid(cond_1, cond_1_val_1, cond_1_val_2))
{
sLog.outErrorDb("Table gossip_menu entry %u, invalid condition 1 for id %u", gMenu.entry, gMenu.text_id);
@ -8573,7 +8588,7 @@ void ObjectMgr::LoadGossipMenu()
ERROR_DB_STRICT_LOG("Gameobject (Entry: %u) has gossip_menu_id = %u for nonexistent menu", gInfo->id, menuid);
}
void ObjectMgr::LoadGossipMenuItems()
void ObjectMgr::LoadGossipMenuItems(std::set<uint32>& gossipScriptSet)
{
m_mGossipMenuItemsMap.clear();
@ -8615,11 +8630,6 @@ void ObjectMgr::LoadGossipMenuItems()
uint32 count = 0;
std::set<uint32> gossipScriptSet;
for(ScriptMapMap::const_iterator itr = sGossipScripts.begin(); itr != sGossipScripts.end(); ++itr)
gossipScriptSet.insert(itr->first);
// prepare menuid -> CreatureInfo map for fast access
typedef std::multimap<uint32, const CreatureInfo*> Menu2CInfoMap;
Menu2CInfoMap menu2CInfoMap;
@ -8749,6 +8759,7 @@ void ObjectMgr::LoadGossipMenuItems()
continue;
}
// Remove used script id
gossipScriptSet.erase(gMenuItem.action_script_id);
}
@ -8765,9 +8776,6 @@ void ObjectMgr::LoadGossipMenuItems()
delete result;
for(std::set<uint32>::const_iterator itr = gossipScriptSet.begin(); itr != gossipScriptSet.end(); ++itr)
sLog.outErrorDb("Table `gossip_scripts` contain unused script, id %u.", *itr);
if (!sLog.HasLogFilter(LOG_FILTER_DB_STRICTED_CHECK))
{
for(std::set<uint32>::const_iterator itr = menu_ids.begin(); itr != menu_ids.end(); ++itr)
@ -8778,6 +8786,23 @@ void ObjectMgr::LoadGossipMenuItems()
sLog.outString(">> Loaded %u gossip_menu_option entries", count);
}
void ObjectMgr::LoadGossipMenus()
{
// Check which script-ids in gossip_scripts are not used
std::set<uint32> gossipScriptSet;
for (ScriptMapMap::const_iterator itr = sGossipScripts.begin(); itr != sGossipScripts.end(); ++itr)
gossipScriptSet.insert(itr->first);
// Load gossip_menu and gossip_menu_option data
sLog.outString( "(Re)Loading Gossip menus..." );
LoadGossipMenu(gossipScriptSet);
sLog.outString( "(Re)Loading Gossip menu options..." );
LoadGossipMenuItems(gossipScriptSet);
for (std::set<uint32>::const_iterator itr = gossipScriptSet.begin(); itr != gossipScriptSet.end(); ++itr)
sLog.outErrorDb("Table `gossip_scripts` contains unused script, id %u.", *itr);
}
void ObjectMgr::AddVendorItem( uint32 entry,uint32 item, uint32 maxcount, uint32 incrtime, uint32 extendedcost )
{
VendorItemData& vList = m_mCacheVendorItemMap[entry];

View file

@ -263,6 +263,7 @@ struct GossipMenus
{
uint32 entry;
uint32 text_id;
uint32 script_id;
uint16 cond_1;
uint16 cond_2;
};
@ -705,8 +706,7 @@ class ObjectMgr
void LoadNpcGossips();
void LoadGossipMenu();
void LoadGossipMenuItems();
void LoadGossipMenus();
void LoadVendorTemplates();
void LoadVendors() { LoadVendors("npc_vendor", false); }
@ -1157,6 +1157,9 @@ class ObjectMgr
void LoadVendors(char const* tableName, bool isTemplates);
void LoadTrainers(char const* tableName, bool isTemplates);
void LoadGossipMenu(std::set<uint32>& gossipScriptSet);
void LoadGossipMenuItems(std::set<uint32>& gossipScriptSet);
MailLevelRewardMap m_mailLevelRewardMap;
typedef std::map<uint32,PetLevelInfo*> PetLevelInfoMap;

View file

@ -13122,7 +13122,7 @@ void Player::SendPreparedGossip(WorldObject *pSource)
uint32 textId = GetGossipTextId(pSource);
if (uint32 menuId = PlayerTalkClass->GetGossipMenu().GetMenuId())
textId = GetGossipTextId(menuId);
textId = GetGossipTextId(menuId, pSource);
PlayerTalkClass->SendGossipMenu(textId, pSource->GetObjectGuid());
}
@ -13271,7 +13271,7 @@ uint32 Player::GetGossipTextId(WorldObject *pSource)
return DEFAULT_GOSSIP_MESSAGE;
}
uint32 Player::GetGossipTextId(uint32 menuId)
uint32 Player::GetGossipTextId(uint32 menuId, WorldObject* pSource)
{
uint32 textId = DEFAULT_GOSSIP_MESSAGE;
@ -13285,6 +13285,10 @@ uint32 Player::GetGossipTextId(uint32 menuId)
if (sObjectMgr.IsPlayerMeetToCondition(this, itr->second.cond_1) && sObjectMgr.IsPlayerMeetToCondition(this, itr->second.cond_2))
{
textId = itr->second.text_id;
// Start related script
if (itr->second.script_id)
GetMap()->ScriptsStart(sGossipScripts, itr->second.script_id, this, pSource);
break;
}
}

View file

@ -1310,7 +1310,7 @@ class MANGOS_DLL_SPEC Player : public Unit
void SendPreparedGossip(WorldObject *pSource);
void OnGossipSelect(WorldObject *pSource, uint32 gossipListId, uint32 menuId);
uint32 GetGossipTextId(uint32 menuId);
uint32 GetGossipTextId(uint32 menuId, WorldObject* pSource);
uint32 GetGossipTextId(WorldObject *pSource);
uint32 GetDefaultGossipMenuForSource(WorldObject *pSource);

View file

@ -755,7 +755,7 @@ void ScriptMgr::LoadGossipScripts()
{
LoadScripts(sGossipScripts, "gossip_scripts");
// checks are done in LoadGossipMenuItems
// checks are done in LoadGossipMenuItems and LoadGossipMenu
}
void ScriptMgr::LoadCreatureMovementScripts()

View file

@ -1195,11 +1195,7 @@ void World::SetInitialWorldSettings()
sLog.outString( "Loading Gossip scripts..." );
sScriptMgr.LoadGossipScripts(); // must be before gossip menu options
sLog.outString( "Loading Gossip menus..." );
sObjectMgr.LoadGossipMenu();
sLog.outString( "Loading Gossip menu options..." );
sObjectMgr.LoadGossipMenuItems();
sObjectMgr.LoadGossipMenus();
sLog.outString( "Loading Vendors..." );
sObjectMgr.LoadVendorTemplates(); // must be after load ItemTemplate

View file

@ -1,4 +1,4 @@
#ifndef __REVISION_NR_H__
#define __REVISION_NR_H__
#define REVISION_NR "11851"
#define REVISION_NR "11852"
#endif // __REVISION_NR_H__

View file

@ -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_11851_01_mangos_string"
#define REVISION_DB_MANGOS "required_11852_01_mangos_gossip_menu"
#define REVISION_DB_REALMD "required_10008_01_realmd_realmd_db_version"
#endif // __REVISION_SQL_H__