Unit* GetHatefullStrikeTarget() { const std::list<HostileReference *> &threatlist = me->getThreatManager().getThreatList(); std::list<Unit*> targetList; for(std::list<HostileReference*>::const_iterator itr = threatlist.begin(); itr != threatlist.end(); ++itr) { HostileReference* ref = (*itr); if(ref->getTarget() && me->IsWithinMeleeRange(ref->getTarget())) targetList.push_back(ref->getTarget()); } uint32 MostHP = 0; Unit* pMostHPTarget = NULL; uint32 counter = 0; for(std::list<Unit*>::const_iterator itr = targetList.begin(); itr != targetList.end(); ++itr) { counter++; if(counter > 3) break; Unit* pTarget = (*itr); if(pTarget->isAlive() && pTarget->GetHealth() > MostHP) { MostHP = pTarget->GetHealth(); pMostHPTarget = pTarget; } } if(pMostHPTarget) return pMostHPTarget; else return me->getVictim(); }
void HostileRefManager::threatAssist(Unit *pVictim, float pThreat, SpellEntry const *pThreatSpell, bool pSingleTarget) { float redirectedMod = pVictim->getHostileRefManager().GetThreatRedirectionMod(); Unit* redirectedTarget = redirectedMod ? pVictim->getHostileRefManager().GetThreatRedirectionTarget() : NULL; uint32 size = pSingleTarget ? 1 : getSize(); // if pSingleTarget do not devide threat HostileReference* ref = getFirst(); while(ref != NULL) { float threat = ThreatCalcHelper::calcThreat(pVictim, iOwner, pThreat, false, (pThreatSpell ? GetSpellSchoolMask(pThreatSpell) : SPELL_SCHOOL_MASK_NORMAL), pThreatSpell); if (threat > 0.0f) { if (redirectedTarget && redirectedTarget != ref->getTarget() && redirectedTarget->isAlive()) { float redirectedThreat = threat * redirectedMod; threat -= redirectedThreat; if(redirectedTarget == getOwner()) // It is faster to modify the threat durectly if possible ref->addThreat(float (threat) / size); else ref->getSource()->addThreat(redirectedTarget, redirectedThreat); } } if (pVictim == getOwner()) ref->addThreat(float (threat) / size); // It is faster to modify the threat durectly if possible else ref->getSource()->addThreat(pVictim, float (threat) / size); ref = ref->next(); } }
HostileReference* ThreatContainer::selectNextVictim(Creature* pAttacker, HostileReference* pCurrentVictim) { HostileReference* pCurrentRef = nullptr; bool found = false; bool onlySecondChoiceTargetsFound = false; bool checkedCurrentVictim = false; ThreatList::const_iterator lastRef = iThreatList.end(); --lastRef; for (ThreatList::const_iterator iter = iThreatList.begin(); iter != iThreatList.end() && !found;) { pCurrentRef = (*iter); Unit* pTarget = pCurrentRef->getTarget(); MANGOS_ASSERT(pTarget); // if the ref has status online the target must be there! // some units are prefered in comparison to others // if (checkThreatArea) consider IsOutOfThreatArea - expected to be only set for pCurrentVictim // This prevents dropping valid targets due to 1.1 or 1.3 threat rule vs invalid current target if (!onlySecondChoiceTargetsFound && pAttacker->IsSecondChoiceTarget(pTarget, pCurrentRef == pCurrentVictim)) { if (iter != lastRef) ++iter; else { // if we reached to this point, everyone in the threatlist is a second choice target. In such a situation the target with the highest threat should be attacked. onlySecondChoiceTargetsFound = true; iter = iThreatList.begin(); } // current victim is a second choice target, so don't compare threat with it below if (pCurrentRef == pCurrentVictim) pCurrentVictim = nullptr; // second choice targets are only handled threat dependend if we have only have second choice targets continue; } if (!pAttacker->IsOutOfThreatArea(pTarget)) // skip non attackable currently targets { if (pCurrentVictim) // select 1.3/1.1 better target in comparison current target { // normal case: pCurrentRef is still valid and most hated if (pCurrentVictim == pCurrentRef) { found = true; break; } // we found a valid target, but only compare its threat if the currect victim is also a valid target // Additional check to prevent unneeded comparision in case of valid current victim if (!checkedCurrentVictim) { Unit* pCurrentTarget = pCurrentVictim->getTarget(); MANGOS_ASSERT(pCurrentTarget); if (pAttacker->IsSecondChoiceTarget(pCurrentTarget, true)) { // CurrentVictim is invalid, so return CurrentRef found = true; break; } checkedCurrentVictim = true; } // list sorted and and we check current target, then this is best case if (pCurrentRef->getThreat() <= 1.1f * pCurrentVictim->getThreat()) { pCurrentRef = pCurrentVictim; found = true; break; } if (pCurrentRef->getThreat() > 1.3f * pCurrentVictim->getThreat() || (pCurrentRef->getThreat() > 1.1f * pCurrentVictim->getThreat() && pAttacker->CanReachWithMeleeAttack(pTarget))) { // implement 110% threat rule for targets in melee range found = true; // and 130% rule for targets in ranged distances break; // for selecting alive targets } } else // select any { found = true; break; } } ++iter; } if (!found) pCurrentRef = nullptr; return pCurrentRef; }
HostileReference* ThreatContainer::selectNextVictim(Creature* attacker, HostileReference* currentVictim) { HostileReference* currentRef = NULL; bool found = false; bool noPriorityTargetFound = false; std::list<HostileReference*>::const_iterator lastRef = iThreatList.end(); --lastRef; for (std::list<HostileReference*>::const_iterator iter = iThreatList.begin(); iter != iThreatList.end() && !found;) { currentRef = (*iter); Unit* target = currentRef->getTarget(); ASSERT(target); // if the ref has status online the target must be there ! // some units are prefered in comparison to others if (!noPriorityTargetFound && (target->IsImmunedToDamage(attacker->GetMeleeDamageSchoolMask()) || target->HasNegativeAuraWithInterruptFlag(AURA_INTERRUPT_FLAG_TAKE_DAMAGE))) { if (iter != lastRef) { // current victim is a second choice target, so don't compare threat with it below if (currentRef == currentVictim) currentVictim = NULL; ++iter; continue; } else { // if we reached to this point, everyone in the threatlist is a second choice target. In such a situation the target with the highest threat should be attacked. noPriorityTargetFound = true; iter = iThreatList.begin(); continue; } } if (attacker->canCreatureAttack(target)) // skip non attackable currently targets { if (currentVictim) // select 1.3/1.1 better target in comparison current target { // list sorted and and we check current target, then this is best case if (currentVictim == currentRef || currentRef->getThreat() <= 1.1f * currentVictim->getThreat()) { if (currentVictim != currentRef && attacker->canCreatureAttack(currentVictim->getTarget())) currentRef = currentVictim; // for second case, if currentvictim is attackable found = true; break; } if (currentRef->getThreat() > 1.3f * currentVictim->getThreat() || (currentRef->getThreat() > 1.1f * currentVictim->getThreat() && attacker->IsWithinMeleeRange(target))) { //implement 110% threat rule for targets in melee range found = true; //and 130% rule for targets in ranged distances break; //for selecting alive targets } } else // select any { found = true; break; } } ++iter; } if (!found) currentRef = NULL; return currentRef; }
HostileReference* ThreatContainer::selectNextVictim(Creature* attacker, HostileReference* currentVictim) { HostileReference* currentRef = NULL; bool found = false; bool noPriorityTargetFound = false; std::list<HostileReference*>::const_iterator lastRef = iThreatList.end(); lastRef--; for(std::list<HostileReference*>::const_iterator iter = iThreatList.begin(); iter != iThreatList.end() && !found;) { currentRef = (*iter); Unit* pTarget = currentRef->getTarget(); ASSERT(pTarget); // if the ref has status online the target must be there ! if(!noPriorityTargetFound && (pTarget->IsImmunedToDamage(attacker->GetMeleeDamageSchoolMask()) || pTarget->HasNegativeAuraWithInterruptFlag(AURA_INTERRUPT_FLAG_TAKE_DAMAGE))) { if(iter != lastRef) { if(currentRef == currentVictim) currentVictim = NULL; ++iter; continue; } else { noPriorityTargetFound = true; iter = iThreatList.begin(); continue; } } if(attacker->canCreatureAttack(pTarget)) // skip non attackable currently targets { if(currentVictim && currentRef) // select 1.3/1.1 better target in comparison current target { if(currentVictim == currentRef || currentRef->getThreat() <= 1.1f * currentVictim->getThreat()) { if(currentVictim != currentRef && attacker->canCreatureAttack(currentVictim->getTarget())) currentRef = currentVictim; // for second case found = true; break; } if(currentRef->getThreat() > 1.3f * currentVictim->getThreat() || (currentRef->getThreat() > 1.1f * currentVictim->getThreat() && attacker->IsWithinMeleeRange(pTarget))) { //implement 110% threat rule for targets in melee range found = true; //and 130% rule for targets in ranged distances break; //for selecting alive targets } } else { found = true; break; } } ++iter; } if(!found) currentRef = NULL; return currentRef; }
HostileReference* ThreatContainer::selectNextVictim(Creature* attacker, HostileReference* currentVictim) const { // pussywizard: pretty much remade this whole function HostileReference* currentRef = NULL; bool found = false; bool noPriorityTargetFound = false; uint32 currTime = sWorld->GetGameTime(); // pussywizard: currentVictim is needed to compare if threat was exceeded by 10%/30% for melee/range targets (only then switching current target) if (currentVictim) { Unit* cvUnit = currentVictim->getTarget(); if (!attacker->_CanDetectFeignDeathOf(cvUnit) || !attacker->CanCreatureAttack(cvUnit) || attacker->isTargetNotAcceptableByMMaps(cvUnit->GetGUID(), currTime, cvUnit)) // pussywizard: if currentVictim is not valid => don't compare the threat with it, just take the highest threat valid target currentVictim = NULL; else if (cvUnit->IsImmunedToDamageOrSchool(attacker->GetMeleeDamageSchoolMask()) || cvUnit->HasNegativeAuraWithInterruptFlag(AURA_INTERRUPT_FLAG_TAKE_DAMAGE)) // pussywizard: no 10%/30% if currentVictim is immune to damage or has auras breakable by damage currentVictim = NULL; } ThreatContainer::StorageType::const_iterator lastRef = iThreatList.end(); --lastRef; // pussywizard: iterate from highest to lowest threat for (ThreatContainer::StorageType::const_iterator iter = iThreatList.begin(); iter != iThreatList.end() && !found;) { currentRef = (*iter); Unit* target = currentRef->getTarget(); ASSERT(target); // if the ref has status online the target must be there ! // pussywizard: don't go to threat comparison if this ref is immune to damage or has aura breakable on damage (second choice target) // pussywizard: if this is the last entry on the threat list, then all targets are second choice, set bool to true and loop threat list again, ignoring this section if (!noPriorityTargetFound && (target->IsImmunedToDamageOrSchool(attacker->GetMeleeDamageSchoolMask()) || target->HasNegativeAuraWithInterruptFlag(AURA_INTERRUPT_FLAG_TAKE_DAMAGE) || target->HasAuraTypeWithCaster(SPELL_AURA_IGNORED, attacker->GetGUID()))) { if (iter != lastRef) { ++iter; continue; } else { noPriorityTargetFound = true; iter = iThreatList.begin(); continue; } } // pussywizard: skip not valid targets if (attacker->_CanDetectFeignDeathOf(target) && attacker->CanCreatureAttack(target) && !attacker->isTargetNotAcceptableByMMaps(target->GetGUID(), currTime, target)) { if (currentVictim) // pussywizard: if not NULL then target must have 10%/30% more threat { if (currentVictim == currentRef) // pussywizard: nothing found previously was good and enough, currentRef passed all necessary tests, so end now { found = true; break; } // pussywizard: implement 110% threat rule for targets in melee range and 130% rule for targets in ranged distances if (currentRef->getThreat() > 1.3f * currentVictim->getThreat()) // pussywizard: enough in all cases, end { found = true; break; } else if (currentRef->getThreat() > 1.1f * currentVictim->getThreat()) // pussywizard: enought only if target in melee range { if (attacker->IsWithinMeleeRange(target)) { found = true; break; } } else // pussywizard: nothing found previously was good and enough, this and next entries on the list have less than 110% threat, and currentVictim is present and valid as checked before the loop (otherwise it's NULL), so end now { currentRef = currentVictim; found = true; break; } } else // pussywizard: no currentVictim, first passing all checks is chosen (highest threat, list is sorted) { found = true; break; } } ++iter; } if (!found) currentRef = NULL; return currentRef; }