Core/SAI: Fix creatures casting with flag SMARTCAST_COMBAT_MOVE not switching to melee when the school of the spell they are trying to cast gets silenced (and other cases of spell failure)
Port From (https://github.com/TrinityCore/TrinityCore/commit/e11e1938b5237a198c82cfdf128a9b6c1e3686ad)
This commit is contained in:
@@ -451,41 +451,14 @@ namespace Game.AI
|
|||||||
if (e.Action.cast.castFlags.HasAnyFlag((uint)SmartCastFlags.InterruptPrevious))
|
if (e.Action.cast.castFlags.HasAnyFlag((uint)SmartCastFlags.InterruptPrevious))
|
||||||
_me.InterruptNonMeleeSpells(false);
|
_me.InterruptNonMeleeSpells(false);
|
||||||
|
|
||||||
|
SpellCastResult result = _me.CastSpell(target.ToUnit(), e.Action.cast.spell, new CastSpellExtraArgs(triggerFlag));
|
||||||
|
bool spellCastFailed = (result != SpellCastResult.SpellCastOk && result != SpellCastResult.SpellInProgress);
|
||||||
|
|
||||||
if (e.Action.cast.castFlags.HasAnyFlag((uint)SmartCastFlags.CombatMove))
|
if (e.Action.cast.castFlags.HasAnyFlag((uint)SmartCastFlags.CombatMove))
|
||||||
{
|
((SmartAI)_me.GetAI()).SetCombatMove(spellCastFailed, true);
|
||||||
// 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 spellInfo = Global.SpellMgr.GetSpellInfo(e.Action.cast.spell, _me.GetMap().GetDifficultyID());
|
|
||||||
var costs = spellInfo.CalcPowerCost(_me, spellInfo.GetSchoolMask());
|
|
||||||
bool hasPower = true;
|
|
||||||
foreach (var cost in costs)
|
|
||||||
{
|
|
||||||
if (cost.Power == PowerType.Health)
|
|
||||||
{
|
|
||||||
if (_me.GetHealth() <= (uint)cost.Amount)
|
|
||||||
{
|
|
||||||
hasPower = false;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (_me.GetPower(cost.Power) < cost.Amount)
|
|
||||||
{
|
|
||||||
hasPower = false;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (_me.GetDistance(target) > spellInfo.GetMaxRange(true) || _me.GetDistance(target) < spellInfo.GetMinRange(true) ||
|
if (spellCastFailed)
|
||||||
!_me.IsWithinLOSInMap(target) || !hasPower || _me.HasUnitFlag(UnitFlags.Silenced))
|
RecalcTimer(e, 500, 500);
|
||||||
allowMove = true;
|
|
||||||
|
|
||||||
((SmartAI)_me.GetAI()).SetCombatMove(allowMove, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
_me.CastSpell(target.ToUnit(), e.Action.cast.spell, new CastSpellExtraArgs(triggerFlag));
|
|
||||||
}
|
}
|
||||||
else if (_go)
|
else if (_go)
|
||||||
_go.CastSpell(target.ToUnit(), e.Action.cast.spell, new CastSpellExtraArgs(triggerFlag));
|
_go.CastSpell(target.ToUnit(), e.Action.cast.spell, new CastSpellExtraArgs(triggerFlag));
|
||||||
|
|||||||
Reference in New Issue
Block a user