Skip to content

Commit ff5bf37

Browse files
authored
Fix creatures not scaling based on LFG information (#207)
1 parent 2bf6098 commit ff5bf37

11 files changed

+99
-112
lines changed

src/ABAllCreatureScript.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ bool AutoBalance_AllCreatureScript::ResetCreatureIfNeeded(Creature* creature)
298298
return false;
299299

300300
// get (or create) map and creature info
301-
AutoBalanceMapInfo* mapABInfo = creature->GetMap()->CustomData.GetDefault<AutoBalanceMapInfo>("AutoBalanceMapInfo");
301+
AutoBalanceMapInfo* mapABInfo = GetMapInfo(creature->GetMap());
302302
AutoBalanceCreatureInfo* creatureABInfo = creature->CustomData.GetDefault<AutoBalanceCreatureInfo>("AutoBalanceCreatureInfo");
303303

304304
// if creature is dead and mapConfigTime is 0, skip for now
@@ -421,7 +421,7 @@ void AutoBalance_AllCreatureScript::ModifyCreatureAttributes(Creature* creature)
421421
AutoBalanceCreatureInfo* creatureABInfo = creature->CustomData.GetDefault<AutoBalanceCreatureInfo>("AutoBalanceCreatureInfo");
422422
Map* map = creature->GetMap();
423423
InstanceMap* instanceMap = map->ToInstanceMap();
424-
AutoBalanceMapInfo* mapABInfo = instanceMap->CustomData.GetDefault<AutoBalanceMapInfo>("AutoBalanceMapInfo");
424+
AutoBalanceMapInfo* mapABInfo = GetMapInfo(instanceMap);
425425

426426
// mark the creature as updated using the current settings if needed
427427
// if this creature is brand new, do not update this so that it will be re-processed next OnCreatureUpdate

src/ABAllMapScript.cpp

Lines changed: 2 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -7,91 +7,6 @@
77
#include "Chat.h"
88
#include "Message.h"
99

10-
void AutoBalance_AllMapScript::OnCreateMap(Map* map)
11-
{
12-
LOG_DEBUG("module.AutoBalance", "AutoBalance_AllMapScript::OnCreateMap(): Map {} ({}{})",
13-
map->GetMapName(),
14-
map->GetId(),
15-
map->GetInstanceId() ? "-" + std::to_string(map->GetInstanceId()) : ""
16-
);
17-
18-
// clear out any previously-recorded data
19-
map->CustomData.Erase("AutoBalanceMapInfo");
20-
21-
AutoBalanceMapInfo* mapABInfo = map->CustomData.GetDefault<AutoBalanceMapInfo>("AutoBalanceMapInfo");
22-
23-
if (map->IsDungeon())
24-
{
25-
// get the map's LFG stats even if not enabled
26-
LFGDungeonEntry const* dungeon = GetLFGDungeon(map->GetId(), map->GetDifficulty());
27-
if (dungeon) {
28-
mapABInfo->lfgMinLevel = dungeon->MinLevel;
29-
mapABInfo->lfgMaxLevel = dungeon->MaxLevel;
30-
mapABInfo->lfgTargetLevel = dungeon->TargetLevel;
31-
}
32-
// if this is a heroic dungeon that isn't in LFG, get the stats from the non-heroic version
33-
else if (map->IsHeroic())
34-
{
35-
LFGDungeonEntry const* nonHeroicDungeon = nullptr;
36-
if (map->GetDifficulty() == DUNGEON_DIFFICULTY_HEROIC)
37-
nonHeroicDungeon = GetLFGDungeon(map->GetId(), DUNGEON_DIFFICULTY_NORMAL);
38-
else if (map->GetDifficulty() == RAID_DIFFICULTY_10MAN_HEROIC)
39-
nonHeroicDungeon = GetLFGDungeon(map->GetId(), RAID_DIFFICULTY_10MAN_NORMAL);
40-
else if (map->GetDifficulty() == RAID_DIFFICULTY_25MAN_HEROIC)
41-
nonHeroicDungeon = GetLFGDungeon(map->GetId(), RAID_DIFFICULTY_25MAN_NORMAL);
42-
43-
LOG_DEBUG("module.AutoBalance", "AutoBalance_AllMapScript::OnCreateMap(): Map {} ({}{}) | is a Heroic dungeon that is not in LFG. Using non-heroic LFG levels.",
44-
map->GetMapName(),
45-
map->GetId(),
46-
map->GetInstanceId() ? "-" + std::to_string(map->GetInstanceId()) : ""
47-
);
48-
49-
if (nonHeroicDungeon)
50-
{
51-
mapABInfo->lfgMinLevel = nonHeroicDungeon->MinLevel;
52-
mapABInfo->lfgMaxLevel = nonHeroicDungeon->MaxLevel;
53-
mapABInfo->lfgTargetLevel = nonHeroicDungeon->TargetLevel;
54-
}
55-
else
56-
{
57-
LOG_ERROR("module.AutoBalance", "AutoBalance_AllMapScript::OnCreateMap(): Map {} ({}{}) | Could not determine LFG level ranges for this map. Level will bet set to 0.",
58-
map->GetMapName(),
59-
map->GetId(),
60-
map->GetInstanceId() ? "-" + std::to_string(map->GetInstanceId()) : ""
61-
);
62-
}
63-
}
64-
65-
if (map->GetInstanceId())
66-
{
67-
LOG_DEBUG("module.AutoBalance", "AutoBalance_AllMapScript::OnCreateMap(): Map {} ({}{}) | is an instance of a map. Loading initial map data.",
68-
map->GetMapName(),
69-
map->GetId(),
70-
map->GetInstanceId() ? "-" + std::to_string(map->GetInstanceId()) : ""
71-
);
72-
UpdateMapDataIfNeeded(map);
73-
74-
// provide a concise summary of the map data we collected
75-
LOG_DEBUG("module.AutoBalance", "AutoBalance_AllMapScript::OnCreateMap(): Map {} ({}{}) | LFG levels ({}-{}) (target {}). {} for AutoBalancing.",
76-
map->GetMapName(),
77-
map->GetId(),
78-
map->GetInstanceId() ? "-" + std::to_string(map->GetInstanceId()) : "",
79-
mapABInfo->lfgMinLevel ? std::to_string(mapABInfo->lfgMinLevel) : "?",
80-
mapABInfo->lfgMaxLevel ? std::to_string(mapABInfo->lfgMaxLevel) : "?",
81-
mapABInfo->lfgTargetLevel ? std::to_string(mapABInfo->lfgTargetLevel) : "?",
82-
mapABInfo->enabled ? "Enabled" : "Disabled"
83-
);
84-
}
85-
else
86-
{
87-
LOG_DEBUG(
88-
"module.AutoBalance", "AutoBalance_AllMapScript::OnCreateMap(): Map {} ({}) | is an instance base map.",
89-
map->GetMapName(),
90-
map->GetId()
91-
);
92-
}
93-
}
94-
}
9510

9611
void AutoBalance_AllMapScript::OnPlayerEnterAll(Map* map, Player* player)
9712
{
@@ -112,7 +27,7 @@ void AutoBalance_AllMapScript::OnPlayerEnterAll(Map* map, Player* player)
11227
);
11328

11429
// get the map's info
115-
AutoBalanceMapInfo* mapABInfo = map->CustomData.GetDefault<AutoBalanceMapInfo>("AutoBalanceMapInfo");
30+
AutoBalanceMapInfo* mapABInfo = GetMapInfo(map);
11631

11732
// store the previous difficulty for comparison later
11833
int prevAdjustedPlayerCount = mapABInfo->adjustedPlayerCount;
@@ -218,7 +133,7 @@ void AutoBalance_AllMapScript::OnPlayerLeaveAll(Map* map, Player* player)
218133
);
219134

