aboutsummaryrefslogtreecommitdiff
path: root/src/server/scripts
diff options
context:
space:
mode:
Diffstat (limited to 'src/server/scripts')
-rw-r--r--src/server/scripts/Commands/cs_cast.cpp34
1 files changed, 14 insertions, 20 deletions
diff --git a/src/server/scripts/Commands/cs_cast.cpp b/src/server/scripts/Commands/cs_cast.cpp
index 24e4656987c..281d4671432 100644
--- a/src/server/scripts/Commands/cs_cast.cpp
+++ b/src/server/scripts/Commands/cs_cast.cpp
@@ -31,6 +31,7 @@ EndScriptData */
#include "SpellMgr.h"
#include "WorldSession.h"
+using namespace Trinity::ChatCommands;
class cast_commandscript : public CommandScript
{
public:
@@ -54,30 +55,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);
- 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)); }
- 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 +84,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;
}