diff --git a/src/ABAllCreatureScript.cpp b/src/ABAllCreatureScript.cpp index a37dc77..e9bdbce 100644 --- a/src/ABAllCreatureScript.cpp +++ b/src/ABAllCreatureScript.cpp @@ -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) { @@ -294,9 +295,7 @@ 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"); @@ -304,9 +303,7 @@ bool AutoBalance_AllCreatureScript::ResetCreatureIfNeeded(Creature* creature) // 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()) @@ -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(), @@ -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(), @@ -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"); @@ -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 ( diff --git a/src/ABAllMapScript.cpp b/src/ABAllMapScript.cpp index 3f4bcd4..527493f 100644 --- a/src/ABAllMapScript.cpp +++ b/src/ABAllMapScript.cpp @@ -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) @@ -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(), @@ -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); - } } } } @@ -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; @@ -252,9 +241,7 @@ void AutoBalance_AllMapScript::OnPlayerLeaveAll(Map* map, Player* player) // see which existing creatures are active for (std::vector::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) diff --git a/src/ABAllMapScript.h b/src/ABAllMapScript.h index 766a491..7ec65de 100644 --- a/src/ABAllMapScript.h +++ b/src/ABAllMapScript.h @@ -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 diff --git a/src/ABCommandScript.cpp b/src/ABCommandScript.cpp index b047601..891123f 100644 --- a/src/ABCommandScript.cpp +++ b/src/ABCommandScript.cpp @@ -1,4 +1,5 @@ #include "ABCommandScript.h" + #include "ABConfig.h" #include "ABCreatureInfo.h" #include "ABMapInfo.h" @@ -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); @@ -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()) @@ -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; - } diff --git a/src/ABCommandScript.h b/src/ABCommandScript.h index 13a74a9..c3529d8 100644 --- a/src/ABCommandScript.h +++ b/src/ABCommandScript.h @@ -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 GetCommands() const + ChatCommandTable GetCommands() const override { - static std::vector 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 commandTable = + static ChatCommandTable commandTable = { { "autobalance", ABCommandTable }, { "ab", ABCommandTable }, diff --git a/src/ABConfig.h b/src/ABConfig.h index c8223c9..560ea99 100644 --- a/src/ABConfig.h +++ b/src/ABConfig.h @@ -5,16 +5,16 @@ #ifndef __AB_CONFIG_H #define __AB_CONFIG_H -#include -#include - -#include "SharedDefines.h" - #include "ABInflectionPointSettings.h" #include "ABLevelScalingDynamicLevelSettings.h" #include "ABStatModifiers.h" #include "AutoBalance.h" +#include "SharedDefines.h" + +#include +#include + extern std::map dungeonOverrides; extern std::map bossOverrides; extern std::map statModifierOverrides; diff --git a/src/ABCreatureInfo.h b/src/ABCreatureInfo.h index d524695..5876e2b 100644 --- a/src/ABCreatureInfo.h +++ b/src/ABCreatureInfo.h @@ -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: diff --git a/src/ABGameObjectScript.cpp b/src/ABGameObjectScript.cpp index 3489871..b4e265a 100644 --- a/src/ABGameObjectScript.cpp +++ b/src/ABGameObjectScript.cpp @@ -1,5 +1,6 @@ -#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) @@ -7,12 +8,14 @@ void AutoBalance_GameObjectScript::OnGameObjectModifyHealth(GameObject* target, // 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) @@ -84,7 +87,8 @@ 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; } @@ -92,7 +96,8 @@ int32 AutoBalance_GameObjectScript::_Modify_GameObject_Damage_Healing(GameObject // 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; } @@ -100,7 +105,8 @@ int32 AutoBalance_GameObjectScript::_Modify_GameObject_Damage_Healing(GameObject // 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; } @@ -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; } diff --git a/src/ABGlobalScript.cpp b/src/ABGlobalScript.cpp index a26d215..7819416 100644 --- a/src/ABGlobalScript.cpp +++ b/src/ABGlobalScript.cpp @@ -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) diff --git a/src/ABGlobalScript.h b/src/ABGlobalScript.h index 41b8f2a..9302a00 100644 --- a/src/ABGlobalScript.h +++ b/src/ABGlobalScript.h @@ -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; }; diff --git a/src/ABMapInfo.h b/src/ABMapInfo.h index 255c53f..e678ba2 100644 --- a/src/ABMapInfo.h +++ b/src/ABMapInfo.h @@ -5,12 +5,12 @@ #ifndef __AB_MAP_INFO_H #define __AB_MAP_INFO_H -#include - #include "Creature.h" #include "DataMap.h" #include "Player.h" +#include + class AutoBalanceMapInfo : public DataMap::Base { public: diff --git a/src/ABPlayerScript.cpp b/src/ABPlayerScript.cpp index db1768b..cb3c908 100644 --- a/src/ABPlayerScript.cpp +++ b/src/ABPlayerScript.cpp @@ -1,19 +1,18 @@ #include -#include "Chat.h" - #include "ABConfig.h" #include "ABCreatureInfo.h" #include "ABMapInfo.h" #include "ABPlayerScript.h" #include "ABUtils.h" + +#include "Chat.h" #include "Message.h" void AutoBalance_PlayerScript::OnPlayerLogin(Player* Player) { - if (EnableGlobal && Announcement) { + if (EnableGlobal && Announcement) ChatHandler(Player->GetSession()).SendSysMessage("This server is running the |cff4CFF00AutoBalance |rmodule."); - } } void AutoBalance_PlayerScript::OnPlayerLevelChanged(Player* player, uint8 oldlevel) @@ -22,16 +21,12 @@ void AutoBalance_PlayerScript::OnPlayerLevelChanged(Player* player, uint8 oldlev LOG_DEBUG("module.AutoBalance", "AutoBalance_PlayerScript::OnLevelChanged: {} has leveled ({}->{})", player->GetName(), oldlevel, player->GetLevel()); if (!player || player->IsGameMaster()) - { return; - } Map* map = player->GetMap(); if (!map || !map->IsDungeon()) - { return; - } // update the map's player stats UpdateMapPlayerStats(map); @@ -47,9 +42,7 @@ void AutoBalance_PlayerScript::OnPlayerGiveXP(Player* player, uint32& amount, Un // If this isn't a dungeon, make no changes if (!map->IsDungeon() || !map->GetInstanceId() || !victim) - { return; - } AutoBalanceMapInfo* mapABInfo = map->CustomData.GetDefault("AutoBalanceMapInfo"); @@ -133,17 +126,13 @@ void AutoBalance_PlayerScript::OnPlayerEnterCombat(Player* player, Unit* /*enemy { // if the player or their map is gone, return if (!player || !player->GetMap()) - { return; - } Map* map = player->GetMap(); // If this isn't a dungeon, no work to do if (!map || !map->IsDungeon()) - { return; - } LOG_DEBUG("module.AutoBalance_CombatLocking", "AutoBalance_PlayerScript::OnPlayerEnterCombat: {} enters combat.", player->GetName()); @@ -151,9 +140,7 @@ void AutoBalance_PlayerScript::OnPlayerEnterCombat(Player* player, Unit* /*enemy // if this map isn't enabled, no work to do if (!mapABInfo->enabled) - { return; - } // lock the current map if (!mapABInfo->combatLocked) @@ -175,17 +162,13 @@ void AutoBalance_PlayerScript::OnPlayerLeaveCombat(Player* player) { // if the player or their map is gone, return if (!player || !player->GetMap()) - { return; - } Map* map = player->GetMap(); // If this isn't a dungeon, no work to do if (!map || !map->IsDungeon()) - { return; - } // this hook can get called even if the player isn't in combat // I believe this happens whenever AC attempts to remove combat, but it doesn't check to see if the player is in combat first @@ -196,9 +179,7 @@ void AutoBalance_PlayerScript::OnPlayerLeaveCombat(Player* player) // if this map isn't enabled, no work to do if (!mapABInfo->enabled) - { return; - } // check to see if any of the other players are in combat bool anyPlayersInCombat = false; @@ -240,9 +221,7 @@ void AutoBalance_PlayerScript::OnPlayerLeaveCombat(Player* player) for (auto player : mapABInfo->allMapPlayers) { if (player && player->GetSession()) - { ChatHandler(player->GetSession()).PSendSysMessage(ABGetLocaleText(locale, "leaving_instance_combat_change").c_str()); - } } } diff --git a/src/ABScriptMgr.cpp b/src/ABScriptMgr.cpp index b67391e..f5ae038 100644 --- a/src/ABScriptMgr.cpp +++ b/src/ABScriptMgr.cpp @@ -2,12 +2,12 @@ * Copyright (C) 2016+ AzerothCore , license: https://github.com/azerothcore/azerothcore-wotlk/blob/master/LICENSE */ -#include "ScriptMgr.h" -#include "ScriptMgrMacros.h" - #include "ABModuleScript.h" #include "ABScriptMgr.h" +#include "ScriptMgr.h" +#include "ScriptMgrMacros.h" + ABScriptMgr* ABScriptMgr::instance() { static ABScriptMgr instance; @@ -22,9 +22,7 @@ bool ABScriptMgr::OnBeforeModifyAttributes(Creature* creature, uint32& instanceP }); if (ret && *ret) - { return false; - } return true; } @@ -37,9 +35,7 @@ bool ABScriptMgr::OnAfterDefaultMultiplier(Creature* creature, float& defaultMul }); if (ret && *ret) - { return false; - } return true; } @@ -52,9 +48,7 @@ bool ABScriptMgr::OnBeforeUpdateStats(Creature* creature, uint32& scaledHealth, }); if (ret && *ret) - { return false; - } return true; } diff --git a/src/ABScriptMgr.h b/src/ABScriptMgr.h index fc50c00..e017264 100644 --- a/src/ABScriptMgr.h +++ b/src/ABScriptMgr.h @@ -5,8 +5,8 @@ #ifndef __AB_SCRIPT_MGR_H #define __AB_SCRIPT_MGR_H -#include "ScriptMgr.h" #include "Creature.h" +#include "ScriptMgr.h" // Manages registration, loading, and execution of scripts. class ABScriptMgr diff --git a/src/ABUnitScript.cpp b/src/ABUnitScript.cpp index c9057f3..3473459 100644 --- a/src/ABUnitScript.cpp +++ b/src/ABUnitScript.cpp @@ -1,7 +1,8 @@ +#include "ABUnitScript.h" + #include "ABConfig.h" #include "ABCreatureInfo.h" #include "ABMapInfo.h" -#include "ABUnitScript.h" void AutoBalance_UnitScript::ModifyPeriodicDamageAurasTick(Unit* target, Unit* source, uint32& amount, SpellInfo const* spellInfo) { @@ -13,14 +14,16 @@ void AutoBalance_UnitScript::ModifyPeriodicDamageAurasTick(Unit* target, Unit* s bool _debug_damage_and_healing = ((source && (source->GetTypeId() == TYPEID_PLAYER || source->IsControlledByPlayer())) || (target && target->GetTypeId() == TYPEID_PLAYER)); _debug_damage_and_healing = (source && source->GetMap()->GetInstanceId()); - if (_debug_damage_and_healing) _Debug_Output("ModifyPeriodicDamageAurasTick", target, source, adjustedAmount, AUTOBALANCE_DAMAGE_HEALING_DEBUG_PHASE_BEFORE, spellInfo->SpellName[0], spellInfo->Id); + if (_debug_damage_and_healing) + _Debug_Output("ModifyPeriodicDamageAurasTick", target, source, adjustedAmount, AUTOBALANCE_DAMAGE_HEALING_DEBUG_PHASE_BEFORE, spellInfo->SpellName[0], spellInfo->Id); // set amount to the absolute value of the function call // the provided amount doesn't indicate whether it's a positive or negative value adjustedAmount = _Modify_Damage_Healing(target, source, adjustedAmount, spellInfo); amount = abs(adjustedAmount); - if (_debug_damage_and_healing) _Debug_Output("ModifyPeriodicDamageAurasTick", target, source, adjustedAmount, AUTOBALANCE_DAMAGE_HEALING_DEBUG_PHASE_AFTER, spellInfo->SpellName[0], spellInfo->Id); + if (_debug_damage_and_healing) + _Debug_Output("ModifyPeriodicDamageAurasTick", target, source, adjustedAmount, AUTOBALANCE_DAMAGE_HEALING_DEBUG_PHASE_AFTER, spellInfo->SpellName[0], spellInfo->Id); } void AutoBalance_UnitScript::ModifySpellDamageTaken(Unit* target, Unit* source, int32& amount, SpellInfo const* spellInfo) @@ -33,14 +36,16 @@ void AutoBalance_UnitScript::ModifySpellDamageTaken(Unit* target, Unit* source, bool _debug_damage_and_healing = ((source && (source->GetTypeId() == TYPEID_PLAYER || source->IsControlledByPlayer())) || (target && target->GetTypeId() == TYPEID_PLAYER)); _debug_damage_and_healing = (source && source->GetMap()->GetInstanceId()); - if (_debug_damage_and_healing) _Debug_Output("ModifySpellDamageTaken", target, source, adjustedAmount, AUTOBALANCE_DAMAGE_HEALING_DEBUG_PHASE_BEFORE, spellInfo->SpellName[0], spellInfo->Id); + if (_debug_damage_and_healing) + _Debug_Output("ModifySpellDamageTaken", target, source, adjustedAmount, AUTOBALANCE_DAMAGE_HEALING_DEBUG_PHASE_BEFORE, spellInfo->SpellName[0], spellInfo->Id); // set amount to the absolute value of the function call // the provided amount doesn't indicate whether it's a positive or negative value adjustedAmount = _Modify_Damage_Healing(target, source, adjustedAmount, spellInfo); amount = abs(adjustedAmount); - if (_debug_damage_and_healing) _Debug_Output("ModifySpellDamageTaken", target, source, adjustedAmount, AUTOBALANCE_DAMAGE_HEALING_DEBUG_PHASE_AFTER, spellInfo->SpellName[0], spellInfo->Id); + if (_debug_damage_and_healing) + _Debug_Output("ModifySpellDamageTaken", target, source, adjustedAmount, AUTOBALANCE_DAMAGE_HEALING_DEBUG_PHASE_AFTER, spellInfo->SpellName[0], spellInfo->Id); } void AutoBalance_UnitScript::ModifyMeleeDamage(Unit* target, Unit* source, uint32& amount) @@ -52,13 +57,15 @@ void AutoBalance_UnitScript::ModifyMeleeDamage(Unit* target, Unit* source, uint3 bool _debug_damage_and_healing = ((source && (source->GetTypeId() == TYPEID_PLAYER || source->IsControlledByPlayer())) || (target && target->GetTypeId() == TYPEID_PLAYER)); _debug_damage_and_healing = (source && source->GetMap()->GetInstanceId()); - if (_debug_damage_and_healing) _Debug_Output("ModifyMeleeDamage", target, source, adjustedAmount, AUTOBALANCE_DAMAGE_HEALING_DEBUG_PHASE_BEFORE, "Melee"); + if (_debug_damage_and_healing) + _Debug_Output("ModifyMeleeDamage", target, source, adjustedAmount, AUTOBALANCE_DAMAGE_HEALING_DEBUG_PHASE_BEFORE, "Melee"); // set amount to the absolute value of the function call adjustedAmount = _Modify_Damage_Healing(target, source, adjustedAmount); amount = abs(adjustedAmount); - if (_debug_damage_and_healing) _Debug_Output("ModifyMeleeDamage", target, source, adjustedAmount, AUTOBALANCE_DAMAGE_HEALING_DEBUG_PHASE_AFTER, "Melee"); + if (_debug_damage_and_healing) + _Debug_Output("ModifyMeleeDamage", target, source, adjustedAmount, AUTOBALANCE_DAMAGE_HEALING_DEBUG_PHASE_AFTER, "Melee"); } void AutoBalance_UnitScript::ModifyHealReceived(Unit* target, Unit* source, uint32& amount, SpellInfo const* spellInfo) @@ -69,11 +76,13 @@ void AutoBalance_UnitScript::ModifyHealReceived(Unit* target, Unit* source, uint bool _debug_damage_and_healing = ((source && (source->GetTypeId() == TYPEID_PLAYER || source->IsControlledByPlayer())) || (target && target->GetTypeId() == TYPEID_PLAYER)); _debug_damage_and_healing = (source && source->GetMap()->GetInstanceId()); - if (_debug_damage_and_healing) _Debug_Output("ModifyHealReceived", target, source, amount, AUTOBALANCE_DAMAGE_HEALING_DEBUG_PHASE_BEFORE, spellInfo->SpellName[0], spellInfo->Id); + if (_debug_damage_and_healing) + _Debug_Output("ModifyHealReceived", target, source, amount, AUTOBALANCE_DAMAGE_HEALING_DEBUG_PHASE_BEFORE, spellInfo->SpellName[0], spellInfo->Id); amount = _Modify_Damage_Healing(target, source, amount, spellInfo); - if (_debug_damage_and_healing) _Debug_Output("ModifyHealReceived", target, source, amount, AUTOBALANCE_DAMAGE_HEALING_DEBUG_PHASE_AFTER, spellInfo->SpellName[0], spellInfo->Id); + if (_debug_damage_and_healing) + _Debug_Output("ModifyHealReceived", target, source, amount, AUTOBALANCE_DAMAGE_HEALING_DEBUG_PHASE_AFTER, spellInfo->SpellName[0], spellInfo->Id); } void AutoBalance_UnitScript::OnAuraApply(Unit* unit, Aura* aura) @@ -90,7 +99,8 @@ void AutoBalance_UnitScript::OnAuraApply(Unit* unit, Aura* aura) // only update if we decided to change it if (auraDuration != (float)aura->GetDuration()) { - if (_debug_damage_and_healing) LOG_DEBUG("module.AutoBalance_DamageHealingCC", "AutoBalance_UnitScript::OnAuraApply(): Spell '{}' had it's duration adjusted ({}->{}).", + if (_debug_damage_and_healing) + LOG_DEBUG("module.AutoBalance_DamageHealingCC", "AutoBalance_UnitScript::OnAuraApply(): Spell '{}' had it's duration adjusted ({}->{}).", aura->GetSpellInfo()->SpellName[0], aura->GetMaxDuration() / 1000, auraDuration / 1000 @@ -499,9 +509,7 @@ uint32 AutoBalance_UnitScript::_Modifier_CCDuration(Unit* target, Unit* caster, return originalDuration * ccDurationMultiplier; } else - { return originalDuration; - } } bool AutoBalance_UnitScript::_isAuraWithEffectType(SpellInfo const* spellInfo, AuraType auraType, bool log) @@ -509,14 +517,16 @@ bool AutoBalance_UnitScript::_isAuraWithEffectType(SpellInfo const* spellInfo, A // if the spell is not defined, return false if (!spellInfo) { - if (log) { LOG_DEBUG("module.AutoBalance_DamageHealingCC", "AutoBalance_UnitScript::_isAuraWithEffectType: SpellInfo is null, returning false."); } + if (log) + LOG_DEBUG("module.AutoBalance_DamageHealingCC", "AutoBalance_UnitScript::_isAuraWithEffectType: SpellInfo is null, returning false."); return false; } // if the spell doesn't have any effects, return false if (!spellInfo->GetEffects().size()) { - if (log) { LOG_DEBUG("module.AutoBalance_DamageHealingCC", "AutoBalance_UnitScript::_isAuraWithEffectType: SpellInfo has no effects, returning false."); } + if (log) + LOG_DEBUG("module.AutoBalance_DamageHealingCC", "AutoBalance_UnitScript::_isAuraWithEffectType: SpellInfo has no effects, returning false."); return false; } @@ -526,7 +536,8 @@ bool AutoBalance_UnitScript::_isAuraWithEffectType(SpellInfo const* spellInfo, A // if the effect is not an aura, continue to next effect if (!effect.IsAura()) { - if (log) { LOG_DEBUG("module.AutoBalance_DamageHealingCC", "AutoBalance_UnitScript::_isAuraWithEffectType: SpellInfo has an effect that is not an aura, continuing to next effect."); } + if (log) + LOG_DEBUG("module.AutoBalance_DamageHealingCC", "AutoBalance_UnitScript::_isAuraWithEffectType: SpellInfo has an effect that is not an aura, continuing to next effect."); continue; } @@ -539,6 +550,7 @@ bool AutoBalance_UnitScript::_isAuraWithEffectType(SpellInfo const* spellInfo, A } // if no aura effect of type auraType was found, return false - if (log) { LOG_DEBUG("module.AutoBalance_DamageHealingCC", "AutoBalance_UnitScript::_isAuraWithEffectType: SpellInfo has no aura of the target type, returning false."); } + if (log) + LOG_DEBUG("module.AutoBalance_DamageHealingCC", "AutoBalance_UnitScript::_isAuraWithEffectType: SpellInfo has no aura of the target type, returning false."); return false; } diff --git a/src/ABUnitScript.h b/src/ABUnitScript.h index a044e96..e8258f2 100644 --- a/src/ABUnitScript.h +++ b/src/ABUnitScript.h @@ -5,17 +5,23 @@ #ifndef __AB_UNIT_SCRIPT_H #define __AB_UNIT_SCRIPT_H +#include "AutoBalance.h" + #include "ScriptMgr.h" #include "SpellAuras.h" #include "SpellInfo.h" -#include "AutoBalance.h" - class AutoBalance_UnitScript : public UnitScript { public: AutoBalance_UnitScript() - : UnitScript("AutoBalance_UnitScript", true) + : UnitScript("AutoBalance_UnitScript", true, { + UNITHOOK_MODIFY_PERIODIC_DAMAGE_AURAS_TICK, + UNITHOOK_MODIFY_SPELL_DAMAGE_TAKEN, + UNITHOOK_MODIFY_MELEE_DAMAGE, + UNITHOOK_MODIFY_HEAL_RECEIVED, + UNITHOOK_ON_AURA_APPLY + }) { } diff --git a/src/ABUtils.cpp b/src/ABUtils.cpp index 34e7465..59bdebf 100644 --- a/src/ABUtils.cpp +++ b/src/ABUtils.cpp @@ -2,17 +2,18 @@ * Copyright (C) 2016+ AzerothCore , license: https://github.com/azerothcore/azerothcore-wotlk/blob/master/LICENSE */ -#include -#include +#include "ABUtils.h" + +#include "ABConfig.h" +#include "ABCreatureInfo.h" +#include "ABMapInfo.h" #include "Log.h" #include "Player.h" #include "TemporarySummon.h" -#include "ABConfig.h" -#include "ABCreatureInfo.h" -#include "ABMapInfo.h" -#include "ABUtils.h" +#include +#include void AddCreatureToMapCreatureList(Creature* creature, bool addToCreatureList, bool forceRecalculation) { @@ -99,7 +100,8 @@ void AddCreatureToMapCreatureList(Creature* creature, bool addToCreatureList, bo (uint8)(((float)mapABInfo->lfgMinLevel * .85f) + 0.5f), (uint8)(((float)mapABInfo->lfgMaxLevel * 1.15f) + 0.5f)); } - else { + else + { creatureABInfo->neverLevelScale = true; LOG_DEBUG("module.AutoBalance", "AutoBalance::AddCreatureToMapCreatureList: Creature {} ({}) (summon) | original level is outside the expected NPC level for this map ({} to {}). It will keep its original level.", @@ -364,9 +366,7 @@ void AddCreatureToMapCreatureList(Creature* creature, bool addToCreatureList, bo // if (thisPlayer->IsGameMaster()) - { continue; - } // // If the creature is friendly and not a boss @@ -401,9 +401,7 @@ void AddCreatureToMapCreatureList(Creature* creature, bool addToCreatureList, bo // if (thisPlayer->IsGameMaster()) - { continue; - } if (thisPlayer->IsWithinDist(creature, 500)) { @@ -530,9 +528,7 @@ void RemoveCreatureFromMapData(Creature* creature) mapABInfo->activeCreatureCount - 1); if (mapABInfo->activeCreatureCount > 0) - { mapABInfo->activeCreatureCount--; - } else { LOG_DEBUG("module.AutoBalance", "AutoBalance::RemoveCreatureFromMapData: Map {} ({}{}) | activeCreatureCount is already 0. This should not happen.", @@ -559,9 +555,7 @@ uint32 getBaseExpansionValueForLevel(const uint32 baseValues[3], uint8 targetLev float floatBaseValues[3]; for (int i = 0; i < 3; i++) - { floatBaseValues[i] = (float)baseValues[i]; - } // return the result return getBaseExpansionValueForLevel(floatBaseValues, targetLevel); @@ -664,9 +658,7 @@ float getDefaultMultiplier(Map* map, AutoBalanceInflectionPointSettings inflecti int GetForcedNumPlayers(int creatureId) { if (forcedCreatureIds.find(creatureId) == forcedCreatureIds.end()) // Don't want the forcedCreatureIds map to blowup to a massive empty array - { return -1; - } return forcedCreatureIds[creatureId]; } @@ -680,18 +672,14 @@ World_Multipliers getWorldMultiplier(Map* map, BaseValueType baseValueType) // if (!map) - { return worldMultipliers; - } // // If this isn't a dungeon, return defaults // if (!(map->IsDungeon())) - { return worldMultipliers; - } // // Grab map data @@ -703,27 +691,21 @@ World_Multipliers getWorldMultiplier(Map* map, BaseValueType baseValueType) // if (!mapABInfo->enabled) - { return worldMultipliers; - } // // If there are no players on the map, return defaults // if (mapABInfo->allMapPlayers.size() == 0) - { return worldMultipliers; - } // // If creatures haven't been counted yet, return defaults // if (mapABInfo->avgCreatureLevel == 0) - { return worldMultipliers; - } // // Create some data variables @@ -760,13 +742,9 @@ World_Multipliers getWorldMultiplier(Map* map, BaseValueType baseValueType) AutoBalanceStatModifiers statModifiers = getStatModifiers(map); if (baseValueType == BaseValueType::AUTOBALANCE_HEALTH) // health - { worldMultiplier = defaultMultiplier * statModifiers.global * statModifiers.health; - } else // damage - { worldMultiplier = defaultMultiplier * statModifiers.global * statModifiers.damage; - } LOG_DEBUG("module.AutoBalance", "AutoBalance::getWorldMultiplier: Map {} ({}) {} | worldMultiplier ({}) = defaultMultiplier ({}) * statModifiers.global ({}) * statModifiers.{} ({})", @@ -1050,8 +1028,10 @@ AutoBalanceInflectionPointSettings getInflectionPointSettings (InstanceMap* inst inflectionValue *= myInflectionPointOverrides->value; } - if (myInflectionPointOverrides->curveFloor != -1) { curveFloor = myInflectionPointOverrides->curveFloor; } - if (myInflectionPointOverrides->curveCeiling != -1) { curveCeiling = myInflectionPointOverrides->curveCeiling; } + if (myInflectionPointOverrides->curveFloor != -1) + curveFloor = myInflectionPointOverrides->curveFloor; + if (myInflectionPointOverrides->curveCeiling != -1) + curveCeiling = myInflectionPointOverrides->curveCeiling; } // @@ -1065,52 +1045,30 @@ AutoBalanceInflectionPointSettings getInflectionPointSettings (InstanceMap* inst if (instanceMap->IsHeroic()) { if (maxNumberOfPlayers <= 5) - { bossInflectionPointMultiplier = InflectionPointHeroicBoss; - } else if (maxNumberOfPlayers <= 10) - { bossInflectionPointMultiplier = InflectionPointRaid10MHeroicBoss; - } else if (maxNumberOfPlayers <= 25) - { bossInflectionPointMultiplier = InflectionPointRaid25MHeroicBoss; - } else - { bossInflectionPointMultiplier = InflectionPointRaidHeroicBoss; - } } else { if (maxNumberOfPlayers <= 5) - { bossInflectionPointMultiplier = InflectionPointBoss; - } else if (maxNumberOfPlayers <= 10) - { bossInflectionPointMultiplier = InflectionPointRaid10MBoss; - } else if (maxNumberOfPlayers <= 15) - { bossInflectionPointMultiplier = InflectionPointRaid15MBoss; - } else if (maxNumberOfPlayers <= 20) - { bossInflectionPointMultiplier = InflectionPointRaid20MBoss; - } else if (maxNumberOfPlayers <= 25) - { bossInflectionPointMultiplier = InflectionPointRaid25MBoss; - } else if (maxNumberOfPlayers <= 40) - { bossInflectionPointMultiplier = InflectionPointRaid40MBoss; - } else - { bossInflectionPointMultiplier = InflectionPointRaidBoss; - } } // @@ -1125,24 +1083,18 @@ AutoBalanceInflectionPointSettings getInflectionPointSettings (InstanceMap* inst // If set, alter the inflectionValue according to the override // if (myBossOverrides->value != -1) - { inflectionValue *= myBossOverrides->value; - } // // Otherwise, calculate using the value determined by instance type // else - { inflectionValue *= bossInflectionPointMultiplier; - } } // // No override, use the value determined by the instance type // else - { inflectionValue *= bossInflectionPointMultiplier; - } } return AutoBalanceInflectionPointSettings(inflectionValue, curveFloor, curveCeiling); @@ -1199,9 +1151,7 @@ AutoBalanceStatModifiers getStatModifiers (Map* map, Creature* creature) AutoBalanceCreatureInfo* creatureABInfo = nullptr; if (creature) - { creatureABInfo = creature->CustomData.GetDefault("AutoBalanceCreatureInfo"); - } // // this will be the return value @@ -1505,12 +1455,23 @@ AutoBalanceStatModifiers getStatModifiers (Map* map, Creature* creature) { AutoBalanceStatModifiers* myStatModifierBossOverrides = &statModifierBossOverrides[mapId]; - if (myStatModifierBossOverrides->global != -1) { statModifiers.global = myStatModifierBossOverrides->global; } - if (myStatModifierBossOverrides->health != -1) { statModifiers.health = myStatModifierBossOverrides->health; } - if (myStatModifierBossOverrides->mana != -1) { statModifiers.mana = myStatModifierBossOverrides->mana; } - if (myStatModifierBossOverrides->armor != -1) { statModifiers.armor = myStatModifierBossOverrides->armor; } - if (myStatModifierBossOverrides->damage != -1) { statModifiers.damage = myStatModifierBossOverrides->damage; } - if (myStatModifierBossOverrides->ccduration != -1) { statModifiers.ccduration = myStatModifierBossOverrides->ccduration; } + if (myStatModifierBossOverrides->global != -1) + statModifiers.global = myStatModifierBossOverrides->global; + + if (myStatModifierBossOverrides->health != -1) + statModifiers.health = myStatModifierBossOverrides->health; + + if (myStatModifierBossOverrides->mana != -1) + statModifiers.mana = myStatModifierBossOverrides->mana; + + if (myStatModifierBossOverrides->armor != -1) + statModifiers.armor = myStatModifierBossOverrides->armor; + + if (myStatModifierBossOverrides->damage != -1) + statModifiers.damage = myStatModifierBossOverrides->damage; + + if (myStatModifierBossOverrides->ccduration != -1) + statModifiers.ccduration = myStatModifierBossOverrides->ccduration; getStatModifiersDebug(map, creature, "Boss Per-Instance Override"); } @@ -1521,12 +1482,23 @@ AutoBalanceStatModifiers getStatModifiers (Map* map, Creature* creature) { AutoBalanceStatModifiers* myStatModifierOverrides = &statModifierOverrides[mapId]; - if (myStatModifierOverrides->global != -1) { statModifiers.global = myStatModifierOverrides->global; } - if (myStatModifierOverrides->health != -1) { statModifiers.health = myStatModifierOverrides->health; } - if (myStatModifierOverrides->mana != -1) { statModifiers.mana = myStatModifierOverrides->mana; } - if (myStatModifierOverrides->armor != -1) { statModifiers.armor = myStatModifierOverrides->armor; } - if (myStatModifierOverrides->damage != -1) { statModifiers.damage = myStatModifierOverrides->damage; } - if (myStatModifierOverrides->ccduration != -1) { statModifiers.ccduration = myStatModifierOverrides->ccduration; } + if (myStatModifierOverrides->global != -1) + statModifiers.global = myStatModifierOverrides->global; + + if (myStatModifierOverrides->health != -1) + statModifiers.health = myStatModifierOverrides->health; + + if (myStatModifierOverrides->mana != -1) + statModifiers.mana = myStatModifierOverrides->mana; + + if (myStatModifierOverrides->armor != -1) + statModifiers.armor = myStatModifierOverrides->armor; + + if (myStatModifierOverrides->damage != -1) + statModifiers.damage = myStatModifierOverrides->damage; + + if (myStatModifierOverrides->ccduration != -1) + statModifiers.ccduration = myStatModifierOverrides->ccduration; getStatModifiersDebug(map, creature, "Per-Instance Override"); } @@ -1539,12 +1511,23 @@ AutoBalanceStatModifiers getStatModifiers (Map* map, Creature* creature) { AutoBalanceStatModifiers* myCreatureOverrides = &statModifierCreatureOverrides[creature->GetEntry()]; - if (myCreatureOverrides->global != -1) { statModifiers.global = myCreatureOverrides->global; } - if (myCreatureOverrides->health != -1) { statModifiers.health = myCreatureOverrides->health; } - if (myCreatureOverrides->mana != -1) { statModifiers.mana = myCreatureOverrides->mana; } - if (myCreatureOverrides->armor != -1) { statModifiers.armor = myCreatureOverrides->armor; } - if (myCreatureOverrides->damage != -1) { statModifiers.damage = myCreatureOverrides->damage; } - if (myCreatureOverrides->ccduration != -1) { statModifiers.ccduration = myCreatureOverrides->ccduration; } + if (myCreatureOverrides->global != -1) + statModifiers.global = myCreatureOverrides->global; + + if (myCreatureOverrides->health != -1) + statModifiers.health = myCreatureOverrides->health; + + if (myCreatureOverrides->mana != -1) + statModifiers.mana = myCreatureOverrides->mana; + + if (myCreatureOverrides->armor != -1) + statModifiers.armor = myCreatureOverrides->armor; + + if (myCreatureOverrides->damage != -1) + statModifiers.damage = myCreatureOverrides->damage; + + if (myCreatureOverrides->ccduration != -1) + statModifiers.ccduration = myCreatureOverrides->ccduration; getStatModifiersDebug(map, creature, "Per-Creature Override"); } @@ -1728,13 +1711,9 @@ bool isCreatureRelevant(Creature* creature) // if this creature has been already been evaluated, just return the previous evaluation if (creatureABInfo->relevance == AUTOBALANCE_RELEVANCE_FALSE) - { return false; - } else if (creatureABInfo->relevance == AUTOBALANCE_RELEVANCE_TRUE) - { return true; - } // otherwise the value is AUTOBALANCE_RELEVANCE_UNCHECKED, so it needs checking LOG_DEBUG("module.AutoBalance", "AutoBalance_AllCreatureScript::isCreatureRelevant: Creature {} ({}) | Needs to be evaluated.", @@ -1884,12 +1863,10 @@ bool isCreatureRelevant(Creature* creature) bool isDungeonInMinPlayerMap(uint32 dungeonId, bool isHeroic) { - if (isHeroic) { + if (isHeroic) return (minPlayersPerHeroicDungeonIdMap.find(dungeonId) != minPlayersPerHeroicDungeonIdMap.end()); - } - else { + else return (minPlayersPerDungeonIdMap.find(dungeonId) != minPlayersPerDungeonIdMap.end()); - } } // Used for reading the string from the configuration file to for those creatures who need to be scaled for XX number of players. @@ -1906,9 +1883,7 @@ void LoadForcedCreatureIdsFromString(std::string creatureIds, int forcedPlayerCo int creatureId = atoi(delimitedValue.c_str()); if (creatureId >= 0) - { forcedCreatureIds[creatureId] = forcedPlayerCount; - } } } @@ -1991,10 +1966,14 @@ std::map LoadDynamicLevelOve auto dungeonMapId = atoi(val1.c_str()); // Replace any missing values with -1 - if (val2.empty()) { val2 = "-1"; } - if (val3.empty()) { val3 = "-1"; } - if (val4.empty()) { val3 = "-1"; } - if (val5.empty()) { val3 = "-1"; } + if (val2.empty()) + val2 = "-1"; + if (val3.empty()) + val3 = "-1"; + if (val4.empty()) + val4 = "-1"; + if (val5.empty()) + val5 = "-1"; AutoBalanceLevelScalingDynamicLevelSettings dynamicLevelSettings = AutoBalanceLevelScalingDynamicLevelSettings( atoi(val2.c_str()), @@ -2033,9 +2012,12 @@ std::map LoadInflectionPointOverride auto dungeonMapId = atoi(val1.c_str()); // Replace any missing values with -1 - if (val2.empty()) { val2 = "-1"; } - if (val3.empty()) { val3 = "-1"; } - if (val4.empty()) { val4 = "-1"; } + if (val2.empty()) + val2 = "-1"; + if (val3.empty()) + val3 = "-1"; + if (val4.empty()) + val4 = "-1"; AutoBalanceInflectionPointSettings ipSettings = AutoBalanceInflectionPointSettings( atof(val2.c_str()), @@ -2076,17 +2058,11 @@ void LoadMapSettings(Map* map) // if (isDungeonInMinPlayerMap(map->GetId(), instanceMap->IsHeroic())) - { mapABInfo->minPlayers = instanceMap->IsHeroic() ? minPlayersPerHeroicDungeonIdMap[map->GetId()] : minPlayersPerDungeonIdMap[map->GetId()]; - } else if (instanceMap->IsHeroic()) - { mapABInfo->minPlayers = minPlayersHeroic; - } else - { mapABInfo->minPlayers = minPlayersNormal; - } // // If the minPlayers value we determined is less than the max number of players in this map, adjust down @@ -2246,12 +2222,18 @@ std::map LoadStatModifierOverrides(std::string auto dungeonMapId = atoi(val1.c_str()); // Replace any missing values with -1 - if (val2.empty()) { val2 = "-1"; } - if (val3.empty()) { val3 = "-1"; } - if (val4.empty()) { val4 = "-1"; } - if (val5.empty()) { val5 = "-1"; } - if (val6.empty()) { val6 = "-1"; } - if (val7.empty()) { val7 = "-1"; } + if (val2.empty()) + val2 = "-1"; + if (val3.empty()) + val3 = "-1"; + if (val4.empty()) + val4 = "-1"; + if (val5.empty()) + val5 = "-1"; + if (val6.empty()) + val6 = "-1"; + if (val7.empty()) + val7 = "-1"; AutoBalanceStatModifiers statSettings = AutoBalanceStatModifiers( atof(val2.c_str()), @@ -2331,54 +2313,32 @@ bool ShouldMapBeEnabled(Map* map) // Enable5MHeroic, Enable10MHeroic, Enable25MHeroic, EnableOtherHeroic); if (instanceMap->GetMaxPlayers() <= 5) - { sizeDifficultyEnabled = Enable5MHeroic; - } else if (instanceMap->GetMaxPlayers() <= 10) - { sizeDifficultyEnabled = Enable10MHeroic; - } else if (instanceMap->GetMaxPlayers() <= 25) - { sizeDifficultyEnabled = Enable25MHeroic; - } else - { sizeDifficultyEnabled = EnableOtherHeroic; - } } else { //LOG_DEBUG("module.AutoBalance", "AutoBalance::ShouldMapBeEnabled: Normal Enables - 5:{} 10:{} 15:{} 20:{} 25:{} 40:{} Other:{}", // Enable5M, Enable10M, Enable15M, Enable20M, Enable25M, Enable40M, EnableOtherNormal); if (instanceMap->GetMaxPlayers() <= 5) - { sizeDifficultyEnabled = Enable5M; - } else if (instanceMap->GetMaxPlayers() <= 10) - { sizeDifficultyEnabled = Enable10M; - } else if (instanceMap->GetMaxPlayers() <= 15) - { sizeDifficultyEnabled = Enable15M; - } else if (instanceMap->GetMaxPlayers() <= 20) - { sizeDifficultyEnabled = Enable20M; - } else if (instanceMap->GetMaxPlayers() <= 25) - { sizeDifficultyEnabled = Enable25M; - } else if (instanceMap->GetMaxPlayers() <= 40) - { sizeDifficultyEnabled = Enable40M; - } else - { sizeDifficultyEnabled = EnableOtherNormal; - } } if (sizeDifficultyEnabled) @@ -2425,9 +2385,7 @@ void UpdateMapPlayerStats(Map* map) // if (!map->IsDungeon() || !map->GetInstanceId()) - { return; - } // // Get the map's info @@ -2579,14 +2537,10 @@ void UpdateMapPlayerStats(Map* map) if (thisPlayer && !thisPlayer->IsGameMaster()) { if (thisPlayer->GetLevel() > highestPlayerLevel || highestPlayerLevel == 0) - { highestPlayerLevel = thisPlayer->GetLevel(); - } if (thisPlayer->GetLevel() < lowestPlayerLevel || lowestPlayerLevel == 0) - { lowestPlayerLevel = thisPlayer->GetLevel(); - } } } @@ -2708,9 +2662,7 @@ bool RemovePlayerFromMap(Map* map, Player* player) // if (mapABInfo->combatLocked) - { mapABInfo->combatLockTripped = true; - } // // Update the map's player stats diff --git a/src/ABUtils.h b/src/ABUtils.h index 5d47898..269afbd 100644 --- a/src/ABUtils.h +++ b/src/ABUtils.h @@ -5,18 +5,18 @@ #ifndef __AB_UTILS_H #define __AB_UTILS_H -#include -#include -#include +#include "ABInflectionPointSettings.h" +#include "ABLevelScalingDynamicLevelSettings.h" +#include "ABStatModifiers.h" +#include "AutoBalance.h" #include "Creature.h" #include "Map.h" #include "SharedDefines.h" -#include "AutoBalance.h" -#include "ABInflectionPointSettings.h" -#include "ABLevelScalingDynamicLevelSettings.h" -#include "ABStatModifiers.h" +#include +#include +#include void AddCreatureToMapCreatureList(Creature* creature, bool addToCreatureList = true, bool forceRecalculation = false); void RemoveCreatureFromMapData(Creature* creature); diff --git a/src/ABWorldScript.cpp b/src/ABWorldScript.cpp index 309d3e9..c59593a 100644 --- a/src/ABWorldScript.cpp +++ b/src/ABWorldScript.cpp @@ -1,9 +1,10 @@ -#include "Configuration/Config.h" -#include "Log.h" +#include "ABWorldScript.h" #include "ABConfig.h" #include "ABUtils.h" -#include "ABWorldScript.h" + +#include "Configuration/Config.h" +#include "Log.h" void AutoBalance_WorldScript::OnBeforeConfigLoad(bool /*reload*/) { @@ -430,13 +431,9 @@ void AutoBalance_WorldScript::SetInitialWorldSettings() std::string LevelScalingMethodString = sConfigMgr->GetOption("AutoBalance.LevelScaling.Method", "dynamic", false); if (LevelScalingMethodString == "fixed") - { LevelScalingMethod = AUTOBALANCE_SCALING_FIXED; - } else if (LevelScalingMethodString == "dynamic") - { LevelScalingMethod = AUTOBALANCE_SCALING_DYNAMIC; - } else { LOG_ERROR("server.loading", "mod-autobalance: invalid value `{}` for `AutoBalance.LevelScaling.Method` defined in `AutoBalance.conf`. Defaulting to a value of `dynamic`.", LevelScalingMethodString); @@ -487,13 +484,9 @@ void AutoBalance_WorldScript::SetInitialWorldSettings() std::string RewardScalingMethodString = sConfigMgr->GetOption("AutoBalance.RewardScaling.Method", "dynamic", false); if (RewardScalingMethodString == "fixed") - { RewardScalingMethod = AUTOBALANCE_SCALING_FIXED; - } else if (RewardScalingMethodString == "dynamic") - { RewardScalingMethod = AUTOBALANCE_SCALING_DYNAMIC; - } else { LOG_ERROR("server.loading", "mod-autobalance: invalid value `{}` for `AutoBalance.RewardScaling.Method` defined in `AutoBalance.conf`. Defaulting to a value of `dynamic`.", RewardScalingMethodString); diff --git a/src/ABWorldScript.h b/src/ABWorldScript.h index 7ceeed4..61133f2 100644 --- a/src/ABWorldScript.h +++ b/src/ABWorldScript.h @@ -11,7 +11,9 @@ class AutoBalance_WorldScript : public WorldScript { public: AutoBalance_WorldScript() - : WorldScript("AutoBalance_WorldScript") + : WorldScript("AutoBalance_WorldScript", { + WORLDHOOK_ON_BEFORE_CONFIG_LOAD + }) { } diff --git a/src/AutoBalance.cpp b/src/AutoBalance.cpp index fbfd103..5f69135 100644 --- a/src/AutoBalance.cpp +++ b/src/AutoBalance.cpp @@ -28,27 +28,8 @@ * instance mobs & world bosses' level, health, mana, and damage. */ -#include -#include - -#include "Configuration/Config.h" -#include "Unit.h" -#include "Chat.h" -#include "Creature.h" -#include "Player.h" -#include "ObjectMgr.h" -#include "MapMgr.h" -#include "World.h" -#include "Map.h" -#include "ScriptMgr.h" -#include "Language.h" -#include "ScriptMgrMacros.h" -#include "Group.h" -#include "Log.h" -#include "SharedDefines.h" -#include "Message.h" - #include "AutoBalance.h" + #include "ABAllCreatureScript.h" #include "ABAllMapScript.h" #include "ABCommandScript.h" @@ -67,6 +48,26 @@ #include "ABUtils.h" #include "ABWorldScript.h" +#include "Configuration/Config.h" +#include "Chat.h" +#include "Creature.h" +#include "Group.h" +#include "Language.h" +#include "Log.h" +#include "Map.h" +#include "MapMgr.h" +#include "Message.h" +#include "ObjectMgr.h" +#include "Player.h" +#include "ScriptMgr.h" +#include "ScriptMgrMacros.h" +#include "SharedDefines.h" +#include "Unit.h" +#include "World.h" + +#include +#include + #if AC_COMPILER == AC_COMPILER_GNU #pragma GCC diagnostic ignored "-Wdeprecated-declarations" #endif diff --git a/src/Message.cpp b/src/Message.cpp index 7ed668c..49ce2d0 100644 --- a/src/Message.cpp +++ b/src/Message.cpp @@ -1,11 +1,13 @@ #include "Message.h" -#include "ItemTemplate.h" + #include "DatabaseEnv.h" +#include "ItemTemplate.h" + +#include +#include #include #include -#include #include -#include const std::unordered_map AB_WELCOME_TO_PLAYER = { {LOCALE_enUS, "|cffc3dbff [AutoBalance]|r|cffFF8000 Welcome to {} ({}-player {}). There are {} player(s) in this instance. Difficulty set to {} player(s).|r"}, @@ -101,15 +103,15 @@ const std::unordered_map AB_SET_OFFSET_COMMAND_ERRO }; const std::unordered_map AB_GET_OFFSET_COMMAND_SUCCESS = { -{LOCALE_enUS, "Current Player Difficulty Offset = {}.|r"}, -{LOCALE_koKR, "현재 플레이어 난이도 오프셋 = {}.|r"}, -{LOCALE_frFR, "Décalage de difficulté actuel du joueur = {}.|r"}, -{LOCALE_deDE, "Aktueller Spieler-Schwierigkeits-Offset = {}.|r"}, -{LOCALE_zhCN, "当前玩家难度偏移 = {}。|r"}, -{LOCALE_zhTW, "當前玩家難度偏移 = {}。|r"}, -{LOCALE_esES, "Desplazamiento de dificultad actual del jugador = {}.|r"}, -{LOCALE_esMX, "Desplazamiento de dificultad actual del jugador = {}.|r"}, -{LOCALE_ruRU, "Текущее смещение сложности игрока = {}.|r"}, + {LOCALE_enUS, "Current Player Difficulty Offset = {}.|r"}, + {LOCALE_koKR, "현재 플레이어 난이도 오프셋 = {}.|r"}, + {LOCALE_frFR, "Décalage de difficulté actuel du joueur = {}.|r"}, + {LOCALE_deDE, "Aktueller Spieler-Schwierigkeits-Offset = {}.|r"}, + {LOCALE_zhCN, "当前玩家难度偏移 = {}。|r"}, + {LOCALE_zhTW, "當前玩家難度偏移 = {}。|r"}, + {LOCALE_esES, "Desplazamiento de dificultad actual del jugador = {}.|r"}, + {LOCALE_esMX, "Desplazamiento de dificultad actual del jugador = {}.|r"}, + {LOCALE_ruRU, "Текущее смещение сложности игрока = {}.|r"}, }; const std::unordered_map AB_ADJUSTED_PLAYER_COUNT_COMBAT_LOCKED = { @@ -555,12 +557,12 @@ std::unordered_map* textMap = textMapIt->second; auto it = textMap->find(locale); - if (it != textMap->end()) { + if (it != textMap->end()) return it->second; - } } return ""; diff --git a/src/Message.h b/src/Message.h index 6d606a8..9f30d86 100644 --- a/src/Message.h +++ b/src/Message.h @@ -1,8 +1,10 @@ // Message.h #ifndef AB_MESSAGE_H #define AB_MESSAGE_H + #include "Common.h" #include "ItemTemplate.h" + #include std::string ABGetLocaleText(LocaleConstant locale, const std::string& titleType);