mirror of
https://github.com/mangosfour/server.git
synced 2025-12-18 01:37:01 +00:00
[11846] Changes to default target selection
* Add a new function: Unit::IsSecondChoiceTarget to evaluate if a target will be selected * Cleanup a bit related code * SelectHostileTarget - Only call AI()->AttackStart for new targets - Remove exception for top-most taunter * Fix a few minor bugs related to selectNextVictim Signed-off-by: Schmoozerd <schmoozerd@scriptdev2.com>
This commit is contained in:
parent
b35dea1703
commit
f4d862ac0a
4 changed files with 86 additions and 52 deletions
|
|
@ -8539,10 +8539,14 @@ void Unit::TauntApply(Unit* taunter)
|
|||
if (target && target == taunter)
|
||||
return;
|
||||
|
||||
SetInFront(taunter);
|
||||
// Only attack taunter if this is a valid target
|
||||
if (!hasUnitState(UNIT_STAT_STUNNED | UNIT_STAT_DIED) && !IsSecondChoiceTarget(taunter, true))
|
||||
{
|
||||
SetInFront(taunter);
|
||||
|
||||
if (((Creature*)this)->AI())
|
||||
((Creature*)this)->AI()->AttackStart(taunter);
|
||||
if (((Creature*)this)->AI())
|
||||
((Creature*)this)->AI()->AttackStart(taunter);
|
||||
}
|
||||
|
||||
m_ThreatManager.tauntApply(taunter);
|
||||
}
|
||||
|
|
@ -8592,6 +8596,18 @@ void Unit::TauntFadeOut(Unit *taunter)
|
|||
|
||||
//======================================================================
|
||||
|
||||
bool Unit::IsSecondChoiceTarget(Unit* pTarget, bool checkThreatArea)
|
||||
{
|
||||
MANGOS_ASSERT(pTarget && GetTypeId() == TYPEID_UNIT);
|
||||
|
||||
return
|
||||
pTarget->IsImmunedToDamage(GetMeleeDamageSchoolMask()) ||
|
||||
pTarget->hasNegativeAuraWithInterruptFlag(AURA_INTERRUPT_FLAG_DAMAGE) ||
|
||||
checkThreatArea && ((Creature*)this)->IsOutOfThreatArea(pTarget);
|
||||
}
|
||||
|
||||
//======================================================================
|
||||
|
||||
bool Unit::SelectHostileTarget()
|
||||
{
|
||||
//function provides main threat functionality
|
||||
|
|
@ -8608,6 +8624,7 @@ bool Unit::SelectHostileTarget()
|
|||
return false;
|
||||
|
||||
Unit* target = NULL;
|
||||
Unit* oldTarget = getVictim();
|
||||
|
||||
// First checking if we have some taunt on us
|
||||
const AuraList& tauntAuras = GetAurasByType(SPELL_AURA_MOD_TAUNT);
|
||||
|
|
@ -8615,26 +8632,17 @@ bool Unit::SelectHostileTarget()
|
|||
{
|
||||
Unit* caster;
|
||||
|
||||
// The last taunt aura caster is alive an we are happy to attack him
|
||||
if ((caster = tauntAuras.back()->GetCaster()) && caster->isAlive())
|
||||
return true;
|
||||
else if (tauntAuras.size() > 1)
|
||||
// Find first available taunter target
|
||||
// Auras are pushed_back, last caster will be on the end
|
||||
for (AuraList::const_reverse_iterator aura = tauntAuras.rbegin(); aura != tauntAuras.rend(); ++aura)
|
||||
{
|
||||
// We do not have last taunt aura caster but we have more taunt auras,
|
||||
// so find first available target
|
||||
|
||||
// Auras are pushed_back, last caster will be on the end
|
||||
AuraList::const_iterator aura = --tauntAuras.end();
|
||||
do
|
||||
if ((caster = (*aura)->GetCaster()) && caster->IsInMap(this) &&
|
||||
caster->isTargetableForAttack() && caster->isInAccessablePlaceFor((Creature*)this) &&
|
||||
!IsSecondChoiceTarget(caster, true))
|
||||
{
|
||||
--aura;
|
||||
if ((caster = (*aura)->GetCaster()) && caster->IsInMap(this) &&
|
||||
caster->isTargetableForAttack() && caster->isInAccessablePlaceFor((Creature*)this))
|
||||
{
|
||||
target = caster;
|
||||
break;
|
||||
}
|
||||
}while (aura != tauntAuras.begin());
|
||||
target = caster;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -8647,7 +8655,8 @@ bool Unit::SelectHostileTarget()
|
|||
if (!hasUnitState(UNIT_STAT_STUNNED | UNIT_STAT_DIED))
|
||||
{
|
||||
SetInFront(target);
|
||||
((Creature*)this)->AI()->AttackStart(target);
|
||||
if (oldTarget != target)
|
||||
((Creature*)this)->AI()->AttackStart(target);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue