Skip to content

Commit 8ca0dff

Browse files
committed
refactor: clean up braces
1 parent 3ae9a6c commit 8ca0dff

File tree

1 file changed

+21
-87
lines changed

1 file changed

+21
-87
lines changed

src/mod_zone_difficulty_scripts.cpp

+21-87
Original file line numberDiff line numberDiff line change
@@ -553,14 +553,15 @@ class mod_zone_difficulty_globalscript : public GlobalScript
553553
void OnBeforeSetBossState(uint32 id, EncounterState newState, EncounterState oldState, Map* instance) override
554554
{
555555
if (!sZoneDifficulty->MythicmodeEnable)
556-
{
557556
return;
558-
}
557+
559558
if (sZoneDifficulty->IsDebugInfoEnabled)
560559
{
561560
//LOG_INFO("module", "MOD-ZONE-DIFFICULTY: OnBeforeSetBossState: bossId = {}, newState = {}, oldState = {}, MapId = {}, InstanceId = {}", id, newState, oldState, instance->GetId(), instance->GetInstanceId());
562561
}
562+
563563
uint32 instanceId = instance->GetInstanceId();
564+
564565
if (!sZoneDifficulty->IsMythicmodeMap(instance->GetId()) ||
565566
(!sZoneDifficulty->MythicmodeInNormalDungeons && !instance->IsRaidOrHeroicDungeon()))
566567
{
@@ -570,9 +571,7 @@ class mod_zone_difficulty_globalscript : public GlobalScript
570571
if (oldState != IN_PROGRESS && newState == IN_PROGRESS)
571572
{
572573
if (sZoneDifficulty->MythicmodeInstanceData[instanceId])
573-
{
574574
sZoneDifficulty->EncountersInProgress[instanceId] = GameTime::GetGameTime().count();
575-
}
576575
}
577576
else if (oldState == IN_PROGRESS && newState == DONE)
578577
{
@@ -581,17 +580,12 @@ class mod_zone_difficulty_globalscript : public GlobalScript
581580
//LOG_INFO("module", "MOD-ZONE-DIFFICULTY: Mythicmode is on.");
582581
if (sZoneDifficulty->EncountersInProgress.find(instanceId) != sZoneDifficulty->EncountersInProgress.end() && sZoneDifficulty->EncountersInProgress[instanceId] != 0)
583582
{
584-
Map::PlayerList const& PlayerList = instance->GetPlayers();
585-
for (Map::PlayerList::const_iterator i = PlayerList.begin(); i != PlayerList.end(); ++i)
583+
instance->DoForAllPlayers([&](Player* player)
586584
{
587-
Player* player = i->GetSource();
588585
if (!player->IsGameMaster() && !player->IsDeveloper())
589-
{
590-
CharacterDatabase.Execute(
591-
"REPLACE INTO `zone_difficulty_encounter_logs` VALUES({}, {}, {}, {}, {}, {}, {})",
586+
CharacterDatabase.Execute("REPLACE INTO `zone_difficulty_encounter_logs` VALUES({}, {}, {}, {}, {}, {}, {})",
592587
instanceId, sZoneDifficulty->EncountersInProgress[instanceId], GameTime::GetGameTime().count(), instance->GetId(), id, player->GetGUID().GetCounter(), 64);
593-
}
594-
}
588+
});
595589
}
596590
}
597591
}
@@ -643,17 +637,14 @@ class mod_zone_difficulty_globalscript : public GlobalScript
643637
{
644638
SourceAwardsMythicmodeLoot = true;
645639
if (!(value.Override & 1))
646-
{
647640
score = 1;
648-
}
641+
649642
break;
650643
}
651644
}
652645

653646
if (!SourceAwardsMythicmodeLoot)
654-
{
655647
return;
656-
}
657648

