feat(Scripts/Commands): Output SpellCastResult if the spell fails to … (#14359)

feat(Scripts/Commands): Output SpellCastResult if the spell fails to cast when using the cast spell commands
This commit is contained in:
Skjalf
2022-12-24 09:47:13 -03:00
committed by GitHub
parent c05c45c51d
commit 4df5302e2f
3 changed files with 49 additions and 7 deletions

View File

@@ -56,6 +56,17 @@ public:
return commandTable;
}
static bool CheckSpellCastResult(ChatHandler* handler, SpellCastResult result)
{
if (result != SPELL_CAST_OK)
{
handler->PSendSysMessage(LANG_CMD_CAST_ERROR_CODE, EnumUtils::ToTitle(SpellCastResult(result)), result);
return false;
}
return true;
}
static bool CheckSpellExistsAndIsValid(ChatHandler* handler, SpellInfo const* spell)
{
if (!spell)
@@ -103,7 +114,11 @@ public:
if (!triggerFlags)
return false;
handler->GetSession()->GetPlayer()->CastSpell(target, spell->Id, *triggerFlags);
if (!CheckSpellCastResult(handler, handler->GetSession()->GetPlayer()->CastSpell(target, spell->Id, *triggerFlags)))
{
handler->SetSentErrorMessage(true);
return false;
}
return true;
}
@@ -125,7 +140,11 @@ public:
if (!triggerFlags)
return false;
caster->CastSpell(handler->GetSession()->GetPlayer(), spell->Id, *triggerFlags);
if (!CheckSpellCastResult(handler, caster->CastSpell(handler->GetSession()->GetPlayer(), spell->Id, *triggerFlags)))
{
handler->SetSentErrorMessage(true);
return false;
}
return true;
}
@@ -141,7 +160,12 @@ public:
float x, y, z;
handler->GetSession()->GetPlayer()->GetClosePoint(x, y, z, dist);
handler->GetSession()->GetPlayer()->CastSpell(x, y, z, spell->Id, *triggerFlags);
if (!CheckSpellCastResult(handler, handler->GetSession()->GetPlayer()->CastSpell(x, y, z, spell->Id, *triggerFlags)))
{
handler->SetSentErrorMessage(true);
return false;
}
return true;
}
@@ -163,7 +187,11 @@ public:
if (!triggerFlags)
return false;
target->CastSpell(target, spell->Id, *triggerFlags);
if (!CheckSpellCastResult(handler, target->CastSpell(target, spell->Id, *triggerFlags)))
{
handler->SetSentErrorMessage(true);
return false;
}
return true;
}
@@ -192,7 +220,11 @@ public:
if (!triggerFlags)
return false;
caster->CastSpell(caster->GetVictim(), spell->Id, *triggerFlags);
if (!CheckSpellCastResult(handler, caster->CastSpell(caster->GetVictim(), spell->Id, *triggerFlags)))
{
handler->SetSentErrorMessage(true);
return false;
}
return true;
}
@@ -214,7 +246,11 @@ public:
if (!triggerFlags)
return false;
caster->CastSpell(x, y, z, spell->Id, *triggerFlags);
if (!CheckSpellCastResult(handler, caster->CastSpell(x, y, z, spell->Id, *triggerFlags)))
{
handler->SetSentErrorMessage(true);
return false;
}
return true;
}