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
23 changes: 4 additions & 19 deletions src/ABAllCreatureScript.cpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
#include "MapMgr.h"

#include "AutoBalance.h"
#include "ABAllCreatureScript.h"

#include "ABConfig.h"
#include "ABCreatureInfo.h"
#include "ABMapInfo.h"
#include "ABScriptMgr.h"
#include "ABUtils.h"
#include "AutoBalance.h"

#include "MapMgr.h"

void AutoBalance_AllCreatureScript::OnBeforeCreatureSelectLevel(const CreatureTemplate* /*creatureTemplate*/, Creature* creature, uint8& level)
{
Expand Down Expand Up @@ -294,19 +295,15 @@ bool AutoBalance_AllCreatureScript::ResetCreatureIfNeeded(Creature* creature)
{
// make sure we have a creature
if (!creature || !isCreatureRelevant(creature))
{
return false;
}

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

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

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

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

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

// Min/Max checking
if (ccDurationMultiplier < MinCCDurationModifier)
{
ccDurationMultiplier = MinCCDurationModifier;
}
else if (ccDurationMultiplier > MaxCCDurationModifier)
{
ccDurationMultiplier = MaxCCDurationModifier;
}

LOG_DEBUG("module.AutoBalance_StatGeneration", "AutoBalance_AllCreatureScript::ModifyCreatureAttributes: Creature {} ({}) | ccDurationMultiplier: ({})",
creature->GetName(),
Expand Down Expand Up @@ -1492,9 +1481,7 @@ bool AutoBalance_AllCreatureScript::_isSummonCloneOfSummoner(Creature* summon)
{
// if the summon doesn't exist or isn't a summon
if (!summon || !summon->IsSummon())
{
return false;
}

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

// if the summoner doesn't exist
if (!summoner)
{
return false;
}

// if this creature's ID is in the list of creatures that are not clones of their summoner (creatureIDsThatAreNotClones), return false
if (
Expand Down
19 changes: 3 additions & 16 deletions src/ABAllMapScript.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
#include "Chat.h"

#include "ABAllMapScript.h"

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

#include "Chat.h"
#include "Message.h"

void AutoBalance_AllMapScript::OnCreateMap(Map* map)
Expand Down Expand Up @@ -33,17 +34,11 @@ void AutoBalance_AllMapScript::OnCreateMap(Map* map)
{
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(),
Expand Down Expand Up @@ -189,17 +184,13 @@ void AutoBalance_AllMapScript::OnPlayerEnterAll(Map* map, Player* player)

// notify GMs that they won't be accounted for
if (player->IsGameMaster())
{
chatHandle.PSendSysMessage(ABGetLocaleText(locale, "welcome_to_gm").c_str());
}
}
else
{
// announce non-GMs entering the instance only
if (!player->IsGameMaster())
{
chatHandle.PSendSysMessage(ABGetLocaleText(locale, "announce_non_gm_entering_instance").c_str(), player->GetName().c_str(), mapABInfo->playerCount, mapABInfo->adjustedPlayerCount);
}
}
}
}
Expand Down Expand Up @@ -240,9 +231,7 @@ void AutoBalance_AllMapScript::OnPlayerLeaveAll(Map* map, Player* player)

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

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

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

// if the previous player count is the same as the new player count, update without force
if (prevAdjustedPlayerCount == mapABInfo->adjustedPlayerCount)
Expand Down
12 changes: 8 additions & 4 deletions src/ABAllMapScript.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,19 @@ class AutoBalance_AllMapScript : public AllMapScript
{
public:
AutoBalance_AllMapScript()
: AllMapScript("AutoBalance_AllMapScript")
: AllMapScript("AutoBalance_AllMapScript", {
ALLMAPHOOK_ON_CREATE_MAP,
ALLMAPHOOK_ON_PLAYER_ENTER_ALL,
ALLMAPHOOK_ON_PLAYER_LEAVE_ALL
})
{
}

void OnCreateMap(Map* map);
void OnCreateMap(Map* map) override;
// hook triggers after the player has already entered the world
void OnPlayerEnterAll(Map* map, Player* player);
void OnPlayerEnterAll(Map* map, Player* player) override;
// hook triggers just before the player left the world
void OnPlayerLeaveAll(Map* map, Player* player);
void OnPlayerLeaveAll(Map* map, Player* player) override;
};

#endif
18 changes: 1 addition & 17 deletions src/ABCommandScript.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "ABCommandScript.h"

#include "ABConfig.h"
#include "ABCreatureInfo.h"
#include "ABMapInfo.h"
Expand Down Expand Up @@ -67,25 +68,15 @@ bool AutoBalance_CommandScript::HandleABMapStatsCommand(ChatHandler* handler, co

// Adjusted player count (multiple scenarios)
if (mapABInfo->combatLockTripped)
{
handler->PSendSysMessage(ABGetLocaleText(locale, "adjusted_player_count_combat_locked").c_str(), mapABInfo->adjustedPlayerCount);
}
else if (mapABInfo->playerCount < mapABInfo->minPlayers && !PlayerCountDifficultyOffset)
{
handler->PSendSysMessage(ABGetLocaleText(locale, "adjusted_player_count_map_minimum").c_str(), mapABInfo->adjustedPlayerCount);
}
else if (mapABInfo->playerCount < mapABInfo->minPlayers && PlayerCountDifficultyOffset)
{
handler->PSendSysMessage(ABGetLocaleText(locale, "adjusted_player_count_map_minimum_difficulty_offset").c_str(), mapABInfo->adjustedPlayerCount, PlayerCountDifficultyOffset);
}
else if (PlayerCountDifficultyOffset)
{
handler->PSendSysMessage(ABGetLocaleText(locale, "adjusted_player_count_difficulty_offset").c_str(), mapABInfo->adjustedPlayerCount, PlayerCountDifficultyOffset);
}
else
{
handler->PSendSysMessage(ABGetLocaleText(locale, "adjusted_player_count").c_str(), mapABInfo->adjustedPlayerCount);
}

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

// summon
if (target->IsSummon() && targetABInfo->summoner && targetABInfo->isCloneOfSummoner)
{
handler->PSendSysMessage(ABGetLocaleText(locale, "clone_of_summon").c_str(), targetABInfo->summonerName, targetABInfo->summonerLevel);
}
else if (target->IsSummon() && targetABInfo->summoner)
{
handler->PSendSysMessage(ABGetLocaleText(locale, "summon_of_summon").c_str(), targetABInfo->summonerName, targetABInfo->summonerLevel);
}
else if (target->IsSummon())
{
handler->PSendSysMessage(ABGetLocaleText(locale, "summon_without_summoner").c_str());
}

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

return true;

}
16 changes: 9 additions & 7 deletions src/ABCommandScript.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,24 @@
#include "Config.h"
#include "ScriptMgr.h"

using namespace Acore::ChatCommands;

class AutoBalance_CommandScript : public CommandScript
{
public:
AutoBalance_CommandScript() : CommandScript("AutoBalance_CommandScript") { }

std::vector<Acore::ChatCommands::ChatCommandBuilder> GetCommands() const
ChatCommandTable GetCommands() const override
{
static std::vector<Acore::ChatCommands::ChatCommandBuilder> ABCommandTable =
static ChatCommandTable ABCommandTable =
{
{ "setoffset", HandleABSetOffsetCommand, SEC_GAMEMASTER, Acore::ChatCommands::Console::Yes },
{ "getoffset", HandleABGetOffsetCommand, SEC_PLAYER, Acore::ChatCommands::Console::Yes },
{ "mapstat", HandleABMapStatsCommand, SEC_PLAYER, Acore::ChatCommands::Console::Yes },
{ "creaturestat", HandleABCreatureStatsCommand, SEC_PLAYER, Acore::ChatCommands::Console::Yes }
{ "setoffset", HandleABSetOffsetCommand, SEC_GAMEMASTER, Console::Yes },
{ "getoffset", HandleABGetOffsetCommand, SEC_PLAYER, Console::Yes },
{ "mapstat", HandleABMapStatsCommand, SEC_PLAYER, Console::Yes },
{ "creaturestat", HandleABCreatureStatsCommand, SEC_PLAYER, Console::Yes }
};

static std::vector<Acore::ChatCommands::ChatCommandBuilder> commandTable =
static ChatCommandTable commandTable =
{
{ "autobalance", ABCommandTable },
{ "ab", ABCommandTable },
Expand Down
10 changes: 5 additions & 5 deletions src/ABConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@
#ifndef __AB_CONFIG_H
#define __AB_CONFIG_H

#include <list>
#include <map>

#include "SharedDefines.h"

#include "ABInflectionPointSettings.h"
#include "ABLevelScalingDynamicLevelSettings.h"
#include "ABStatModifiers.h"
#include "AutoBalance.h"

#include "SharedDefines.h"

#include <list>
#include <map>

extern std::map<uint32, AutoBalanceInflectionPointSettings> dungeonOverrides;
extern std::map<uint32, AutoBalanceInflectionPointSettings> bossOverrides;
extern std::map<uint32, AutoBalanceStatModifiers> statModifierOverrides;
Expand Down
4 changes: 2 additions & 2 deletions src/ABCreatureInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
#ifndef __AB_CREATURE_INFO_H
#define __AB_CREATURE_INFO_H

#include "AutoBalance.h"

#include "Creature.h"
#include "DataMap.h"

#include "AutoBalance.h"

class AutoBalanceCreatureInfo : public DataMap::Base
{
public:
Expand Down
21 changes: 14 additions & 7 deletions src/ABGameObjectScript.cpp
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
#include "ABConfig.h"
#include "ABGameObjectScript.h"

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

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

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

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

if (_debug_damage_and_healing) _Debug_Output("OnGameObjectModifyHealth", target, source, amount, "AFTER:", spellInfo->SpellName[0], spellInfo->Id);
if (_debug_damage_and_healing)
_Debug_Output("OnGameObjectModifyHealth", target, source, amount, "AFTER:", spellInfo->SpellName[0], spellInfo->Id);
}

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)
Expand Down Expand Up @@ -84,23 +87,26 @@ int32 AutoBalance_GameObjectScript::_Modify_GameObject_Damage_Healing(GameObject
// check that we're enabled globally, else return the original value
if (!EnableGlobal)
{
if (_debug_damage_and_healing) LOG_DEBUG("module.AutoBalance_DamageHealingCC", "AutoBalance_GameObjectScript::_Modify_GameObject_Damage_Healing: EnableGlobal is false, returning original value of ({}).", amount);
if (_debug_damage_and_healing)
LOG_DEBUG("module.AutoBalance_DamageHealingCC", "AutoBalance_GameObjectScript::_Modify_GameObject_Damage_Healing: EnableGlobal is false, returning original value of ({}).", amount);

return amount;
}

// make sure the target is in an instance, else return the original damage
if (!(target->GetMap()->IsDungeon()))
{
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);
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);

return amount;
}

// make sure the target is in the world, else return the original value
if (!target->IsInWorld())
{
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);
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);

return amount;
}
Expand Down Expand Up @@ -134,7 +140,8 @@ int32 AutoBalance_GameObjectScript::_Modify_GameObject_Damage_Healing(GameObject
// if the target's map is not enabled, return the original damage
if (!targetMapABInfo->enabled)
{
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);
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);

return amount;
}
Expand Down
3 changes: 2 additions & 1 deletion src/ABGlobalScript.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "ABConfig.h"
#include "ABGlobalScript.h"

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

void AutoBalance_GlobalScript::OnAfterUpdateEncounterState(Map* map, EncounterCreditType type, uint32 /*creditEntry*/, Unit* /*source*/, Difficulty /*difficulty_fixed*/, DungeonEncounterList const* /*encounters*/, uint32 /*dungeonCompleted*/, bool updated)
Expand Down
4 changes: 3 additions & 1 deletion src/ABGlobalScript.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@

class AutoBalance_GlobalScript : public GlobalScript {
public:
AutoBalance_GlobalScript() : GlobalScript("AutoBalance_GlobalScript") { }
AutoBalance_GlobalScript() : GlobalScript("AutoBalance_GlobalScript", {
GLOBALHOOK_ON_AFTER_UPDATE_ENCOUNTER_STATE
}) { }

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