658649
if (map->IsHeroic() && map->IsNonRaidDungeon())
659650
{
@@ -769,12 +760,8 @@ class mod_zone_difficulty_rewardnpc : public CreatureScript
769760
// Check if the player has enough score in the respective category.
770761
uint32 availableScore = 0;
771762
if (sZoneDifficulty->MythicmodeScore.find(player->GetGUID().GetCounter()) != sZoneDifficulty->MythicmodeScore.end())
772-
{
773763
if (sZoneDifficulty->MythicmodeScore[player->GetGUID().GetCounter()].find(category) != sZoneDifficulty->MythicmodeScore[player->GetGUID().GetCounter()].end())
774-
{
775764
availableScore = sZoneDifficulty->MythicmodeScore[player->GetGUID().GetCounter()][category];
776-
}
777-
}
778765

779766
if (availableScore < sZoneDifficulty->TierRewards[category].Price)
780767
{
@@ -794,10 +781,10 @@ class mod_zone_difficulty_rewardnpc : public CreatureScript
794781
ItemTemplate const* proto = sObjectMgr->GetItemTemplate(sZoneDifficulty->TierRewards[category].Entry);
795782
std::string gossip;
796783
std::string name = proto->Name1;
784+
797785
if (ItemLocale const* leftIl = sObjectMgr->GetItemLocale(sZoneDifficulty->TierRewards[category].Entry))
798-
{
799786
ObjectMgr::GetLocaleString(leftIl->Name, player->GetSession()->GetSessionDbcLocale(), name);
800-
}
787+
801788
gossip.append("Yes, ").append(name).append(" is the item i want.");
802789
AddGossipItemFor(player, GOSSIP_ICON_CHAT, "No!", GOSSIP_SENDER_MAIN, 999998);
803790
AddGossipItemFor(player, GOSSIP_ICON_VENDOR, gossip, GOSSIP_SENDER_MAIN, 99001000 + category);
@@ -852,12 +839,9 @@ class mod_zone_difficulty_rewardnpc : public CreatureScript
852839
ItemTemplate const* proto = sObjectMgr->GetItemTemplate(sZoneDifficulty->Rewards[category][counter][i].Entry);
853840
std::string name = proto->Name1;
854841
if (ItemLocale const* leftIl = sObjectMgr->GetItemLocale(sZoneDifficulty->Rewards[category][counter][i].Entry))
855-
{
856842
ObjectMgr::GetLocaleString(leftIl->Name, player->GetSession()->GetSessionDbcLocale(), name);
857-
}
858843

859844
AddGossipItemFor(player, GOSSIP_ICON_MONEY_BAG, name, GOSSIP_SENDER_MAIN, (1000 * category) + (100 * counter) + i);
860-
//LOG_INFO("module", "MOD-ZONE-DIFFICULTY: AddingGossipItem with action {}", (1000 * category) + (100 * counter) + i);
861845
}
862846
}
863847
else if (action < 100000)
@@ -880,12 +864,8 @@ class mod_zone_difficulty_rewardnpc : public CreatureScript
880864
// Check if the player has enough score in the respective category.
881865
uint32 availableScore = 0;
882866
if (sZoneDifficulty->MythicmodeScore.find(player->GetGUID().GetCounter()) != sZoneDifficulty->MythicmodeScore.end())
883-
{
884867
if (sZoneDifficulty->MythicmodeScore[player->GetGUID().GetCounter()].find(category) != sZoneDifficulty->MythicmodeScore[player->GetGUID().GetCounter()].end())
885-
{
886868
availableScore = sZoneDifficulty->MythicmodeScore[player->GetGUID().GetCounter()][category];
887-
}
888-
}
889869

