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: ScriptMgr.h:850

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:68
std::vector< ChatCommandBuilder > ChatCommandTable
Definition: ChatCommand.h:50
static bool HandleTitlesRemoveCommand(ChatHandler *handler, Variant< Hyperlink< title >, uint16 > titleId)
Definition: cs_titles.cpp:122
static bool HandleTitlesAddCommand(ChatHandler *handler, Variant< Hyperlink< title >, uint16 > titleId)
Definition: cs_titles.cpp:91
static bool HandleTitlesSetMaskCommand(ChatHandler *handler, uint64 mask)
Definition: cs_titles.cpp:161
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
92 {
93 Player* target = handler->getSelectedPlayer();
94 if (!target)
95 {
97 handler->SetSentErrorMessage(true);
98 return false;
99 }
100
101 // check online security
102 if (handler->HasLowerSecurity(target, ObjectGuid::Empty))
103 return false;
104
105 CharTitlesEntry const* titleInfo = sCharTitlesStore.LookupEntry(titleId);
106 if (!titleInfo)
107 {
108 handler->PSendSysMessage(LANG_INVALID_TITLE_ID, uint32(titleId));
109 handler->SetSentErrorMessage(true);
110 return false;
111 }
112
113 std::string tNameLink = handler->GetNameLink(target);
114 std::string titleNameStr = Acore::StringFormat(target->getGender() == GENDER_MALE ? titleInfo->nameMale[handler->GetSessionDbcLocale()] : titleInfo->nameFemale[handler->GetSessionDbcLocale()], target->GetName());
115
116 target->SetTitle(titleInfo);
117 handler->PSendSysMessage(LANG_TITLE_ADD_RES, uint32(titleId), titleNameStr, tNameLink);
118
119 return true;
120 }
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:60
std::string StringFormat(Format &&fmt, Args &&... args)
Default AC string format function.
Definition: StringFormat.h:29
virtual std::string GetNameLink() const
Definition: Chat.h:84
virtual LocaleConstant GetSessionDbcLocale() const
Definition: Chat.cpp:782
void SetSentErrorMessage(bool val)
Definition: Chat.h:118
void PSendSysMessage(char const *fmt, Args &&... args)
Definition: Chat.h:60
virtual void SendSysMessage(std::string_view str, bool escapeCharacters=false)
Definition: Chat.cpp:103
Player * getSelectedPlayer() const
Definition: Chat.cpp:301
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:1046
void SetTitle(CharTitlesEntry const *title, bool lost=false)
Definition: Player.cpp:13228
uint8 getGender() const
Definition: Unit.h:1428
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::SendSysMessage(), ChatHandler::SetSentErrorMessage(), 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 handler->SetSentErrorMessage(true);
65 return false;
66 }
67
68 // check online security
69 if (handler->HasLowerSecurity(target, ObjectGuid::Empty))
70 return false;
71
72 CharTitlesEntry const* titleInfo = sCharTitlesStore.LookupEntry(titleId);
73 if (!titleInfo)
74 {
76 handler->SetSentErrorMessage(true);
77 return false;
78 }
79
80 std::string tNameLink = handler->GetNameLink(target);
81 std::string titleNameStr = Acore::StringFormat(target->getGender() == GENDER_MALE ? titleInfo->nameMale[handler->GetSessionDbcLocale()] : titleInfo->nameFemale[handler->GetSessionDbcLocale()], target->GetName());
82
83 target->SetTitle(titleInfo);
84 target->SetUInt32Value(PLAYER_CHOSEN_TITLE, titleInfo->bit_index);
85
86 handler->PSendSysMessage(LANG_TITLE_CURRENT_RES, uint32(titleId), titleNameStr, tNameLink);
87
88 return true;
89 }
@ 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::SendSysMessage(), ChatHandler::SetSentErrorMessage(), Player::SetTitle(), Object::SetUInt32Value(), and Acore::StringFormat().

Referenced by GetCommands().

◆ HandleTitlesRemoveCommand()

static bool titles_commandscript::HandleTitlesRemoveCommand ( ChatHandler handler,
Variant< Hyperlink< title >, uint16 titleId 
)
inlinestatic
123 {
124 Player* target = handler->getSelectedPlayer();
125 if (!target)
126 {
128 handler->SetSentErrorMessage(true);
129 return false;
130 }
131
132 // check online security
133 if (handler->HasLowerSecurity(target, ObjectGuid::Empty))
134 return false;
135
136 CharTitlesEntry const* titleInfo = sCharTitlesStore.LookupEntry(titleId);
137 if (!titleInfo)
138 {
139 handler->PSendSysMessage(LANG_INVALID_TITLE_ID, uint32(titleId));
140 handler->SetSentErrorMessage(true);
141 return false;
142 }
143
144 target->SetTitle(titleInfo, true);
145
146 std::string tNameLink = handler->GetNameLink(target);
147 std::string titleNameStr = Acore::StringFormat(target->getGender() == GENDER_MALE ? titleInfo->nameMale[handler->GetSessionDbcLocale()] : titleInfo->nameFemale[handler->GetSessionDbcLocale()], target->GetName());
148
149 handler->PSendSysMessage(LANG_TITLE_REMOVE_RES, uint32(titleId), titleNameStr, tNameLink);
150
151 if (!target->HasTitle(target->GetInt32Value(PLAYER_CHOSEN_TITLE)))
152 {
154 handler->PSendSysMessage(LANG_CURRENT_TITLE_RESET, tNameLink);
155 }
156
157 return true;
158 }
@ 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:13218

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::SendSysMessage(), ChatHandler::SetSentErrorMessage(), Player::SetTitle(), Object::SetUInt32Value(), and Acore::StringFormat().

Referenced by GetCommands().

◆ HandleTitlesSetMaskCommand()

static bool titles_commandscript::HandleTitlesSetMaskCommand ( ChatHandler handler,
uint64  mask 
)
inlinestatic
162 {
163 Player* target = handler->getSelectedPlayer();
164 if (!target)
165 {
167 handler->SetSentErrorMessage(true);
168 return false;
169 }
170
171 // check online security
172 if (handler->HasLowerSecurity(target, ObjectGuid::Empty))
173 return false;
174
175 uint64 titles2 = mask;
176
177 for (uint32 i = 1; i < sCharTitlesStore.GetNumRows(); ++i)
178 if (CharTitlesEntry const* tEntry = sCharTitlesStore.LookupEntry(i))
179 titles2 &= ~(uint64(1) << tEntry->bit_index);
180
181 mask &= ~titles2; // remove non-existing titles
182
184 handler->SendSysMessage(LANG_DONE);
185
186 if (!target->HasTitle(target->GetInt32Value(PLAYER_CHOSEN_TITLE)))
187 {
189 handler->PSendSysMessage(LANG_CURRENT_TITLE_RESET, handler->GetNameLink(target));
190 }
191
192 return true;
193 }
std::uint64_t uint64
Definition: Define.h:107
@ PLAYER__FIELD_KNOWN_TITLES
Definition: UpdateFields.h:335
@ LANG_DONE
Definition: Language.h:75
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::SendSysMessage(), ChatHandler::SetSentErrorMessage(), Object::SetUInt32Value(), and Object::SetUInt64Value().

Referenced by GetCommands().