From 106b36b4987322fb9d793c0bbfb3c1a5719fe9af Mon Sep 17 00:00:00 2001 From: achyles222 <72513145+achyles222@users.noreply.github.com> Date: Sat, 18 Jan 2025 20:28:20 +0100 Subject: [PATCH] Added ability to specify bot target for spell casting (#874) --- .../actions/CastCustomSpellAction.cpp | 30 ++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/src/strategy/actions/CastCustomSpellAction.cpp b/src/strategy/actions/CastCustomSpellAction.cpp index 9e8254a2..c7b2d0a8 100644 --- a/src/strategy/actions/CastCustomSpellAction.cpp +++ b/src/strategy/actions/CastCustomSpellAction.cpp @@ -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)