AzerothCore 3.3.5a
OpenSource WoW Emulator
Loading...
Searching...
No Matches
titles_commandscript Class Reference
Inheritance diagram for titles_commandscript:
CommandScript ScriptObject

Public Member Functions

 titles_commandscript ()
 
ChatCommandTable GetCommands () const override
 
virtual std::vector< Acore::ChatCommands::ChatCommandBuilderGetCommands () const =0
 
- Public Member Functions inherited from ScriptObject
virtual bool IsDatabaseBound () const
 
virtual bool isAfterLoadScript () const
 
virtual void checkValidity ()
 
const std::string & GetName () const
 

Static Public Member Functions

static bool HandleTitlesCurrentCommand (ChatHandler *handler, Variant< Hyperlink< title >, uint16 > titleId)
 
static bool HandleTitlesAddCommand (ChatHandler *handler, Variant< Hyperlink< title >, uint16 > titleId)
 
static bool HandleTitlesRemoveCommand (ChatHandler *handler, Variant< Hyperlink< title >, uint16 > titleId)
 
static bool HandleTitlesSetMaskCommand (ChatHandler *handler, uint64 mask)
 

Additional Inherited Members

- Protected Member Functions inherited from CommandScript
 CommandScript (const char *name)
 
- Protected Member Functions inherited from ScriptObject
 ScriptObject (const char *name)
 
virtual ~ScriptObject ()=default
 

Detailed Description

Constructor & Destructor Documentation

◆ titles_commandscript()

titles_commandscript::titles_commandscript ( )
inline
36: CommandScript("titles_commandscript") { }
Definition: CommandScript.h:25

Member Function Documentation

◆ GetCommands()

ChatCommandTable titles_commandscript::GetCommands ( ) const
inlineoverridevirtual

Implements CommandScript.

39 {
40 static ChatCommandTable titlesSetCommandTable =
41 {
42 { "mask", HandleTitlesSetMaskCommand, SEC_GAMEMASTER, Console::No },
43 };
44 static ChatCommandTable titlesCommandTable =
45 {
46 { "add", HandleTitlesAddCommand, SEC_GAMEMASTER, Console::No },
47 { "current", HandleTitlesCurrentCommand, SEC_GAMEMASTER, Console::No },
48 { "remove", HandleTitlesRemoveCommand, SEC_GAMEMASTER, Console::No },
49 { "set", titlesSetCommandTable },
50 };
51 static ChatCommandTable commandTable =
52 {
53 { "titles", titlesCommandTable },
54 };
55 return commandTable;
56 }
@ SEC_GAMEMASTER
Definition: Common.h:61
std::vector< ChatCommandBuilder > ChatCommandTable
Definition: ChatCommand.h:49
static bool HandleTitlesRemoveCommand(ChatHandler *handler, Variant< Hyperlink< title >, uint16 > titleId)
Definition: cs_titles.cpp:118
static bool HandleTitlesAddCommand(ChatHandler *handler, Variant< Hyperlink< title >, uint16 > titleId)
Definition: cs_titles.cpp:89
static bool HandleTitlesSetMaskCommand(ChatHandler *handler, uint64 mask)
Definition: cs_titles.cpp:155
static bool HandleTitlesCurrentCommand(ChatHandler *handler, Variant< Hyperlink< title >, uint16 > titleId)
Definition: cs_titles.cpp:58

References HandleTitlesAddCommand(), HandleTitlesCurrentCommand(), HandleTitlesRemoveCommand(), HandleTitlesSetMaskCommand(), and SEC_GAMEMASTER.

◆ HandleTitlesAddCommand()