220135
// get the map's info
221-
AutoBalanceMapInfo* mapABInfo = map->CustomData.GetDefault<AutoBalanceMapInfo>("AutoBalanceMapInfo");
136+
AutoBalanceMapInfo* mapABInfo = GetMapInfo(map);
222137

223138
// store the previous difficulty for comparison later
224139
int prevAdjustedPlayerCount = mapABInfo->adjustedPlayerCount;

src/ABAllMapScript.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,12 @@ class AutoBalance_AllMapScript : public AllMapScript
1212
public:
1313
AutoBalance_AllMapScript()
1414
: AllMapScript("AutoBalance_AllMapScript", {
15-
ALLMAPHOOK_ON_CREATE_MAP,
1615
ALLMAPHOOK_ON_PLAYER_ENTER_ALL,
1716
ALLMAPHOOK_ON_PLAYER_LEAVE_ALL
1817
})
1918
{
2019
}
2120

22-
void OnCreateMap(Map* map) override;
2321
// hook triggers after the player has already entered the world
2422
void OnPlayerEnterAll(Map* map, Player* player) override;
2523
// hook triggers just before the player left the world

src/ABCommandScript.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ bool AutoBalance_CommandScript::HandleABMapStatsCommand(ChatHandler* handler, co
4242
Player* player = handler->GetPlayer();
4343
auto locale = handler->GetSession()->GetSessionDbLocaleIndex();
4444

45-
AutoBalanceMapInfo* mapABInfo = player->GetMap()->CustomData.GetDefault<AutoBalanceMapInfo>("AutoBalanceMapInfo");
45+
AutoBalanceMapInfo* mapABInfo = GetMapInfo(player->GetMap());
4646

4747
if (player->GetMap()->IsDungeon())
4848
{

src/ABGameObjectScript.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
#include "ABConfig.h"
44
#include "ABMapInfo.h"
5+
#include "ABUtils.h"
56

67
void AutoBalance_GameObjectScript::OnGameObjectModifyHealth(GameObject* target, Unit* source, int32& amount, SpellInfo const* spellInfo)
78
{
@@ -135,7 +136,7 @@ int32 AutoBalance_GameObjectScript::_Modify_GameObject_Damage_Healing(GameObject
135136
}
136137

137138
// get the map's info
138-
AutoBalanceMapInfo* targetMapABInfo = target->GetMap()->CustomData.GetDefault<AutoBalanceMapInfo>("AutoBalanceMapInfo");
139+
AutoBalanceMapInfo* targetMapABInfo = GetMapInfo(target->GetMap());
139140

140141
// if the target's map is not enabled, return the original damage
141142
if (!targetMapABInfo->enabled)

src/ABGlobalScript.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
#include "ABConfig.h"
44
#include "ABMapInfo.h"
5+
#include "ABUtils.h"
56

67
void AutoBalance_GlobalScript::OnAfterUpdateEncounterState(Map* map, EncounterCreditType type, uint32 /*creditEntry*/, Unit* /*source*/, Difficulty /*difficulty_fixed*/, DungeonEncounterList const* /*encounters*/, uint32 /*dungeonCompleted*/, bool updated)
78
{
@@ -11,7 +12,7 @@ void AutoBalance_GlobalScript::OnAfterUpdateEncounterState(Map* map, EncounterCr
1112
if (!rewardEnabled || !updated)
1213
return;
1314

14-
AutoBalanceMapInfo* mapABInfo = map->CustomData.GetDefault<AutoBalanceMapInfo>("AutoBalanceMapInfo");
15+
AutoBalanceMapInfo* mapABInfo = GetMapInfo(map);
1516

1617
if (mapABInfo->adjustedPlayerCount < MinPlayerReward)
1718
return;

src/ABMapInfo.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,6 @@ class AutoBalanceMapInfo : public DataMap::Base
5757
uint8 levelScalingDynamicFloor = 0; // How many levels LESS than the highestPlayerLevel creature should be scaled to
5858

5959
uint8 prevMapLevel = 0; // Used to reduce calculations when they are not necessary
60+
bool initialized = false; // Whether or not the map has been initialized
6061
};
61-
6262
#endif

src/ABPlayerScript.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ void AutoBalance_PlayerScript::OnPlayerLevelChanged(Player* player, uint8 oldlev
3232
UpdateMapPlayerStats(map);
3333

3434
// schedule all creatures for an update
35-
AutoBalanceMapInfo* mapABInfo = map->CustomData.GetDefault<AutoBalanceMapInfo>("AutoBalanceMapInfo");
35+
AutoBalanceMapInfo* mapABInfo = GetMapInfo(map);
3636
mapABInfo->mapConfigTime = GetCurrentConfigTime();
3737
}
3838

@@ -44,7 +44,7 @@ void AutoBalance_PlayerScript::OnPlayerGiveXP(Player* player, uint32& amount, Un
4444
if (!map->IsDungeon() || !map->GetInstanceId() || !victim)
4545
return;
4646

47-
AutoBalanceMapInfo* mapABInfo = map->CustomData.GetDefault<AutoBalanceMapInfo>("AutoBalanceMapInfo");
47+
AutoBalanceMapInfo* mapABInfo = GetMapInfo(map);
4848

4949
if (victim && RewardScalingXP && mapABInfo->enabled)
5050
{
@@ -81,7 +81,7 @@ void AutoBalance_PlayerScript::OnPlayerBeforeLootMoney(Player* player, Loot* loo
8181
if (!map->IsDungeon())
8282
return;
8383

84-
AutoBalanceMapInfo* mapABInfo = map->CustomData.GetDefault<AutoBalanceMapInfo>("AutoBalanceMapInfo");
84+
AutoBalanceMapInfo* mapABInfo = GetMapInfo(map);
8585
ObjectGuid sourceGuid = loot->sourceWorldObjectGUID;
8686

8787
if (mapABInfo->enabled && RewardScalingMoney)
@@ -136,7 +136,7 @@ void AutoBalance_PlayerScript::OnPlayerEnterCombat(Player* player, Unit* /*enemy
136136

137137
LOG_DEBUG("module.AutoBalance_CombatLocking", "AutoBalance_PlayerScript::OnPlayerEnterCombat: {} enters combat.", player->GetName());
138138

139-
AutoBalanceMapInfo* mapABInfo = map->CustomData.GetDefault<AutoBalanceMapInfo>("AutoBalanceMapInfo");
139+
AutoBalanceMapInfo* mapABInfo = GetMapInfo(map);
140140

141141
// if this map isn't enabled, no work to do
142142
if (!mapABInfo->enabled)
@@ -175,7 +175,7 @@ void AutoBalance_PlayerScript::OnPlayerLeaveCombat(Player* player)
175175
// unfortunately, `player->IsInCombat()` doesn't work here
176176
LOG_DEBUG("module.AutoBalance_CombatLocking", "AutoBalance_PlayerScript::OnPlayerLeaveCombat: {} leaves (or wasn't in) combat.", player->GetName());
177177

178-
AutoBalanceMapInfo* mapABInfo = map->CustomData.GetDefault<AutoBalanceMapInfo>("AutoBalanceMapInfo");
178+
AutoBalanceMapInfo* mapABInfo = GetMapInfo(map);
179179

180180
// if this map isn't enabled, no work to do
181181
if (!mapABInfo->enabled)

src/ABUnitScript.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include "ABConfig.h"
44
#include "ABCreatureInfo.h"
55
#include "ABMapInfo.h"
6+
#include "ABUtils.h"
67

78
void AutoBalance_UnitScript::ModifyPeriodicDamageAurasTick(Unit* target, Unit* source, uint32& amount, SpellInfo const* spellInfo)
89
{
@@ -253,8 +254,8 @@ int32 AutoBalance_UnitScript::_Modify_Damage_Healing(Unit* target, Unit* source,
253254
}
254255

255256
// get the maps' info
256-
AutoBalanceMapInfo* sourceMapABInfo = source->GetMap()->CustomData.GetDefault<AutoBalanceMapInfo>("AutoBalanceMapInfo");
257-
AutoBalanceMapInfo* targetMapABInfo = target->GetMap()->CustomData.GetDefault<AutoBalanceMapInfo>("AutoBalanceMapInfo");
257+
AutoBalanceMapInfo* sourceMapABInfo = GetMapInfo(source->GetMap());
258+
AutoBalanceMapInfo* targetMapABInfo = GetMapInfo(target->GetMap());
258259

259260
// if either the target or the source's maps are not enabled, return the original damage
260261
if (!sourceMapABInfo->enabled || !targetMapABInfo->enabled)

0 commit comments

Comments
 (0)