From 3fc20584bc14ca0edb007b3d0b6861d19d6d33d4 Mon Sep 17 00:00:00 2001 From: Ovahlord Date: Fri, 5 Jul 2019 18:21:00 +0200 Subject: Core/Creature: Reworked creature aggro radius calculation (#20615) * Core/Creatures: rewrote creature aggro radius calculation * Formulas are taken from WoW Wiki (cherry picked from commit 980047763a685217e712f58b8713d48523d90ccb) --- src/server/game/Entities/Creature/Creature.cpp | 29 +++++++++++++------------- 1 file changed, 14 insertions(+), 15 deletions(-) (limited to 'src') diff --git a/src/server/game/Entities/Creature/Creature.cpp b/src/server/game/Entities/Creature/Creature.cpp index c8c55690b7f..3ffbd97a2b7 100644 --- a/src/server/game/Entities/Creature/Creature.cpp +++ b/src/server/game/Entities/Creature/Creature.cpp @@ -2012,39 +2012,38 @@ bool Creature::CheckNoGrayAggroConfig(uint32 playerLevel, uint32 creatureLevel) float Creature::GetAttackDistance(Unit const* player) const { - // WoW Wiki: the minimum radius seems to be 5 yards, while the maximum range is 45 yards - float maxRadius = (45.0f * sWorld->getRate(RATE_CREATURE_AGGRO)); - float minRadius = (5.0f * sWorld->getRate(RATE_CREATURE_AGGRO)); float aggroRate = sWorld->getRate(RATE_CREATURE_AGGRO); - uint8 expansionMaxLevel = uint8(GetMaxLevelForExpansion(GetCreatureTemplate()->RequiredExpansion)); + if (aggroRate == 0) + return 0.0f; - uint32 playerLevel = player->GetLevelForTarget(this); - uint32 creatureLevel = GetLevelForTarget(player); + // WoW Wiki: the minimum radius seems to be 5 yards, while the maximum range is 45 yards + float maxRadius = 45.0f * aggroRate; + float minRadius = 5.0f * aggroRate; - if (aggroRate == 0.0f) - return 0.0f; + int32 expansionMaxLevel = int32(GetMaxLevelForExpansion(GetCreatureTemplate()->RequiredExpansion)); + int32 playerLevel = player->GetLevelForTarget(this); + int32 creatureLevel = GetLevelForTarget(player); + int32 levelDifference = creatureLevel - playerLevel; // The aggro radius for creatures with equal level as the player is 20 yards. // The combatreach should not get taken into account for the distance so we drop it from the range (see Supremus as expample) float baseAggroDistance = 20.0f - GetCombatReach(); - float aggroRadius = baseAggroDistance; + + // + - 1 yard for each level difference between player and creature + float aggroRadius = baseAggroDistance + float(levelDifference); // detect range auras if ((creatureLevel + 5) <= sWorld->getIntConfig(CONFIG_MAX_PLAYER_LEVEL)) { aggroRadius += GetTotalAuraModifier(SPELL_AURA_MOD_DETECT_RANGE); - aggroRadius += player->GetTotalAuraModifier(SPELL_AURA_MOD_DETECTED_RANGE); } // The aggro range of creatures with higher levels than the total player level for the expansion should get the maxlevel treatment // This makes sure that creatures such as bosses wont have a bigger aggro range than the rest of the npc's - // The following code is used for blizzlike behavior such as skipable bosses (e.g. Commander Springvale at level 85) + // The following code is used for blizzlike behaviour such as skippable bosses if (creatureLevel > expansionMaxLevel) - aggroRadius += float(expansionMaxLevel) - float(playerLevel); - // + - 1 yard for each level difference between player and creature - else - aggroRadius += float(creatureLevel) - float(playerLevel); + aggroRadius = baseAggroDistance + float(expansionMaxLevel - playerLevel); // Make sure that we wont go over the total range limits if (aggroRadius > maxRadius) -- cgit v1.2.3