mirror of
https://github.com/mod-playerbots/azerothcore-wotlk.git
synced 2026-01-17 19:05:42 +00:00
refactor(Scripts/Commands): Convert commands to new system Part 1 (#8704)
This commit is contained in:
committed by
GitHub
parent
67b3ac442a
commit
fe682805ab
@@ -22,15 +22,11 @@ Comment: All titles related commands
|
||||
Category: commandscripts
|
||||
EndScriptData */
|
||||
|
||||
#include "Chat.h"
|
||||
#include "Language.h"
|
||||
#include "ObjectMgr.h"
|
||||
#include "Player.h"
|
||||
#include "ScriptMgr.h"
|
||||
|
||||
#if AC_COMPILER == AC_COMPILER_GNU
|
||||
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
|
||||
#endif
|
||||
#include "Chat.h"
|
||||
#include "DBCStores.h"
|
||||
#include "Language.h"
|
||||
#include "Player.h"
|
||||
|
||||
using namespace Acore::ChatCommands;
|
||||
|
||||
@@ -43,37 +39,24 @@ public:
|
||||
{
|
||||
static ChatCommandTable titlesSetCommandTable =
|
||||
{
|
||||
{ "mask", SEC_GAMEMASTER, false, &HandleTitlesSetMaskCommand, "" }
|
||||
{ "mask", HandleTitlesSetMaskCommand, SEC_GAMEMASTER, Console::No },
|
||||
};
|
||||
static ChatCommandTable titlesCommandTable =
|
||||
{
|
||||
{ "add", SEC_GAMEMASTER, false, &HandleTitlesAddCommand, "" },
|
||||
{ "current", SEC_GAMEMASTER, false, &HandleTitlesCurrentCommand, "" },
|
||||
{ "remove", SEC_GAMEMASTER, false, &HandleTitlesRemoveCommand, "" },
|
||||
{ "set", SEC_GAMEMASTER, false, nullptr, "", titlesSetCommandTable }
|
||||
{ "add", HandleTitlesAddCommand, SEC_GAMEMASTER, Console::No },
|
||||
{ "current", HandleTitlesCurrentCommand, SEC_GAMEMASTER, Console::No },
|
||||
{ "remove", HandleTitlesRemoveCommand, SEC_GAMEMASTER, Console::No },
|
||||
{ "set", titlesSetCommandTable },
|
||||
};
|
||||
static ChatCommandTable commandTable =
|
||||
{
|
||||
{ "titles", SEC_GAMEMASTER, false, nullptr, "", titlesCommandTable }
|
||||
{ "titles", titlesCommandTable },
|
||||
};
|
||||
return commandTable;
|
||||
}
|
||||
|
||||
static bool HandleTitlesCurrentCommand(ChatHandler* handler, const char* args)
|
||||
static bool HandleTitlesCurrentCommand(ChatHandler* handler, Variant<Hyperlink<title>, uint16> 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;
|
||||
|
||||
int32 id = atoi(id_p);
|
||||
if (id <= 0)
|
||||
{
|
||||
handler->PSendSysMessage(LANG_INVALID_TITLE_ID, id);
|
||||
handler->SetSentErrorMessage(true);
|
||||
return false;
|
||||
}
|
||||
|
||||
Player* target = handler->getSelectedPlayer();
|
||||
if (!target)
|
||||
{
|
||||
@@ -83,88 +66,30 @@ public:
|
||||
}
|
||||
|
||||
// check online security
|
||||
if (handler->HasLowerSecurity(target))
|
||||
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, uint32(titleId));
|
||||
handler->SetSentErrorMessage(true);
|
||||
return false;
|
||||
}
|
||||
|
||||
std::string tNameLink = handler->GetNameLink(target);
|
||||
|
||||
target->SetTitle(titleInfo); // to be sure that title now known
|
||||
target->SetUInt32Value(PLAYER_CHOSEN_TITLE, titleInfo->bit_index);
|
||||
|
||||
handler->PSendSysMessage(LANG_TITLE_CURRENT_RES, id, target->getGender() == GENDER_MALE ? titleInfo->nameMale[handler->GetSessionDbcLocale()] : titleInfo->nameFemale[handler->GetSessionDbcLocale()], tNameLink.c_str());
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool HandleTitlesAddCommand(ChatHandler* handler, const char* 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;
|
||||
|
||||
int32 id = atoi(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))
|
||||
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);
|
||||
|
||||
char titleNameStr[80];
|
||||
snprintf(titleNameStr, 80, target->getGender() == GENDER_MALE ? titleInfo->nameMale[handler->GetSessionDbcLocale()] : titleInfo->nameFemale[handler->GetSessionDbcLocale()], target->GetName().c_str());
|
||||
std::string titleNameStr = Acore::StringFormat(target->getGender() == GENDER_MALE ? titleInfo->nameMale[handler->GetSessionDbcLocale()] : titleInfo->nameFemale[handler->GetSessionDbcLocale()], target->GetName());
|
||||
|
||||
target->SetTitle(titleInfo);
|
||||
handler->PSendSysMessage(LANG_TITLE_ADD_RES, id, titleNameStr, tNameLink.c_str());
|
||||
target->SetUInt32Value(PLAYER_CHOSEN_TITLE, titleInfo->bit_index);
|
||||
|
||||
handler->PSendSysMessage(LANG_TITLE_CURRENT_RES, uint32(titleId), titleNameStr, tNameLink);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool HandleTitlesRemoveCommand(ChatHandler* handler, char const* args)
|
||||
static bool HandleTitlesAddCommand(ChatHandler* handler, Variant<Hyperlink<title>, uint16> 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;
|
||||
|
||||
int32 id = atoi(id_p);
|
||||
if (id <= 0)
|
||||
{
|
||||
handler->PSendSysMessage(LANG_INVALID_TITLE_ID, id);
|
||||
handler->SetSentErrorMessage(true);
|
||||
return false;
|
||||
}
|
||||
|
||||
Player* target = handler->getSelectedPlayer();
|
||||
if (!target)
|
||||
{
|
||||
@@ -174,13 +99,44 @@ public:
|
||||
}
|
||||
|
||||
// check online security
|
||||
if (handler->HasLowerSecurity(target))
|
||||
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, uint32(titleId));
|
||||
handler->SetSentErrorMessage(true);
|
||||
return false;
|
||||
}
|
||||
|
||||
std::string tNameLink = handler->GetNameLink(target);
|
||||
std::string titleNameStr = Acore::StringFormat(target->getGender() == GENDER_MALE ? titleInfo->nameMale[handler->GetSessionDbcLocale()] : titleInfo->nameFemale[handler->GetSessionDbcLocale()], target->GetName());
|
||||
|
||||
target->SetTitle(titleInfo);
|
||||
handler->PSendSysMessage(LANG_TITLE_ADD_RES, uint32(titleId), titleNameStr, tNameLink);
|
||||
|
||||
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, uint32(titleId));
|
||||
handler->SetSentErrorMessage(true);
|
||||
return false;
|
||||
}
|
||||
@@ -188,31 +144,22 @@ public:
|
||||
target->SetTitle(titleInfo, true);
|
||||
|
||||
std::string tNameLink = handler->GetNameLink(target);
|
||||
std::string titleNameStr = Acore::StringFormat(target->getGender() == GENDER_MALE ? titleInfo->nameMale[handler->GetSessionDbcLocale()] : titleInfo->nameFemale[handler->GetSessionDbcLocale()], target->GetName());
|
||||
|
||||
char titleNameStr[80];
|
||||
snprintf(titleNameStr, 80, target->getGender() == GENDER_MALE ? titleInfo->nameMale[handler->GetSessionDbcLocale()] : titleInfo->nameFemale[handler->GetSessionDbcLocale()], target->GetName().c_str());
|
||||
|
||||
handler->PSendSysMessage(LANG_TITLE_REMOVE_RES, id, titleNameStr, tNameLink.c_str());
|
||||
handler->PSendSysMessage(LANG_TITLE_REMOVE_RES, uint32(titleId), titleNameStr, tNameLink);
|
||||
|
||||
if (!target->HasTitle(target->GetInt32Value(PLAYER_CHOSEN_TITLE)))
|
||||
{
|
||||
target->SetUInt32Value(PLAYER_CHOSEN_TITLE, 0);
|
||||
handler->PSendSysMessage(LANG_CURRENT_TITLE_RESET, tNameLink.c_str());
|
||||
handler->PSendSysMessage(LANG_CURRENT_TITLE_RESET, tNameLink);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//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)
|
||||
{
|
||||
@@ -222,24 +169,24 @@ public:
|
||||
}
|
||||
|
||||
// check online security
|
||||
if (handler->HasLowerSecurity(target))
|
||||
if (handler->HasLowerSecurity(target, ObjectGuid::Empty))
|
||||
return false;
|
||||
|
||||
uint64 titles2 = titles;
|
||||
uint64 titles2 = mask;
|
||||
|
||||
for (uint32 i = 1; i < sCharTitlesStore.GetNumRows(); ++i)
|
||||
if (CharTitlesEntry const* tEntry = sCharTitlesStore.LookupEntry(i))
|
||||
titles2 &= ~(uint64(1) << tEntry->bit_index);
|
||||
|
||||
titles &= ~titles2; // remove not existed titles
|
||||
mask &= ~titles2; // remove non-existing titles
|
||||
|
||||
target->SetUInt64Value(PLAYER__FIELD_KNOWN_TITLES, titles);
|
||||
target->SetUInt64Value(PLAYER__FIELD_KNOWN_TITLES, mask);
|
||||
handler->SendSysMessage(LANG_DONE);
|
||||
|
||||
if (!target->HasTitle(target->GetInt32Value(PLAYER_CHOSEN_TITLE)))
|
||||
{
|
||||
target->SetUInt32Value(PLAYER_CHOSEN_TITLE, 0);
|
||||
handler->PSendSysMessage(LANG_CURRENT_TITLE_RESET, handler->GetNameLink(target).c_str());
|
||||
handler->PSendSysMessage(LANG_CURRENT_TITLE_RESET, handler->GetNameLink(target));
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
Reference in New Issue
Block a user