mirror of
https://github.com/mod-playerbots/azerothcore-wotlk.git
synced 2026-01-15 01:59:09 +00:00
feat(Core/CommandScript): New GM command "player learn" (#2487)
This commit is contained in:
@@ -10,6 +10,7 @@
|
||||
|
||||
set(scripts_STAT_SRCS
|
||||
${scripts_STAT_SRCS}
|
||||
Commands/PlayerCommand.cpp
|
||||
Commands/cs_account.cpp
|
||||
Commands/cs_achievement.cpp
|
||||
Commands/cs_arena.cpp
|
||||
@@ -46,6 +47,7 @@ set(scripts_STAT_SRCS
|
||||
Commands/cs_titles.cpp
|
||||
Commands/cs_wp.cpp
|
||||
Commands/cs_spectator.cpp
|
||||
Commands/cs_player.cpp
|
||||
# Commands/cs_pdump.cpp
|
||||
# Commands/cs_channel.cpp
|
||||
# Commands/cs_pet.cpp
|
||||
|
||||
86
src/server/scripts/Commands/PlayerCommand.cpp
Normal file
86
src/server/scripts/Commands/PlayerCommand.cpp
Normal file
@@ -0,0 +1,86 @@
|
||||
/*
|
||||
* Copyright (C) 2016+ AzerothCore <www.azerothcore.org>, released under GNU AGPL v3 license: https://github.com/azerothcore/azerothcore-wotlk/blob/master/LICENSE-AGPL3
|
||||
*/
|
||||
|
||||
#include "Chat.h"
|
||||
#include "ScriptMgr.h"
|
||||
#include "Language.h"
|
||||
#include "Player.h"
|
||||
#include "PlayerCommand.h"
|
||||
|
||||
bool PlayerCommand::Learn(ChatHandler* handler, Player* targetPlayer, uint32 spell, char const* all)
|
||||
{
|
||||
if (!spell)
|
||||
return false;
|
||||
|
||||
SpellInfo const* spellInfo = sSpellMgr->GetSpellInfo(spell);
|
||||
if (!spellInfo)
|
||||
{
|
||||
handler->PSendSysMessage(LANG_COMMAND_NOSPELLFOUND);
|
||||
handler->SetSentErrorMessage(true);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!SpellMgr::IsSpellValid(spellInfo))
|
||||
{
|
||||
handler->PSendSysMessage(LANG_COMMAND_SPELL_BROKEN, spell);
|
||||
handler->SetSentErrorMessage(true);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (handler->GetSession())
|
||||
{
|
||||
SpellScriptsBounds bounds = sObjectMgr->GetSpellScriptsBounds(spell);
|
||||
uint32 spellDifficultyId = sSpellMgr->GetSpellDifficultyId(spell);
|
||||
if (handler->GetSession() && handler->GetSession()->GetSecurity() < SEC_ADMINISTRATOR && (bounds.first != bounds.second || spellDifficultyId))
|
||||
{
|
||||
handler->PSendSysMessage("Spell %u cannot be learnt using a command!", spell);
|
||||
handler->SetSentErrorMessage(true);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool allRanks = all ? (strncmp(all, "all", 3) == 0) : false;
|
||||
|
||||
if (!allRanks && targetPlayer->HasSpell(spell))
|
||||
{
|
||||
if (targetPlayer == handler->GetSession()->GetPlayer())
|
||||
handler->SendSysMessage(LANG_YOU_KNOWN_SPELL);
|
||||
else
|
||||
handler->PSendSysMessage(LANG_TARGET_KNOWN_SPELL, handler->GetNameLink(targetPlayer).c_str());
|
||||
handler->SetSentErrorMessage(true);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (allRanks)
|
||||
targetPlayer->learnSpellHighRank(spell);
|
||||
else
|
||||
targetPlayer->learnSpell(spell);
|
||||
|
||||
uint32 firstSpell = sSpellMgr->GetFirstSpellInChain(spell);
|
||||
if (GetTalentSpellCost(firstSpell))
|
||||
targetPlayer->SendTalentsInfoData(false);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool PlayerCommand::UnLearn(ChatHandler* handler, Player* target, uint32 spellId, char const* allStr)
|
||||
{
|
||||
if (!spellId)
|
||||
return false;
|
||||
|
||||
bool allRanks = allStr ? (strncmp(allStr, "all", 3) == 0) : false;
|
||||
|
||||
if (allRanks)
|
||||
spellId = sSpellMgr->GetFirstSpellInChain (spellId);
|
||||
|
||||
if (target->HasSpell(spellId))
|
||||
target->removeSpell(spellId, SPEC_MASK_ALL, false);
|
||||
else
|
||||
handler->SendSysMessage(LANG_FORGET_SPELL);
|
||||
|
||||
if (GetTalentSpellCost(spellId))
|
||||
target->SendTalentsInfoData(false);
|
||||
|
||||
return true;
|
||||
}
|
||||
10
src/server/scripts/Commands/PlayerCommand.h
Normal file
10
src/server/scripts/Commands/PlayerCommand.h
Normal file
@@ -0,0 +1,10 @@
|
||||
/*
|
||||
* Copyright (C) 2016+ AzerothCore <www.azerothcore.org>, released under GNU AGPL v3 license: https://github.com/azerothcore/azerothcore-wotlk/blob/master/LICENSE-AGPL3
|
||||
*/
|
||||
|
||||
class PlayerCommand
|
||||
{
|
||||
public:
|
||||
static bool Learn(ChatHandler* handler, Player* targetPlayer, uint32 spell, char const* all);
|
||||
static bool UnLearn(ChatHandler* handler, Player* targetPlayer, uint32 spell, char const* all);
|
||||
};
|
||||
@@ -19,8 +19,9 @@ EndScriptData */
|
||||
#include "SpellInfo.h"
|
||||
#include "Player.h"
|
||||
#include "Pet.h"
|
||||
#include "PlayerCommand.h"
|
||||
|
||||
class learn_commandscript : public CommandScript
|
||||
class learn_commandscript : public CommandScript, public PlayerCommand
|
||||
{
|
||||
public:
|
||||
learn_commandscript() : CommandScript("learn_commandscript") { }
|
||||
@@ -37,7 +38,7 @@ public:
|
||||
|
||||
static std::vector<ChatCommand> learnAllCommandTable =
|
||||
{
|
||||
{ "my", SEC_GAMEMASTER, false, nullptr, "", learnAllMyCommandTable },
|
||||
{ "my", SEC_GAMEMASTER, false, nullptr, "", learnAllMyCommandTable },
|
||||
{ "gm", SEC_GAMEMASTER, false, &HandleLearnAllGMCommand, "" },
|
||||
{ "crafts", SEC_GAMEMASTER, false, &HandleLearnAllCraftsCommand, "" },
|
||||
{ "default", SEC_GAMEMASTER, false, &HandleLearnAllDefaultCommand, "" },
|
||||
@@ -47,13 +48,13 @@ public:
|
||||
|
||||
static std::vector<ChatCommand> learnCommandTable =
|
||||
{
|
||||
{ "all", SEC_GAMEMASTER, false, nullptr, "", learnAllCommandTable },
|
||||
{ "all", SEC_GAMEMASTER, false, nullptr, "", learnAllCommandTable },
|
||||
{ "", SEC_GAMEMASTER, false, &HandleLearnCommand, "" }
|
||||
};
|
||||
|
||||
static std::vector<ChatCommand> commandTable =
|
||||
{
|
||||
{ "learn", SEC_GAMEMASTER, false, nullptr, "", learnCommandTable },
|
||||
{ "learn", SEC_GAMEMASTER, false, nullptr, "", learnCommandTable },
|
||||
{ "unlearn", SEC_GAMEMASTER, false, &HandleUnLearnCommand, "" }
|
||||
};
|
||||
return commandTable;
|
||||
@@ -61,6 +62,9 @@ public:
|
||||
|
||||
static bool HandleLearnCommand(ChatHandler* handler, char const* args)
|
||||
{
|
||||
if (!*args)
|
||||
return false;
|
||||
|
||||
Player* targetPlayer = handler->getSelectedPlayer();
|
||||
|
||||
if (!targetPlayer)
|
||||
@@ -72,56 +76,8 @@ public:
|
||||
|
||||
// number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
|
||||
uint32 spell = handler->extractSpellIdFromLink((char*)args);
|
||||
if (!spell)
|
||||
return false;
|
||||
|
||||
SpellInfo const* spellInfo = sSpellMgr->GetSpellInfo(spell);
|
||||
if (!spellInfo)
|
||||
{
|
||||
handler->PSendSysMessage(LANG_COMMAND_NOSPELLFOUND);
|
||||
handler->SetSentErrorMessage(true);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!SpellMgr::IsSpellValid(spellInfo))
|
||||
{
|
||||
handler->PSendSysMessage(LANG_COMMAND_SPELL_BROKEN, spell);
|
||||
handler->SetSentErrorMessage(true);
|
||||
return false;
|
||||
}
|
||||
|
||||
SpellScriptsBounds bounds = sObjectMgr->GetSpellScriptsBounds(spell);
|
||||
uint32 spellDifficultyId = sSpellMgr->GetSpellDifficultyId(spell);
|
||||
if (handler->GetSession()->GetSecurity() < SEC_ADMINISTRATOR && (bounds.first != bounds.second || spellDifficultyId))
|
||||
{
|
||||
handler->PSendSysMessage("Spell %u cannot be learnt using a command!", spell);
|
||||
handler->SetSentErrorMessage(true);
|
||||
return false;
|
||||
}
|
||||
|
||||
char const* all = strtok(nullptr, " ");
|
||||
bool allRanks = all ? (strncmp(all, "all", strlen(all)) == 0) : false;
|
||||
|
||||
if (!allRanks && targetPlayer->HasSpell(spell))
|
||||
{
|
||||
if (targetPlayer == handler->GetSession()->GetPlayer())
|
||||
handler->SendSysMessage(LANG_YOU_KNOWN_SPELL);
|
||||
else
|
||||
handler->PSendSysMessage(LANG_TARGET_KNOWN_SPELL, handler->GetNameLink(targetPlayer).c_str());
|
||||
handler->SetSentErrorMessage(true);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (allRanks)
|
||||
targetPlayer->learnSpellHighRank(spell);
|
||||
else
|
||||
targetPlayer->learnSpell(spell);
|
||||
|
||||
uint32 firstSpell = sSpellMgr->GetFirstSpellInChain(spell);
|
||||
if (GetTalentSpellCost(firstSpell))
|
||||
targetPlayer->SendTalentsInfoData(false);
|
||||
|
||||
return true;
|
||||
return Learn(handler, targetPlayer, spell, all);
|
||||
}
|
||||
|
||||
static bool HandleLearnAllGMCommand(ChatHandler* handler, char const* /*args*/)
|
||||
@@ -476,14 +432,6 @@ public:
|
||||
if (!*args)
|
||||
return false;
|
||||
|
||||
// number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r
|
||||
uint32 spellId = handler->extractSpellIdFromLink((char*)args);
|
||||
if (!spellId)
|
||||
return false;
|
||||
|
||||
char const* allStr = strtok(nullptr, " ");
|
||||
bool allRanks = allStr ? (strncmp(allStr, "all", strlen(allStr)) == 0) : false;
|
||||
|
||||
Player* target = handler->getSelectedPlayer();
|
||||
if (!target)
|
||||
{
|
||||
@@ -492,18 +440,10 @@ public:
|
||||
return false;
|
||||
}
|
||||
|
||||
if (allRanks)
|
||||
spellId = sSpellMgr->GetFirstSpellInChain (spellId);
|
||||
|
||||
if (target->HasSpell(spellId))
|
||||
target->removeSpell(spellId, SPEC_MASK_ALL, false);
|
||||
else
|
||||
handler->SendSysMessage(LANG_FORGET_SPELL);
|
||||
|
||||
if (GetTalentSpellCost(spellId))
|
||||
target->SendTalentsInfoData(false);
|
||||
|
||||
return true;
|
||||
// number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r
|
||||
uint32 spellId = handler->extractSpellIdFromLink((char*)args);
|
||||
char const* allStr = strtok(nullptr, " ");
|
||||
return UnLearn(handler, target, spellId, allStr);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
93
src/server/scripts/Commands/cs_player.cpp
Normal file
93
src/server/scripts/Commands/cs_player.cpp
Normal file
@@ -0,0 +1,93 @@
|
||||
/*
|
||||
* Copyright (C) 2016+ AzerothCore <www.azerothcore.org>, released under GNU AGPL v3 license: https://github.com/azerothcore/azerothcore-wotlk/blob/master/LICENSE-AGPL3
|
||||
*/
|
||||
|
||||
#include "Chat.h"
|
||||
#include "ScriptMgr.h"
|
||||
#include "Language.h"
|
||||
#include "Player.h"
|
||||
#include "PlayerCommand.h"
|
||||
|
||||
class player_commandscript : public CommandScript, public PlayerCommand
|
||||
{
|
||||
public:
|
||||
player_commandscript() : CommandScript("player_commandscript") { }
|
||||
|
||||
std::vector<ChatCommand> GetCommands() const override
|
||||
{
|
||||
static std::vector<ChatCommand> playerCommandTable =
|
||||
{
|
||||
{ "learn", SEC_GAMEMASTER, true, &HandlePlayerLearnCommand, "" },
|
||||
{ "unlearn", SEC_GAMEMASTER, true, &HandlePlayerUnLearnCommand, "" }
|
||||
};
|
||||
|
||||
static std::vector<ChatCommand> 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 Learn(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 UnLearn(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();
|
||||
}
|
||||
@@ -62,6 +62,7 @@ void AddSC_tele_commandscript();
|
||||
void AddSC_ticket_commandscript();
|
||||
void AddSC_titles_commandscript();
|
||||
void AddSC_wp_commandscript();
|
||||
void AddSC_player_commandscript();
|
||||
|
||||
#ifdef SCRIPTS
|
||||
//world
|
||||
@@ -613,7 +614,7 @@ void AddCommandScripts()
|
||||
AddSC_character_commandscript();
|
||||
AddSC_cheat_commandscript();
|
||||
AddSC_debug_commandscript();
|
||||
AddSC_deserter_commandscript();
|
||||
AddSC_deserter_commandscript();
|
||||
AddSC_disable_commandscript();
|
||||
AddSC_event_commandscript();
|
||||
AddSC_gm_commandscript();
|
||||
@@ -639,6 +640,7 @@ void AddCommandScripts()
|
||||
AddSC_ticket_commandscript();
|
||||
AddSC_titles_commandscript();
|
||||
AddSC_wp_commandscript();
|
||||
AddSC_player_commandscript();
|
||||
}
|
||||
|
||||
void AddWorldScripts()
|
||||
|
||||
Reference in New Issue
Block a user