static bool titles_commandscript::HandleTitlesAddCommand ( ChatHandler handler,
Variant< Hyperlink< title >, uint16 titleId 
)
inlinestatic
90 {
91 Player* target = handler->getSelectedPlayer();
92 if (!target)
93 {
95 return false;
96 }
97
98 // check online security
99 if (handler->HasLowerSecurity(target, ObjectGuid::Empty))
100 return false;
101
102 CharTitlesEntry const* titleInfo = sCharTitlesStore.LookupEntry(titleId);
103 if (!titleInfo)
104 {
106 return false;
107 }
108
109 std::string tNameLink = handler->GetNameLink(target);
110 std::string titleNameStr = Acore::StringFormat(target->getGender() == GENDER_MALE ? titleInfo->nameMale[handler->GetSessionDbcLocale()] : titleInfo->nameFemale[handler->GetSessionDbcLocale()], target->GetName());
111
112 target->SetTitle(titleInfo);
113 handler->PSendSysMessage(LANG_TITLE_ADD_RES, uint32(titleId), titleNameStr, tNameLink);
114
115 return true;
116 }
std::uint32_t uint32
Definition: Define.h:108
DBCStorage< CharTitlesEntry > sCharTitlesStore(CharTitlesEntryfmt)
@ LANG_TITLE_ADD_RES
Definition: Language.h:394
@ LANG_INVALID_TITLE_ID
Definition: Language.h:393
@ LANG_NO_CHAR_SELECTED
Definition: Language.h:148
@ GENDER_MALE
Definition: SharedDefines.h:61
std::string StringFormat(Format &&fmt, Args &&... args)
Default AC string format function.
Definition: StringFormat.h:30
virtual std::string GetNameLink() const
Definition: Chat.h:101
virtual LocaleConstant GetSessionDbcLocale() const
Definition: Chat.cpp:789
void SendErrorMessage(uint32 entry)
Definition: Chat.cpp:152
void PSendSysMessage(char const *fmt, Args &&... args)
Definition: Chat.h:60
Player * getSelectedPlayer() const
Definition: Chat.cpp:310
bool HasLowerSecurity(Player *target, ObjectGuid guid=ObjectGuid::Empty, bool strong=false)
Definition: Chat.cpp:53
std::string const & GetName() const
Definition: Object.h:446
static ObjectGuid const Empty
Definition: ObjectGuid.h:122
Definition: Player.h:1056
void SetTitle(CharTitlesEntry const *title, bool lost=false)
Definition: Player.cpp:13251
uint8 getGender() const
Definition: Unit.h:1440
Definition: DBCStructure.h:632
char const * nameMale[16]
Definition: DBCStructure.h:635
char const * nameFemale[16]
Definition: DBCStructure.h:637

References ObjectGuid::Empty, GENDER_MALE, Unit::getGender(), WorldObject::GetName(), ChatHandler::GetNameLink(), ChatHandler::getSelectedPlayer(), ChatHandler::GetSessionDbcLocale(), ChatHandler::HasLowerSecurity(), LANG_INVALID_TITLE_ID, LANG_NO_CHAR_SELECTED, LANG_TITLE_ADD_RES, CharTitlesEntry::nameFemale, CharTitlesEntry::nameMale, ChatHandler::PSendSysMessage(), sCharTitlesStore, ChatHandler::SendErrorMessage(), Player::SetTitle(), and Acore::StringFormat().

Referenced by GetCommands().

◆ HandleTitlesCurrentCommand()

static bool titles_commandscript::HandleTitlesCurrentCommand ( ChatHandler handler,
Variant< Hyperlink< title >, uint16 titleId 
)
inlinestatic
59 {
60 Player* target = handler->getSelectedPlayer();
61 if (!target)
62 {
64 return false;
65 }
66
67 // check online security
68 if (handler->HasLowerSecurity(target, ObjectGuid::Empty))
69 return false;
70
71 CharTitlesEntry const* titleInfo = sCharTitlesStore.LookupEntry(titleId);
72 if (!titleInfo)
73 {
75 return false;
76 }
77
78 std::string tNameLink = handler->GetNameLink(target);
79 std::string titleNameStr = Acore::StringFormat(target->getGender() == GENDER_MALE ? titleInfo->nameMale[handler->GetSessionDbcLocale()] : titleInfo->nameFemale[handler->GetSessionDbcLocale()], target->GetName());
80
81 target->SetTitle(titleInfo);
82 target->SetUInt32Value(PLAYER_CHOSEN_TITLE, titleInfo->bit_index);
83
84 handler->PSendSysMessage(LANG_TITLE_CURRENT_RES, uint32(titleId), titleNameStr, tNameLink);
85
86 return true;
87 }
@ PLAYER_CHOSEN_TITLE
Definition: UpdateFields.h:324
@ LANG_TITLE_CURRENT_RES
Definition: Language.h:396
void SetUInt32Value(uint16 index, uint32 value)
Definition: Object.cpp:650
uint32 bit_index
Definition: DBCStructure.h:639

References CharTitlesEntry::bit_index, ObjectGuid::Empty, GENDER_MALE, Unit::getGender(), WorldObject::GetName(), ChatHandler::GetNameLink(), ChatHandler::getSelectedPlayer(), ChatHandler::GetSessionDbcLocale(), ChatHandler::HasLowerSecurity(), LANG_INVALID_TITLE_ID, LANG_NO_CHAR_SELECTED, LANG_TITLE_CURRENT_RES, CharTitlesEntry::nameFemale, CharTitlesEntry::nameMale, PLAYER_CHOSEN_TITLE, ChatHandler::PSendSysMessage(), sCharTitlesStore, ChatHandler::SendErrorMessage(), Player::SetTitle(), Object::SetUInt32Value(), and Acore::StringFormat().

Referenced by GetCommands().

◆ HandleTitlesRemoveCommand()

