Skip to content

Commit

Permalink
World/HFP: Reimplement Magtheridons head to be despawned and respawn …
Browse files Browse the repository at this point in the history
…on quest
  • Loading branch information
killerwife committed Dec 29, 2023
1 parent f5b08d9 commit 33760d2
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 53 deletions.
23 changes: 12 additions & 11 deletions src/game/AI/ScriptDevAI/scripts/outland/hellfire_peninsula.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
};
Expand Down Expand Up @@ -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<ScriptedInstance*>(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;
Expand Down Expand Up @@ -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<ScriptedInstance*>(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;
Expand Down
10 changes: 10 additions & 0 deletions src/game/AI/ScriptDevAI/scripts/outland/world_outland.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions src/game/AI/ScriptDevAI/scripts/outland/world_outland.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ enum
NPC_YSIEL_WINDSINGER = 17841,

GO_HALAA_BANNER = 182210,

GO_MAGTHERIDONS_HEAD = 184640,
};

enum Shartuul
Expand Down
53 changes: 11 additions & 42 deletions src/game/World/WorldState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -381,26 +381,6 @@ void WorldState::HandleGameObjectUse(GameObject* go, Unit* user)
{
switch (go->GetEntry())
{
case OBJECT_MAGTHERIDONS_HEAD:
{
std::lock_guard<std::mutex> guard(m_mutex);
if (Player* player = dynamic_cast<Player*>(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);
Expand Down Expand Up @@ -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<std::mutex> 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)
Expand Down Expand Up @@ -732,6 +691,11 @@ Map* WorldState::GetMap(uint32 mapId, Position const& invZone)

void WorldState::BuffMagtheridonTeam(Team team)
{
std::lock_guard<std::mutex> guard(m_mutex);
if (team == HORDE)
m_isMagtheridonHeadSpawnedHorde = true;
else
m_isMagtheridonHeadSpawnedAlliance = true;
for (ObjectGuid& guid : m_magtheridonHeadPlayers)
{
if (Player* player = sObjectMgr.GetPlayer(guid))
Expand All @@ -758,6 +722,11 @@ void WorldState::BuffMagtheridonTeam(Team team)

void WorldState::DispelMagtheridonTeam(Team team)
{
std::lock_guard<std::mutex> guard(m_mutex);
if (team == HORDE)
m_isMagtheridonHeadSpawnedHorde = false;
else
m_isMagtheridonHeadSpawnedAlliance = false;
for (ObjectGuid& guid : m_magtheridonHeadPlayers)
{
if (Player* player = sObjectMgr.GetPlayer(guid))
Expand Down

0 comments on commit 33760d2

Please sign in to comment.