mirror of
https://github.com/mod-playerbots/azerothcore-wotlk.git
synced 2026-01-21 20:56:23 +00:00
Using TC structure allowing easier patches importing
This commit is contained in:
235
src/server/scripts/Commands/cs_titles.cpp
Normal file
235
src/server/scripts/Commands/cs_titles.cpp
Normal file
@@ -0,0 +1,235 @@
|
||||
/*
|
||||
* Copyright (C) 2016+ AzerothCore <www.azerothcore.org>, released under GNU GPL v2 license: http://github.com/azerothcore/azerothcore-wotlk/LICENSE-GPL2
|
||||
* Copyright (C) 2008-2016 TrinityCore <http://www.trinitycore.org/>
|
||||
* Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
|
||||
*/
|
||||
|
||||
/* ScriptData
|
||||
Name: titles_commandscript
|
||||
%Complete: 100
|
||||
Comment: All titles related commands
|
||||
Category: commandscripts
|
||||
EndScriptData */
|
||||
|
||||
#include "Chat.h"
|
||||
#include "Language.h"
|
||||
#include "ObjectMgr.h"
|
||||
#include "Player.h"
|
||||
#include "ScriptMgr.h"
|
||||
|
||||
class titles_commandscript : public CommandScript
|
||||
{
|
||||
public:
|
||||
titles_commandscript() : CommandScript("titles_commandscript") { }
|
||||
|
||||
std::vector<ChatCommand> GetCommands() const override
|
||||
{
|
||||
static std::vector<ChatCommand> titlesSetCommandTable =
|
||||
{
|
||||
{ "mask", SEC_GAMEMASTER, false, &HandleTitlesSetMaskCommand, "" }
|
||||
};
|
||||
static std::vector<ChatCommand> titlesCommandTable =
|
||||
{
|
||||
{ "add", SEC_GAMEMASTER, false, &HandleTitlesAddCommand, "" },
|
||||
{ "current", SEC_GAMEMASTER, false, &HandleTitlesCurrentCommand, "" },
|
||||
{ "remove", SEC_GAMEMASTER, false, &HandleTitlesRemoveCommand, "" },
|
||||
{ "set", SEC_GAMEMASTER, false, nullptr, "", titlesSetCommandTable }
|
||||
};
|
||||
static std::vector<ChatCommand> commandTable =
|
||||
{
|
||||
{ "titles", SEC_GAMEMASTER, false, nullptr, "", titlesCommandTable }
|
||||
};
|
||||
return commandTable;
|
||||
}
|
||||
|
||||
static bool HandleTitlesCurrentCommand(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, 0))
|
||||
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);
|
||||
|
||||
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, 0))
|
||||
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());
|
||||
|
||||
target->SetTitle(titleInfo);
|
||||
handler->PSendSysMessage(LANG_TITLE_ADD_RES, id, titleNameStr, tNameLink.c_str());
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool HandleTitlesRemoveCommand(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;
|
||||
|
||||
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, 0))
|
||||
return false;
|
||||
|
||||
CharTitlesEntry const* titleInfo = sCharTitlesStore.LookupEntry(id);
|
||||
if (!titleInfo)
|
||||
{
|
||||
handler->PSendSysMessage(LANG_INVALID_TITLE_ID, id);
|
||||
handler->SetSentErrorMessage(true);
|
||||
return false;
|
||||
}
|
||||
|
||||
target->SetTitle(titleInfo, true);
|
||||
|
||||
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());
|
||||
|
||||
handler->PSendSysMessage(LANG_TITLE_REMOVE_RES, id, titleNameStr, tNameLink.c_str());
|
||||
|
||||
if (!target->HasTitle(target->GetInt32Value(PLAYER_CHOSEN_TITLE)))
|
||||
{
|
||||
target->SetUInt32Value(PLAYER_CHOSEN_TITLE, 0);
|
||||
handler->PSendSysMessage(LANG_CURRENT_TITLE_RESET, tNameLink.c_str());
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//Edit Player KnownTitles
|
||||
static bool HandleTitlesSetMaskCommand(ChatHandler* handler, char const* args)
|
||||
{
|
||||
if (!*args)
|
||||
return false;
|
||||
|
||||
uint64 titles = 0;
|
||||
|
||||
sscanf((char*)args, UI64FMTD, &titles);
|
||||
|
||||
Player* target = handler->getSelectedPlayer();
|
||||
if (!target)
|
||||
{
|
||||
handler->SendSysMessage(LANG_NO_CHAR_SELECTED);
|
||||
handler->SetSentErrorMessage(true);
|
||||
return false;
|
||||
}
|
||||
|
||||
// check online security
|
||||
if (handler->HasLowerSecurity(target, 0))
|
||||
return false;
|
||||
|
||||
uint64 titles2 = titles;
|
||||
|
||||
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
|
||||
|
||||
target->SetUInt64Value(PLAYER__FIELD_KNOWN_TITLES, titles);
|
||||
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());
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
void AddSC_titles_commandscript()
|
||||
{
|
||||
new titles_commandscript();
|
||||
}
|
||||
Reference in New Issue
Block a user