mirror of
https://github.com/TrinityCore/TrinityCore.git
synced 2026-01-15 23:20:36 +01:00
Core/Chat: Add SpellInfo const* handler for command args. Use it to update .cast <spellId/link> <triggered>.
(cherry picked from commit 7ac6ccb36b)
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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)
|
||||
if (!CheckSpellExistsAndIsValid(handler, spell))
|
||||
return false;
|
||||
|
||||
if (!CheckSpellExistsAndIsValid(handler, spellId))
|
||||
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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user