From 1f1d9c8e6f17eaddc483d2aedcfb5367239db433 Mon Sep 17 00:00:00 2001 From: AnchyDev Date: Sat, 14 Oct 2023 20:16:39 +1100 Subject: [PATCH] The wave should fail when all players are dead. --- src/TrialOfStrength.h | 1 + src/scripts/ToSInstanceScript.h | 73 ++++++++++++++++++++++++++++++++- 2 files changed, 73 insertions(+), 1 deletion(-) diff --git a/src/TrialOfStrength.h b/src/TrialOfStrength.h index 36183f2..a285be7 100644 --- a/src/TrialOfStrength.h +++ b/src/TrialOfStrength.h @@ -29,6 +29,7 @@ enum ToSConstants { TOS_DATA_ENCOUNTER_COMBATANTS_HOSTILE = 7, TOS_DATA_ENCOUNTER_CHECK_WAVE_COMPLETE = 8, TOS_DATA_ENCOUNTER_START_NEXT_WAVE = 9, + TOS_DATA_ENCOUNTER_CHECK_FAILURE = 10, }; struct ToSWaveTemplate { diff --git a/src/scripts/ToSInstanceScript.h b/src/scripts/ToSInstanceScript.h index 1d0ab94..7cee4e4 100644 --- a/src/scripts/ToSInstanceScript.h +++ b/src/scripts/ToSInstanceScript.h @@ -32,7 +32,7 @@ class instance_trial_of_strength : public InstanceMapScript bool IsWaveCleared() const { - return GetRemainingAlive() == 0; + return encounterInProgress && GetRemainingAlive() == 0; } bool HasMoreWaves() const @@ -77,6 +77,7 @@ class instance_trial_of_strength : public InstanceMapScript events.ScheduleEvent(TOS_DATA_ENCOUNTER_COMBATANTS_HOSTILE, 5s); events.ScheduleEvent(TOS_DATA_ENCOUNTER_CHECK_WAVE_COMPLETE, 10s); + events.ScheduleEvent(TOS_DATA_ENCOUNTER_CHECK_FAILURE, 5s); } void MakeEntrance(Creature* creature) @@ -125,6 +126,71 @@ class instance_trial_of_strength : public InstanceMapScript case TOS_DATA_ENCOUNTER_START_NEXT_WAVE: SpawnNextWave(); break; + + case TOS_DATA_ENCOUNTER_CHECK_FAILURE: + if (!CheckFailure()) + { + events.RescheduleEvent(TOS_DATA_ENCOUNTER_CHECK_FAILURE, 3s); + } + break; + } + } + + bool AnyPlayerAlive() + { + Map::PlayerList const& players = instance->GetPlayers(); + + for (const auto& it : players) + { + Player* player = it.GetSource(); + + if (!player) + continue; + + if (!player->isDead()) + { + return true; + } + } + + return false; + } + + bool CheckFailure() + { + // Check if all players are dead. + if (AnyPlayerAlive()) + { + return false; + } + + NotifyFailure(); + ResetEncounter(); + + return true; + } + + void NotifyFailure() + { + std::string message = Acore::StringFormatFmt("|cffFF9900Wave failed!|r", currentWave); + Map::PlayerList const& players = instance->GetPlayers(); + + for (const auto& it : players) + { + Player* player = it.GetSource(); + + if (!player) + continue; + + player->SendSystemMessage(message); + player->PlayDirectSound(847 /* Quest Failed Sound */); + + { + WorldPacket data(SMSG_NOTIFICATION, (message.size() + 1)); + data << message; + + player->SendDirectMessage(&data); + } } } @@ -332,7 +398,12 @@ class instance_trial_of_strength : public InstanceMapScript void ResetEncounter() { encounterInProgress = false; + currentWave = 0; + currentSubGroup = 0; + totalSubGroups = 0; + + events.Reset(); CleanupCreatures(); }