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

@@ -0,0 +1,4 @@
--
DELETE FROM `acore_string` WHERE `entry` = 5084;
INSERT INTO `acore_string` (`entry`, `content_default`) VALUES
(5084, 'Spell cast failed! SpellCastResult returned: %s (%u).');

View File

@@ -1148,7 +1148,9 @@ enum AcoreStrings
LANG_CMD_CHAR_CHANGE_ACC_SUCCESS = 5083,
// Room for more strings 5083-9999
LANG_CMD_CAST_ERROR_CODE = 5084,
// Room for more strings 5084-9999
// Level requirement notifications
LANG_SAY_REQ = 6604,

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;
}