Skip to content

Commit

Permalink
Merge pull request #16467 from Treeston/3.3.5-FixEvadeMode
Browse files Browse the repository at this point in the history
[3.3.5] Creature/AI: Fix incorrect evade logic
(cherry picked from commit 8eabbb0)
  • Loading branch information
Treeston authored and Shauren committed Apr 5, 2016
1 parent c8752c8 commit 7135a23
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 14 deletions.
5 changes: 5 additions & 0 deletions src/server/game/Entities/Creature/Creature.cpp
Expand Up @@ -2184,6 +2184,11 @@ bool Creature::CanCreatureAttack(Unit const* victim, bool /*force*/) const
if (GetMap()->IsDungeon())
return true;

// if the mob is actively being damaged, do not reset due to distance unless it's a world boss
if (!isWorldBoss())
if (time(NULL) - GetLastDamagedTime() <= MAX_AGGRO_RESET_TIME)
return true;

//Use AttackDistance in distance check if threat radius is lower. This prevents creature bounce in and out of combat every update tick.
float dist = std::max(GetAttackDistance(victim), sWorld->getFloatConfig(CONFIG_THREAT_RADIUS)) + m_CombatDistance;

Expand Down
20 changes: 6 additions & 14 deletions src/server/game/Entities/Unit/Unit.cpp
Expand Up @@ -10842,7 +10842,7 @@ Unit* Creature::SelectVictim()
}
}
else
return NULL;
return nullptr;

if (target && _IsTargetAcceptable(target) && CanCreatureAttack(target))
{
Expand All @@ -10851,14 +10851,6 @@ Unit* Creature::SelectVictim()
return target;
}

// Case where mob is being kited.
// Mob may not be in range to attack or may have dropped target. In any case,
// don't evade if damage received within the last 10 seconds
// Does not apply to world bosses to prevent kiting to cities
if (!isWorldBoss() && !GetInstanceId())
if (time(NULL) - GetLastDamagedTime() <= MAX_AGGRO_RESET_TIME)
return target;

// last case when creature must not go to evade mode:
// it in combat but attacker not make any damage and not enter to aggro radius to have record in threat list
// for example at owner command to pet attack some far away creature
Expand All @@ -10867,12 +10859,12 @@ Unit* Creature::SelectVictim()
{
if ((*itr) && !CanCreatureAttack(*itr) && (*itr)->GetTypeId() != TYPEID_PLAYER
&& !(*itr)->ToCreature()->HasUnitTypeMask(UNIT_MASK_CONTROLABLE_GUARDIAN))
return NULL;
return nullptr;
}

/// @todo a vehicle may eat some mob, so mob should not evade
if (GetVehicle())
return NULL;
return nullptr;

// search nearby enemy before enter evade mode
if (HasReactState(REACT_AGGRESSIVE))
Expand All @@ -10890,17 +10882,17 @@ Unit* Creature::SelectVictim()
{
if ((*itr)->GetBase()->IsPermanent())
{
AI()->EnterEvadeMode();
AI()->EnterEvadeMode(CreatureAI::EVADE_REASON_OTHER);
break;
}
}
return NULL;
return nullptr;
}

// enter in evade mode in other case
AI()->EnterEvadeMode(CreatureAI::EVADE_REASON_NO_HOSTILES);

return NULL;
return nullptr;
}

//======================================================================
Expand Down

0 comments on commit 7135a23

Please sign in to comment.