Core/Spells: CastSpell Cleanup

Port From (https://github.com/TrinityCore/TrinityCore/commit/)
This commit is contained in:
hondacrx
2021-04-18 18:42:11 -04:00
parent b1ea7212f3
commit d0faa12ef6
45 changed files with 775 additions and 632 deletions
+6 -1
View File
@@ -17,6 +17,7 @@
using Framework.Constants;
using Game.Entities;
using Game.Spells;
using System.Collections.Generic;
namespace Game.AI
@@ -128,7 +129,11 @@ namespace Game.AI
public override void IsSummonedBy(Unit summoner)
{
if (me.m_spells[0] != 0)
me.CastSpell(me, me.m_spells[0], false, null, null, summoner.GetGUID());
{
CastSpellExtraArgs extra = new();
extra.OriginalCaster = summoner.GetGUID();
me.CastSpell(me, me.m_spells[0], extra);
}
}
}
}
+13 -20
View File
@@ -98,17 +98,17 @@ namespace Game.AI
}
}
public bool DoSpellAttackIfReady(uint spell)
public bool DoSpellAttackIfReady(uint spellId)
{
if (me.HasUnitState(UnitState.Casting) || !me.IsAttackReady())
return true;
var spellInfo = Global.SpellMgr.GetSpellInfo(spell, me.GetMap().GetDifficultyID());
var spellInfo = Global.SpellMgr.GetSpellInfo(spellId, me.GetMap().GetDifficultyID());
if (spellInfo != null)
{
if (me.IsWithinCombatRange(me.GetVictim(), spellInfo.GetMaxRange(false)))
{
me.CastSpell(me.GetVictim(), spellInfo, TriggerCastFlags.None);
me.CastSpell(me.GetVictim(), spellId, new CastSpellExtraArgs(me.GetMap().GetDifficultyID()));
me.ResetAttackTimer();
return true;
}
@@ -300,32 +300,25 @@ namespace Game.AI
me.CastSpell(target, spellId, false);
}
public void DoCast(Unit victim, uint spellId, bool triggered = false)
public void DoCast(Unit victim, uint spellId, CastSpellExtraArgs args = null)
{
if (victim == null || (me.HasUnitState(UnitState.Casting) && !triggered))
if (me.HasUnitState(UnitState.Casting) && !args.TriggerFlags.HasAnyFlag(TriggerCastFlags.IgnoreCastInProgress))
return;
me.CastSpell(victim, spellId, triggered);
me.CastSpell(victim, spellId, args);
}
public void DoCastSelf(uint spellId, bool triggered = false) { DoCast(me, spellId, triggered); }
public void DoCastSelf(uint spellId, CastSpellExtraArgs args = null) { DoCast(me, spellId, args); }
public void DoCastVictim(uint spellId, bool triggered = false)
public void DoCastVictim(uint spellId, CastSpellExtraArgs args = null)
{
if (me.GetVictim() == null || (me.HasUnitState(UnitState.Casting) && !triggered))
return;
me.CastSpell(me.GetVictim(), spellId, triggered);
}
public void DoCastAOE(uint spellId, bool triggered = false)
{
if (!triggered && me.HasUnitState(UnitState.Casting))
return;
me.CastSpell((Unit)null, spellId, triggered);
Unit victim = me.GetVictim();
if (victim != null)
DoCast(victim, spellId, args);
}
public void DoCastAOE(uint spellId, CastSpellExtraArgs args = null) { DoCast(null, spellId, args); }
public static void FillAISpellInfo()
{
//AISpellInfo = new AISpellInfoType[spellStorage.Keys.Max() + 1];
+1 -1
View File
@@ -602,7 +602,7 @@ namespace Game.AI
if (rangedAttackSpell == 0)
return;
me.CastSpell(victim, rangedAttackSpell, TriggerCastFlags.CastDirectly);
me.CastSpell(victim, rangedAttackSpell, new CastSpellExtraArgs(TriggerCastFlags.CastDirectly));
me.ResetAttackTimer(WeaponAttackType.RangedAttack);
}
+1 -1
View File
@@ -97,7 +97,7 @@ namespace Game.AI
return;
me.StopMoving();
me.CastSpell(target, spellInfo, triggered ? TriggerCastFlags.FullMask : TriggerCastFlags.None);
me.CastSpell(target, spellInfo.Id, triggered);
}
//Plays a sound to all nearby players
+2 -4
View File
@@ -486,12 +486,10 @@ namespace Game.AI
((SmartAI)_me.GetAI()).SetCombatMove(allowMove);
}
_me.CastSpell(target.ToUnit(), e.Action.cast.spell, triggerFlag);
_me.CastSpell(target.ToUnit(), e.Action.cast.spell, new CastSpellExtraArgs(triggerFlag));
}
else if (_go)
_go.CastSpell(target.ToUnit(), e.Action.cast.spell, triggerFlag);
else if (target != null)
target.ToUnit().CastSpell(target.ToUnit(), e.Action.cast.spell);
}
else
Log.outDebug(LogFilter.ScriptsAi, "Spell {0} not casted because it has flag SMARTCAST_AURA_NOT_PRESENT and the target (Guid: {1} Entry: {2} Type: {3}) already has the aura",
@@ -531,7 +529,7 @@ namespace Game.AI
triggerFlag = TriggerCastFlags.FullMask;
}
tempLastInvoker.CastSpell(target.ToUnit(), e.Action.cast.spell, triggerFlag);
tempLastInvoker.CastSpell(target.ToUnit(), e.Action.cast.spell, new CastSpellExtraArgs(triggerFlag));
Log.outDebug(LogFilter.ScriptsAi, "SmartScript.ProcessAction. SMART_ACTION_INVOKER_CAST: Invoker {0} casts spell {1} on target {2} with castflags {3}",
tempLastInvoker.GetGUID().ToString(), e.Action.cast.spell, target.GetGUID().ToString(), e.Action.cast.castFlags);