Skip to content

Commit 9adf21a

Browse files
NyeriahCopilot
andauthored
refactor: Improve creature credit functions (#70)
Co-authored-by: Copilot <[email protected]>
1 parent 25dd609 commit 9adf21a

File tree

1 file changed

+51
-83
lines changed

1 file changed

+51
-83
lines changed

src/mod_zone_difficulty_handler.cpp

Lines changed: 51 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -1088,96 +1088,64 @@ void ZoneDifficulty::LogAndAnnounceKill(Map* map, bool isMythic)
10881088

10891089
bool ZoneDifficulty::CheckCompletionStatus(Creature* creature, Player* player, uint32 category) const
10901090
{
1091-
switch (category)
1091+
struct MythicRequirement
10921092
{
1093-
case TYPE_RAID_SSC:
1094-
if (!player->GetPlayerSetting(ModZoneDifficultyString + "ct", SETTING_SSC).value)
1095-
{
1096-
creature->Whisper("Ah, hero! The threads of fate bring you to me. To claim the rewards you desire, you must first confront Lady Vashj on Mythic difficulty.",
1097-
LANG_UNIVERSAL, player);
1098-
return false;
1099-
}
1100-
break;
1101-
case TYPE_RAID_T6:
1102-
if (!player->GetPlayerSetting(ModZoneDifficultyString + "ct", SETTING_BLACK_TEMPLE).value)
1103-
{
1104-
creature->Whisper("Ah, hero! The threads of fate bring you to me. To claim the rewards you desire, you must first confront Illidan Stormrage on Mythic difficulty.",
1105-
LANG_UNIVERSAL, player);
1106-
return false;
1107-
}
1108-
break;
1109-
case TYPE_RAID_ZA:
1110-
if (!player->GetPlayerSetting(ModZoneDifficultyString + "ct", SETTING_ZULAMAN).value)
1111-
{
1112-
creature->Whisper("Ah, hero! The threads of fate bring you to me. To claim the rewards you desire, you must first confront Zul'jin on Mythic difficulty.",
1113-
LANG_UNIVERSAL, player);
1114-
return false;
1115-
}
1116-
break;
1117-
case TYPE_RAID_HYJAL:
1118-
if (!player->GetPlayerSetting(ModZoneDifficultyString + "ct", SETTING_HYJAL).value)
1119-
{
1120-
creature->Whisper("Ah, hero! The threads of fate bring you to me. To claim the rewards you desire, you must first confront Archimonde on Mythic difficulty.",
1121-
LANG_UNIVERSAL, player);
1122-
return false;
1123-
}
1124-
break;
1125-
case TYPE_RAID_SWP:
1126-
if (!player->GetPlayerSetting(ModZoneDifficultyString + "ct", SETTING_SWP).value)
1127-
{
1128-
creature->Whisper("Ah, hero! The threads of fate bring you to me. To claim the rewards you desire, you must first confront Kil'jaeden on Mythic difficulty.",
1129-
LANG_UNIVERSAL, player);
1130-
return false;
1131-
}
1132-
break;
1133-
}
1093+
uint32 category;
1094+
uint32 setting;
1095+
char const* bossName;
1096+
};
11341097

1098+
static constexpr std::array<MythicRequirement, 5> requirements
1099+
{
1100+
MythicRequirement{ TYPE_RAID_SSC, SETTING_SSC, "Lady Vashj" },
1101+
MythicRequirement{ TYPE_RAID_T6, SETTING_BLACK_TEMPLE, "Illidan Stormrage" },
1102+
MythicRequirement{ TYPE_RAID_ZA, SETTING_ZULAMAN, "Zul'jin" },
1103+
MythicRequirement{ TYPE_RAID_HYJAL, SETTING_HYJAL, "Archimonde" },
1104+
MythicRequirement{ TYPE_RAID_SWP, SETTING_SWP, "Kil'jaeden" },
1105+
};
1106+
1107+
for (auto const& req : requirements)
1108+
{
1109+
if (req.category != category)
1110+
continue;
1111+
1112+
if (player->GetPlayerSetting(ModZoneDifficultyString + "ct", req.setting).value)
1113+
return true;
1114+
1115+
creature->Whisper(
1116+
Acore::StringFormat("Ah, hero! The threads of fate bring you to me. To claim the rewards you desire, you must first confront {} on Mythic difficulty.", req.bossName),
1117+
LANG_UNIVERSAL, player);
1118+
return false;
1119+
}
1120+
11351121
return true;
11361122
}
11371123

