aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/server/game/AI/SmartScripts/SmartScript.cpp19
-rw-r--r--src/server/game/AI/SmartScripts/SmartScriptMgr.h3
2 files changed, 21 insertions, 1 deletions
diff --git a/src/server/game/AI/SmartScripts/SmartScript.cpp b/src/server/game/AI/SmartScripts/SmartScript.cpp
index d2d5027ce7d..7555471e091 100644
--- a/src/server/game/AI/SmartScripts/SmartScript.cpp
+++ b/src/server/game/AI/SmartScripts/SmartScript.cpp
@@ -516,7 +516,26 @@ void SmartScript::ProcessAction(SmartScriptHolder& e, Unit* unit, uint32 var0, u
if (e.action.cast.flags & SMARTCAST_INTERRUPT_PREVIOUS)
me->InterruptNonMeleeSpells(false);
+ if (e.action.cast.flags & SMARTCAST_COMBAT_MOVE)
+ {
+ // If cast flag SMARTCAST_COMBAT_MOVE is set combat movement will not be allowed
+ // unless target is outside spell range, out of mana, or LOS.
+
+ bool _allowMove = false;
+ SpellInfo const* spellInfo = sSpellMgr->GetSpellInfo(e.action.cast.spell);
+ int32 mana = me->GetPower(POWER_MANA);
+
+ if (me->GetDistance((*itr)->ToUnit()) > spellInfo->GetMaxRange(true) ||
+ me->GetDistance((*itr)->ToUnit()) < spellInfo->GetMinRange(true) ||
+ !me->ToUnit()->IsWithinLOSInMap((*itr)->ToUnit()) ||
+ mana < spellInfo->CalcPowerCost(me, spellInfo->GetSchoolMask()))
+ _allowMove = true;
+
+ CAST_AI(SmartAI, me->AI())->SetCombatMove(_allowMove);
+ }
+
me->CastSpell((*itr)->ToUnit(), e.action.cast.spell, (e.action.cast.flags & SMARTCAST_TRIGGERED));
+
TC_LOG_DEBUG("scripts.ai", "SmartScript::ProcessAction:: SMART_ACTION_CAST:: Creature %u casts spell %u on target %u with castflags %u",
me->GetGUIDLow(), e.action.cast.spell, (*itr)->GetGUIDLow(), e.action.cast.flags);
}
diff --git a/src/server/game/AI/SmartScripts/SmartScriptMgr.h b/src/server/game/AI/SmartScripts/SmartScriptMgr.h
index 35abdcc47f0..d6bf318b8ac 100644
--- a/src/server/game/AI/SmartScripts/SmartScriptMgr.h
+++ b/src/server/game/AI/SmartScripts/SmartScriptMgr.h
@@ -1283,7 +1283,8 @@ enum SmartCastFlags
//SMARTCAST_FORCE_CAST = 0x04, //Forces cast even if creature is out of mana or out of range
//SMARTCAST_NO_MELEE_IF_OOM = 0x08, //Prevents creature from entering melee if out of mana or out of range
//SMARTCAST_FORCE_TARGET_SELF = 0x10, //Forces the target to cast this spell on itself
- SMARTCAST_AURA_NOT_PRESENT = 0x20 //Only casts the spell if the target does not have an aura from the spell
+ SMARTCAST_AURA_NOT_PRESENT = 0x20, //Only casts the spell if the target does not have an aura from the spell
+ SMARTCAST_COMBAT_MOVE = 0x40 //Prevents combat movement if cast successful. Allows movement on range, OOM, LOS
};
// one line in DB is one event