aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/server/game/Chat/ChatCommands/ChatCommandArgs.cpp15
-rw-r--r--src/server/game/Chat/ChatCommands/ChatCommandArgs.h7
-rw-r--r--src/server/scripts/Commands/cs_cast.cpp35
3 files changed, 37 insertions, 20 deletions
diff --git a/src/server/game/Chat/ChatCommands/ChatCommandArgs.cpp b/src/server/game/Chat/ChatCommands/ChatCommandArgs.cpp
index 340a13bd15d..6029089972b 100644
--- a/src/server/game/Chat/ChatCommands/ChatCommandArgs.cpp
+++ b/src/server/game/Chat/ChatCommands/ChatCommandArgs.cpp
@@ -19,6 +19,7 @@
#include "ChatCommand.h"
#include "DB2Stores.h"
#include "ObjectMgr.h"
+#include "SpellMgr.h"
using namespace Trinity::ChatCommands;
@@ -64,6 +65,20 @@ char const* Trinity::ChatCommands::ArgInfo<GameTele const*>::TryConsume(GameTele
return args;
}
+struct SpellInfoVisitor
+{
+ using value_type = SpellInfo const*;
+ value_type operator()(Hyperlink<spell> spell) const { return spell->Spell; }
+ value_type operator()(uint32 spellId) const { return sSpellMgr->GetSpellInfo(spellId, DIFFICULTY_NONE); }
+};
+char const* Trinity::ChatCommands::ArgInfo<SpellInfo const*>::TryConsume(SpellInfo const*& data, char const* args)
+{
+ Variant<Hyperlink<spell>, uint32> val;
+ if ((args = CommandArgsConsumerSingle<decltype(val)>::TryConsumeTo(val, args)))
+ data = boost::apply_visitor(SpellInfoVisitor(), val);
+ return args;
+}
+
struct BoolVisitor
{
using value_type = bool;
diff --git a/src/server/game/Chat/ChatCommands/ChatCommandArgs.h b/src/server/game/Chat/ChatCommands/ChatCommandArgs.h
index db5deddb1dc..1ef74c2430f 100644
--- a/src/server/game/Chat/ChatCommands/ChatCommandArgs.h
+++ b/src/server/game/Chat/ChatCommands/ChatCommandArgs.h
@@ -130,6 +130,13 @@ struct TC_GAME_API ArgInfo<GameTele const*>
static char const* TryConsume(GameTele const*&, char const*);
};
+// SpellInfo const* from spell id or link
+template <>
+struct TC_GAME_API ArgInfo<SpellInfo const*>
+{
+ static char const* TryConsume(SpellInfo const*&, char const*);
+};
+
// bool from 1/0 or on/off
template <>
struct TC_GAME_API ArgInfo<bool>
diff --git a/src/server/scripts/Commands/cs_cast.cpp b/src/server/scripts/Commands/cs_cast.cpp
index a444d31f37a..e252d875aad 100644
--- a/src/server/scripts/Commands/cs_cast.cpp
+++ b/src/server/scripts/Commands/cs_cast.cpp
@@ -28,9 +28,11 @@ EndScriptData */
#include "Language.h"
#include "Player.h"
#include "RBAC.h"
+#include "SpellInfo.h"
#include "SpellMgr.h"
#include "WorldSession.h"
+using namespace Trinity::ChatCommands;
class cast_commandscript : public CommandScript
{
public:
@@ -54,30 +56,27 @@ public:
return commandTable;
}
- static bool CheckSpellExistsAndIsValid(ChatHandler* handler, uint32 spellId)
+ static bool CheckSpellExistsAndIsValid(ChatHandler* handler, SpellInfo const* spell)
{
- SpellInfo const* spellInfo = sSpellMgr->GetSpellInfo(spellId, DIFFICULTY_NONE);
- if (!spellInfo)
+ if (!spell)
{
handler->PSendSysMessage(LANG_COMMAND_NOSPELLFOUND);
handler->SetSentErrorMessage(true);
return false;
}
- if (!SpellMgr::IsSpellValid(spellInfo, handler->GetSession()->GetPlayer()))
+ if (!SpellMgr::IsSpellValid(spell, handler->GetSession()->GetPlayer()))
{
- handler->PSendSysMessage(LANG_COMMAND_SPELL_BROKEN, spellId);
+ handler->PSendSysMessage(LANG_COMMAND_SPELL_BROKEN, spell->Id);
handler->SetSentErrorMessage(true);
return false;
}
return true;
}
+ static bool CheckSpellExistsAndIsValid(ChatHandler* handler, uint32 const spellId) { return CheckSpellExistsAndIsValid(handler, sSpellMgr->GetSpellInfo(spellId, DIFFICULTY_NONE)); }
- static bool HandleCastCommand(ChatHandler* handler, char const* args)
+ static bool HandleCastCommand(ChatHandler* handler, SpellInfo const* spell, Optional<std::string> triggeredStr)
{
- if (!*args)
- return false;
-
Unit* target = handler->getSelectedUnit();
if (!target)
{
@@ -86,24 +85,20 @@ public:
return false;
}
- // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
- uint32 spellId = handler->extractSpellIdFromLink((char*)args);
- if (!spellId)
- return false;
-
- if (!CheckSpellExistsAndIsValid(handler, spellId))
+ if (!CheckSpellExistsAndIsValid(handler, spell))
return false;
- char* triggeredStr = strtok(nullptr, " ");
+ TriggerCastFlags triggerFlags = TRIGGERED_NONE;
if (triggeredStr)
{
- int l = strlen(triggeredStr);
- if (strncmp(triggeredStr, "triggered", l) != 0)
+ if (std::string("triggered").rfind(*triggeredStr, 0) == 0) // check if "triggered" starts with *triggeredStr (e.g. "trig", "trigger", etc.)
+ triggerFlags = TRIGGERED_FULL_DEBUG_MASK;
+ else
return false;
+
}
- TriggerCastFlags triggered = (triggeredStr != nullptr) ? TRIGGERED_FULL_DEBUG_MASK : TRIGGERED_NONE;
- handler->GetSession()->GetPlayer()->CastSpell(target, spellId, triggered);
+ handler->GetSession()->GetPlayer()->CastSpell(target, spell->Id, triggerFlags);
return true;
}