11381124
void ZoneDifficulty::ProcessCreatureDeath(Map* map, uint32 entry)
11391125
{
1140-
switch (entry)
1126+
constexpr std::array<std::pair<uint32, std::tuple<uint32, const char*>>, 5> deathData =
11411127
{
1142-
case NPC_ILLIDAN_STORMRAGE:
1143-
map->DoForAllPlayers([&](Player* player)
1144-
{
1145-
player->UpdatePlayerSetting(ModZoneDifficultyString + "ct", SETTING_BLACK_TEMPLE, 1);
1146-
player->SendSystemMessage("Congratulations on completing the Black Temple!");
1147-
});
1148-
sZoneDifficulty->LogAndAnnounceKill(map, true);
1149-
break;
1150-
case NPC_ZULJIN:
1151-
map->DoForAllPlayers([&](Player* player)
1152-
{
1153-
player->UpdatePlayerSetting(ModZoneDifficultyString + "ct", SETTING_ZULAMAN, 1);
1154-
player->SendSystemMessage("Congratulations on completing Zul'Aman!");
1155-
});
1156-
sZoneDifficulty->LogAndAnnounceKill(map, true);
1157-
break;
1158-
case NPC_ARCHIMONDE:
1159-
map->DoForAllPlayers([&](Player* player)
1160-
{
1161-
player->UpdatePlayerSetting(ModZoneDifficultyString + "ct", SETTING_HYJAL, 1);
1162-
player->SendSystemMessage("Congratulations on completing Battle for Mount Hyjal!");
1163-
});
1164-
sZoneDifficulty->LogAndAnnounceKill(map, true);
1165-
break;
1166-
case NPC_LADY_VASHJ:
1167-
map->DoForAllPlayers([&](Player* player)
1168-
{
1169-
player->UpdatePlayerSetting(ModZoneDifficultyString + "ct", SETTING_SSC, 1);
1170-
player->SendSystemMessage("Congratulations on completing Serpentshrine Cavern!");
1171-
});
1172-
sZoneDifficulty->LogAndAnnounceKill(map, true);
1173-
break;
1174-
case NPC_KILJAEDEN:
1175-
map->DoForAllPlayers([&](Player* player)
1176-
{
1177-
player->UpdatePlayerSetting(ModZoneDifficultyString + "ct", SETTING_SWP, 1);
1178-
player->SendSystemMessage("Congratulations on completing Sunwell Plateau!");
1179-
});
1180-
sZoneDifficulty->LogAndAnnounceKill(map, true);
1181-
break;
1128+
std::pair{ NPC_ILLIDAN_STORMRAGE, std::tuple{ SETTING_BLACK_TEMPLE, "Black Temple" } },
1129+
std::pair{ NPC_ZULJIN, std::tuple{ SETTING_ZULAMAN, "Zul'Aman" } },
1130+
std::pair{ NPC_ARCHIMONDE, std::tuple{ SETTING_HYJAL, "Battle for Mount Hyjal" } },
1131+
std::pair{ NPC_LADY_VASHJ, std::tuple{ SETTING_SSC, "Serpentshrine Cavern" } },
1132+
std::pair{ NPC_KILJAEDEN, std::tuple{ SETTING_SWP, "Sunwell Plateau" } }
1133+
};
1134+
1135+
for (auto const& [npcId, data] : deathData)
1136+
{
1137+
if (npcId != entry)
1138+
continue;
1139+
1140+
auto const& [setting, zoneName] = data;
1141+
1142+
map->DoForAllPlayers([&](Player* player)
1143+
{
1144+
player->UpdatePlayerSetting(ModZoneDifficultyString + "ct", setting, 1);
1145+
player->SendSystemMessage(Acore::StringFormat("Congratulations on completing {}!", zoneName));
1146+
});
1147+
1148+
sZoneDifficulty->LogAndAnnounceKill(map, true);
1149+
break;
11821150
}
11831151
}

0 commit comments

Comments
 (0)