aboutsummaryrefslogtreecommitdiff
path: root/src/server/scripts/Commands
diff options
context:
space:
mode:
authorTreeston <treeston.mmoc@gmail.com>2020-03-19 16:13:01 +0100
committerShauren <shauren.trinity@gmail.com>2021-12-24 00:34:08 +0100
commitfdcef115e00c3fc4242d8e6372a5bf349bc06c43 (patch)
treeeb559d13c09e134474d1c569217078535b7740d9 /src/server/scripts/Commands
parente7295fd3de2ac45825ce0876b7199c8cec635d99 (diff)
Core/Chat: Add SpellInfo const* handler for command args. Use it to update .cast <spellId/link> <triggered>.
(cherry picked from commit 7ac6ccb36ba6ffba542f3e9a60bca4d9e6a6b84d)
Diffstat (limited to 'src/server/scripts/Commands')
-rw-r--r--src/server/scripts/Commands/cs_cast.cpp35
1 files changed, 15 insertions, 20 deletions
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;
}