static bool titles_commandscript::HandleTitlesRemoveCommand ( ChatHandler handler,
Variant< Hyperlink< title >, uint16 titleId 
)
inlinestatic
119 {
120 Player* target = handler->getSelectedPlayer();
121 if (!target)
122 {
124 return false;
125 }
126
127 // check online security
128 if (handler->HasLowerSecurity(target, ObjectGuid::Empty))
129 return false;
130
131 CharTitlesEntry const* titleInfo = sCharTitlesStore.LookupEntry(titleId);
132 if (!titleInfo)
133 {
135 return false;
136 }
137
138 target->SetTitle(titleInfo, true);
139
140 std::string tNameLink = handler->GetNameLink(target);
141 std::string titleNameStr = Acore::StringFormat(target->getGender() == GENDER_MALE ? titleInfo->nameMale[handler->GetSessionDbcLocale()] : titleInfo->nameFemale[handler->GetSessionDbcLocale()], target->GetName());
142
143 handler->PSendSysMessage(LANG_TITLE_REMOVE_RES, uint32(titleId), titleNameStr, tNameLink);
144
145 if (!target->HasTitle(target->GetInt32Value(PLAYER_CHOSEN_TITLE)))
146 {
148 handler->PSendSysMessage(LANG_CURRENT_TITLE_RESET, tNameLink);
149 }
150
151 return true;
152 }
@ LANG_TITLE_REMOVE_RES
Definition: Language.h:395
@ LANG_CURRENT_TITLE_RESET
Definition: Language.h:397
int32 GetInt32Value(uint16 index) const
Definition: Object.cpp:299
bool HasTitle(uint32 bitIndex) const
Definition: Player.cpp:13241

References ObjectGuid::Empty, GENDER_MALE, Unit::getGender(), Object::GetInt32Value(), WorldObject::GetName(), ChatHandler::GetNameLink(), ChatHandler::getSelectedPlayer(), ChatHandler::GetSessionDbcLocale(), ChatHandler::HasLowerSecurity(), Player::HasTitle(), LANG_CURRENT_TITLE_RESET, LANG_INVALID_TITLE_ID, LANG_NO_CHAR_SELECTED, LANG_TITLE_REMOVE_RES, CharTitlesEntry::nameFemale, CharTitlesEntry::nameMale, PLAYER_CHOSEN_TITLE, ChatHandler::PSendSysMessage(), sCharTitlesStore, ChatHandler::SendErrorMessage(), Player::SetTitle(), Object::SetUInt32Value(), and Acore::StringFormat().

Referenced by GetCommands().

◆ HandleTitlesSetMaskCommand()

static bool titles_commandscript::HandleTitlesSetMaskCommand ( ChatHandler handler,
uint64  mask 
)
inlinestatic
156 {
157 Player* target = handler->getSelectedPlayer();
158 if (!target)
159 {
161 return false;
162 }
163
164 // check online security
165 if (handler->HasLowerSecurity(target, ObjectGuid::Empty))
166 return false;
167
168 uint64 titles2 = mask;
169
170 for (uint32 i = 1; i < sCharTitlesStore.GetNumRows(); ++i)
171 if (CharTitlesEntry const* tEntry = sCharTitlesStore.LookupEntry(i))
172 titles2 &= ~(uint64(1) << tEntry->bit_index);
173
174 mask &= ~titles2; // remove non-existing titles
175
177 handler->SendSysMessage(LANG_DONE);
178
179 if (!target->HasTitle(target->GetInt32Value(PLAYER_CHOSEN_TITLE)))
180 {
182 handler->PSendSysMessage(LANG_CURRENT_TITLE_RESET, handler->GetNameLink(target));
183 }
184
185 return true;
186 }
std::uint64_t uint64
Definition: Define.h:107
@ PLAYER__FIELD_KNOWN_TITLES
Definition: UpdateFields.h:335
@ LANG_DONE
Definition: Language.h:75
virtual void SendSysMessage(std::string_view str, bool escapeCharacters=false)
Definition: Chat.cpp:101
void SetUInt64Value(uint16 index, uint64 value)
Definition: Object.cpp:671

References ObjectGuid::Empty, Object::GetInt32Value(), ChatHandler::GetNameLink(), ChatHandler::getSelectedPlayer(), ChatHandler::HasLowerSecurity(), Player::HasTitle(), LANG_CURRENT_TITLE_RESET, LANG_DONE, LANG_NO_CHAR_SELECTED, PLAYER__FIELD_KNOWN_TITLES, PLAYER_CHOSEN_TITLE, ChatHandler::PSendSysMessage(), sCharTitlesStore, ChatHandler::SendErrorMessage(), ChatHandler::SendSysMessage(), Object::SetUInt32Value(), and Object::SetUInt64Value().

Referenced by GetCommands().