Scripts/Spells: Added spell effect validation helper

Port From (https://github.com/TrinityCore/TrinityCore/commit/f8a6a9b01713a5dbe5ed38bd3d1b1c72191cf288)
This commit is contained in:
hondacrx
2023-06-13 03:59:41 -04:00
parent 71a878c2cf
commit b7146a011e
14 changed files with 73 additions and 51 deletions
+29
View File
@@ -45,6 +45,35 @@ namespace Game.Scripting
return allValid;
}
public bool ValidateSpellEffect(params (uint spellId, uint effectIndex)[] pairs)
{
bool allValid = true;
foreach (var (spellId, effectIndex) in pairs)
{
if (!ValidateSpellEffect(spellId, effectIndex))
allValid = false;
}
return allValid;
}
public bool ValidateSpellEffect(uint spellId, uint effectIndex)
{
SpellInfo spellInfo = Global.SpellMgr.GetSpellInfo(spellId, Difficulty.None);
if (spellInfo == null)
{
Log.outError(LogFilter.Scripts, $"BaseSpellScript::ValidateSpellEffect: Spell {spellId} does not exist.");
return false;
}
if (spellInfo.GetEffects().Count <= effectIndex)
{
Log.outError(LogFilter.Scripts, $"BaseSpellScript::ValidateSpellEffect: Spell {spellId} does not have EFFECT_{effectIndex}.");
return false;
}
return true;
}
public void _Register()
{
m_currentScriptState = (byte)SpellScriptState.Registration;