From 94e29ce6a89b3629a793dc504b86a698ddaa8d17 Mon Sep 17 00:00:00 2001 From: GriffonHeart Date: Mon, 27 Oct 2008 22:12:45 +0300 Subject: [PATCH] [2008_10_27_01_npc_option.sql,2008_10_27_02_locales_npc_option.sql] Implement npc_option localization support, also store in DB BoxText/BoxMoney/Coded. Signed-off-by: VladimirMangos --- sql/mangos.sql | 45 +++++++++- sql/updates/2008_10_27_01_npc_option.sql | 7 ++ .../2008_10_27_02_locales_npc_option.sql | 22 +++++ sql/updates/Makefile.am | 4 + src/game/Creature.cpp | 20 ++++- src/game/Creature.h | 13 ++- src/game/NPCHandler.cpp | 16 ++-- src/game/ObjectMgr.cpp | 89 +++++++++++++++++-- src/game/ObjectMgr.h | 9 ++ src/game/QuestHandler.cpp | 4 +- src/game/World.cpp | 1 + 11 files changed, 206 insertions(+), 24 deletions(-) create mode 100644 sql/updates/2008_10_27_01_npc_option.sql create mode 100644 sql/updates/2008_10_27_02_locales_npc_option.sql diff --git a/sql/mangos.sql b/sql/mangos.sql index c320c9169..47c30e301 100644 --- a/sql/mangos.sql +++ b/sql/mangos.sql @@ -1803,6 +1803,42 @@ LOCK TABLES `locales_item` WRITE; /*!40000 ALTER TABLE `locales_item` ENABLE KEYS */; UNLOCK TABLES; + +-- +-- Table structure for table `locales_npc_option` +-- + +DROP TABLE IF EXISTS `locales_npc_option`; +CREATE TABLE `locales_npc_option` ( + `entry` mediumint(8) unsigned NOT NULL default '0', + `option_text_loc1` text, + `option_text_loc2` text, + `option_text_loc3` text, + `option_text_loc4` text, + `option_text_loc5` text, + `option_text_loc6` text, + `option_text_loc7` text, + `option_text_loc8` text, + `box_text_loc1` text, + `box_text_loc2` text, + `box_text_loc3` text, + `box_text_loc4` text, + `box_text_loc5` text, + `box_text_loc6` text, + `box_text_loc7` text, + `box_text_loc8` text, + PRIMARY KEY (`entry`) +) ENGINE=MyISAM DEFAULT CHARSET=utf8; + +-- +-- Dumping data for table `locales_npc_option` +-- + +LOCK TABLES `locales_npc_option` WRITE; +/*!40000 ALTER TABLE `locales_npc_option` DISABLE KEYS */; +/*!40000 ALTER TABLE `locales_npc_option` ENABLE KEYS */; +UNLOCK TABLES; + -- -- Table structure for table `locales_npc_text` -- @@ -2707,12 +2743,15 @@ UNLOCK TABLES; DROP TABLE IF EXISTS `npc_option`; CREATE TABLE `npc_option` ( - `id` tinyint(3) unsigned NOT NULL default '0', - `gossip_id` tinyint(3) unsigned NOT NULL default '0', + `id` mediumint(8) unsigned NOT NULL default '0', + `gossip_id` mediumint(8) unsigned NOT NULL default '0', `npcflag` int(10) unsigned NOT NULL default '0', `icon` tinyint(3) unsigned NOT NULL default '0', - `action` tinyint(3) unsigned NOT NULL default '0', + `action` mediumint(8) unsigned NOT NULL default '0', + `box_money` int(10) unsigned NOT NULL default '0', + `coded` tinyint(3) unsigned NOT NULL default '0', `option_text` text, + `box_text` text, PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8; diff --git a/sql/updates/2008_10_27_01_npc_option.sql b/sql/updates/2008_10_27_01_npc_option.sql new file mode 100644 index 000000000..983a6c9e6 --- /dev/null +++ b/sql/updates/2008_10_27_01_npc_option.sql @@ -0,0 +1,7 @@ +ALTER TABLE `npc_option` + CHANGE COLUMN `id` `id` mediumint(8) unsigned NOT NULL default '0', + CHANGE COLUMN `gossip_id` `gossip_id` mediumint(8) unsigned NOT NULL default '0', + CHANGE COLUMN `action` `action` mediumint(8) unsigned NOT NULL default '0', + ADD COLUMN `box_money` int(10) unsigned NOT NULL default '0' AFTER `action`, + ADD COLUMN `coded` tinyint(3) unsigned NOT NULL default '0' AFTER `box_money`, + ADD COLUMN `box_text` text AFTER `option_text`; diff --git a/sql/updates/2008_10_27_02_locales_npc_option.sql b/sql/updates/2008_10_27_02_locales_npc_option.sql new file mode 100644 index 000000000..172e35a24 --- /dev/null +++ b/sql/updates/2008_10_27_02_locales_npc_option.sql @@ -0,0 +1,22 @@ +CREATE TABLE `locales_npc_option` ( + `entry` mediumint(8) unsigned NOT NULL default '0', + `option_text_loc1` text, + `option_text_loc2` text, + `option_text_loc3` text, + `option_text_loc4` text, + `option_text_loc5` text, + `option_text_loc6` text, + `option_text_loc7` text, + `option_text_loc8` text, + `box_text_loc1` text, + `box_text_loc2` text, + `box_text_loc3` text, + `box_text_loc4` text, + `box_text_loc5` text, + `box_text_loc6` text, + `box_text_loc7` text, + `box_text_loc8` text, + PRIMARY KEY (`entry`) +) ENGINE=MyISAM DEFAULT CHARSET=utf8; + + diff --git a/sql/updates/Makefile.am b/sql/updates/Makefile.am index da45d285a..5acb7d68d 100644 --- a/sql/updates/Makefile.am +++ b/sql/updates/Makefile.am @@ -107,6 +107,8 @@ pkgdata_DATA = \ 2008_10_23_04_mangos_command.sql \ 2008_10_23_05_mangos_command.sql \ 2008_10_26_01_mangos_mangos_string.sql \ + 2008_10_27_01_npc_option.sql \ + 2008_10_27_02_locales_npc_option.sql \ README ## Additional files to include when running 'make dist' @@ -195,4 +197,6 @@ EXTRA_DIST = \ 2008_10_23_04_mangos_command.sql \ 2008_10_23_05_mangos_command.sql \ 2008_10_26_01_mangos_mangos_string.sql \ + 2008_10_27_01_npc_option.sql \ + 2008_10_27_02_locales_npc_option.sql \ README diff --git a/src/game/Creature.cpp b/src/game/Creature.cpp index 783a1a7c1..070007792 100644 --- a/src/game/Creature.cpp +++ b/src/game/Creature.cpp @@ -738,14 +738,30 @@ void Creature::prepareGossipMenu( Player *pPlayer,uint32 gossipid ) case GOSSIP_OPTION_AUCTIONEER: break; // no checks default: - sLog.outErrorDb("Creature %u (entry: %u) have unknown gossip option %u",GetGUIDLow(),GetEntry(),gso->Action); + sLog.outErrorDb("Creature %u (entry: %u) have unknown gossip option %u",GetDBTableGUIDLow(),GetEntry(),gso->Action); break; } } //note for future dev: should have database fields for BoxMessage & BoxMoney if(!gso->OptionText.empty() && cantalking) - pm->GetGossipMenu().AddMenuItem((uint8)gso->Icon,gso->OptionText, gossipid,gso->Action,"",0,false); + { + std::string OptionText = gso->OptionText; + std::string BoxText = gso->BoxText; + int loc_idx = pPlayer->GetSession()->GetSessionDbLocaleIndex(); + if (loc_idx >= 0) + { + NpcOptionLocale const *no = objmgr.GetNpcOptionLocale(gso->Id); + if (no) + { + if (no->OptionText.size() > loc_idx && !no->OptionText[loc_idx].empty()) + OptionText=no->OptionText[loc_idx]; + if (no->BoxText.size() > loc_idx && !no->BoxText[loc_idx].empty()) + BoxText=no->BoxText[loc_idx]; + } + } + pm->GetGossipMenu().AddMenuItem((uint8)gso->Icon,OptionText, gossipid,gso->Action,BoxText,gso->BoxMoney,gso->Coded); + } } } diff --git a/src/game/Creature.h b/src/game/Creature.h index 678c6e14a..3e01aec3e 100644 --- a/src/game/Creature.h +++ b/src/game/Creature.h @@ -109,7 +109,10 @@ struct GossipOption uint32 NpcFlag; uint32 Icon; uint32 Action; + uint32 BoxMoney; + bool Coded; std::string OptionText; + std::string BoxText; }; enum CreatureFlagsExtra @@ -207,6 +210,12 @@ struct CreatureLocale std::vector SubName; }; +struct NpcOptionLocale +{ + std::vector OptionText; + std::vector BoxText; +}; + struct EquipmentInfo { uint32 entry; @@ -467,8 +476,8 @@ class MANGOS_DLL_SPEC Creature : public Unit CreatureDataAddon const* GetCreatureAddon() const; char const* GetScriptName() const; - void prepareGossipMenu( Player *pPlayer,uint32 gossipid ); - void sendPreparedGossip( Player* player); + void prepareGossipMenu( Player *pPlayer, uint32 gossipid = 0 ); + void sendPreparedGossip( Player* player ); void OnGossipSelect(Player* player, uint32 option); void OnPoiSelect(Player* player, GossipOption const *gossip); diff --git a/src/game/NPCHandler.cpp b/src/game/NPCHandler.cpp index 2fd973610..076ec192a 100644 --- a/src/game/NPCHandler.cpp +++ b/src/game/NPCHandler.cpp @@ -295,8 +295,8 @@ void WorldSession::HandleGossipHelloOpcode( WorldPacket & recv_data ) if(!Script->GossipHello( _player, unit )) { _player->TalkedToCreature(unit->GetEntry(),unit->GetGUID()); - unit->prepareGossipMenu(_player,0); - unit->sendPreparedGossip( _player ); + unit->prepareGossipMenu(_player); + unit->sendPreparedGossip(_player); } } @@ -335,14 +335,14 @@ void WorldSession::HandleGossipSelectOptionOpcode( WorldPacket & recv_data ) if(!code.empty()) { - - if(!Script->GossipSelectWithCode( _player, unit, _player->PlayerTalkClass->GossipOptionSender( option ), _player->PlayerTalkClass->GossipOptionAction( option ), code.c_str()) ) - unit->OnGossipSelect( _player, option ); + if (!Script->GossipSelectWithCode(_player, unit, _player->PlayerTalkClass->GossipOptionSender (option), _player->PlayerTalkClass->GossipOptionAction( option ), code.c_str())) + unit->OnGossipSelect (_player, option); } else - - if(!Script->GossipSelect( _player, unit, _player->PlayerTalkClass->GossipOptionSender( option ), _player->PlayerTalkClass->GossipOptionAction( option )) ) - unit->OnGossipSelect( _player, option ); + { + if (!Script->GossipSelect (_player, unit, _player->PlayerTalkClass->GossipOptionSender (option), _player->PlayerTalkClass->GossipOptionAction (option))) + unit->OnGossipSelect (_player, option); + } } void WorldSession::HandleSpiritHealerActivateOpcode( WorldPacket & recv_data ) diff --git a/src/game/ObjectMgr.cpp b/src/game/ObjectMgr.cpp index eeee3a4a0..49c4f93c7 100644 --- a/src/game/ObjectMgr.cpp +++ b/src/game/ObjectMgr.cpp @@ -563,6 +563,74 @@ void ObjectMgr::LoadCreatureLocales() sLog.outString( ">> Loaded %u creature locale strings", mCreatureLocaleMap.size() ); } +void ObjectMgr::LoadNpcOptionLocales() +{ + mNpcOptionLocaleMap.clear(); // need for reload case + + QueryResult *result = WorldDatabase.Query("SELECT entry," + "option_text_loc1,box_text_loc1,option_text_loc2,box_text_loc2," + "option_text_loc3,box_text_loc3,option_text_loc4,box_text_loc4," + "option_text_loc5,box_text_loc5,option_text_loc6,box_text_loc6," + "option_text_loc7,box_text_loc7,option_text_loc8,box_text_loc8 " + "FROM locales_npc_option"); + + if(!result) + { + barGoLink bar(1); + + bar.step(); + + sLog.outString(""); + sLog.outString(">> Loaded 0 npc_option locale strings. DB table `locales_npc_option` is empty."); + return; + } + + barGoLink bar(result->GetRowCount()); + + do + { + Field *fields = result->Fetch(); + bar.step(); + + uint32 entry = fields[0].GetUInt32(); + + NpcOptionLocale& data = mNpcOptionLocaleMap[entry]; + + for(int i = 1; i < MAX_LOCALE; ++i) + { + std::string str = fields[1+2*(i-1)].GetCppString(); + if(!str.empty()) + { + int idx = GetOrNewIndexForLocale(LocaleConstant(i)); + if(idx >= 0) + { + if(data.OptionText.size() <= idx) + data.OptionText.resize(idx+1); + + data.OptionText[idx] = str; + } + } + str = fields[1+2*(i-1)+1].GetCppString(); + if(!str.empty()) + { + int idx = GetOrNewIndexForLocale(LocaleConstant(i)); + if(idx >= 0) + { + if(data.BoxText.size() <= idx) + data.BoxText.resize(idx+1); + + data.BoxText[idx] = str; + } + } + } + } while (result->NextRow()); + + delete result; + + sLog.outString(); + sLog.outString( ">> Loaded %u npc_option locale strings", mNpcOptionLocaleMap.size() ); +} + void ObjectMgr::LoadCreatureTemplates() { sCreatureStorage.Load(); @@ -6886,7 +6954,11 @@ void ObjectMgr::LoadNpcOptions() { m_mCacheNpcOptionList.clear(); // For reload case - QueryResult *result = WorldDatabase.Query( "SELECT id,gossip_id,npcflag,icon,action,option_text FROM npc_option"); + QueryResult *result = WorldDatabase.Query( + // 0 1 2 3 4 5 6 7 8 + "SELECT id,gossip_id,npcflag,icon,action,box_money,coded,option_text,box_text " + "FROM npc_option"); + if( !result ) { barGoLink bar( 1 ); @@ -6909,12 +6981,15 @@ void ObjectMgr::LoadNpcOptions() Field* fields = result->Fetch(); GossipOption go; - go.Id = fields[0].GetUInt32(); - go.GossipId = fields[1].GetUInt32(); - go.NpcFlag = fields[2].GetUInt32(); - go.Icon = fields[3].GetUInt32(); - go.Action = fields[4].GetUInt32(); - go.OptionText = fields[5].GetCppString(); + go.Id = fields[0].GetUInt32(); + go.GossipId = fields[1].GetUInt32(); + go.NpcFlag = fields[2].GetUInt32(); + go.Icon = fields[3].GetUInt32(); + go.Action = fields[4].GetUInt32(); + go.BoxMoney = fields[5].GetUInt32(); + go.Coded = fields[6].GetUInt8()!=0; + go.OptionText = fields[7].GetCppString(); + go.BoxText = fields[8].GetCppString(); m_mCacheNpcOptionList.push_back(go); diff --git a/src/game/ObjectMgr.h b/src/game/ObjectMgr.h index e7a03d3a4..c9b4e9bdf 100644 --- a/src/game/ObjectMgr.h +++ b/src/game/ObjectMgr.h @@ -139,6 +139,7 @@ typedef HM_NAMESPACE::hash_map QuestLocaleMap; typedef HM_NAMESPACE::hash_map NpcTextLocaleMap; typedef HM_NAMESPACE::hash_map PageTextLocaleMap; typedef HM_NAMESPACE::hash_map MangosStringLocaleMap; +typedef HM_NAMESPACE::hash_map NpcOptionLocaleMap; typedef std::multimap QuestRelations; @@ -515,6 +516,7 @@ class ObjectMgr void LoadQuestLocales(); void LoadNpcTextLocales(); void LoadPageTextLocales(); + void LoadNpcOptionLocales(); void LoadInstanceTemplate(); void LoadGossipText(); @@ -639,6 +641,12 @@ class ObjectMgr if(itr==mPageTextLocaleMap.end()) return NULL; return &itr->second; } + NpcOptionLocale const* GetNpcOptionLocale(uint32 entry) const + { + NpcOptionLocaleMap::const_iterator itr = mNpcOptionLocaleMap.find(entry); + if(itr==mNpcOptionLocaleMap.end()) return NULL; + return &itr->second; + } GameObjectData const* GetGOData(uint32 guid) const { @@ -844,6 +852,7 @@ class ObjectMgr NpcTextLocaleMap mNpcTextLocaleMap; PageTextLocaleMap mPageTextLocaleMap; MangosStringLocaleMap mMangosStringLocaleMap; + NpcOptionLocaleMap mNpcOptionLocaleMap; RespawnTimes mCreatureRespawnTimes; RespawnTimes mGORespawnTimes; diff --git a/src/game/QuestHandler.cpp b/src/game/QuestHandler.cpp index 42eea5082..0334332a9 100644 --- a/src/game/QuestHandler.cpp +++ b/src/game/QuestHandler.cpp @@ -103,8 +103,8 @@ void WorldSession::HandleQuestgiverHelloOpcode( WorldPacket & recv_data ) if(Script->GossipHello( _player, pCreature ) ) return; - pCreature->prepareGossipMenu(_player,0); - pCreature->sendPreparedGossip( _player ); + pCreature->prepareGossipMenu(_player); + pCreature->sendPreparedGossip(_player); } void WorldSession::HandleQuestgiverAcceptQuestOpcode( WorldPacket & recv_data ) diff --git a/src/game/World.cpp b/src/game/World.cpp index 135493f7d..c32c29759 100644 --- a/src/game/World.cpp +++ b/src/game/World.cpp @@ -945,6 +945,7 @@ void World::SetInitialWorldSettings() objmgr.LoadQuestLocales(); objmgr.LoadNpcTextLocales(); objmgr.LoadPageTextLocales(); + objmgr.LoadNpcOptionLocales(); objmgr.SetDBCLocaleIndex(GetDefaultDbcLocale()); // Get once for all the locale index of DBC language (console/broadcasts) sLog.outString( "Loading Page Texts..." );