diff options
-rw-r--r-- | sql/updates/world/master/2017_11_18_00_world.sql | 2 | ||||
-rw-r--r-- | src/server/game/Entities/Conversation/Conversation.cpp | 8 | ||||
-rw-r--r-- | src/server/game/Entities/Conversation/Conversation.h | 2 | ||||
-rw-r--r-- | src/server/game/Globals/ConversationDataStore.cpp | 3 | ||||
-rw-r--r-- | src/server/game/Globals/ConversationDataStore.h | 2 | ||||
-rw-r--r-- | src/server/game/Globals/ObjectMgr.cpp | 2 | ||||
-rw-r--r-- | src/server/game/Scripting/ScriptMgr.cpp | 22 | ||||
-rw-r--r-- | src/server/game/Scripting/ScriptMgr.h | 17 | ||||
-rw-r--r-- | src/server/scripts/World/conversation_scripts.cpp | 20 | ||||
-rw-r--r-- | src/server/scripts/World/world_script_loader.cpp | 2 |
10 files changed, 78 insertions, 2 deletions
diff --git a/sql/updates/world/master/2017_11_18_00_world.sql b/sql/updates/world/master/2017_11_18_00_world.sql new file mode 100644 index 00000000000..643e5654187 --- /dev/null +++ b/sql/updates/world/master/2017_11_18_00_world.sql @@ -0,0 +1,2 @@ +ALTER TABLE `conversation_template` + ADD COLUMN `ScriptName` VARCHAR(64) NOT NULL DEFAULT '' AFTER `LastLineEndTime`; diff --git a/src/server/game/Entities/Conversation/Conversation.cpp b/src/server/game/Entities/Conversation/Conversation.cpp index 9d985683d0b..f781c5bf066 100644 --- a/src/server/game/Entities/Conversation/Conversation.cpp +++ b/src/server/game/Entities/Conversation/Conversation.cpp @@ -20,6 +20,7 @@ #include "IteratorPair.h" #include "Log.h" #include "Map.h" +#include "ScriptMgr.h" #include "Unit.h" #include "UpdateData.h" @@ -154,6 +155,8 @@ bool Conversation::Create(ObjectGuid::LowType lowGuid, uint32 conversationEntry, AddDynamicStructuredValue(CONVERSATION_DYNAMIC_FIELD_LINES, line); } + sScriptMgr->OnConversationCreate(this, creator); + // All actors need to be set for (uint16 actorIndex : actorIndices) { @@ -183,3 +186,8 @@ void Conversation::AddParticipant(ObjectGuid const& participantGuid) { _participants.insert(participantGuid); } + +uint32 Conversation::GetScriptId() const +{ + return sConversationDataStore->GetConversationTemplate(GetEntry())->ScriptId; +} diff --git a/src/server/game/Entities/Conversation/Conversation.h b/src/server/game/Entities/Conversation/Conversation.h index 780252a260a..d27dc0dea97 100644 --- a/src/server/game/Entities/Conversation/Conversation.h +++ b/src/server/game/Entities/Conversation/Conversation.h @@ -89,6 +89,8 @@ class TC_GAME_API Conversation : public WorldObject, public GridObject<Conversat float GetStationaryO() const override { return _stationaryPosition.GetOrientation(); } void RelocateStationaryPosition(Position const& pos) { _stationaryPosition.Relocate(pos); } + uint32 GetScriptId() const; + private: Position _stationaryPosition; ObjectGuid _creatorGuid; diff --git a/src/server/game/Globals/ConversationDataStore.cpp b/src/server/game/Globals/ConversationDataStore.cpp index 1e825f5171b..f8187056c89 100644 --- a/src/server/game/Globals/ConversationDataStore.cpp +++ b/src/server/game/Globals/ConversationDataStore.cpp @@ -150,7 +150,7 @@ void ConversationDataStore::LoadConversationTemplates() TC_LOG_INFO("server.loading", ">> Loaded 0 Conversation actors. DB table `conversation_actors` is empty."); } - if (QueryResult templates = WorldDatabase.Query("SELECT Id, FirstLineId, LastLineEndTime, VerifiedBuild FROM conversation_template")) + if (QueryResult templates = WorldDatabase.Query("SELECT Id, FirstLineId, LastLineEndTime, ScriptName FROM conversation_template")) { uint32 oldMSTime = getMSTime(); @@ -162,6 +162,7 @@ void ConversationDataStore::LoadConversationTemplates() conversationTemplate.Id = fields[0].GetUInt32(); conversationTemplate.FirstLineId = fields[1].GetUInt32(); conversationTemplate.LastLineEndTime = fields[2].GetUInt32(); + conversationTemplate.ScriptId = sObjectMgr->GetScriptId(fields[3].GetString()); conversationTemplate.Actors = std::move(actorsByConversation[conversationTemplate.Id]); conversationTemplate.ActorGuids = std::move(actorGuidsByConversation[conversationTemplate.Id]); diff --git a/src/server/game/Globals/ConversationDataStore.h b/src/server/game/Globals/ConversationDataStore.h index ff4969b285c..d375354093d 100644 --- a/src/server/game/Globals/ConversationDataStore.h +++ b/src/server/game/Globals/ConversationDataStore.h @@ -50,6 +50,8 @@ struct ConversationTemplate std::vector<ConversationActorTemplate const*> Actors; std::vector<ObjectGuid::LowType> ActorGuids; std::vector<ConversationLineTemplate const*> Lines; + + uint32 ScriptId; }; class TC_GAME_API ConversationDataStore diff --git a/src/server/game/Globals/ObjectMgr.cpp b/src/server/game/Globals/ObjectMgr.cpp index 3761fd2b142..2bfab7ca5a8 100644 --- a/src/server/game/Globals/ObjectMgr.cpp +++ b/src/server/game/Globals/ObjectMgr.cpp @@ -9089,6 +9089,8 @@ void ObjectMgr::LoadScriptNames() QueryResult result = WorldDatabase.Query( "SELECT DISTINCT(ScriptName) FROM battleground_template WHERE ScriptName <> '' " "UNION " + "SELECT DISTINCT(ScriptName) FROM conversation_template WHERE ScriptName <> '' " + "UNION " "SELECT DISTINCT(ScriptName) FROM creature WHERE ScriptName <> '' " "UNION " "SELECT DISTINCT(ScriptName) FROM creature_template WHERE ScriptName <> '' " diff --git a/src/server/game/Scripting/ScriptMgr.cpp b/src/server/game/Scripting/ScriptMgr.cpp index 3eed0132d3c..2e7bd6b52da 100644 --- a/src/server/game/Scripting/ScriptMgr.cpp +++ b/src/server/game/Scripting/ScriptMgr.cpp @@ -20,6 +20,7 @@ #include "AreaTrigger.h" #include "AreaTriggerAI.h" #include "Chat.h" +#include "Conversation.h" #include "Creature.h" #include "CreatureAI.h" #include "CreatureAIImpl.h" @@ -110,6 +111,10 @@ struct is_script_database_bound<AreaTriggerEntityScript> : std::true_type { }; template<> +struct is_script_database_bound<ConversationScript> + : std::true_type { }; + +template<> struct is_script_database_bound<SceneScript> : std::true_type { }; @@ -328,7 +333,6 @@ class ScriptRegistrySwapHooks { }; -/// This hook is responsible for swapping OutdoorPvP's template<typename Base> class UnsupportedScriptRegistrySwapHooks : public ScriptRegistrySwapHookBase @@ -2410,6 +2414,15 @@ void ScriptMgr::ModifySpellDamageTaken(Unit* target, Unit* attacker, int32& dama FOREACH_SCRIPT(PlayerScript)->ModifySpellDamageTaken(target, attacker, damage); } +// Conversation +void ScriptMgr::OnConversationCreate(Conversation* conversation, Unit* creator) +{ + ASSERT(conversation); + + GET_SCRIPT(ConversationScript, conversation->GetScriptId(), tmpscript); + tmpscript->OnConversationCreate(conversation, creator); +} + // Scene void ScriptMgr::OnSceneStart(Player* player, uint32 sceneInstanceID, SceneTemplate const* sceneTemplate) { @@ -2644,6 +2657,12 @@ AreaTriggerEntityScript::AreaTriggerEntityScript(const char* name) ScriptRegistry<AreaTriggerEntityScript>::Instance()->AddScript(this); } +ConversationScript::ConversationScript(char const* name) + : ScriptObject(name) +{ + ScriptRegistry<ConversationScript>::Instance()->AddScript(this); +} + // Specialize for each script type class like so: template class TC_GAME_API ScriptRegistry<SpellScriptLoader>; template class TC_GAME_API ScriptRegistry<ServerScript>; @@ -2672,4 +2691,5 @@ template class TC_GAME_API ScriptRegistry<GroupScript>; template class TC_GAME_API ScriptRegistry<UnitScript>; template class TC_GAME_API ScriptRegistry<AccountScript>; template class TC_GAME_API ScriptRegistry<AreaTriggerEntityScript>; +template class TC_GAME_API ScriptRegistry<ConversationScript>; template class TC_GAME_API ScriptRegistry<SceneScript>; diff --git a/src/server/game/Scripting/ScriptMgr.h b/src/server/game/Scripting/ScriptMgr.h index eea4d7cc39c..fb1e8668558 100644 --- a/src/server/game/Scripting/ScriptMgr.h +++ b/src/server/game/Scripting/ScriptMgr.h @@ -33,6 +33,7 @@ class Battleground; class BattlegroundMap; class Channel; class ChatCommand; +class Conversation; class Creature; class CreatureAI; class DynamicObject; @@ -859,6 +860,17 @@ class TC_GAME_API AreaTriggerEntityScript : public ScriptObject virtual AreaTriggerAI* GetAI(AreaTrigger* /*at*/) const { return nullptr; } }; +class TC_GAME_API ConversationScript : public ScriptObject +{ + protected: + ConversationScript(char const* name); + + public: + + // Called when Conversation is created but not added to Map yet. + virtual void OnConversationCreate(Conversation* /*conversation*/, Unit* /*creator*/) { } +}; + class TC_GAME_API SceneScript : public ScriptObject { protected: @@ -1161,7 +1173,12 @@ class TC_GAME_API ScriptMgr AreaTriggerAI* GetAreaTriggerAI(AreaTrigger* areaTrigger); + public: /* ConversationScript */ + + void OnConversationCreate(Conversation* conversation, Unit* creator); + public: /* SceneScript */ + void OnSceneStart(Player* player, uint32 sceneInstanceID, SceneTemplate const* sceneTemplate); void OnSceneTrigger(Player* player, uint32 sceneInstanceID, SceneTemplate const* sceneTemplate, std::string const& triggerName); void OnSceneCancel(Player* player, uint32 sceneInstanceID, SceneTemplate const* sceneTemplate); diff --git a/src/server/scripts/World/conversation_scripts.cpp b/src/server/scripts/World/conversation_scripts.cpp new file mode 100644 index 00000000000..f00d5e8a75a --- /dev/null +++ b/src/server/scripts/World/conversation_scripts.cpp @@ -0,0 +1,20 @@ +/* + * Copyright (C) 2008-2017 TrinityCore <http://www.trinitycore.org/> + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your + * option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +void AddSC_conversation_scripts() +{ +} diff --git a/src/server/scripts/World/world_script_loader.cpp b/src/server/scripts/World/world_script_loader.cpp index e1a47362770..03187e13acc 100644 --- a/src/server/scripts/World/world_script_loader.cpp +++ b/src/server/scripts/World/world_script_loader.cpp @@ -20,6 +20,7 @@ // This is where scripts' loading functions should be declared: // world void AddSC_areatrigger_scripts(); +void AddSC_conversation_scripts(); void AddSC_emerald_dragons(); void AddSC_generic_creature(); void AddSC_go_scripts(); @@ -40,6 +41,7 @@ void AddSC_duel_reset(); void AddWorldScripts() { AddSC_areatrigger_scripts(); + AddSC_conversation_scripts(); AddSC_emerald_dragons(); AddSC_generic_creature(); AddSC_go_scripts(); |