Skip to content

Commit

Permalink
The wave should fail when all players are dead.
Browse files Browse the repository at this point in the history
  • Loading branch information
AnchyDev committed Oct 14, 2023
1 parent c013119 commit 1f1d9c8
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/TrialOfStrength.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
73 changes: 72 additions & 1 deletion src/scripts/ToSInstanceScript.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class instance_trial_of_strength : public InstanceMapScript

bool IsWaveCleared() const
{
return GetRemainingAlive() == 0;
return encounterInProgress && GetRemainingAlive() == 0;
}

bool HasMoreWaves() const
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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);
}
}
}

Expand Down Expand Up @@ -332,7 +398,12 @@ class instance_trial_of_strength : public InstanceMapScript
void ResetEncounter()
{
encounterInProgress = false;

currentWave = 0;
currentSubGroup = 0;
totalSubGroups = 0;

events.Reset();

CleanupCreatures();
}
Expand Down

0 comments on commit 1f1d9c8

Please sign in to comment.