Core/SAI: Fix creatures casting spells while moving with flag SMARTCAST_COMBAT_MOVE

Fixes #24019

(cherry picked from commit 2910d0fb2436d9865d792ef92cb415f831a0af93)
This commit is contained in:
jackpoz
2022-01-26 16:23:15 +01:00
committed by Shauren
parent ffd85f9139
commit b3545479bf
3 changed files with 12 additions and 8 deletions
+10 -6
View File
@@ -788,7 +788,7 @@ void SmartAI::QuestReward(Player* player, Quest const* quest, LootItemType /*typ
GetScript()->ProcessEventsFor(SMART_EVENT_REWARD_QUEST, player, quest->GetQuestId(), opt); GetScript()->ProcessEventsFor(SMART_EVENT_REWARD_QUEST, player, quest->GetQuestId(), opt);
} }
void SmartAI::SetCombatMove(bool on) void SmartAI::SetCombatMove(bool on, bool stopMoving)
{ {
if (_canCombatMove == on) if (_canCombatMove == on)
return; return;
@@ -803,19 +803,23 @@ void SmartAI::SetCombatMove(bool on)
if (on) if (on)
{ {
if (!me->HasReactState(REACT_PASSIVE) && me->GetVictim() && !me->GetMotionMaster()->HasMovementGenerator([](MovementGenerator const* movement) -> bool if (!me->HasReactState(REACT_PASSIVE) && me->GetVictim() && !me->GetMotionMaster()->HasMovementGenerator([](MovementGenerator const* movement) -> bool
{ {
return movement->GetMovementGeneratorType() == CHASE_MOTION_TYPE && movement->Mode == MOTION_MODE_DEFAULT && movement->Priority == MOTION_PRIORITY_NORMAL; return movement->GetMovementGeneratorType() == CHASE_MOTION_TYPE && movement->Mode == MOTION_MODE_DEFAULT && movement->Priority == MOTION_PRIORITY_NORMAL;
})) }))
{ {
SetRun(_run); SetRun(_run);
me->GetMotionMaster()->MoveChase(me->GetVictim()); me->GetMotionMaster()->MoveChase(me->GetVictim());
} }
} }
else if (MovementGenerator* movement = me->GetMotionMaster()->GetMovementGenerator([](MovementGenerator const* a) -> bool else if (MovementGenerator* movement = me->GetMotionMaster()->GetMovementGenerator([](MovementGenerator const* a) -> bool
{
return a->GetMovementGeneratorType() == CHASE_MOTION_TYPE && a->Mode == MOTION_MODE_DEFAULT && a->Priority == MOTION_PRIORITY_NORMAL;
}))
{ {
return a->GetMovementGeneratorType() == CHASE_MOTION_TYPE && a->Mode == MOTION_MODE_DEFAULT && a->Priority == MOTION_PRIORITY_NORMAL;
}))
me->GetMotionMaster()->Remove(movement); me->GetMotionMaster()->Remove(movement);
if (stopMoving)
me->StopMoving();
}
} }
} }
+1 -1
View File
@@ -60,7 +60,7 @@ class TC_GAME_API SmartAI : public CreatureAI
void AddEscortState(uint32 escortState) { _escortState |= escortState; } void AddEscortState(uint32 escortState) { _escortState |= escortState; }
void RemoveEscortState(uint32 escortState) { _escortState &= ~escortState; } void RemoveEscortState(uint32 escortState) { _escortState &= ~escortState; }
void SetAutoAttack(bool on) { _canAutoAttack = on; } void SetAutoAttack(bool on) { _canAutoAttack = on; }
void SetCombatMove(bool on); void SetCombatMove(bool on, bool stopMoving = false);
bool CanCombatMove() { return _canCombatMove; } bool CanCombatMove() { return _canCombatMove; }
void SetFollow(Unit* target, float dist = 0.0f, float angle = 0.0f, uint32 credit = 0, uint32 end = 0, uint32 creditType = 0); void SetFollow(Unit* target, float dist = 0.0f, float angle = 0.0f, uint32 credit = 0, uint32 end = 0, uint32 creditType = 0);
void StopFollow(bool complete); void StopFollow(bool complete);
@@ -599,7 +599,7 @@ void SmartScript::ProcessAction(SmartScriptHolder& e, Unit* unit, uint32 var0, u
me->HasUnitFlag(UNIT_FLAG_SILENCED)) me->HasUnitFlag(UNIT_FLAG_SILENCED))
allowMove = true; allowMove = true;
ENSURE_AI(SmartAI, me->AI())->SetCombatMove(allowMove); ENSURE_AI(SmartAI, me->AI())->SetCombatMove(allowMove, true);
} }
me->CastSpell(target->ToUnit(), e.action.cast.spell, triggerFlag); me->CastSpell(target->ToUnit(), e.action.cast.spell, triggerFlag);