Added ability to specify bot target for spell casting (#874)

This commit is contained in:
achyles222
2025-01-18 20:28:20 +01:00
committed by GitHub
parent e27c28b125
commit 106b36b498

View File

@@ -54,6 +54,33 @@ bool CastCustomSpellAction::Execute(Event event)
ltrim(text);
}
uint32 spell = 0;
if (!target)
{
size_t onPos = FindLastSeparator(text, " on ");
if (onPos != std::string::npos)
{
std::string targetName = text.substr(onPos + 4);
ltrim(targetName);
if (!targetName.empty())
{
// check if spell still exists after we remove " on PlayerName" part
std::string truncatedText = text.substr(0, onPos);
ltrim(truncatedText);
spell = AI_VALUE2(uint32, "spell id", truncatedText);
if (spell)
{
if (Player* targetPlayer = ObjectAccessor::FindPlayerByName(targetName))
{
target = targetPlayer;
text = truncatedText;
}
}
}
}
}
if (!target)
if (master && master->GetTarget())
target = botAI->GetUnit(master->GetTarget());
@@ -81,7 +108,8 @@ bool CastCustomSpellAction::Execute(Event event)
}
}
uint32 spell = AI_VALUE2(uint32, "spell id", text);
if (!spell)
spell = AI_VALUE2(uint32, "spell id", text);
std::ostringstream msg;
if (!spell)