aboutsummaryrefslogtreecommitdiff
path: root/src/server/game/Scripting/ScriptMgr.cpp
diff options
context:
space:
mode:
authorModoX <moardox@gmail.com>2024-12-28 23:25:10 +0100
committerOvahlord <dreadkiller@gmx.de>2024-12-29 12:16:46 +0100
commit1f81c961f24337abdc8de25bd23d9834d0c7392b (patch)
tree46b4699d0b3ffbc4b197913064659abd978d1ed3 /src/server/game/Scripting/ScriptMgr.cpp
parent9b49b9009d010b56b0289e8122bedceb172e4948 (diff)
Core/AI: Implemented conversation ai (#30538)
(cherry picked from commit 309ba22a15e5e0b4321b99f7157ccb18e0adc8dd) # Conflicts: # src/server/scripts/BrokenIsles/zone_mardum.cpp # src/server/scripts/DragonIsles/AberrusTheShadowedCrucible/aberrus_the_shadowed_crucible.cpp # src/server/scripts/EasternKingdoms/zone_stormwind_city.cpp # src/server/scripts/KulTiras/WaycrestManor/waycrest_manor.cpp # src/server/scripts/KulTiras/zone_boralus.cpp # src/server/scripts/Shadowlands/SanctumOfDomination/boss_sylvanas_windrunner.cpp # src/server/scripts/Shadowlands/SepulcherOfTheFirstOnes/boss_anduin_wrynn.cpp # src/server/scripts/Zandalar/KingsRest/kings_rest.cpp
Diffstat (limited to 'src/server/game/Scripting/ScriptMgr.cpp')
-rw-r--r--src/server/game/Scripting/ScriptMgr.cpp118
1 files changed, 66 insertions, 52 deletions
diff --git a/src/server/game/Scripting/ScriptMgr.cpp b/src/server/game/Scripting/ScriptMgr.cpp
index e69b64a73fa..99f25980a0d 100644
--- a/src/server/game/Scripting/ScriptMgr.cpp
+++ b/src/server/game/Scripting/ScriptMgr.cpp
@@ -21,6 +21,7 @@
#include "AreaTriggerAI.h"
#include "ChatCommand.h"
#include "Conversation.h"
+#include "ConversationAI.h"
#include "Creature.h"
#include "CreatureAI.h"
#include "CreatureAIImpl.h"
@@ -382,7 +383,7 @@ public:
/// This hook is responsible for swapping Creature, GameObject and AreaTrigger AI's
template<typename ObjectType, typename ScriptType, typename Base>
-class CreatureGameObjectAreaTriggerScriptRegistrySwapHooks
+class CreatureGameObjectAreaTriggerConversationScriptRegistrySwapHooks
: public ScriptRegistrySwapHookBase
{
template<typename W>
@@ -484,6 +485,24 @@ class CreatureGameObjectAreaTriggerScriptRegistrySwapHooks
"The AI should be null here!");
}
+ // Hook which is called before a conversation is swapped
+ static void UnloadResetScript(Conversation* conversation)
+ {
+ // Remove deletable events only,
+ // otherwise it causes crashes with non-deletable spell events.
+ conversation->m_Events.KillAllEvents(false);
+
+ conversation->AI()->OnRemove();
+ }
+
+ static void UnloadDestroyScript(Conversation* conversation)
+ {
+ conversation->AI_Destroy();
+
+ ASSERT(!conversation->AI(),
+ "The AI should be null here!");
+ }
+
// Hook which is called after a creature was swapped
static void LoadInitializeScript(Creature* creature)
{
@@ -543,6 +562,20 @@ class CreatureGameObjectAreaTriggerScriptRegistrySwapHooks
at->AI()->OnCreate(nullptr);
}
+ // Hook which is called after a conversation was swapped
+ static void LoadInitializeScript(Conversation* conversation)
+ {
+ ASSERT(!conversation->AI(),
+ "The AI should be null here!");
+
+ conversation->AI_Initialize();
+ }
+
+ static void LoadResetScript(Conversation* conversation)
+ {
+ conversation->AI()->OnCreate(nullptr);
+ }
+
static Creature* GetEntityFromMap(std::common_type<Creature>, Map* map, ObjectGuid const& guid)
{
return map->GetCreature(guid);
@@ -558,6 +591,11 @@ class CreatureGameObjectAreaTriggerScriptRegistrySwapHooks
return map->GetAreaTrigger(guid);
}
+ static Conversation* GetEntityFromMap(std::common_type<Conversation>, Map* map, ObjectGuid const& guid)
+ {
+ return map->GetConversation(guid);
+ }
+
static auto VisitObjectsToSwapOnMap(std::unordered_set<uint32> const& idsToRemove)
{
return [&idsToRemove](Map* map, auto&& visitor)
@@ -731,24 +769,32 @@ private:
// This hook is responsible for swapping CreatureAI's
template<typename Base>
class ScriptRegistrySwapHooks<CreatureScript, Base>
- : public CreatureGameObjectAreaTriggerScriptRegistrySwapHooks<
+ : public CreatureGameObjectAreaTriggerConversationScriptRegistrySwapHooks<
Creature, CreatureScript, Base
> { };
// This hook is responsible for swapping GameObjectAI's
template<typename Base>
class ScriptRegistrySwapHooks<GameObjectScript, Base>
- : public CreatureGameObjectAreaTriggerScriptRegistrySwapHooks<
+ : public CreatureGameObjectAreaTriggerConversationScriptRegistrySwapHooks<
GameObject, GameObjectScript, Base
> { };
// This hook is responsible for swapping AreaTriggerAI's
template<typename Base>
class ScriptRegistrySwapHooks<AreaTriggerEntityScript, Base>
- : public CreatureGameObjectAreaTriggerScriptRegistrySwapHooks<
+ : public CreatureGameObjectAreaTriggerConversationScriptRegistrySwapHooks<
AreaTrigger, AreaTriggerEntityScript, Base
> { };
+// This hook is responsible for swapping ConversationAI's
+template<typename Base>
+class ScriptRegistrySwapHooks<ConversationScript, Base>
+ : public CreatureGameObjectAreaTriggerConversationScriptRegistrySwapHooks<
+ Conversation, ConversationScript, Base
+ > {
+};
+
/// This hook is responsible for swapping BattlefieldScripts
template<typename Base>
class ScriptRegistrySwapHooks<BattlefieldScript, Base>
@@ -955,7 +1001,7 @@ class SpecializedScriptRegistry<ScriptType, true>
friend class ScriptRegistrySwapHooks;
template<typename, typename, typename>
- friend class CreatureGameObjectAreaTriggerScriptRegistrySwapHooks;
+ friend class CreatureGameObjectAreaTriggerConversationScriptRegistrySwapHooks;
public:
SpecializedScriptRegistry() { }
@@ -1752,6 +1798,19 @@ bool ScriptMgr::OnAreaTrigger(Player* player, AreaTriggerEntry const* trigger, b
return entered ? tmpscript->OnTrigger(player, trigger) : tmpscript->OnExit(player, trigger);
}
+bool ScriptMgr::CanCreateConversationAI(uint32 scriptId) const
+{
+ return !!ScriptRegistry<ConversationScript>::Instance()->GetScriptById(scriptId);
+}
+
+ConversationAI* ScriptMgr::GetConversationAI(Conversation* conversation)
+{
+ ASSERT(conversation);
+
+ GET_SCRIPT_RET(ConversationScript, conversation->GetScriptId(), tmpscript, nullptr);
+ return tmpscript->GetAI(conversation);
+}
+
Battlefield* ScriptMgr::CreateBattlefield(uint32 scriptId, Map* map)
{
GET_SCRIPT_RET(BattlefieldScript, scriptId, tmpscript, nullptr);
@@ -2279,40 +2338,6 @@ void ScriptMgr::ModifySpellDamageTaken(Unit* target, Unit* attacker, int32& dama
FOREACH_SCRIPT(UnitScript)->ModifySpellDamageTaken(target, attacker, damage, spellInfo);
}
-// Conversation
-void ScriptMgr::OnConversationCreate(Conversation* conversation, Unit* creator)
-{
- ASSERT(conversation);
-
- GET_SCRIPT(ConversationScript, conversation->GetScriptId(), tmpscript);
- tmpscript->OnConversationCreate(conversation, creator);
-}
-
-void ScriptMgr::OnConversationStart(Conversation* conversation)
-{
- ASSERT(conversation);
-
- GET_SCRIPT(ConversationScript, conversation->GetScriptId(), tmpscript);
- tmpscript->OnConversationStart(conversation);
-}
-
-void ScriptMgr::OnConversationLineStarted(Conversation* conversation, uint32 lineId, Player* sender)
-{
- ASSERT(conversation);
- ASSERT(sender);
-
- GET_SCRIPT(ConversationScript, conversation->GetScriptId(), tmpscript);
- tmpscript->OnConversationLineStarted(conversation, lineId, sender);
-}
-
-void ScriptMgr::OnConversationUpdate(Conversation* conversation, uint32 diff)
-{
- ASSERT(conversation);
-
- GET_SCRIPT(ConversationScript, conversation->GetScriptId(), tmpscript);
- tmpscript->OnConversationUpdate(conversation, diff);
-}
-
// Scene
void ScriptMgr::OnSceneStart(Player* player, uint32 sceneInstanceID, SceneTemplate const* sceneTemplate)
{
@@ -3172,20 +3197,9 @@ ConversationScript::ConversationScript(char const* name)
ConversationScript::~ConversationScript() = default;
-void ConversationScript::OnConversationCreate(Conversation* /*conversation*/, Unit* /*creator*/)
-{
-}
-
-void ConversationScript::OnConversationStart(Conversation* /*conversation*/ )
-{
-}
-
-void ConversationScript::OnConversationLineStarted(Conversation* /*conversation*/, uint32 /*lineId*/, Player* /*sender*/)
-{
-}
-
-void ConversationScript::OnConversationUpdate(Conversation* /*conversation*/, uint32 /*diff*/)
+ConversationAI* ConversationScript::GetAI(Conversation* /*conversation*/) const
{
+ return nullptr;
}
SceneScript::SceneScript(char const* name)