mirror of
https://github.com/TrinityCore/TrinityCore.git
synced 2026-01-25 19:31:59 +01:00
Convert misc commands in commandscript
This commit is contained in:
@@ -26,6 +26,7 @@ set(scripts_STAT_SRCS
|
||||
Commands/cs_learn.cpp
|
||||
Commands/cs_list.cpp
|
||||
Commands/cs_lookup.cpp
|
||||
Commands/cs_message.cpp
|
||||
Commands/cs_misc.cpp
|
||||
Commands/cs_modify.cpp
|
||||
Commands/cs_npc.cpp
|
||||
|
||||
@@ -60,6 +60,7 @@ public:
|
||||
static ChatCommand commandTable[] =
|
||||
{
|
||||
{ "character", SEC_GAMEMASTER, true, NULL, "", characterCommandTable},
|
||||
{ "levelup", SEC_ADMINISTRATOR, false, &HandleLevelUpCommand, "", NULL },
|
||||
{ NULL, 0, false, NULL, "", NULL }
|
||||
};
|
||||
return commandTable;
|
||||
@@ -218,6 +219,34 @@ public:
|
||||
sWorld->AddCharacterNameData(delInfo.lowGuid, delInfo.name, (*result)[2].GetUInt8(), (*result)[0].GetUInt8(), (*result)[1].GetUInt8());
|
||||
}
|
||||
|
||||
static void HandleCharacterLevel(Player* player, uint64 playerGuid, uint32 oldLevel, uint32 newLevel, ChatHandler* handler)
|
||||
{
|
||||
if (player)
|
||||
{
|
||||
player->GiveLevel(newLevel);
|
||||
player->InitTalentForLevel();
|
||||
player->SetUInt32Value(PLAYER_XP, 0);
|
||||
|
||||
if (handler->needReportToTarget(player))
|
||||
{
|
||||
if (oldLevel == newLevel)
|
||||
ChatHandler(player).PSendSysMessage(LANG_YOURS_LEVEL_PROGRESS_RESET, handler->GetNameLink().c_str());
|
||||
else if (oldLevel < newLevel)
|
||||
ChatHandler(player).PSendSysMessage(LANG_YOURS_LEVEL_UP, handler->GetNameLink().c_str(), newLevel);
|
||||
else // if (oldlevel > newlevel)
|
||||
ChatHandler(player).PSendSysMessage(LANG_YOURS_LEVEL_DOWN, handler->GetNameLink().c_str(), newLevel);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Update level and reset XP, everything else will be updated at login
|
||||
PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_UPD_LEVEL);
|
||||
stmt->setUInt8(0, uint8(newLevel));
|
||||
stmt->setUInt32(1, GUID_LOPART(playerGuid));
|
||||
CharacterDatabase.Execute(stmt);
|
||||
}
|
||||
}
|
||||
|
||||
static bool HandleCharacterTitlesCommand(ChatHandler* handler, char const* args)
|
||||
{
|
||||
if (!*args)
|
||||
@@ -326,7 +355,7 @@ public:
|
||||
if (newlevel > STRONG_MAX_LEVEL) // hardcoded maximum level
|
||||
newlevel = STRONG_MAX_LEVEL;
|
||||
|
||||
handler->HandleCharacterLevel(target, targetGuid, oldlevel, newlevel);
|
||||
HandleCharacterLevel(target, targetGuid, oldlevel, newlevel, handler);
|
||||
if (!handler->GetSession() || handler->GetSession()->GetPlayer() != target) // including player == NULL
|
||||
{
|
||||
std::string nameLink = handler->playerLink(targetName);
|
||||
@@ -671,6 +700,46 @@ public:
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool HandleLevelUpCommand(ChatHandler* handler, char const* args)
|
||||
{
|
||||
char* nameStr;
|
||||
char* levelStr;
|
||||
handler->extractOptFirstArg((char*)args, &nameStr, &levelStr);
|
||||
|
||||
// exception opt second arg: .character level $name
|
||||
if (levelStr && isalpha(levelStr[0]))
|
||||
{
|
||||
nameStr = levelStr;
|
||||
levelStr = NULL; // current level will used
|
||||
}
|
||||
|
||||
Player* target;
|
||||
uint64 targetGuid;
|
||||
std::string targetName;
|
||||
if (!handler->extractPlayerTarget(nameStr, &target, &targetGuid, &targetName))
|
||||
return false;
|
||||
|
||||
int32 oldlevel = target ? target->getLevel() : Player::GetLevelFromDB(targetGuid);
|
||||
int32 addlevel = levelStr ? atoi(levelStr) : 1;
|
||||
int32 newlevel = oldlevel + addlevel;
|
||||
|
||||
if (newlevel < 1)
|
||||
newlevel = 1;
|
||||
|
||||
if (newlevel > STRONG_MAX_LEVEL) // hardcoded maximum level
|
||||
newlevel = STRONG_MAX_LEVEL;
|
||||
|
||||
HandleCharacterLevel(target, targetGuid, oldlevel, newlevel, handler);
|
||||
|
||||
if (!handler->GetSession() || handler->GetSession()->GetPlayer() != target) // including chr == NULL
|
||||
{
|
||||
std::string nameLink = handler->playerLink(targetName);
|
||||
handler->PSendSysMessage(LANG_YOU_CHANGE_LVL, nameLink.c_str(), newlevel);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
void AddSC_character_commandscript()
|
||||
|
||||
@@ -22,10 +22,10 @@ Comment: All learn related commands
|
||||
Category: commandscripts
|
||||
EndScriptData */
|
||||
|
||||
#include "Chat.h"
|
||||
#include "ScriptMgr.h"
|
||||
#include "ObjectMgr.h"
|
||||
#include "SpellMgr.h"
|
||||
#include "Chat.h"
|
||||
#include "SpellInfo.h"
|
||||
|
||||
class learn_commandscript : public CommandScript
|
||||
@@ -37,35 +37,36 @@ public:
|
||||
{
|
||||
static ChatCommand learnAllMyCommandTable[] =
|
||||
{
|
||||
{ "class", SEC_ADMINISTRATOR, false, &HandleLearnAllMyClassCommand, "", NULL },
|
||||
{ "pettalents", SEC_ADMINISTRATOR, false, &HandleLearnAllMyPetTalentsCommand, "", NULL },
|
||||
{ "spells", SEC_ADMINISTRATOR, false, &HandleLearnAllMySpellsCommand, "", NULL },
|
||||
{ "talents", SEC_ADMINISTRATOR, false, &HandleLearnAllMyTalentsCommand, "", NULL },
|
||||
{ NULL, 0, false, NULL, "", NULL }
|
||||
{ "class", SEC_ADMINISTRATOR, false, &HandleLearnAllMyClassCommand, "", NULL },
|
||||
{ "pettalents", SEC_ADMINISTRATOR, false, &HandleLearnAllMyPetTalentsCommand, "", NULL },
|
||||
{ "spells", SEC_ADMINISTRATOR, false, &HandleLearnAllMySpellsCommand, "", NULL },
|
||||
{ "talents", SEC_ADMINISTRATOR, false, &HandleLearnAllMyTalentsCommand, "", NULL },
|
||||
{ NULL, 0, false, NULL, "", NULL }
|
||||
};
|
||||
|
||||
static ChatCommand learnAllCommandTable[] =
|
||||
{
|
||||
{ "my", SEC_ADMINISTRATOR, false, NULL, "", learnAllMyCommandTable },
|
||||
{ "gm", SEC_GAMEMASTER, false, &HandleLearnAllGMCommand, "", NULL },
|
||||
{ "crafts", SEC_GAMEMASTER, false, &HandleLearnAllCraftsCommand, "", NULL },
|
||||
{ "default", SEC_MODERATOR, false, &HandleLearnAllDefaultCommand, "", NULL },
|
||||
{ "lang", SEC_MODERATOR, false, &HandleLearnAllLangCommand, "", NULL },
|
||||
{ "recipes", SEC_GAMEMASTER, false, &HandleLearnAllRecipesCommand, "", NULL },
|
||||
{ NULL, 0, false, NULL, "", NULL }
|
||||
{ "my", SEC_ADMINISTRATOR, false, NULL, "", learnAllMyCommandTable },
|
||||
{ "gm", SEC_GAMEMASTER, false, &HandleLearnAllGMCommand, "", NULL },
|
||||
{ "crafts", SEC_GAMEMASTER, false, &HandleLearnAllCraftsCommand, "", NULL },
|
||||
{ "default", SEC_MODERATOR, false, &HandleLearnAllDefaultCommand, "", NULL },
|
||||
{ "lang", SEC_MODERATOR, false, &HandleLearnAllLangCommand, "", NULL },
|
||||
{ "recipes", SEC_GAMEMASTER, false, &HandleLearnAllRecipesCommand, "", NULL },
|
||||
{ NULL, 0, false, NULL, "", NULL }
|
||||
};
|
||||
|
||||
static ChatCommand learnCommandTable[] =
|
||||
{
|
||||
{ "all", SEC_ADMINISTRATOR, false, NULL, "", learnAllCommandTable },
|
||||
{ "", SEC_ADMINISTRATOR, false, &HandleLearnCommand, "", NULL },
|
||||
{ NULL, 0, false, NULL, "", NULL }
|
||||
{ "all", SEC_ADMINISTRATOR, false, NULL, "", learnAllCommandTable },
|
||||
{ "", SEC_ADMINISTRATOR, false, &HandleLearnCommand, "", NULL },
|
||||
{ NULL, 0, false, NULL, "", NULL }
|
||||
};
|
||||
|
||||
static ChatCommand commandTable[] =
|
||||
{
|
||||
{ "learn", SEC_MODERATOR, false, NULL, "", learnCommandTable },
|
||||
{ NULL, 0, false, NULL, "", NULL }
|
||||
{ "learn", SEC_MODERATOR, false, NULL, "", learnCommandTable },
|
||||
{ "unlearn", SEC_ADMINISTRATOR, false, &HandleUnLearnCommand, "", NULL },
|
||||
{ NULL, 0, false, NULL, "", NULL }
|
||||
};
|
||||
return commandTable;
|
||||
}
|
||||
@@ -466,6 +467,41 @@ public:
|
||||
player->learnSpell(skillLine->spellId, false);
|
||||
}
|
||||
}
|
||||
|
||||
static bool HandleUnLearnCommand(ChatHandler* handler, char const* args)
|
||||
{
|
||||
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(NULL, " ");
|
||||
bool allRanks = allStr ? (strncmp(allStr, "all", strlen(allStr)) == 0) : false;
|
||||
|
||||
Player* target = handler->getSelectedPlayer();
|
||||
if (!target)
|
||||
{
|
||||
handler->SendSysMessage(LANG_NO_CHAR_SELECTED);
|
||||
handler->SetSentErrorMessage(true);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (allRanks)
|
||||
spellId = sSpellMgr->GetFirstSpellInChain (spellId);
|
||||
|
||||
if (target->HasSpell(spellId))
|
||||
target->removeSpell(spellId, false, !allRanks);
|
||||
else
|
||||
handler->SendSysMessage(LANG_FORGET_SPELL);
|
||||
|
||||
if (GetTalentSpellCost(spellId))
|
||||
target->SendTalentsInfoData(false);
|
||||
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
void AddSC_learn_commandscript()
|
||||
|
||||
215
src/server/scripts/Commands/cs_message.cpp
Normal file
215
src/server/scripts/Commands/cs_message.cpp
Normal file
@@ -0,0 +1,215 @@
|
||||
/*
|
||||
* Copyright (C) 2008-2012 TrinityCore <http://www.trinitycore.org/>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the
|
||||
* Free Software Foundation; either version 2 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 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/>.
|
||||
*/
|
||||
|
||||
/* ScriptData
|
||||
Name: message_commandscript
|
||||
%Complete: 100
|
||||
Comment: All message related commands
|
||||
Category: commandscripts
|
||||
EndScriptData */
|
||||
|
||||
#include "ScriptMgr.h"
|
||||
#include "Chat.h"
|
||||
#include "ChannelMgr.h"
|
||||
|
||||
class message_commandscript : public CommandScript
|
||||
{
|
||||
public:
|
||||
message_commandscript() : CommandScript("message_commandscript") { }
|
||||
|
||||
ChatCommand* GetCommands() const
|
||||
{
|
||||
static ChatCommand channelSetCommandTable[] =
|
||||
{
|
||||
{ "ownership", SEC_ADMINISTRATOR, false, &HandleChannelSetOwnership, "", NULL },
|
||||
{ NULL, 0, false, NULL, "", NULL }
|
||||
};
|
||||
static ChatCommand channelCommandTable[] =
|
||||
{
|
||||
{ "set", SEC_ADMINISTRATOR, true, NULL, "", channelSetCommandTable },
|
||||
{ NULL, 0, false, NULL, "", NULL }
|
||||
};
|
||||
static ChatCommand commandTable[] =
|
||||
{
|
||||
{ "channel", SEC_ADMINISTRATOR, true, NULL, "", channelCommandTable },
|
||||
{ "nameannounce", SEC_MODERATOR, true, &HandleNameAnnounceCommand, "", NULL },
|
||||
{ "gmnameannounce", SEC_MODERATOR, true, &HandleGMNameAnnounceCommand, "", NULL },
|
||||
{ "announce", SEC_MODERATOR, true, &HandleAnnounceCommand, "", NULL },
|
||||
{ "gmannounce", SEC_MODERATOR, true, &HandleGMAnnounceCommand, "", NULL },
|
||||
{ "notify", SEC_MODERATOR, true, &HandleNotifyCommand, "", NULL },
|
||||
{ "gmnotify", SEC_MODERATOR, true, &HandleGMNotifyCommand, "", NULL },
|
||||
{ "whispers", SEC_MODERATOR, false, &HandleWhispersCommand, "", NULL },
|
||||
{ NULL, 0, false, NULL, "", NULL }
|
||||
};
|
||||
return commandTable;
|
||||
}
|
||||
|
||||
static bool HandleChannelSetOwnership(ChatHandler* handler, char const* args)
|
||||
{
|
||||
if (!*args)
|
||||
return false;
|
||||
char const* channelStr = strtok((char*)args, " ");
|
||||
char const* argStr = strtok(NULL, "");
|
||||
|
||||
if (!channelStr || !argStr)
|
||||
return false;
|
||||
|
||||
Player* player = handler->GetSession()->GetPlayer();
|
||||
Channel* channcel = NULL;
|
||||
|
||||
if (ChannelMgr* cMgr = channelMgr(player->GetTeam()))
|
||||
channcel = cMgr->GetChannel(channelStr, player);
|
||||
|
||||
if (strcmp(argStr, "on") == 0)
|
||||
{
|
||||
if (channcel)
|
||||
channcel->SetOwnership(true);
|
||||
PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_UPD_CHANNEL_OWNERSHIP);
|
||||
stmt->setUInt8 (0, 1);
|
||||
stmt->setString(1, channelStr);
|
||||
CharacterDatabase.Execute(stmt);
|
||||
handler->PSendSysMessage(LANG_CHANNEL_ENABLE_OWNERSHIP, channelStr);
|
||||
}
|
||||
else if (strcmp(argStr, "off") == 0)
|
||||
{
|
||||
if (channcel)
|
||||
channcel->SetOwnership(false);
|
||||
PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_UPD_CHANNEL_OWNERSHIP);
|
||||
stmt->setUInt8 (0, 0);
|
||||
stmt->setString(1, channelStr);
|
||||
CharacterDatabase.Execute(stmt);
|
||||
handler->PSendSysMessage(LANG_CHANNEL_DISABLE_OWNERSHIP, channelStr);
|
||||
}
|
||||
else
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool HandleNameAnnounceCommand(ChatHandler* handler, char const* args)
|
||||
{
|
||||
if (!*args)
|
||||
return false;
|
||||
|
||||
std::string name("Console");
|
||||
if (WorldSession* session = handler->GetSession())
|
||||
name = session->GetPlayer()->GetName();
|
||||
|
||||
sWorld->SendWorldText(LANG_ANNOUNCE_COLOR, name.c_str(), args);
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool HandleGMNameAnnounceCommand(ChatHandler* handler, char const* args)
|
||||
{
|
||||
if (!*args)
|
||||
return false;
|
||||
|
||||
std::string name("Console");
|
||||
if (WorldSession* session = handler->GetSession())
|
||||
name = session->GetPlayer()->GetName();
|
||||
|
||||
sWorld->SendGMText(LANG_GM_ANNOUNCE_COLOR, name.c_str(), args);
|
||||
return true;
|
||||
}
|
||||
// global announce
|
||||
static bool HandleAnnounceCommand(ChatHandler* handler, char const* args)
|
||||
{
|
||||
if (!*args)
|
||||
return false;
|
||||
|
||||
char buff[2048];
|
||||
sprintf(buff, handler->GetTrinityString(LANG_SYSTEMMESSAGE), args);
|
||||
sWorld->SendServerMessage(SERVER_MSG_STRING, buff);
|
||||
return true;
|
||||
}
|
||||
// announce to logged in GMs
|
||||
static bool HandleGMAnnounceCommand(ChatHandler* /*handler*/, char const* args)
|
||||
{
|
||||
if (!*args)
|
||||
return false;
|
||||
|
||||
sWorld->SendGMText(LANG_GM_BROADCAST, args);
|
||||
return true;
|
||||
}
|
||||
// notification player at the screen
|
||||
static bool HandleNotifyCommand(ChatHandler* handler, char const* args)
|
||||
{
|
||||
if (!*args)
|
||||
return false;
|
||||
|
||||
std::string str = handler->GetTrinityString(LANG_GLOBAL_NOTIFY);
|
||||
str += args;
|
||||
|
||||
WorldPacket data(SMSG_NOTIFICATION, (str.size()+1));
|
||||
data << str;
|
||||
sWorld->SendGlobalMessage(&data);
|
||||
|
||||
return true;
|
||||
}
|
||||
// notification GM at the screen
|
||||
static bool HandleGMNotifyCommand(ChatHandler* handler, char const* args)
|
||||
{
|
||||
if (!*args)
|
||||
return false;
|
||||
|
||||
std::string str = handler->GetTrinityString(LANG_GM_NOTIFY);
|
||||
str += args;
|
||||
|
||||
WorldPacket data(SMSG_NOTIFICATION, (str.size()+1));
|
||||
data << str;
|
||||
sWorld->SendGlobalGMMessage(&data);
|
||||
|
||||
return true;
|
||||
}
|
||||
// Enable\Dissable accept whispers (for GM)
|
||||
static bool HandleWhispersCommand(ChatHandler* handler, char const* args)
|
||||
{
|
||||
if (!*args)
|
||||
{
|
||||
handler->PSendSysMessage(LANG_COMMAND_WHISPERACCEPTING, handler->GetSession()->GetPlayer()->isAcceptWhispers() ? handler->GetTrinityString(LANG_ON) : handler->GetTrinityString(LANG_OFF));
|
||||
return true;
|
||||
}
|
||||
|
||||
std::string argStr = (char*)args;
|
||||
// whisper on
|
||||
if (argStr == "on")
|
||||
{
|
||||
handler->GetSession()->GetPlayer()->SetAcceptWhispers(true);
|
||||
handler->SendSysMessage(LANG_COMMAND_WHISPERON);
|
||||
return true;
|
||||
}
|
||||
|
||||
// whisper off
|
||||
if (argStr == "off")
|
||||
{
|
||||
// Remove all players from the Gamemaster's whisper whitelist
|
||||
handler->GetSession()->GetPlayer()->ClearWhisperWhiteList();
|
||||
handler->GetSession()->GetPlayer()->SetAcceptWhispers(false);
|
||||
handler->SendSysMessage(LANG_COMMAND_WHISPEROFF);
|
||||
return true;
|
||||
}
|
||||
|
||||
handler->SendSysMessage(LANG_USE_BOL);
|
||||
handler->SetSentErrorMessage(true);
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
void AddSC_message_commandscript()
|
||||
{
|
||||
new message_commandscript();
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user