Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 17 additions & 7 deletions src/server/game/AI/SmartScripts/SmartScript.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -696,7 +696,7 @@ void SmartScript::ProcessAction(SmartScriptHolder& e, Unit* unit, uint32 var0, u
{
failedSpellCast = true; // Mark spellcast as failed so we can retry it later

if (me->IsRooted()) // Rooted inhabit type, never move/reposition
if (me->IsRooted() || !IsSmart()) // Rooted inhabit type, never move/reposition
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't tested with an ASSERT for this, but maybe that would be better then have a silent bug?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We also have ASSERT here.

continue;

float minDistance = std::max(meleeRange, spellMinRange) - distanceToTarget + NOMINAL_MELEE_RANGE;
Expand All @@ -708,7 +708,7 @@ void SmartScript::ProcessAction(SmartScriptHolder& e, Unit* unit, uint32 var0, u
{
failedSpellCast = true;

if (me->IsRooted()) // Rooted inhabit type, never move/reposition
if (me->IsRooted() || !IsSmart()) // Rooted inhabit type, never move/reposition
continue;

if (e.action.cast.castFlags & SMARTCAST_COMBAT_MOVE)
Expand All @@ -720,7 +720,7 @@ void SmartScript::ProcessAction(SmartScriptHolder& e, Unit* unit, uint32 var0, u
{
failedSpellCast = true;

if (me->IsRooted()) // Rooted inhabit type, never move/reposition
if (me->IsRooted() || !IsSmart()) // Rooted inhabit type, never move/reposition
continue;

CAST_AI(SmartAI, me->AI())->SetCurrentRangeMode(true, 0.f);
Expand All @@ -743,6 +743,9 @@ void SmartScript::ProcessAction(SmartScriptHolder& e, Unit* unit, uint32 var0, u

if (e.action.cast.castFlags & SMARTCAST_COMBAT_MOVE)
{
if (!IsSmart())
continue;

if (result == SPELL_FAILED_OUT_OF_RANGE)
CAST_AI(SmartAI, me->AI())->SetCurrentRangeMode(true, std::max(spellMaxRange - NOMINAL_MELEE_RANGE, 0.0f));
else if (result != SPELL_CAST_OK)
Expand Down Expand Up @@ -1041,13 +1044,13 @@ void SmartScript::ProcessAction(SmartScriptHolder& e, Unit* unit, uint32 var0, u

// Suppress evade during script-initiated combat stop so
// JustExitedCombat does not trigger EnterEvadeMode.
if (SmartAI* sai = CAST_AI(SmartAI, me->AI()))
sai->SetSuppressEvade(true);
if (IsSmart())
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CAST_AI is just dynamic_cast. Old code is already null safe? This replaces one dynamic_cast with two? Maybe only thing is probably the null guard for SMARTCAST_COMBAT_MOVE

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just for the sake of format consistency

CAST_AI(SmartAI, me->AI())->SetSuppressEvade(true);

me->CombatStop(true);

if (SmartAI* sai = CAST_AI(SmartAI, me->AI()))
sai->SetSuppressEvade(false);
if (IsSmart())
CAST_AI(SmartAI, me->AI())->SetSuppressEvade(false);

break;
}
Expand Down Expand Up @@ -2763,13 +2766,20 @@ void SmartScript::ProcessAction(SmartScriptHolder& e, Unit* unit, uint32 var0, u
float spellMaxRange = me->GetSpellMaxRangeForTarget(target->ToUnit(), spellInfo);
if (e.action.cast.castFlags & SMARTCAST_COMBAT_MOVE)
{
if (!IsSmart())
continue;

// 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.
if (result == SPELL_FAILED_OUT_OF_RANGE || result == SPELL_CAST_OK)
{
// if we are just out of range, we only chase until we are back in spell range.
CAST_AI(SmartAI, me->AI())->SetCurrentRangeMode(true, std::max(spellMaxRange - NOMINAL_MELEE_RANGE, 0.0f));
}
else // move into melee on any other fail
{
// if spell fail for any other reason, we chase to melee range, or stay where we are if spellcast was successful.
CAST_AI(SmartAI, me->AI())->SetCurrentRangeMode(false, 0.f);
}
}
}
}
Expand Down
Loading