mirror of
https://github.com/mod-playerbots/azerothcore-wotlk.git
synced 2026-01-14 09:39:11 +00:00
349 lines
11 KiB
C++
349 lines
11 KiB
C++
/*
|
|
* Copyright (C) 2016+ AzerothCore <www.azerothcore.org>, released under GNU GPL v2 license: https://github.com/azerothcore/azerothcore-wotlk/blob/master/LICENSE-GPL2
|
|
* Copyright (C) 2008-2016 TrinityCore <http://www.trinitycore.org/>
|
|
* Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
|
|
*/
|
|
|
|
/* ScriptData
|
|
Name: cast_commandscript
|
|
%Complete: 100
|
|
Comment: All cast related commands
|
|
Category: commandscripts
|
|
EndScriptData */
|
|
|
|
#include "ScriptMgr.h"
|
|
#include "Chat.h"
|
|
#include "Creature.h"
|
|
#include "Language.h"
|
|
#include "Player.h"
|
|
#include "SpellInfo.h"
|
|
|
|
class cast_commandscript : public CommandScript
|
|
{
|
|
public:
|
|
cast_commandscript() : CommandScript("cast_commandscript") { }
|
|
|
|
std::vector<ChatCommand> GetCommands() const override
|
|
{
|
|
static std::vector<ChatCommand> castCommandTable =
|
|
{
|
|
{ "back", SEC_GAMEMASTER, false, &HandleCastBackCommand, "" },
|
|
{ "dist", SEC_GAMEMASTER, false, &HandleCastDistCommand, "" },
|
|
{ "self", SEC_GAMEMASTER, false, &HandleCastSelfCommand, "" },
|
|
{ "target", SEC_GAMEMASTER, false, &HandleCastTargetCommad, "" },
|
|
{ "dest", SEC_GAMEMASTER, false, &HandleCastDestCommand, "" },
|
|
{ "", SEC_GAMEMASTER, false, &HandleCastCommand, "" }
|
|
};
|
|
static std::vector<ChatCommand> commandTable =
|
|
{
|
|
{ "cast", SEC_GAMEMASTER, false, nullptr, "", castCommandTable }
|
|
};
|
|
return commandTable;
|
|
}
|
|
|
|
static bool HandleCastCommand(ChatHandler* handler, char const* args)
|
|
{
|
|
if (!*args)
|
|
return false;
|
|
|
|
Unit* target = handler->getSelectedUnit();
|
|
if (!target)
|
|
{
|
|
handler->SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
|
|
handler->SetSentErrorMessage(true);
|
|
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;
|
|
|
|
SpellInfo const* spellInfo = sSpellMgr->GetSpellInfo(spellId);
|
|
if (!spellInfo)
|
|
{
|
|
handler->PSendSysMessage(LANG_COMMAND_NOSPELLFOUND);
|
|
handler->SetSentErrorMessage(true);
|
|
return false;
|
|
}
|
|
|
|
if (!SpellMgr::IsSpellValid(spellInfo))
|
|
{
|
|
handler->PSendSysMessage(LANG_COMMAND_SPELL_BROKEN, spellId);
|
|
handler->SetSentErrorMessage(true);
|
|
return false;
|
|
}
|
|
|
|
char* triggeredStr = strtok(nullptr, " ");
|
|
if (triggeredStr)
|
|
{
|
|
int l = strlen(triggeredStr);
|
|
if (strncmp(triggeredStr, "triggered", l) != 0)
|
|
return false;
|
|
}
|
|
|
|
bool triggered = (triggeredStr != nullptr);
|
|
|
|
handler->GetSession()->GetPlayer()->CastSpell(target, spellId, triggered);
|
|
|
|
return true;
|
|
}
|
|
|
|
static bool HandleCastBackCommand(ChatHandler* handler, char const* args)
|
|
{
|
|
Creature* caster = handler->getSelectedCreature();
|
|
if (!caster)
|
|
{
|
|
handler->SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
|
|
handler->SetSentErrorMessage(true);
|
|
return false;
|
|
}
|
|
|
|
// number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r
|
|
// 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;
|
|
|
|
SpellInfo const* spellInfo = sSpellMgr->GetSpellInfo(spellId);
|
|
if (!spellInfo)
|
|
{
|
|
handler->PSendSysMessage(LANG_COMMAND_NOSPELLFOUND);
|
|
handler->SetSentErrorMessage(true);
|
|
return false;
|
|
}
|
|
|
|
if (!SpellMgr::IsSpellValid(spellInfo))
|
|
{
|
|
handler->PSendSysMessage(LANG_COMMAND_SPELL_BROKEN, spellId);
|
|
handler->SetSentErrorMessage(true);
|
|
return false;
|
|
}
|
|
|
|
char* triggeredStr = strtok(nullptr, " ");
|
|
if (triggeredStr)
|
|
{
|
|
int l = strlen(triggeredStr);
|
|
if (strncmp(triggeredStr, "triggered", l) != 0)
|
|
return false;
|
|
}
|
|
|
|
bool triggered = (triggeredStr != nullptr);
|
|
|
|
caster->CastSpell(handler->GetSession()->GetPlayer(), spellId, triggered);
|
|
|
|
return true;
|
|
}
|
|
|
|
static bool HandleCastDistCommand(ChatHandler* handler, char const* args)
|
|
{
|
|
if (!*args)
|
|
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;
|
|
|
|
SpellInfo const* spellInfo = sSpellMgr->GetSpellInfo(spellId);
|
|
if (!spellInfo)
|
|
{
|
|
handler->PSendSysMessage(LANG_COMMAND_NOSPELLFOUND);
|
|
handler->SetSentErrorMessage(true);
|
|
return false;
|
|
}
|
|
|
|
if (!SpellMgr::IsSpellValid(spellInfo))
|
|
{
|
|
handler->PSendSysMessage(LANG_COMMAND_SPELL_BROKEN, spellId);
|
|
handler->SetSentErrorMessage(true);
|
|
return false;
|
|
}
|
|
|
|
char* distStr = strtok(nullptr, " ");
|
|
|
|
float dist = 0;
|
|
|
|
if (distStr)
|
|
sscanf(distStr, "%f", &dist);
|
|
|
|
char* triggeredStr = strtok(nullptr, " ");
|
|
if (triggeredStr)
|
|
{
|
|
int l = strlen(triggeredStr);
|
|
if (strncmp(triggeredStr, "triggered", l) != 0)
|
|
return false;
|
|
}
|
|
|
|
bool triggered = (triggeredStr != nullptr);
|
|
|
|
float x, y, z;
|
|
handler->GetSession()->GetPlayer()->GetClosePoint(x, y, z, dist);
|
|
|
|
handler->GetSession()->GetPlayer()->CastSpell(x, y, z, spellId, triggered);
|
|
|
|
return true;
|
|
}
|
|
|
|
static bool HandleCastSelfCommand(ChatHandler* handler, char const* args)
|
|
{
|
|
if (!*args)
|
|
return false;
|
|
|
|
Unit* target = handler->getSelectedUnit();
|
|
if (!target)
|
|
{
|
|
handler->SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
|
|
handler->SetSentErrorMessage(true);
|
|
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;
|
|
|
|
SpellInfo const* spellInfo = sSpellMgr->GetSpellInfo(spellId);
|
|
if (!spellInfo)
|
|
{
|
|
handler->PSendSysMessage(LANG_COMMAND_NOSPELLFOUND);
|
|
handler->SetSentErrorMessage(true);
|
|
return false;
|
|
}
|
|
|
|
if (!SpellMgr::IsSpellValid(spellInfo))
|
|
{
|
|
handler->PSendSysMessage(LANG_COMMAND_SPELL_BROKEN, spellId);
|
|
handler->SetSentErrorMessage(true);
|
|
return false;
|
|
}
|
|
|
|
char* triggeredStr = strtok(nullptr, " ");
|
|
if (triggeredStr)
|
|
{
|
|
int l = strlen(triggeredStr);
|
|
if (strncmp(triggeredStr, "triggered", l) != 0)
|
|
return false;
|
|
}
|
|
|
|
bool triggered = (triggeredStr != nullptr);
|
|
|
|
target->CastSpell(target, spellId, triggered);
|
|
|
|
return true;
|
|
}
|
|
|
|
static bool HandleCastTargetCommad(ChatHandler* handler, char const* args)
|
|
{
|
|
Creature* caster = handler->getSelectedCreature();
|
|
if (!caster)
|
|
{
|
|
handler->SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
|
|
handler->SetSentErrorMessage(true);
|
|
return false;
|
|
}
|
|
|
|
if (!caster->GetVictim())
|
|
{
|
|
handler->SendSysMessage(LANG_SELECTED_TARGET_NOT_HAVE_VICTIM);
|
|
handler->SetSentErrorMessage(true);
|
|
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;
|
|
|
|
SpellInfo const* spellInfo = sSpellMgr->GetSpellInfo(spellId);
|
|
if (!spellInfo)
|
|
{
|
|
handler->PSendSysMessage(LANG_COMMAND_NOSPELLFOUND);
|
|
handler->SetSentErrorMessage(true);
|
|
return false;
|
|
}
|
|
|
|
if (!SpellMgr::IsSpellValid(spellInfo))
|
|
{
|
|
handler->PSendSysMessage(LANG_COMMAND_SPELL_BROKEN, spellId);
|
|
handler->SetSentErrorMessage(true);
|
|
return false;
|
|
}
|
|
|
|
char* triggeredStr = strtok(nullptr, " ");
|
|
if (triggeredStr)
|
|
{
|
|
int l = strlen(triggeredStr);
|
|
if (strncmp(triggeredStr, "triggered", l) != 0)
|
|
return false;
|
|
}
|
|
|
|
bool triggered = (triggeredStr != nullptr);
|
|
|
|
caster->CastSpell(caster->GetVictim(), spellId, triggered);
|
|
|
|
return true;
|
|
}
|
|
|
|
static bool HandleCastDestCommand(ChatHandler* handler, char const* args)
|
|
{
|
|
Unit* caster = handler->getSelectedUnit();
|
|
if (!caster)
|
|
{
|
|
handler->SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
|
|
handler->SetSentErrorMessage(true);
|
|
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;
|
|
|
|
SpellInfo const* spellInfo = sSpellMgr->GetSpellInfo(spellId);
|
|
if (!spellInfo)
|
|
{
|
|
handler->PSendSysMessage(LANG_COMMAND_NOSPELLFOUND);
|
|
handler->SetSentErrorMessage(true);
|
|
return false;
|
|
}
|
|
|
|
if (!SpellMgr::IsSpellValid(spellInfo))
|
|
{
|
|
handler->PSendSysMessage(LANG_COMMAND_SPELL_BROKEN, spellId);
|
|
handler->SetSentErrorMessage(true);
|
|
return false;
|
|
}
|
|
|
|
char* posX = strtok(nullptr, " ");
|
|
char* posY = strtok(nullptr, " ");
|
|
char* posZ = strtok(nullptr, " ");
|
|
|
|
if (!posX || !posY || !posZ)
|
|
return false;
|
|
|
|
float x = float(atof(posX));
|
|
float y = float(atof(posY));
|
|
float z = float(atof(posZ));
|
|
|
|
char* triggeredStr = strtok(nullptr, " ");
|
|
if (triggeredStr)
|
|
{
|
|
int l = strlen(triggeredStr);
|
|
if (strncmp(triggeredStr, "triggered", l) != 0)
|
|
return false;
|
|
}
|
|
|
|
bool triggered = (triggeredStr != nullptr);
|
|
|
|
caster->CastSpell(x, y, z, spellId, triggered);
|
|
|
|
return true;
|
|
}
|
|
};
|
|
|
|
void AddSC_cast_commandscript()
|
|
{
|
|
new cast_commandscript();
|
|
}
|