Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/ABAllCreatureScript.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ bool AutoBalance_AllCreatureScript::ResetCreatureIfNeeded(Creature* creature)
return false;

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

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

// mark the creature as updated using the current settings if needed
// if this creature is brand new, do not update this so that it will be re-processed next OnCreatureUpdate
Expand Down
89 changes: 2 additions & 87 deletions src/ABAllMapScript.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,91 +7,6 @@
#include "Chat.h"
#include "Message.h"

void AutoBalance_AllMapScript::OnCreateMap(Map* map)
{
LOG_DEBUG("module.AutoBalance", "AutoBalance_AllMapScript::OnCreateMap(): Map {} ({}{})",
map->GetMapName(),
map->GetId(),
map->GetInstanceId() ? "-" + std::to_string(map->GetInstanceId()) : ""
);

// clear out any previously-recorded data
map->CustomData.Erase("AutoBalanceMapInfo");

AutoBalanceMapInfo* mapABInfo = map->CustomData.GetDefault<AutoBalanceMapInfo>("AutoBalanceMapInfo");

if (map->IsDungeon())
{
// get the map's LFG stats even if not enabled
LFGDungeonEntry const* dungeon = GetLFGDungeon(map->GetId(), map->GetDifficulty());
if (dungeon) {
mapABInfo->lfgMinLevel = dungeon->MinLevel;
mapABInfo->lfgMaxLevel = dungeon->MaxLevel;
mapABInfo->lfgTargetLevel = dungeon->TargetLevel;
}
// if this is a heroic dungeon that isn't in LFG, get the stats from the non-heroic version
else if (map->IsHeroic())
{
LFGDungeonEntry const* nonHeroicDungeon = nullptr;
if (map->GetDifficulty() == DUNGEON_DIFFICULTY_HEROIC)
nonHeroicDungeon = GetLFGDungeon(map->GetId(), DUNGEON_DIFFICULTY_NORMAL);
else if (map->GetDifficulty() == RAID_DIFFICULTY_10MAN_HEROIC)
nonHeroicDungeon = GetLFGDungeon(map->GetId(), RAID_DIFFICULTY_10MAN_NORMAL);
else if (map->GetDifficulty() == RAID_DIFFICULTY_25MAN_HEROIC)
nonHeroicDungeon = GetLFGDungeon(map->GetId(), RAID_DIFFICULTY_25MAN_NORMAL);

LOG_DEBUG("module.AutoBalance", "AutoBalance_AllMapScript::OnCreateMap(): Map {} ({}{}) | is a Heroic dungeon that is not in LFG. Using non-heroic LFG levels.",
map->GetMapName(),
map->GetId(),
map->GetInstanceId() ? "-" + std::to_string(map->GetInstanceId()) : ""
);

if (nonHeroicDungeon)
{
mapABInfo->lfgMinLevel = nonHeroicDungeon->MinLevel;
mapABInfo->lfgMaxLevel = nonHeroicDungeon->MaxLevel;
mapABInfo->lfgTargetLevel = nonHeroicDungeon->TargetLevel;
}
else
{
LOG_ERROR("module.AutoBalance", "AutoBalance_AllMapScript::OnCreateMap(): Map {} ({}{}) | Could not determine LFG level ranges for this map. Level will bet set to 0.",
map->GetMapName(),
map->GetId(),
map->GetInstanceId() ? "-" + std::to_string(map->GetInstanceId()) : ""
);
}
}

if (map->GetInstanceId())
{
LOG_DEBUG("module.AutoBalance", "AutoBalance_AllMapScript::OnCreateMap(): Map {} ({}{}) | is an instance of a map. Loading initial map data.",
map->GetMapName(),
map->GetId(),
map->GetInstanceId() ? "-" + std::to_string(map->GetInstanceId()) : ""
);
UpdateMapDataIfNeeded(map);

// provide a concise summary of the map data we collected
LOG_DEBUG("module.AutoBalance", "AutoBalance_AllMapScript::OnCreateMap(): Map {} ({}{}) | LFG levels ({}-{}) (target {}). {} for AutoBalancing.",
map->GetMapName(),
map->GetId(),
map->GetInstanceId() ? "-" + std::to_string(map->GetInstanceId()) : "",
mapABInfo->lfgMinLevel ? std::to_string(mapABInfo->lfgMinLevel) : "?",
mapABInfo->lfgMaxLevel ? std::to_string(mapABInfo->lfgMaxLevel) : "?",
mapABInfo->lfgTargetLevel ? std::to_string(mapABInfo->lfgTargetLevel) : "?",
mapABInfo->enabled ? "Enabled" : "Disabled"
);
}
else
{
LOG_DEBUG(
"module.AutoBalance", "AutoBalance_AllMapScript::OnCreateMap(): Map {} ({}) | is an instance base map.",
map->GetMapName(),
map->GetId()
);
}
}
}

