From 33760d280a34ad45902a33178863f9c1b13abbc9 Mon Sep 17 00:00:00 2001 From: killerwife Date: Fri, 29 Dec 2023 11:04:06 +0100 Subject: [PATCH] World/HFP: Reimplement Magtheridons head to be despawned and respawn on quest --- .../scripts/outland/hellfire_peninsula.cpp | 23 ++++---- .../scripts/outland/world_outland.cpp | 10 ++++ .../scripts/outland/world_outland.h | 2 + src/game/World/WorldState.cpp | 53 ++++--------------- 4 files changed, 35 insertions(+), 53 deletions(-) diff --git a/src/game/AI/ScriptDevAI/scripts/outland/hellfire_peninsula.cpp b/src/game/AI/ScriptDevAI/scripts/outland/hellfire_peninsula.cpp index 4a9c3fd6f5..2221d0b9ca 100644 --- a/src/game/AI/ScriptDevAI/scripts/outland/hellfire_peninsula.cpp +++ b/src/game/AI/ScriptDevAI/scripts/outland/hellfire_peninsula.cpp @@ -39,6 +39,8 @@ EndContentData */ #include "AI/BaseAI/PetAI.h" #include "AI/ScriptDevAI/base/CombatAI.h" #include "Entities/TemporarySpawn.h" +#include "AI/ScriptDevAI/scripts/outland/world_outland.h" +#include "World/WorldState.h" /*###### ## npc_aeranas @@ -1403,13 +1405,8 @@ enum YELL_NAZGREL_1 = -1000592, YELL_NAZGREL_2 = -1000593, - SPELL_TROLLBANES_COMMAND = 39911, - SPELL_NAZGRELS_FAVOR = 39913, - MAX_SEARCH_DIST = 2170, - OBJECT_MAGTHERIDONS_HEAD = 184640 - // NPC_DANATH_TROLLBANE = 16819, // NPC_NAZGREL = 3230 }; @@ -1457,9 +1454,11 @@ struct npc_danath_trollbaneAI : public ScriptedAI m_bOnYell2 = false; // Mount Magtheridon's Head (update object) - if (GameObject* goHead = GetClosestGameObjectWithEntry(m_creature, OBJECT_MAGTHERIDONS_HEAD, 120.0f)) - if (Unit* invoker = m_creature->GetMap()->GetUnit(m_guidInvoker)) - goHead->Use(invoker); + if (ScriptedInstance* instance = dynamic_cast(m_creature->GetInstanceData())) + if (GameObject* goHead = GetClosestGameObjectWithEntry(m_creature, GO_MAGTHERIDONS_HEAD, 120.0f)) + instance->DoRespawnGameObject(goHead->GetObjectGuid(), 120 * MINUTE); + + sWorldState.BuffMagtheridonTeam(ALLIANCE); } else m_uiYell2DelayRemaining -= uiDiff; @@ -1541,9 +1540,11 @@ struct npc_nazgrelAI : public ScriptedAI m_bOnYell2 = false; // Mount Magtheridon's Head (update object) - if (GameObject* goHead = GetClosestGameObjectWithEntry(m_creature, OBJECT_MAGTHERIDONS_HEAD, 120.0f)) - if (Unit* invoker = m_creature->GetMap()->GetUnit(m_guidInvoker)) - goHead->Use(invoker); + if (ScriptedInstance* instance = dynamic_cast(m_creature->GetInstanceData())) + if (GameObject* goHead = GetClosestGameObjectWithEntry(m_creature, GO_MAGTHERIDONS_HEAD, 120.0f)) + instance->DoRespawnGameObject(goHead->GetObjectGuid(), 120 * MINUTE); + + sWorldState.BuffMagtheridonTeam(HORDE); } else m_uiYell2DelayRemaining -= uiDiff; diff --git a/src/game/AI/ScriptDevAI/scripts/outland/world_outland.cpp b/src/game/AI/ScriptDevAI/scripts/outland/world_outland.cpp index 40556c3787..2db9cc0aea 100644 --- a/src/game/AI/ScriptDevAI/scripts/outland/world_outland.cpp +++ b/src/game/AI/ScriptDevAI/scripts/outland/world_outland.cpp @@ -1770,6 +1770,16 @@ struct world_map_outland : public ScriptedMap, public TimerManager } } + void OnObjectDespawn(GameObject* go) override + { + switch (go->GetEntry()) + { + case GO_MAGTHERIDONS_HEAD: + sWorldState.DispelMagtheridonTeam(go->GetPositionX() > 0.f ? HORDE : ALLIANCE); + break; + } + } + void Update(const uint32 diff) override { UpdateTimers(diff); diff --git a/src/game/AI/ScriptDevAI/scripts/outland/world_outland.h b/src/game/AI/ScriptDevAI/scripts/outland/world_outland.h index a214d47c5f..d9fabdd7b1 100644 --- a/src/game/AI/ScriptDevAI/scripts/outland/world_outland.h +++ b/src/game/AI/ScriptDevAI/scripts/outland/world_outland.h @@ -69,6 +69,8 @@ enum NPC_YSIEL_WINDSINGER = 17841, GO_HALAA_BANNER = 182210, + + GO_MAGTHERIDONS_HEAD = 184640, }; enum Shartuul diff --git a/src/game/World/WorldState.cpp b/src/game/World/WorldState.cpp index 04f5dc2497..1fafb36d73 100644 --- a/src/game/World/WorldState.cpp +++ b/src/game/World/WorldState.cpp @@ -381,26 +381,6 @@ void WorldState::HandleGameObjectUse(GameObject* go, Unit* user) { switch (go->GetEntry()) { - case OBJECT_MAGTHERIDONS_HEAD: - { - std::lock_guard guard(m_mutex); - if (Player* player = dynamic_cast(user)) - { - if (player->GetTeam() == HORDE) - { - m_isMagtheridonHeadSpawnedHorde = true; - m_guidMagtheridonHeadHorde = go->GetObjectGuid(); - BuffMagtheridonTeam(HORDE); - } - else - { - m_isMagtheridonHeadSpawnedAlliance = true; - m_guidMagtheridonHeadAlliance = go->GetObjectGuid(); - BuffMagtheridonTeam(ALLIANCE); - } - } - break; - } case OBJECT_EVENT_TRAP_THRALL: { HandleExternalEvent(CUSTOM_EVENT_LOVE_IS_IN_THE_AIR_LEADER, LOVE_LEADER_THRALL); @@ -456,28 +436,7 @@ void WorldState::HandleGameObjectUse(GameObject* go, Unit* user) void WorldState::HandleGameObjectRevertState(GameObject* go) { - switch (go->GetEntry()) - { - case OBJECT_MAGTHERIDONS_HEAD: - { - std::lock_guard guard(m_mutex); - if (go->GetObjectGuid() == m_guidMagtheridonHeadHorde) - { - m_isMagtheridonHeadSpawnedHorde = false; - m_guidMagtheridonHeadHorde = ObjectGuid(); - DispelMagtheridonTeam(HORDE); - } - else if (go->GetObjectGuid() == m_guidMagtheridonHeadAlliance) - { - m_isMagtheridonHeadSpawnedAlliance = false; - m_guidMagtheridonHeadAlliance = ObjectGuid(); - DispelMagtheridonTeam(ALLIANCE); - } - break; - } - default: - break; - } + } void WorldState::HandlePlayerEnterZone(Player* player, uint32 zoneId) @@ -732,6 +691,11 @@ Map* WorldState::GetMap(uint32 mapId, Position const& invZone) void WorldState::BuffMagtheridonTeam(Team team) { + std::lock_guard guard(m_mutex); + if (team == HORDE) + m_isMagtheridonHeadSpawnedHorde = true; + else + m_isMagtheridonHeadSpawnedAlliance = true; for (ObjectGuid& guid : m_magtheridonHeadPlayers) { if (Player* player = sObjectMgr.GetPlayer(guid)) @@ -758,6 +722,11 @@ void WorldState::BuffMagtheridonTeam(Team team) void WorldState::DispelMagtheridonTeam(Team team) { + std::lock_guard guard(m_mutex); + if (team == HORDE) + m_isMagtheridonHeadSpawnedHorde = false; + else + m_isMagtheridonHeadSpawnedAlliance = false; for (ObjectGuid& guid : m_magtheridonHeadPlayers) { if (Player* player = sObjectMgr.GetPlayer(guid))