diff --git a/src/game/Object/CreatureAI.cpp b/src/game/Object/CreatureAI.cpp index ddfee798..cb0d5864 100644 --- a/src/game/Object/CreatureAI.cpp +++ b/src/game/Object/CreatureAI.cpp @@ -57,6 +57,9 @@ CanCastResult CreatureAI::CanCastSpell(Unit* pTarget, const SpellEntry* pSpell, if (pSpell->PreventionType == SPELL_PREVENTION_TYPE_PACIFY && m_creature->HasFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_PACIFIED)) { return CAST_FAIL_STATE; } + if (!m_creature->IsWithinLOSInMap(pTarget)) + { return CAST_FAIL_NO_LOS; } + // Check for power (also done by Spell::CheckCast()) if (m_creature->GetPower((Powers)pSpell->powerType) < Spell::CalculatePowerCost(pSpell, m_creature)) { return CAST_FAIL_POWER; } @@ -145,10 +148,19 @@ void CreatureAI::SetCombatMovement(bool enable, bool stopOrStartMovement /*=fals if (stopOrStartMovement && m_creature->getVictim()) // Only change current movement while in combat { + MotionMaster* creatureMotion = m_creature->GetMotionMaster(); if (enable) - { m_creature->GetMotionMaster()->MoveChase(m_creature->getVictim(), m_attackDistance, m_attackAngle); } - else if (!enable && m_creature->GetMotionMaster()->GetCurrentMovementGeneratorType() == CHASE_MOTION_TYPE) - { m_creature->StopMoving(); } + { + m_creature->CastStop(); + creatureMotion->MoveChase(m_creature->getVictim(), m_attackDistance, m_attackAngle); + } + else if (creatureMotion->GetCurrentMovementGeneratorType() == CHASE_MOTION_TYPE) + { + creatureMotion->MovementExpired(); + creatureMotion->Clear(false); + m_creature->StopMoving(); + creatureMotion->MoveIdle(); + } } } @@ -160,8 +172,8 @@ void CreatureAI::HandleMovementOnAttackStart(Unit* victim) // TODO - adapt this to only stop OOC-MMGens when MotionMaster rewrite is finished else if (creatureMotion->GetCurrentMovementGeneratorType() == WAYPOINT_MOTION_TYPE || creatureMotion->GetCurrentMovementGeneratorType() == RANDOM_MOTION_TYPE) { - creatureMotion->MoveIdle(); m_creature->StopMoving(); + creatureMotion->MoveIdle(); } } diff --git a/src/game/Object/CreatureAI.h b/src/game/Object/CreatureAI.h index e1d82208..6a298d57 100644 --- a/src/game/Object/CreatureAI.h +++ b/src/game/Object/CreatureAI.h @@ -52,7 +52,8 @@ enum CanCastResult CAST_FAIL_TOO_CLOSE = 4, CAST_FAIL_POWER = 5, CAST_FAIL_STATE = 6, - CAST_FAIL_TARGET_AURA = 7 + CAST_FAIL_TARGET_AURA = 7, + CAST_FAIL_NO_LOS = 8 }; enum CastFlags diff --git a/src/game/Object/CreatureEventAI.cpp b/src/game/Object/CreatureEventAI.cpp index 684ffb0f..dfac84ec 100644 --- a/src/game/Object/CreatureEventAI.cpp +++ b/src/game/Object/CreatureEventAI.cpp @@ -637,7 +637,7 @@ void CreatureEventAI::ProcessAction(CreatureEventAI_Action const& action, uint32 if (!target) { if (reportTargetError) - { sLog.outErrorEventAI("NULL target for ACTION_T_CAST creature entry %u casting spell id %u", m_creature->GetEntry(), action.cast.spellId); } + { sLog.outErrorEventAI("NULL target for ACTION_T_CAST %s casting spell id %u", m_creature->GetGuidStr().c_str(), action.cast.spellId); } return; } @@ -647,30 +647,18 @@ void CreatureEventAI::ProcessAction(CreatureEventAI_Action const& action, uint32 { case CAST_FAIL_POWER: case CAST_FAIL_TOO_FAR: + case CAST_FAIL_NO_LOS: { // Melee current victim if flag not set if (!(action.cast.castFlags & CAST_NO_MELEE_IF_OOM)) { - switch (m_creature->GetMotionMaster()->GetCurrentMovementGeneratorType()) - { - case CHASE_MOTION_TYPE: - case FOLLOW_MOTION_TYPE: - m_attackDistance = 0.0f; - m_attackAngle = 0.0f; - - m_creature->GetMotionMaster()->Clear(false); - m_creature->GetMotionMaster()->MoveChase(m_creature->getVictim(), m_attackDistance, m_attackAngle); - break; - default: - break; - } + SetCombatMovement(true,true); } break; } default: break; } - break; } case ACTION_T_SUMMON: //12