void AutoBalance_AllMapScript::OnPlayerEnterAll(Map* map, Player* player)
{
Expand All @@ -112,7 +27,7 @@ void AutoBalance_AllMapScript::OnPlayerEnterAll(Map* map, Player* player)
);

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

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

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

// store the previous difficulty for comparison later
int prevAdjustedPlayerCount = mapABInfo->adjustedPlayerCount;
Expand Down
2 changes: 0 additions & 2 deletions src/ABAllMapScript.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,12 @@ class AutoBalance_AllMapScript : public AllMapScript
public:
AutoBalance_AllMapScript()
: AllMapScript("AutoBalance_AllMapScript", {
ALLMAPHOOK_ON_CREATE_MAP,
ALLMAPHOOK_ON_PLAYER_ENTER_ALL,
ALLMAPHOOK_ON_PLAYER_LEAVE_ALL
})
{
}

void OnCreateMap(Map* map) override;
// hook triggers after the player has already entered the world
void OnPlayerEnterAll(Map* map, Player* player) override;
// hook triggers just before the player left the world
Expand Down
2 changes: 1 addition & 1 deletion src/ABCommandScript.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ bool AutoBalance_CommandScript::HandleABMapStatsCommand(ChatHandler* handler, co
Player* player = handler->GetPlayer();
auto locale = handler->GetSession()->GetSessionDbLocaleIndex();

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

if (player->GetMap()->IsDungeon())
{
Expand Down
3 changes: 2 additions & 1 deletion src/ABGameObjectScript.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include "ABConfig.h"
#include "ABMapInfo.h"
#include "ABUtils.h"

void AutoBalance_GameObjectScript::OnGameObjectModifyHealth(GameObject* target, Unit* source, int32& amount, SpellInfo const* spellInfo)
{
Expand Down Expand Up @@ -135,7 +136,7 @@ int32 AutoBalance_GameObjectScript::_Modify_GameObject_Damage_Healing(GameObject
}

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

// if the target's map is not enabled, return the original damage
if (!targetMapABInfo->enabled)
Expand Down
3 changes: 2 additions & 1 deletion src/ABGlobalScript.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include "ABConfig.h"
#include "ABMapInfo.h"
#include "ABUtils.h"

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

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

if (mapABInfo->adjustedPlayerCount < MinPlayerReward)
return;
Expand Down
2 changes: 1 addition & 1 deletion src/ABMapInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,6 @@ class AutoBalanceMapInfo : public DataMap::Base
uint8 levelScalingDynamicFloor = 0; // How many levels LESS than the highestPlayerLevel creature should be scaled to

uint8 prevMapLevel = 0; // Used to reduce calculations when they are not necessary
bool initialized = false; // Whether or not the map has been initialized
};

#endif
10 changes: 5 additions & 5 deletions src/ABPlayerScript.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ void AutoBalance_PlayerScript::OnPlayerLevelChanged(Player* player, uint8 oldlev
UpdateMapPlayerStats(map);

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

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

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

if (victim && RewardScalingXP && mapABInfo->enabled)
{
Expand Down Expand Up @@ -81,7 +81,7 @@ void AutoBalance_PlayerScript::OnPlayerBeforeLootMoney(Player* player, Loot* loo
if (!map->IsDungeon())
return;

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

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

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

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

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

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

// if this map isn't enabled, no work to do
if (!mapABInfo->enabled)
Expand Down
5 changes: 3 additions & 2 deletions src/ABUnitScript.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "ABConfig.h"
#include "ABCreatureInfo.h"
#include "ABMapInfo.h"
#include "ABUtils.h"

void AutoBalance_UnitScript::ModifyPeriodicDamageAurasTick(Unit* target, Unit* source, uint32& amount, SpellInfo const* spellInfo)
{
Expand Down Expand Up @@ -253,8 +254,8 @@ int32 AutoBalance_UnitScript::_Modify_Damage_Healing(Unit* target, Unit* source,
}

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

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