From 289758094ce9d4a457d25f0f42e0b4a855dd7888 Mon Sep 17 00:00:00 2001 From: Andrew <47818697+Nyeriah@users.noreply.github.com> Date: Sun, 9 Jun 2024 17:32:29 -0300 Subject: [PATCH] chore(Scripts/Hyjal): Clean up redundancy (#19035) --- .../CavernsOfTime/BattleForMountHyjal/hyjal.h | 2 + .../BattleForMountHyjal/instance_hyjal.cpp | 126 +++++++----------- 2 files changed, 47 insertions(+), 81 deletions(-) diff --git a/src/server/scripts/Kalimdor/CavernsOfTime/BattleForMountHyjal/hyjal.h b/src/server/scripts/Kalimdor/CavernsOfTime/BattleForMountHyjal/hyjal.h index 4f2493e7c..8575d7e35 100644 --- a/src/server/scripts/Kalimdor/CavernsOfTime/BattleForMountHyjal/hyjal.h +++ b/src/server/scripts/Kalimdor/CavernsOfTime/BattleForMountHyjal/hyjal.h @@ -90,6 +90,7 @@ enum HyjalCreaturesIds NPC_ALLIANCE_RIFLEMAN = 17921, NPC_ALLIANCE_PRIEST = 17928, NPC_ALLIANCE_SORCERESS = 17922, + NPC_GUARDIAN_ELEMENTAL = 18001, // Horde Base NPC_THRALL = 17852, @@ -102,6 +103,7 @@ enum HyjalCreaturesIds NPC_HORDE_PEON = 17937, NPC_INFERNAL_RELAY = 18242, NPC_INFERNAL_TARGET = 21075, + NPC_DIRE_WOLF = 17854, // Night Elf Base NPC_TYRANDE = 17948, diff --git a/src/server/scripts/Kalimdor/CavernsOfTime/BattleForMountHyjal/instance_hyjal.cpp b/src/server/scripts/Kalimdor/CavernsOfTime/BattleForMountHyjal/instance_hyjal.cpp index 2589d7067..76749ed62 100644 --- a/src/server/scripts/Kalimdor/CavernsOfTime/BattleForMountHyjal/instance_hyjal.cpp +++ b/src/server/scripts/Kalimdor/CavernsOfTime/BattleForMountHyjal/instance_hyjal.cpp @@ -51,11 +51,6 @@ ObjectData const creatureData[] = { 0, 0 } }; -ObjectData const objectData[] = -{ - { 0, 0 } -}; - Milliseconds hyjalWaveTimers[4][MAX_WAVES_STANDARD] { { 130000ms, 130000ms, 130000ms, 130000ms, 130000ms, 130000ms, 130000ms, 190000ms, 0ms }, // Winterchill @@ -92,7 +87,7 @@ public: SetHeaders(DataHeader); SetBossNumber(EncounterCount); LoadDoorData(doorData); - LoadObjectData(creatureData, objectData); + LoadObjectData(creatureData, nullptr); } void Initialize() override @@ -203,6 +198,8 @@ public: break; case NPC_TOWERING_INFERNAL: case NPC_LESSER_DOOMGUARD: + case NPC_DIRE_WOLF: + case NPC_GUARDIAN_ELEMENTAL: if (creature->IsSummon()) { _summonedNPCs.insert(creature->GetGUID()); @@ -243,6 +240,8 @@ public: break; case NPC_TOWERING_INFERNAL: case NPC_LESSER_DOOMGUARD: + case NPC_DIRE_WOLF: + case NPC_GUARDIAN_ELEMENTAL: _summonedNPCs.erase(creature->GetGUID()); break; case NPC_WINTERCHILL: @@ -250,9 +249,9 @@ public: case NPC_KAZROGAL: case NPC_AZGALOR: if (Creature* jaina = GetCreature(DATA_JAINA)) - jaina->SetFlag(UNIT_NPC_FLAGS, UNIT_NPC_FLAG_GOSSIP); + jaina->SetNpcFlag(UNIT_NPC_FLAG_GOSSIP); if (Creature* thrall = GetCreature(DATA_THRALL)) - thrall->SetFlag(UNIT_NPC_FLAGS, UNIT_NPC_FLAG_GOSSIP); + thrall->SetNpcFlag(UNIT_NPC_FLAG_GOSSIP); SetData(DATA_RESET_WAVES, 1); break; } @@ -290,14 +289,14 @@ public: } // Despawn all alliance NPCs - _scheduler.Schedule(21000ms, [this](TaskContext) + scheduler.Schedule(21000ms, [this](TaskContext) { for (ObjectGuid const& guid : _baseAlliance) if (Creature* creature = instance->GetCreature(guid)) creature->DespawnOrUnsummon(); // Spawn Roaring Flame after a delay - _scheduler.Schedule(30s, [this](TaskContext) + scheduler.Schedule(30s, [this](TaskContext) { for (ObjectGuid const& guid : _roaringFlameAlliance) { @@ -338,13 +337,13 @@ public: } } - _scheduler.Schedule(21000ms, [this](TaskContext) + scheduler.Schedule(21000ms, [this](TaskContext) { for (ObjectGuid const& guid : _baseHorde) if (Creature* creature = instance->GetCreature(guid)) creature->DespawnOrUnsummon(); - _scheduler.Schedule(30s, [this](TaskContext) + scheduler.Schedule(30s, [this](TaskContext) { for (ObjectGuid const& guid : _roaringFlameHorde) if (GameObject* flame = instance->GetGameObject(guid)) @@ -399,6 +398,10 @@ public: _bossWave = DATA_ARCHIMONDE; ScheduleWaves(1ms, START_WAVE_NIGHT_ELF, MAX_WAVES_NIGHT_ELF, hyjalNightElfWaveTimers[0]); } + + if (_bossWave) + DoUpdateWorldState(WORLD_STATE_WAVES, 0); + break; case DATA_SPAWN_INFERNALS: { @@ -419,84 +422,46 @@ public: } } break; - case DATA_RESET_ALLIANCE: - for (ObjectGuid const& guid : _baseAlliance) - if (Creature* creature = instance->GetCreature(guid)) - creature->DespawnOrUnsummon(); - - for (ObjectGuid const& guid : _encounterNPCs) - if (Creature* creature = instance->GetCreature(guid)) - creature->DespawnOrUnsummon(); - - // also force despawn boss summons - for (ObjectGuid const& guid : _summonedNPCs) - if (Creature* creature = instance->GetCreature(guid)) - creature->DespawnOrUnsummon(); - - if (_bossWave && (GetBossState(_bossWave) != DONE)) - SetBossState(_bossWave, NOT_STARTED); - - _scheduler.Schedule(300s, [this](TaskContext) - { - for (ObjectGuid const& guid : _baseAlliance) - if (Creature* creature = instance->GetCreature(guid)) - creature->Respawn(); - }); - - SetData(DATA_RESET_WAVES, 0); - break; - case DATA_RESET_HORDE: - for (ObjectGuid const& guid : _baseHorde) - if (Creature* creature = instance->GetCreature(guid)) - creature->DespawnOrUnsummon(); - - for (ObjectGuid const& guid : _encounterNPCs) - if (Creature* creature = instance->GetCreature(guid)) - creature->DespawnOrUnsummon(); - - // also force despawn boss summons - for (ObjectGuid const& guid : _summonedNPCs) - if (Creature* creature = instance->GetCreature(guid)) - creature->DespawnOrUnsummon(); - - if (_bossWave && (GetBossState(_bossWave) != DONE)) - SetBossState(_bossWave, NOT_STARTED); - - _scheduler.Schedule(300s, [this](TaskContext) - { - for (ObjectGuid const& guid : _baseHorde) - if (Creature* creature = instance->GetCreature(guid)) - creature->Respawn(); - }); - - SetData(DATA_RESET_WAVES, 0); - break; case DATA_RESET_NIGHT_ELF: + if (Creature* archimonde = GetCreature(DATA_ARCHIMONDE)) + archimonde->DespawnOrUnsummon(0s, 300s); + [[fallthrough]]; + case DATA_RESET_ALLIANCE: + case DATA_RESET_HORDE: + if (GetBossState(DATA_ANETHERON) != DONE) + { + for (ObjectGuid const& guid : _baseAlliance) + if (Creature* creature = instance->GetCreature(guid)) + creature->DespawnOrUnsummon(0s, 300s); + } + + if (GetBossState(DATA_AZGALOR) != DONE) + { + for (ObjectGuid const& guid : _baseHorde) + if (Creature* creature = instance->GetCreature(guid)) + creature->DespawnOrUnsummon(0s, 300s); + } + for (ObjectGuid const& guid : _baseNightElf) if (Creature* creature = instance->GetCreature(guid)) - creature->DespawnOrUnsummon(); + creature->DespawnOrUnsummon(0s, 300s); for (ObjectGuid const& guid : _encounterNPCs) if (Creature* creature = instance->GetCreature(guid)) creature->DespawnOrUnsummon(); - if (Creature* archimonde = GetCreature(DATA_ARCHIMONDE)) - archimonde->DespawnOrUnsummon(); + // also force despawn boss summons + for (ObjectGuid const& guid : _summonedNPCs) + if (Creature* creature = instance->GetCreature(guid)) + creature->DespawnOrUnsummon(); - _scheduler.Schedule(300s, [this](TaskContext) - { - for (ObjectGuid const& guid : _baseNightElf) - if (Creature* creature = instance->GetCreature(guid)) - creature->Respawn(); - - if (Creature* archi = GetCreature(DATA_ARCHIMONDE)) - archi->Respawn(); - }); + if (_bossWave && (GetBossState(_bossWave) != DONE)) + SetBossState(_bossWave, NOT_STARTED); SetData(DATA_RESET_WAVES, 0); break; case DATA_RESET_WAVES: - _scheduler.CancelGroup(CONTEXT_GROUP_WAVES); + scheduler.CancelGroup(CONTEXT_GROUP_WAVES); _encounterNPCs.clear(); _summonedNPCs.clear(); _currentWave = 0; @@ -533,10 +498,10 @@ public: void ScheduleWaves(Milliseconds /* time */, uint8 startWaves, uint8 maxWaves, Milliseconds timerptr[]) { // No overlapping! - _scheduler.CancelGroup(CONTEXT_GROUP_WAVES); + scheduler.CancelGroup(CONTEXT_GROUP_WAVES); trash = 0; // Reset counter here to avoid resetting the counter from scheduled waves. Required because creatures killed for RP events counts towards the kill counter as well, confirmed in Retail. - _scheduler.Schedule(1ms, [this, startWaves, maxWaves, timerptr](TaskContext context) + scheduler.Schedule(1ms, [this, startWaves, maxWaves, timerptr](TaskContext context) { // If all waves reached, cancel scheduling new ones if (_currentWave >= maxWaves) @@ -572,7 +537,7 @@ public: void Update(uint32 diff) override { - _scheduler.Update(diff); + scheduler.Update(diff); } void OnPlayerInWaterStateUpdate(Player* player, bool inWater) override @@ -588,7 +553,6 @@ public: uint8 _currentWave; uint8 _bossWave; uint8 _retreat; - TaskScheduler _scheduler; GuidSet _encounterNPCs; GuidSet _summonedNPCs; GuidSet _baseAlliance;