Skip to content

Commit 2bf6098

Browse files
authored
fix: codestyle and add enabled hook lists for performance improvement (#204)
1 parent df6a554 commit 2bf6098

23 files changed

+243
-328
lines changed

src/ABAllCreatureScript.cpp

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1-
#include "MapMgr.h"
2-
3-
#include "AutoBalance.h"
41
#include "ABAllCreatureScript.h"
2+
53
#include "ABConfig.h"
64
#include "ABCreatureInfo.h"
75
#include "ABMapInfo.h"
86
#include "ABScriptMgr.h"
97
#include "ABUtils.h"
8+
#include "AutoBalance.h"
9+
10+
#include "MapMgr.h"
1011

1112
void AutoBalance_AllCreatureScript::OnBeforeCreatureSelectLevel(const CreatureTemplate* /*creatureTemplate*/, Creature* creature, uint8& level)
1213
{
@@ -294,19 +295,15 @@ bool AutoBalance_AllCreatureScript::ResetCreatureIfNeeded(Creature* creature)
294295
{
295296
// make sure we have a creature
296297
if (!creature || !isCreatureRelevant(creature))
297-
{
298298
return false;
299-
}
300299

301300
// get (or create) map and creature info
302301
AutoBalanceMapInfo* mapABInfo = creature->GetMap()->CustomData.GetDefault<AutoBalanceMapInfo>("AutoBalanceMapInfo");
303302
AutoBalanceCreatureInfo* creatureABInfo = creature->CustomData.GetDefault<AutoBalanceCreatureInfo>("AutoBalanceCreatureInfo");
304303

305304
// if creature is dead and mapConfigTime is 0, skip for now
306305
if (creature->isDead() && creatureABInfo->mapConfigTime == 1)
307-
{
308306
return false;
309-
}
310307
// if the creature is dead but mapConfigTime is NOT 0, we set it to 0 so that it will be recalculated if revived
311308
// also remember that this creature was once alive but is now dead
312309
else if (creature->isDead())
@@ -584,15 +581,11 @@ void AutoBalance_AllCreatureScript::ModifyCreatureAttributes(Creature* creature)
584581

585582
// check to be sure that the creature's new level is at least the dynamic scaling floor
586583
if (selectedLevel < (mapABInfo->highestPlayerLevel - mapABInfo->levelScalingDynamicFloor))
587-
{
588584
selectedLevel = mapABInfo->highestPlayerLevel - mapABInfo->levelScalingDynamicFloor;
589-
}
590585

591586
// check to be sure that the creature's new level is no higher than the dynamic scaling ceiling
592587
if (selectedLevel > (mapABInfo->highestPlayerLevel + mapABInfo->levelScalingDynamicCeiling))
593-
{
594588
selectedLevel = mapABInfo->highestPlayerLevel + mapABInfo->levelScalingDynamicCeiling;
595-
}
596589

597590
LOG_DEBUG("module.AutoBalance", "AutoBalance_AllCreatureScript::ModifyCreatureAttributes: Creature {} ({}) | scaled to level ({}) via dynamic scaling.",
598591
creature->GetName(),
@@ -1159,13 +1152,9 @@ void AutoBalance_AllCreatureScript::ModifyCreatureAttributes(Creature* creature)
11591152

11601153
// Min/Max checking
11611154
if (ccDurationMultiplier < MinCCDurationModifier)
1162-
{
11631155
ccDurationMultiplier = MinCCDurationModifier;
1164-
}
11651156
else if (ccDurationMultiplier > MaxCCDurationModifier)
1166-
{
11671157
ccDurationMultiplier = MaxCCDurationModifier;
1168-
}
11691158

11701159
LOG_DEBUG("module.AutoBalance_StatGeneration", "AutoBalance_AllCreatureScript::ModifyCreatureAttributes: Creature {} ({}) | ccDurationMultiplier: ({})",
11711160
creature->GetName(),
@@ -1492,9 +1481,7 @@ bool AutoBalance_AllCreatureScript::_isSummonCloneOfSummoner(Creature* summon)
14921481
{
14931482
// if the summon doesn't exist or isn't a summon
14941483
if (!summon || !summon->IsSummon())
1495-
{
14961484
return false;
1497-
}
14981485

14991486
// get the summon's info
15001487
AutoBalanceCreatureInfo* summonABInfo = summon->CustomData.GetDefault<AutoBalanceCreatureInfo>("AutoBalanceCreatureInfo");
@@ -1504,9 +1491,7 @@ bool AutoBalance_AllCreatureScript::_isSummonCloneOfSummoner(Creature* summon)
15041491

15051492
// if the summoner doesn't exist
15061493
if (!summoner)
1507-
{
15081494
return false;
1509-
}
15101495

15111496
// if this creature's ID is in the list of creatures that are not clones of their summoner (creatureIDsThatAreNotClones), return false
15121497
if (

src/ABAllMapScript.cpp

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
#include "Chat.h"
2-
31
#include "ABAllMapScript.h"
2+
43
#include "ABConfig.h"
54
#include "ABMapInfo.h"
65
#include "ABUtils.h"
6+
7+
#include "Chat.h"
78
#include "Message.h"
89

910
void AutoBalance_AllMapScript::OnCreateMap(Map* map)
@@ -33,17 +34,11 @@ void AutoBalance_AllMapScript::OnCreateMap(Map* map)
3334
{
3435
LFGDungeonEntry const* nonHeroicDungeon = nullptr;
3536
if (map->GetDifficulty() == DUNGEON_DIFFICULTY_HEROIC)
36-
{
3737
nonHeroicDungeon = GetLFGDungeon(map->GetId(), DUNGEON_DIFFICULTY_NORMAL);
38-
}
3938
else if (map->GetDifficulty() == RAID_DIFFICULTY_10MAN_HEROIC)
40-
{
4139
nonHeroicDungeon = GetLFGDungeon(map->GetId(), RAID_DIFFICULTY_10MAN_NORMAL);
42-
}
4340
else if (map->GetDifficulty() == RAID_DIFFICULTY_25MAN_HEROIC)
44-
{
4541
nonHeroicDungeon = GetLFGDungeon(map->GetId(), RAID_DIFFICULTY_25MAN_NORMAL);
46-
}
4742

4843
LOG_DEBUG("module.AutoBalance", "AutoBalance_AllMapScript::OnCreateMap(): Map {} ({}{}) | is a Heroic dungeon that is not in LFG. Using non-heroic LFG levels.",
4944
map->GetMapName(),
@@ -189,17 +184,13 @@ void AutoBalance_AllMapScript::OnPlayerEnterAll(Map* map, Player* player)
189184

190185
// notify GMs that they won't be accounted for
191186
if (player->IsGameMaster())
192-
{
193187
chatHandle.PSendSysMessage(ABGetLocaleText(locale, "welcome_to_gm").c_str());
194-
}
195188
}
196189
else
197190
{
198191
// announce non-GMs entering the instance only
199192
if (!player->IsGameMaster())
200-
{
201193
chatHandle.PSendSysMessage(ABGetLocaleText(locale, "announce_non_gm_entering_instance").c_str(), player->GetName().c_str(), mapABInfo->playerCount, mapABInfo->adjustedPlayerCount);
202-
}
203194
}
204195
}
205196
}
@@ -240,9 +231,7 @@ void AutoBalance_AllMapScript::OnPlayerLeaveAll(Map* map, Player* player)
240231

241232
// if a player was NOT removed, return now - stats don't need to be updated
242233
if (!playerWasRemoved)
243-
{
244234
return;
245-
}
246235

247236
// recalculate the zone's level stats
248237
mapABInfo->highestCreatureLevel = 0;
@@ -252,9 +241,7 @@ void AutoBalance_AllMapScript::OnPlayerLeaveAll(Map* map, Player* player)
252241

253242
// see which existing creatures are active
254243
for (std::vector<Creature*>::iterator creatureIterator = mapABInfo->allMapCreatures.begin(); creatureIterator != mapABInfo->allMapCreatures.end(); ++creatureIterator)
255-
{
256244
AddCreatureToMapCreatureList(*creatureIterator, false, true);
257-
}
258245

259246
// if the previous player count is the same as the new player count, update without force
260247
if (prevAdjustedPlayerCount == mapABInfo->adjustedPlayerCount)

src/ABAllMapScript.h

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,19 @@ class AutoBalance_AllMapScript : public AllMapScript
1111
{
1212
public:
1313
AutoBalance_AllMapScript()
14-
: AllMapScript("AutoBalance_AllMapScript")
14+
: AllMapScript("AutoBalance_AllMapScript", {
15+
ALLMAPHOOK_ON_CREATE_MAP,
16+
ALLMAPHOOK_ON_PLAYER_ENTER_ALL,
17+
ALLMAPHOOK_ON_PLAYER_LEAVE_ALL
18+
})
1519
{
1620
}
1721

18-
void OnCreateMap(Map* map);
22+
void OnCreateMap(Map* map) override;
1923
// hook triggers after the player has already entered the world
20-
void OnPlayerEnterAll(Map* map, Player* player);
24+
void OnPlayerEnterAll(Map* map, Player* player) override;
2125
// hook triggers just before the player left the world
22-
void OnPlayerLeaveAll(Map* map, Player* player);
26+
void OnPlayerLeaveAll(Map* map, Player* player) override;
2327
};
2428

2529
#endif

src/ABCommandScript.cpp

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include "ABCommandScript.h"
2+
23
#include "ABConfig.h"
34
#include "ABCreatureInfo.h"
45
#include "ABMapInfo.h"
@@ -67,25 +68,15 @@ bool AutoBalance_CommandScript::HandleABMapStatsCommand(ChatHandler* handler, co
6768

6869
// Adjusted player count (multiple scenarios)
6970
if (mapABInfo->combatLockTripped)
70-
{
7171
handler->PSendSysMessage(ABGetLocaleText(locale, "adjusted_player_count_combat_locked").c_str(), mapABInfo->adjustedPlayerCount);
72-
}
7372
else if (mapABInfo->playerCount < mapABInfo->minPlayers && !PlayerCountDifficultyOffset)
74-
{
7573
handler->PSendSysMessage(ABGetLocaleText(locale, "adjusted_player_count_map_minimum").c_str(), mapABInfo->adjustedPlayerCount);
76-
}
7774
else if (mapABInfo->playerCount < mapABInfo->minPlayers && PlayerCountDifficultyOffset)
78-
{
7975
handler->PSendSysMessage(ABGetLocaleText(locale, "adjusted_player_count_map_minimum_difficulty_offset").c_str(), mapABInfo->adjustedPlayerCount, PlayerCountDifficultyOffset);
80-
}
8176
else if (PlayerCountDifficultyOffset)
82-
{
8377
handler->PSendSysMessage(ABGetLocaleText(locale, "adjusted_player_count_difficulty_offset").c_str(), mapABInfo->adjustedPlayerCount, PlayerCountDifficultyOffset);
84-
}
8578
else
86-
{
8779
handler->PSendSysMessage(ABGetLocaleText(locale, "adjusted_player_count").c_str(), mapABInfo->adjustedPlayerCount);
88-
}
8980

9081
// LFG levels
9182
handler->PSendSysMessage(ABGetLocaleText(locale, "lfg_range").c_str(), mapABInfo->lfgMinLevel, mapABInfo->lfgMaxLevel, mapABInfo->lfgTargetLevel);
@@ -166,17 +157,11 @@ bool AutoBalance_CommandScript::HandleABCreatureStatsCommand(ChatHandler* handle
166157

167158
// summon
168159
if (target->IsSummon() && targetABInfo->summoner && targetABInfo->isCloneOfSummoner)
169-
{
170160
handler->PSendSysMessage(ABGetLocaleText(locale, "clone_of_summon").c_str(), targetABInfo->summonerName, targetABInfo->summonerLevel);
171-
}
172161
else if (target->IsSummon() && targetABInfo->summoner)
173-
{
174162
handler->PSendSysMessage(ABGetLocaleText(locale, "summon_of_summon").c_str(), targetABInfo->summonerName, targetABInfo->summonerLevel);
175-
}
176163
else if (target->IsSummon())
177-
{
178164
handler->PSendSysMessage(ABGetLocaleText(locale, "summon_without_summoner").c_str());
179-
}
180165

181166
// level scaled
182167
if (targetABInfo->UnmodifiedLevel != target->GetLevel())
@@ -198,5 +183,4 @@ bool AutoBalance_CommandScript::HandleABCreatureStatsCommand(ChatHandler* handle
198183
handler->PSendSysMessage(ABGetLocaleText(locale, "xp_money_multiplier").c_str(), targetABInfo->XPModifier, targetABInfo->MoneyModifier);
199184

200185
return true;
201-
202186
}

src/ABCommandScript.h

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,24 @@
99
#include "Config.h"
1010
#include "ScriptMgr.h"
1111

12+
using namespace Acore::ChatCommands;
13+
1214
class AutoBalance_CommandScript : public CommandScript
1315
{
1416
public:
1517
AutoBalance_CommandScript() : CommandScript("AutoBalance_CommandScript") { }
1618

17-
std::vector<Acore::ChatCommands::ChatCommandBuilder> GetCommands() const
19+
ChatCommandTable GetCommands() const override
1820
{
19-
static std::vector<Acore::ChatCommands::ChatCommandBuilder> ABCommandTable =
21+
static ChatCommandTable ABCommandTable =
2022
{
21-
{ "setoffset", HandleABSetOffsetCommand, SEC_GAMEMASTER, Acore::ChatCommands::Console::Yes },
22-
{ "getoffset", HandleABGetOffsetCommand, SEC_PLAYER, Acore::ChatCommands::Console::Yes },
23-
{ "mapstat", HandleABMapStatsCommand, SEC_PLAYER, Acore::ChatCommands::Console::Yes },
24-
{ "creaturestat", HandleABCreatureStatsCommand, SEC_PLAYER, Acore::ChatCommands::Console::Yes }
23+
{ "setoffset", HandleABSetOffsetCommand, SEC_GAMEMASTER, Console::Yes },
24+
{ "getoffset", HandleABGetOffsetCommand, SEC_PLAYER, Console::Yes },
25+
{ "mapstat", HandleABMapStatsCommand, SEC_PLAYER, Console::Yes },
26+
{ "creaturestat", HandleABCreatureStatsCommand, SEC_PLAYER, Console::Yes }
2527
};
2628

27-
static std::vector<Acore::ChatCommands::ChatCommandBuilder> commandTable =
29+
static ChatCommandTable commandTable =
2830
{
2931
{ "autobalance", ABCommandTable },
3032
{ "ab", ABCommandTable },

src/ABConfig.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,16 @@
55
#ifndef __AB_CONFIG_H
66
#define __AB_CONFIG_H
77

8-
#include <list>
9-
#include <map>
10-
11-
#include "SharedDefines.h"
12-
138
#include "ABInflectionPointSettings.h"
149
#include "ABLevelScalingDynamicLevelSettings.h"
1510
#include "ABStatModifiers.h"
1611
#include "AutoBalance.h"
1712

13+
#include "SharedDefines.h"
14+
15+
#include <list>
16+
#include <map>
17+
1818
extern std::map<uint32, AutoBalanceInflectionPointSettings> dungeonOverrides;
1919
extern std::map<uint32, AutoBalanceInflectionPointSettings> bossOverrides;
2020
extern std::map<uint32, AutoBalanceStatModifiers> statModifierOverrides;

src/ABCreatureInfo.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55
#ifndef __AB_CREATURE_INFO_H
66
#define __AB_CREATURE_INFO_H
77

8+
#include "AutoBalance.h"
9+
810
#include "Creature.h"
911
#include "DataMap.h"
1012

11-
#include "AutoBalance.h"
12-
1313
class AutoBalanceCreatureInfo : public DataMap::Base
1414
{
1515
public:

src/ABGameObjectScript.cpp

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,21 @@
1-
#include "ABConfig.h"
21
#include "ABGameObjectScript.h"
2+
3+
#include "ABConfig.h"
34
#include "ABMapInfo.h"
45

56
void AutoBalance_GameObjectScript::OnGameObjectModifyHealth(GameObject* target, Unit* source, int32& amount, SpellInfo const* spellInfo)
67
{
78
// uncomment to debug this hook
89
bool _debug_damage_and_healing = (source && target && (source->GetTypeId() == TYPEID_PLAYER || source->IsControlledByPlayer()));
910

10-
if (_debug_damage_and_healing) _Debug_Output("OnGameObjectModifyHealth", target, source, amount, "BEFORE:", spellInfo->SpellName[0], spellInfo->Id);
11+
if (_debug_damage_and_healing)
12+
_Debug_Output("OnGameObjectModifyHealth", target, source, amount, "BEFORE:", spellInfo->SpellName[0], spellInfo->Id);
1113

1214
// modify the amount
1315
amount = _Modify_GameObject_Damage_Healing(target, source, amount, spellInfo);
1416

15-
if (_debug_damage_and_healing) _Debug_Output("OnGameObjectModifyHealth", target, source, amount, "AFTER:", spellInfo->SpellName[0], spellInfo->Id);
17+
if (_debug_damage_and_healing)
18+
_Debug_Output("OnGameObjectModifyHealth", target, source, amount, "AFTER:", spellInfo->SpellName[0], spellInfo->Id);
1619
}
1720

1821
void AutoBalance_GameObjectScript::_Debug_Output(std::string function_name, GameObject* target, Unit* source, int32 amount, std::string prefix, std::string spell_name, uint32 spell_id)
@@ -84,23 +87,26 @@ int32 AutoBalance_GameObjectScript::_Modify_GameObject_Damage_Healing(GameObject
8487
// check that we're enabled globally, else return the original value
8588
if (!EnableGlobal)
8689
{
87-
if (_debug_damage_and_healing) LOG_DEBUG("module.AutoBalance_DamageHealingCC", "AutoBalance_GameObjectScript::_Modify_GameObject_Damage_Healing: EnableGlobal is false, returning original value of ({}).", amount);
90+
if (_debug_damage_and_healing)
91+
LOG_DEBUG("module.AutoBalance_DamageHealingCC", "AutoBalance_GameObjectScript::_Modify_GameObject_Damage_Healing: EnableGlobal is false, returning original value of ({}).", amount);
8892

8993
return amount;
9094
}
9195

9296
// make sure the target is in an instance, else return the original damage
9397
if (!(target->GetMap()->IsDungeon()))
9498
{
95-
if (_debug_damage_and_healing) LOG_DEBUG("module.AutoBalance_DamageHealingCC", "AutoBalance_GameObjectScript::_Modify_GameObject_Damage_Healing: Target is not in an instance, returning original value of ({}).", amount);
99+
if (_debug_damage_and_healing)
100+
LOG_DEBUG("module.AutoBalance_DamageHealingCC", "AutoBalance_GameObjectScript::_Modify_GameObject_Damage_Healing: Target is not in an instance, returning original value of ({}).", amount);
96101

97102
return amount;
98103
}
99104

100105
// make sure the target is in the world, else return the original value
101106
if (!target->IsInWorld())
102107
{
103-
if (_debug_damage_and_healing) LOG_DEBUG("module.AutoBalance_DamageHealingCC", "AutoBalance_GameObjectScript::_Modify_GameObject_Damage_Healing: Target does not exist in the world, returning original value of ({}).", amount);
108+
if (_debug_damage_and_healing)
109+
LOG_DEBUG("module.AutoBalance_DamageHealingCC", "AutoBalance_GameObjectScript::_Modify_GameObject_Damage_Healing: Target does not exist in the world, returning original value of ({}).", amount);
104110

105111
return amount;
106112
}
@@ -134,7 +140,8 @@ int32 AutoBalance_GameObjectScript::_Modify_GameObject_Damage_Healing(GameObject
134140
// if the target's map is not enabled, return the original damage
135141
if (!targetMapABInfo->enabled)
136142
{
137-
if (_debug_damage_and_healing) LOG_DEBUG("module.AutoBalance_DamageHealingCC", "AutoBalance_GameObjectScript::_Modify_GameObject_Damage_Healing: Target's map is not enabled, returning original value of ({}).", amount);
143+
if (_debug_damage_and_healing)
144+
LOG_DEBUG("module.AutoBalance_DamageHealingCC", "AutoBalance_GameObjectScript::_Modify_GameObject_Damage_Healing: Target's map is not enabled, returning original value of ({}).", amount);
138145

139146
return amount;
140147
}

src/ABGlobalScript.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
#include "ABConfig.h"
21
#include "ABGlobalScript.h"
2+
3+
#include "ABConfig.h"
34
#include "ABMapInfo.h"
45

56
void AutoBalance_GlobalScript::OnAfterUpdateEncounterState(Map* map, EncounterCreditType type, uint32 /*creditEntry*/, Unit* /*source*/, Difficulty /*difficulty_fixed*/, DungeonEncounterList const* /*encounters*/, uint32 /*dungeonCompleted*/, bool updated)

src/ABGlobalScript.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99

1010
class AutoBalance_GlobalScript : public GlobalScript {
1111
public:
12-
AutoBalance_GlobalScript() : GlobalScript("AutoBalance_GlobalScript") { }
12+
AutoBalance_GlobalScript() : GlobalScript("AutoBalance_GlobalScript", {
13+
GLOBALHOOK_ON_AFTER_UPDATE_ENCOUNTER_STATE
14+
}) { }
1315

1416
void OnAfterUpdateEncounterState(Map* map, EncounterCreditType type, uint32 creditEntry, Unit* source, Difficulty difficulty_fixed, DungeonEncounterList const* encounters, uint32 dungeonCompleted, bool updated) override;
1517
};

0 commit comments

Comments
 (0)