From d0bdf7611aab582a3cb28fced2301687648ceb3f Mon Sep 17 00:00:00 2001 From: sixsixnine Date: Mon, 30 Jan 2012 00:10:01 +0100 Subject: [PATCH] [11918] Let creatures evade when the enemy is unreachable This commit is not great, but will be improved hopefully soon. However it seems that it doesn't really cause problems, it is just not as good as it should be! --- src/game/ThreatManager.cpp | 10 +++++++++- src/game/Unit.cpp | 26 ++++++++++++++++++++++++++ src/shared/revision_nr.h | 2 +- 3 files changed, 36 insertions(+), 2 deletions(-) diff --git a/src/game/ThreatManager.cpp b/src/game/ThreatManager.cpp index 7f7820fe1..3593bd3a9 100644 --- a/src/game/ThreatManager.cpp +++ b/src/game/ThreatManager.cpp @@ -252,7 +252,15 @@ HostileReference* ThreatContainer::addThreat(Unit* pVictim, float pThreat) void ThreatContainer::modifyThreatPercent(Unit *pVictim, int32 pPercent) { if(HostileReference* ref = getReferenceByTarget(pVictim)) - ref->addThreatPercent(pPercent); + { + if(pPercent < -100) + { + ref->removeReference(); + delete ref; + } + else + ref->addThreatPercent(pPercent); + } } //============================================================ diff --git a/src/game/Unit.cpp b/src/game/Unit.cpp index 621c25713..bd35c474b 100644 --- a/src/game/Unit.cpp +++ b/src/game/Unit.cpp @@ -8666,6 +8666,32 @@ bool Unit::SelectHostileTarget() SetInFront(target); if (oldTarget != target) ((Creature*)this)->AI()->AttackStart(target); + + // check if currently selected target is reachable + // NOTE: path alrteady generated from AttackStart() + if(!GetMotionMaster()->operator->()->IsReachable()) + { + // remove all taunts + RemoveSpellsCausingAura(SPELL_AURA_MOD_TAUNT); + + if(m_ThreatManager.getThreatList().size() < 2) + { + // only one target in list, we have to evade after timer + // TODO: make timer - inside Creature class + ((Creature*)this)->AI()->EnterEvadeMode(); + } + else + { + // remove unreachable target from our threat list + // next iteration we will select next possible target + m_HostileRefManager.deleteReference(target); + m_ThreatManager.modifyThreatPercent(target, -101); + + _removeAttacker(target); + } + + return false; + } } return true; } diff --git a/src/shared/revision_nr.h b/src/shared/revision_nr.h index 56768fa2a..8038fd532 100644 --- a/src/shared/revision_nr.h +++ b/src/shared/revision_nr.h @@ -1,4 +1,4 @@ #ifndef __REVISION_NR_H__ #define __REVISION_NR_H__ - #define REVISION_NR "11917" + #define REVISION_NR "11918" #endif // __REVISION_NR_H__