mirror of
https://github.com/liyunfan1223/azerothcore-wotlk.git
synced 2026-08-05 22:37:57 +00:00
122 lines
3.5 KiB
C++
122 lines
3.5 KiB
C++
/*
|
|
* This file is part of the AzerothCore Project. See AUTHORS file for Copyright information
|
|
*
|
|
* This program is free software; you can redistribute it and/or modify it
|
|
* under the terms of the GNU Affero General Public License as published by the
|
|
* Free Software Foundation; either version 3 of the License, or (at your
|
|
* option) any later version.
|
|
*
|
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for
|
|
* more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License along
|
|
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
#include "ScriptMgr.h"
|
|
#include "Language.h"
|
|
#include "PlayerCommand.h"
|
|
|
|
#if AC_COMPILER == AC_COMPILER_GNU
|
|
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
|
|
#endif
|
|
|
|
using namespace Acore::ChatCommands;
|
|
|
|
class player_commandscript : public CommandScript
|
|
{
|
|
public:
|
|
player_commandscript() : CommandScript("player_commandscript") { }
|
|
|
|
ChatCommandTable GetCommands() const override
|
|
{
|
|
static ChatCommandTable playerCommandTable =
|
|
{
|
|
{ "learn", SEC_GAMEMASTER, true, &HandlePlayerLearnCommand, "" },
|
|
{ "unlearn", SEC_GAMEMASTER, true, &HandlePlayerUnLearnCommand, "" }
|
|
};
|
|
|
|
static ChatCommandTable commandTable =
|
|
{
|
|
{ "player", SEC_GAMEMASTER, true, nullptr, "", playerCommandTable }
|
|
};
|
|
return commandTable;
|
|
}
|
|
|
|
static bool HandlePlayerLearnCommand(ChatHandler* handler, char const* args)
|
|
{
|
|
if (!*args)
|
|
return false;
|
|
|
|
char* playerName = strtok((char*)args, " ");
|
|
char* spellId = strtok(nullptr, " ");
|
|
char const* all = strtok(nullptr, " ");
|
|
Player* targetPlayer = FindPlayer(handler, playerName);
|
|
if (!spellId || !targetPlayer)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
uint32 spell = handler->extractSpellIdFromLink(spellId);
|
|
|
|
if (!spell)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
return Acore::PlayerCommand::HandleLearnSpellCommand(handler, targetPlayer, spell, all);
|
|
}
|
|
|
|
static bool HandlePlayerUnLearnCommand(ChatHandler* handler, char const* args)
|
|
{
|
|
if (!*args)
|
|
return false;
|
|
|
|
char* playerName = strtok((char*)args, " ");
|
|
char* spellId = strtok(nullptr, " ");
|
|
char const* all = strtok(nullptr, " ");
|
|
Player* targetPlayer = FindPlayer(handler, playerName);
|
|
|
|
if (!spellId || !targetPlayer)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
uint32 spell = handler->extractSpellIdFromLink(spellId);
|
|
|
|
if (!spell)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
return Acore::PlayerCommand::HandleUnlearnSpellCommand(handler, targetPlayer, spell, all);
|
|
}
|
|
|
|
private:
|
|
static Player* FindPlayer(ChatHandler* handler, char* playerName)
|
|
{
|
|
if (!playerName)
|
|
return nullptr;
|
|
|
|
Player* targetPlayer;
|
|
if (!handler->extractPlayerTarget(playerName, &targetPlayer))
|
|
return nullptr;
|
|
|
|
if (!targetPlayer)
|
|
{
|
|
handler->SendSysMessage(LANG_PLAYER_NOT_FOUND);
|
|
handler->SetSentErrorMessage(true);
|
|
return nullptr;
|
|
}
|
|
|
|
return targetPlayer;
|
|
}
|
|
};
|
|
|
|
void AddSC_player_commandscript()
|
|
{
|
|
new player_commandscript();
|
|
}
|