chore(Scripts/Hyjal): Clean up redundancy (#19035)

This commit is contained in:
Andrew
2024-06-09 17:32:29 -03:00
committed by GitHub
parent 24b4975320
commit 289758094c
2 changed files with 47 additions and 81 deletions
@@ -90,6 +90,7 @@ enum HyjalCreaturesIds
NPC_ALLIANCE_RIFLEMAN = 17921, NPC_ALLIANCE_RIFLEMAN = 17921,
NPC_ALLIANCE_PRIEST = 17928, NPC_ALLIANCE_PRIEST = 17928,
NPC_ALLIANCE_SORCERESS = 17922, NPC_ALLIANCE_SORCERESS = 17922,
NPC_GUARDIAN_ELEMENTAL = 18001,
// Horde Base // Horde Base
NPC_THRALL = 17852, NPC_THRALL = 17852,
@@ -102,6 +103,7 @@ enum HyjalCreaturesIds
NPC_HORDE_PEON = 17937, NPC_HORDE_PEON = 17937,
NPC_INFERNAL_RELAY = 18242, NPC_INFERNAL_RELAY = 18242,
NPC_INFERNAL_TARGET = 21075, NPC_INFERNAL_TARGET = 21075,
NPC_DIRE_WOLF = 17854,
// Night Elf Base // Night Elf Base
NPC_TYRANDE = 17948, NPC_TYRANDE = 17948,
@@ -51,11 +51,6 @@ ObjectData const creatureData[] =
{ 0, 0 } { 0, 0 }
}; };
ObjectData const objectData[] =
{
{ 0, 0 }
};
Milliseconds hyjalWaveTimers[4][MAX_WAVES_STANDARD] Milliseconds hyjalWaveTimers[4][MAX_WAVES_STANDARD]
{ {
{ 130000ms, 130000ms, 130000ms, 130000ms, 130000ms, 130000ms, 130000ms, 190000ms, 0ms }, // Winterchill { 130000ms, 130000ms, 130000ms, 130000ms, 130000ms, 130000ms, 130000ms, 190000ms, 0ms }, // Winterchill
@@ -92,7 +87,7 @@ public:
SetHeaders(DataHeader); SetHeaders(DataHeader);
SetBossNumber(EncounterCount); SetBossNumber(EncounterCount);
LoadDoorData(doorData); LoadDoorData(doorData);
LoadObjectData(creatureData, objectData); LoadObjectData(creatureData, nullptr);
} }
void Initialize() override void Initialize() override
@@ -203,6 +198,8 @@ public:
break; break;
case NPC_TOWERING_INFERNAL: case NPC_TOWERING_INFERNAL:
case NPC_LESSER_DOOMGUARD: case NPC_LESSER_DOOMGUARD:
case NPC_DIRE_WOLF:
case NPC_GUARDIAN_ELEMENTAL:
if (creature->IsSummon()) if (creature->IsSummon())
{ {
_summonedNPCs.insert(creature->GetGUID()); _summonedNPCs.insert(creature->GetGUID());
@@ -243,6 +240,8 @@ public:
break; break;
case NPC_TOWERING_INFERNAL: case NPC_TOWERING_INFERNAL:
case NPC_LESSER_DOOMGUARD: case NPC_LESSER_DOOMGUARD:
case NPC_DIRE_WOLF:
case NPC_GUARDIAN_ELEMENTAL:
_summonedNPCs.erase(creature->GetGUID()); _summonedNPCs.erase(creature->GetGUID());
break; break;
case NPC_WINTERCHILL: case NPC_WINTERCHILL:
@@ -250,9 +249,9 @@ public:
case NPC_KAZROGAL: case NPC_KAZROGAL:
case NPC_AZGALOR: case NPC_AZGALOR:
if (Creature* jaina = GetCreature(DATA_JAINA)) 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)) 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); SetData(DATA_RESET_WAVES, 1);
break; break;
} }
@@ -290,14 +289,14 @@ public:
} }
// Despawn all alliance NPCs // Despawn all alliance NPCs
_scheduler.Schedule(21000ms, [this](TaskContext) scheduler.Schedule(21000ms, [this](TaskContext)
{ {
for (ObjectGuid const& guid : _baseAlliance) for (ObjectGuid const& guid : _baseAlliance)
if (Creature* creature = instance->GetCreature(guid)) if (Creature* creature = instance->GetCreature(guid))
creature->DespawnOrUnsummon(); creature->DespawnOrUnsummon();
// Spawn Roaring Flame after a delay // Spawn Roaring Flame after a delay
_scheduler.Schedule(30s, [this](TaskContext) scheduler.Schedule(30s, [this](TaskContext)
{ {
for (ObjectGuid const& guid : _roaringFlameAlliance) 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) for (ObjectGuid const& guid : _baseHorde)
if (Creature* creature = instance->GetCreature(guid)) if (Creature* creature = instance->GetCreature(guid))
creature->DespawnOrUnsummon(); creature->DespawnOrUnsummon();
_scheduler.Schedule(30s, [this](TaskContext) scheduler.Schedule(30s, [this](TaskContext)
{ {
for (ObjectGuid const& guid : _roaringFlameHorde) for (ObjectGuid const& guid : _roaringFlameHorde)
if (GameObject* flame = instance->GetGameObject(guid)) if (GameObject* flame = instance->GetGameObject(guid))
@@ -399,6 +398,10 @@ public:
_bossWave = DATA_ARCHIMONDE; _bossWave = DATA_ARCHIMONDE;
ScheduleWaves(1ms, START_WAVE_NIGHT_ELF, MAX_WAVES_NIGHT_ELF, hyjalNightElfWaveTimers[0]); ScheduleWaves(1ms, START_WAVE_NIGHT_ELF, MAX_WAVES_NIGHT_ELF, hyjalNightElfWaveTimers[0]);
} }
if (_bossWave)
DoUpdateWorldState(WORLD_STATE_WAVES, 0);
break; break;
case DATA_SPAWN_INFERNALS: case DATA_SPAWN_INFERNALS:
{ {
@@ -419,84 +422,46 @@ public:
} }
} }
break; 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: 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) for (ObjectGuid const& guid : _baseNightElf)
if (Creature* creature = instance->GetCreature(guid)) if (Creature* creature = instance->GetCreature(guid))
creature->DespawnOrUnsummon(); creature->DespawnOrUnsummon(0s, 300s);
for (ObjectGuid const& guid : _encounterNPCs) for (ObjectGuid const& guid : _encounterNPCs)
if (Creature* creature = instance->GetCreature(guid)) if (Creature* creature = instance->GetCreature(guid))
creature->DespawnOrUnsummon(); creature->DespawnOrUnsummon();
if (Creature* archimonde = GetCreature(DATA_ARCHIMONDE)) // also force despawn boss summons
archimonde->DespawnOrUnsummon(); for (ObjectGuid const& guid : _summonedNPCs)
if (Creature* creature = instance->GetCreature(guid))
creature->DespawnOrUnsummon();
_scheduler.Schedule(300s, [this](TaskContext) if (_bossWave && (GetBossState(_bossWave) != DONE))
{ SetBossState(_bossWave, NOT_STARTED);
for (ObjectGuid const& guid : _baseNightElf)
if (Creature* creature = instance->GetCreature(guid))
creature->Respawn();
if (Creature* archi = GetCreature(DATA_ARCHIMONDE))
archi->Respawn();
});
SetData(DATA_RESET_WAVES, 0); SetData(DATA_RESET_WAVES, 0);
break; break;
case DATA_RESET_WAVES: case DATA_RESET_WAVES:
_scheduler.CancelGroup(CONTEXT_GROUP_WAVES); scheduler.CancelGroup(CONTEXT_GROUP_WAVES);
_encounterNPCs.clear(); _encounterNPCs.clear();
_summonedNPCs.clear(); _summonedNPCs.clear();
_currentWave = 0; _currentWave = 0;
@@ -533,10 +498,10 @@ public:
void ScheduleWaves(Milliseconds /* time */, uint8 startWaves, uint8 maxWaves, Milliseconds timerptr[]) void ScheduleWaves(Milliseconds /* time */, uint8 startWaves, uint8 maxWaves, Milliseconds timerptr[])
{ {
// No overlapping! // 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. 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 all waves reached, cancel scheduling new ones
if (_currentWave >= maxWaves) if (_currentWave >= maxWaves)
@@ -572,7 +537,7 @@ public:
void Update(uint32 diff) override void Update(uint32 diff) override
{ {
_scheduler.Update(diff); scheduler.Update(diff);
} }
void OnPlayerInWaterStateUpdate(Player* player, bool inWater) override void OnPlayerInWaterStateUpdate(Player* player, bool inWater) override
@@ -588,7 +553,6 @@ public:
uint8 _currentWave; uint8 _currentWave;
uint8 _bossWave; uint8 _bossWave;
uint8 _retreat; uint8 _retreat;
TaskScheduler _scheduler;
GuidSet _encounterNPCs; GuidSet _encounterNPCs;
GuidSet _summonedNPCs; GuidSet _summonedNPCs;
GuidSet _baseAlliance; GuidSet _baseAlliance;