mirror of
https://github.com/TrinityCore/TrinityCore.git
synced 2026-01-23 02:25:38 +01:00
Scripts/Commands: Convert title commands to new system
(cherry picked from commit cd1ef2de06)
This commit is contained in:
@@ -630,11 +630,11 @@ enum RBACPermissions
|
||||
RBAC_PERM_COMMAND_TICKET_UNASSIGN = 758, // deprecated since Draenor DON'T reuse
|
||||
RBAC_PERM_COMMAND_TICKET_VIEWID = 759, // deprecated since Draenor DON'T reuse
|
||||
RBAC_PERM_COMMAND_TICKET_VIEWNAME = 760, // deprecated since Draenor DON'T reuse
|
||||
RBAC_PERM_COMMAND_TITLES = 761,
|
||||
// 761 previously used, do not reuse
|
||||
RBAC_PERM_COMMAND_TITLES_ADD = 762,
|
||||
RBAC_PERM_COMMAND_TITLES_CURRENT = 763,
|
||||
RBAC_PERM_COMMAND_TITLES_REMOVE = 764,
|
||||
RBAC_PERM_COMMAND_TITLES_SET = 765,
|
||||
// 765 previously used, do not reuse
|
||||
RBAC_PERM_COMMAND_TITLES_SET_MASK = 766,
|
||||
RBAC_PERM_COMMAND_WP = 767,
|
||||
RBAC_PERM_COMMAND_WP_ADD = 768,
|
||||
|
||||
@@ -30,50 +30,35 @@ EndScriptData */
|
||||
#include "Player.h"
|
||||
#include "RBAC.h"
|
||||
|
||||
#if TRINITY_COMPILER == TRINITY_COMPILER_GNU
|
||||
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
|
||||
#endif
|
||||
using namespace Trinity::ChatCommands;
|
||||
|
||||
class titles_commandscript : public CommandScript
|
||||
{
|
||||
public:
|
||||
titles_commandscript() : CommandScript("titles_commandscript") { }
|
||||
|
||||
std::vector<ChatCommand> GetCommands() const override
|
||||
ChatCommandTable GetCommands() const override
|
||||
{
|
||||
static std::vector<ChatCommand> titlesSetCommandTable =
|
||||
static ChatCommandTable titlesSetCommandTable =
|
||||
{
|
||||
{ "mask", rbac::RBAC_PERM_COMMAND_TITLES_SET_MASK, false, &HandleTitlesSetMaskCommand, "" },
|
||||
{ "mask", HandleTitlesSetMaskCommand, rbac::RBAC_PERM_COMMAND_TITLES_SET_MASK, Console::No },
|
||||
};
|
||||
static std::vector<ChatCommand> titlesCommandTable =
|
||||
static ChatCommandTable titlesCommandTable =
|
||||
{
|
||||
{ "add", rbac::RBAC_PERM_COMMAND_TITLES_ADD, false, &HandleTitlesAddCommand, "" },
|
||||
{ "current", rbac::RBAC_PERM_COMMAND_TITLES_CURRENT, false, &HandleTitlesCurrentCommand, "" },
|
||||
{ "remove", rbac::RBAC_PERM_COMMAND_TITLES_REMOVE, false, &HandleTitlesRemoveCommand, "" },
|
||||
{ "set", rbac::RBAC_PERM_COMMAND_TITLES_SET, false, nullptr, "", titlesSetCommandTable },
|
||||
{ "add", HandleTitlesAddCommand, rbac::RBAC_PERM_COMMAND_TITLES_ADD, Console::No },
|
||||
{ "current", HandleTitlesCurrentCommand, rbac::RBAC_PERM_COMMAND_TITLES_CURRENT, Console::No },
|
||||
{ "remove", HandleTitlesRemoveCommand, rbac::RBAC_PERM_COMMAND_TITLES_REMOVE, Console::No },
|
||||
{ "set", titlesSetCommandTable },
|
||||
};
|
||||
static std::vector<ChatCommand> commandTable =
|
||||
static ChatCommandTable commandTable =
|
||||
{
|
||||
{ "titles", rbac::RBAC_PERM_COMMAND_TITLES, false, nullptr, "", titlesCommandTable },
|
||||
{ "titles", titlesCommandTable },
|
||||
};
|
||||
return commandTable;
|
||||
}
|
||||
|
||||
static bool HandleTitlesCurrentCommand(ChatHandler* handler, char const* args)
|
||||
static bool HandleTitlesCurrentCommand(ChatHandler* handler, Variant<Hyperlink<title>, uint32> titleId)
|
||||
{
|
||||
// number or [name] Shift-click form |color|Htitle:title_id|h[name]|h|r
|
||||
char* id_p = handler->extractKeyFromLink((char*)args, "Htitle");
|
||||
if (!id_p)
|
||||
return false;
|
||||
|
||||
uint32 id = atoul(id_p);
|
||||
if (id == 0)
|
||||
{
|
||||
handler->PSendSysMessage(LANG_INVALID_TITLE_ID, id);
|
||||
handler->SetSentErrorMessage(true);
|
||||
return false;
|
||||
}
|
||||
|
||||
Player* target = handler->getSelectedPlayer();
|
||||
if (!target)
|
||||
{
|
||||
@@ -86,88 +71,27 @@ public:
|
||||
if (handler->HasLowerSecurity(target, ObjectGuid::Empty))
|
||||
return false;
|
||||
|
||||
CharTitlesEntry const* titleInfo = sCharTitlesStore.LookupEntry(id);
|
||||
CharTitlesEntry const* titleInfo = sCharTitlesStore.LookupEntry(titleId);
|
||||
if (!titleInfo)
|
||||
{
|
||||
handler->PSendSysMessage(LANG_INVALID_TITLE_ID, id);
|
||||
handler->PSendSysMessage(LANG_INVALID_TITLE_ID, titleId);
|
||||
handler->SetSentErrorMessage(true);
|
||||
return false;
|
||||
}
|
||||
|
||||
std::string tNameLink = handler->GetNameLink(target);
|
||||
|
||||
target->SetTitle(titleInfo); // to be sure that title now known
|
||||
target->SetChosenTitle(titleInfo->MaskID);
|
||||
|
||||
handler->PSendSysMessage(LANG_TITLE_CURRENT_RES, id,
|
||||
(target->GetNativeGender() == GENDER_MALE ? titleInfo->Name : titleInfo->Name1)[handler->GetSessionDbcLocale()],
|
||||
tNameLink.c_str());
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool HandleTitlesAddCommand(ChatHandler* handler, char const* args)
|
||||
{
|
||||
// number or [name] Shift-click form |color|Htitle:title_id|h[name]|h|r
|
||||
char* id_p = handler->extractKeyFromLink((char*)args, "Htitle");
|
||||
if (!id_p)
|
||||
return false;
|
||||
|
||||
uint32 id = atoul(id_p);
|
||||
if (id == 0)
|
||||
{
|
||||
handler->PSendSysMessage(LANG_INVALID_TITLE_ID, id);
|
||||
handler->SetSentErrorMessage(true);
|
||||
return false;
|
||||
}
|
||||
|
||||
Player* target = handler->getSelectedPlayer();
|
||||
if (!target)
|
||||
{
|
||||
handler->SendSysMessage(LANG_NO_CHAR_SELECTED);
|
||||
handler->SetSentErrorMessage(true);
|
||||
return false;
|
||||
}
|
||||
|
||||
// check online security
|
||||
if (handler->HasLowerSecurity(target, ObjectGuid::Empty))
|
||||
return false;
|
||||
|
||||
CharTitlesEntry const* titleInfo = sCharTitlesStore.LookupEntry(id);
|
||||
if (!titleInfo)
|
||||
{
|
||||
handler->PSendSysMessage(LANG_INVALID_TITLE_ID, id);
|
||||
handler->SetSentErrorMessage(true);
|
||||
return false;
|
||||
}
|
||||
|
||||
std::string tNameLink = handler->GetNameLink(target);
|
||||
|
||||
std::string titleNameStr = Trinity::StringFormat(
|
||||
(target->GetNativeGender() == GENDER_MALE ? titleInfo->Name : titleInfo->Name1)[handler->GetSessionDbcLocale()],
|
||||
target->GetName().c_str()
|
||||
);
|
||||
std::string titleNameStr = Trinity::StringFormat(target->GetNativeGender() == GENDER_MALE ? titleInfo->Name[handler->GetSessionDbcLocale()] : titleInfo->Name1[handler->GetSessionDbcLocale()], target->GetName());
|
||||
|
||||
target->SetTitle(titleInfo);
|
||||
handler->PSendSysMessage(LANG_TITLE_ADD_RES, id, titleNameStr.c_str(), tNameLink.c_str());
|
||||
target->SetChosenTitle(titleInfo->MaskID);
|
||||
|
||||
handler->PSendSysMessage(LANG_TITLE_CURRENT_RES, titleId, titleNameStr.c_str(), tNameLink.c_str());
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool HandleTitlesRemoveCommand(ChatHandler* handler, char const* args)
|
||||
static bool HandleTitlesAddCommand(ChatHandler* handler, Variant<Hyperlink<title>, uint32> titleId)
|
||||
{
|
||||
// number or [name] Shift-click form |color|Htitle:title_id|h[name]|h|r
|
||||
char* id_p = handler->extractKeyFromLink((char*)args, "Htitle");
|
||||
if (!id_p)
|
||||
return false;
|
||||
|
||||
uint32 id = atoul(id_p);
|
||||
if (id == 0)
|
||||
{
|
||||
handler->PSendSysMessage(LANG_INVALID_TITLE_ID, id);
|
||||
handler->SetSentErrorMessage(true);
|
||||
return false;
|
||||
}
|
||||
|
||||
Player* target = handler->getSelectedPlayer();
|
||||
if (!target)
|
||||
{
|
||||
@@ -180,10 +104,41 @@ public:
|
||||
if (handler->HasLowerSecurity(target, ObjectGuid::Empty))
|
||||
return false;
|
||||
|
||||
CharTitlesEntry const* titleInfo = sCharTitlesStore.LookupEntry(id);
|
||||
CharTitlesEntry const* titleInfo = sCharTitlesStore.LookupEntry(titleId);
|
||||
if (!titleInfo)
|
||||
{
|
||||
handler->PSendSysMessage(LANG_INVALID_TITLE_ID, id);
|
||||
handler->PSendSysMessage(LANG_INVALID_TITLE_ID, titleId);
|
||||
handler->SetSentErrorMessage(true);
|
||||
return false;
|
||||
}
|
||||
|
||||
std::string tNameLink = handler->GetNameLink(target);
|
||||
std::string titleNameStr = Trinity::StringFormat(target->GetNativeGender() == GENDER_MALE ? titleInfo->Name[handler->GetSessionDbcLocale()] : titleInfo->Name1[handler->GetSessionDbcLocale()], target->GetName());
|
||||
|
||||
target->SetTitle(titleInfo);
|
||||
handler->PSendSysMessage(LANG_TITLE_ADD_RES, titleId, titleNameStr.c_str(), tNameLink.c_str());
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool HandleTitlesRemoveCommand(ChatHandler* handler, Variant<Hyperlink<title>, uint16> titleId)
|
||||
{
|
||||
Player* target = handler->getSelectedPlayer();
|
||||
if (!target)
|
||||
{
|
||||
handler->SendSysMessage(LANG_NO_CHAR_SELECTED);
|
||||
handler->SetSentErrorMessage(true);
|
||||
return false;
|
||||
}
|
||||
|
||||
// check online security
|
||||
if (handler->HasLowerSecurity(target, ObjectGuid::Empty))
|
||||
return false;
|
||||
|
||||
CharTitlesEntry const* titleInfo = sCharTitlesStore.LookupEntry(titleId);
|
||||
if (!titleInfo)
|
||||
{
|
||||
handler->PSendSysMessage(LANG_INVALID_TITLE_ID, titleId);
|
||||
handler->SetSentErrorMessage(true);
|
||||
return false;
|
||||
}
|
||||
@@ -191,13 +146,9 @@ public:
|
||||
target->SetTitle(titleInfo, true);
|
||||
|
||||
std::string tNameLink = handler->GetNameLink(target);
|
||||
std::string titleNameStr = Trinity::StringFormat(target->GetNativeGender() == GENDER_MALE ? titleInfo->Name[handler->GetSessionDbcLocale()] : titleInfo->Name1[handler->GetSessionDbcLocale()], target->GetName());
|
||||
|
||||
std::string titleNameStr = Trinity::StringFormat(
|
||||
(target->GetNativeGender() == GENDER_MALE ? titleInfo->Name : titleInfo->Name1)[handler->GetSessionDbcLocale()],
|
||||
target->GetName().c_str()
|
||||
);
|
||||
|
||||
handler->PSendSysMessage(LANG_TITLE_REMOVE_RES, id, titleNameStr.c_str(), tNameLink.c_str());
|
||||
handler->PSendSysMessage(LANG_TITLE_REMOVE_RES, titleId, titleNameStr.c_str(), tNameLink.c_str());
|
||||
|
||||
if (!target->HasTitle(target->m_playerData->PlayerTitle))
|
||||
{
|
||||
@@ -209,15 +160,8 @@ public:
|
||||
}
|
||||
|
||||
//Edit Player KnownTitles
|
||||
static bool HandleTitlesSetMaskCommand(ChatHandler* handler, char const* args)
|
||||
static bool HandleTitlesSetMaskCommand(ChatHandler* handler, uint64 mask)
|
||||
{
|
||||
if (!*args)
|
||||
return false;
|
||||
|
||||
uint64 titles = 0;
|
||||
|
||||
sscanf((char*)args, UI64FMTD, &titles);
|
||||
|
||||
Player* target = handler->getSelectedPlayer();
|
||||
if (!target)
|
||||
{
|
||||
@@ -230,15 +174,15 @@ public:
|
||||
if (handler->HasLowerSecurity(target, ObjectGuid::Empty))
|
||||
return false;
|
||||
|
||||
uint64 titles2 = titles;
|
||||
uint64 titles2 = mask;
|
||||
|
||||
for (uint32 i = 1; i < sCharTitlesStore.GetNumRows(); ++i)
|
||||
for (uint32 i = 1; i < sCharTitlesStore.GetNumRows() && i < 64; ++i)
|
||||
if (CharTitlesEntry const* tEntry = sCharTitlesStore.LookupEntry(i))
|
||||
titles2 &= ~(uint64(1) << tEntry->MaskID);
|
||||
|
||||
titles &= ~titles2; // remove non-existing titles
|
||||
mask &= ~titles2; // remove non-existing titles
|
||||
|
||||
target->SetKnownTitles(0, titles);
|
||||
target->SetKnownTitles(0, mask);
|
||||
handler->SendSysMessage(LANG_DONE);
|
||||
|
||||
if (!target->HasTitle(target->m_playerData->PlayerTitle))
|
||||
|
||||
Reference in New Issue
Block a user