890870
if (availableScore < sZoneDifficulty->Rewards[category][itemType][counter].Price)
891871
{
@@ -906,10 +886,10 @@ class mod_zone_difficulty_rewardnpc : public CreatureScript
906886
ItemTemplate const* proto = sObjectMgr->GetItemTemplate(sZoneDifficulty->Rewards[category][itemType][counter].Entry);
907887
std::string gossip;
908888
std::string name = proto->Name1;
889+
909890
if (ItemLocale const* leftIl = sObjectMgr->GetItemLocale(sZoneDifficulty->Rewards[category][itemType][counter].Entry))
910-
{
911891
ObjectMgr::GetLocaleString(leftIl->Name, player->GetSession()->GetSessionDbcLocale(), name);
912-
}
892+
913893
gossip.append("Yes, ").append(name).append(" is the item i want.");
914894
AddGossipItemFor(player, GOSSIP_ICON_CHAT, "No!", GOSSIP_SENDER_MAIN, 999998);
915895
AddGossipItemFor(player, GOSSIP_ICON_VENDOR, gossip, GOSSIP_SENDER_MAIN, 100000 + (1000 * category) + (100 * itemType) + counter);
@@ -936,16 +916,11 @@ class mod_zone_difficulty_rewardnpc : public CreatureScript
936916
// Check (again) if the player has enough score in the respective category.
937917
uint32 availableScore = 0;
938918
if (sZoneDifficulty->MythicmodeScore.find(player->GetGUID().GetCounter()) != sZoneDifficulty->MythicmodeScore.end())
939-
{
940919
if (sZoneDifficulty->MythicmodeScore[player->GetGUID().GetCounter()].find(category) != sZoneDifficulty->MythicmodeScore[player->GetGUID().GetCounter()].end())
941-
{
942920
availableScore = sZoneDifficulty->MythicmodeScore[player->GetGUID().GetCounter()][category];
943-
}
944-
}
921+
945922
if (availableScore < sZoneDifficulty->Rewards[category][itemType][counter].Price)
946-
{
947923
return true;
948-
}
949924

950925
// Check if the player has the neccesary achievement
951926
if (sZoneDifficulty->Rewards[category][itemType][counter].Achievement != 0)
@@ -1082,7 +1057,6 @@ class mod_zone_difficulty_dungeonmaster : public CreatureScript
10821057
{
10831058
if (player->GetInstanceScript()->GetBossState(0) == DONE)
10841059
{
1085-
//LOG_INFO("module", "MOD-ZONE-DIFFICULTY: Mythicmode is not Possible for instanceId {}", instanceId);
10861060
canTurnOn = false;
10871061
creature->Whisper("I am sorry, time-traveler. You can not return to this version of the time-line anymore. You have already completed one of the lessons.", LANG_UNIVERSAL, player);
10881062
sZoneDifficulty->SaveMythicmodeInstanceData(instanceId);
@@ -1091,16 +1065,12 @@ class mod_zone_difficulty_dungeonmaster : public CreatureScript
10911065
// ... if there is an encounter in progress
10921066
if (player->GetInstanceScript()->IsEncounterInProgress())
10931067
{
1094-
//LOG_INFO("module", "MOD-ZONE-DIFFICULTY: IsEncounterInProgress");
10951068
canTurnOn = false;
10961069
creature->Whisper("I am sorry, time-traveler. You can not return to this version of the time-line currently. There is already a battle in progress.", LANG_UNIVERSAL, player);
10971070
}
10981071

10991072
if (player->IsGameMaster())
1100-
{
1101-
LOG_ERROR("module", "MOD-ZONE-DIFFICULTY: GM {} has allowed Mythicmode for instance {}", player->GetName(), instanceId);
11021073
canTurnOn = true;
1103-
}
11041074

11051075
if (canTurnOn)
11061076
{
@@ -1169,14 +1139,8 @@ class mod_zone_difficulty_dungeonmaster : public CreatureScript
11691139
AddGossipItemFor(player, GOSSIP_ICON_CHAT, "Please Chromie, let us re-experience how all the things really happened back then. (Mythic Mode)", GOSSIP_SENDER_MAIN, 100);
11701140
AddGossipItemFor(player, GOSSIP_ICON_CHAT, "I think we will be fine with the cinematic version from here. (Normal mode)", GOSSIP_SENDER_MAIN, 101);
11711141

1172-
if (sZoneDifficulty->MythicmodeInstanceData[player->GetMap()->GetInstanceId()])
1173-
{
1174-
npcText = NPC_TEXT_LEADER_HARD;
1175-
}
1176-
else
1177-
{
1178-
npcText = NPC_TEXT_LEADER_NORMAL;
1179-
}
1142+
npcText = sZoneDifficulty->MythicmodeInstanceData[player->GetMap()->GetInstanceId()] ?
1143+
NPC_TEXT_LEADER_HARD : NPC_TEXT_LEADER_NORMAL;
11801144
}
11811145
else
11821146
{
@@ -1195,56 +1159,41 @@ class mod_zone_difficulty_allcreaturescript : public AllCreatureScript
11951159
void OnAllCreatureUpdate(Creature* creature, uint32 /*diff*/) override
11961160
{
11971161
if (!sZoneDifficulty->MythicmodeEnable)
1198-
{
11991162
return;
1200-
}
1163+
12011164
// Heavily inspired by https://github.com/azerothcore/mod-autobalance/blob/1d82080237e62376b9a030502264c90b5b8f272b/src/AutoBalance.cpp
12021165
Map* map = creature->GetMap();
12031166
if (!creature || !map)
1204-
{
12051167
return;
1206-
}
12071168

1208-
if (!map->IsRaid() &&
1209-
(!(map->IsHeroic() && map->IsDungeon())))
1210-
{
1169+
if (!map->IsRaid() && (!(map->IsHeroic() && map->IsDungeon())))
12111170
return;
1212-
}
12131171

12141172
uint32 mapId = creature->GetMapId();
12151173
if (sZoneDifficulty->NerfInfo.find(mapId) == sZoneDifficulty->NerfInfo.end())
1216-
{
12171174
return;
1218-
}
12191175

12201176
if ((creature->IsHunterPet() || creature->IsPet() || creature->IsSummon()) && creature->IsControlledByPlayer())
1221-
{
12221177
return;
1223-
}
12241178

12251179
if (!creature->IsAlive())
1226-
{
12271180
return;
1228-
}
12291181

12301182
CreatureTemplate const* creatureTemplate = creature->GetCreatureTemplate();
12311183
//skip critters and special creatures (spell summons etc.) in instances
12321184
if (creatureTemplate->maxlevel <= 1)
1233-
{
12341185
return;
1235-
}
12361186

12371187
CreatureBaseStats const* origCreatureStats = sObjectMgr->GetCreatureBaseStats(creature->GetLevel(), creatureTemplate->unit_class);
12381188
uint32 baseHealth = origCreatureStats->GenerateHealth(creatureTemplate);
12391189
uint32 newHp;
12401190
uint32 entry = creature->GetEntry();
1241-
//LOG_INFO("module", "MOD-ZONE-DIFFICULTY: Checking hp for creature with entry {}.", entry);
1191+
12421192
if (sZoneDifficulty->CreatureOverrides.find(entry) == sZoneDifficulty->CreatureOverrides.end())
12431193
{
12441194
if (creature->IsDungeonBoss())
1245-
{
12461195
return;
1247-
}
1196+
12481197
newHp = round(baseHealth * sZoneDifficulty->MythicmodeHpModifier);
12491198
}
12501199
else
@@ -1260,25 +1209,18 @@ class mod_zone_difficulty_allcreaturescript : public AllCreatureScript
12601209
if (sZoneDifficulty->HasMythicmode(mode) && sZoneDifficulty->MythicmodeInstanceData[creature->GetMap()->GetInstanceId()])
12611210
{
12621211
if (creature->GetMaxHealth() == newHp)
1263-
{
12641212
return;
1265-
}
1266-
//if (sZoneDifficulty->IsDebugInfoEnabled)
1267-
//{
1268-
//LOG_INFO("module", "MOD-ZONE-DIFFICULTY: Modify creature hp for Mythic Mode: {} to {}", baseHealth, newHp);
1269-
//}
1213+
12701214
bool hpIsFull = false;
1215+
12711216
if (creature->GetHealthPct() >= 100)
1272-
{
12731217
hpIsFull = true;
1274-
}
1218+
12751219
creature->SetMaxHealth(newHp);
12761220
creature->SetCreateHealth(newHp);
12771221
creature->SetModifierValue(UNIT_MOD_HEALTH, BASE_VALUE, (float)newHp);
12781222
if (hpIsFull)
1279-
{
12801223
creature->SetHealth(newHp);
1281-
}
12821224
creature->UpdateAllStats();
12831225
creature->ResetPlayerDamageReq();
12841226
return;
@@ -1288,22 +1230,14 @@ class mod_zone_difficulty_allcreaturescript : public AllCreatureScript
12881230
{
12891231
if (creature->GetMaxHealth() == newHp)
12901232
{
1291-
//if (sZoneDifficulty->IsDebugInfoEnabled)
1292-
//{
1293-
// //LOG_INFO("module", "MOD-ZONE-DIFFICULTY: Modify creature hp for normal mode: {} to {}", baseHealth, baseHealth);
1294-
//}
12951233
bool hpIsFull = false;
12961234
if (creature->GetHealthPct() >= 100)
1297-
{
12981235
hpIsFull = true;
1299-
}
13001236
creature->SetMaxHealth(baseHealth);
13011237
creature->SetCreateHealth(baseHealth);
13021238
creature->SetModifierValue(UNIT_MOD_HEALTH, BASE_VALUE, (float)baseHealth);
13031239
if (hpIsFull)
1304-
{
13051240
creature->SetHealth(baseHealth);
1306-
}
13071241
creature->UpdateAllStats();
13081242
creature->ResetPlayerDamageReq();
13091243
return;

0 commit comments

Comments
 (0)