Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[3.3.5] Creature/AI: Fix incorrect evade logic #16467

Merged
merged 1 commit into from Feb 9, 2016
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/server/game/Entities/Creature/Creature.cpp
Expand Up @@ -2142,6 +2142,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 @@ -12750,7 +12750,7 @@ Unit* Creature::SelectVictim()
}
}
else
return NULL;
return nullptr;

if (target && _IsTargetAcceptable(target) && CanCreatureAttack(target))
{
Expand All @@ -12759,14 +12759,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 @@ -12775,12 +12767,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 @@ -12798,17 +12790,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