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
 
uint16 GetTotalAvailableHooks ()
 

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, uint16 totalAvailableHooks=0)
 
virtual ~ScriptObject ()=default
 

Detailed Description

Constructor & Destructor Documentation

◆ titles_commandscript()

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

Member Function Documentation

◆ GetCommands()

ChatCommandTable titles_commandscript::GetCommands ( ) const
inlineoverridevirtual

Implements CommandScript.

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

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

◆ HandleTitlesAddCommand()

static bool titles_commandscript::HandleTitlesAddCommand ( ChatHandler handler,
Variant< Hyperlink< title >, uint16 titleId 
)
inlinestatic
89 {
90 Player* target = handler->getSelectedPlayer();
91 if (!target)
92 {
94 return false;
95 }
96
97 // check online security
98 if (handler->HasLowerSecurity(target, ObjectGuid::Empty))
99 return false;
100
101 CharTitlesEntry const* titleInfo = sCharTitlesStore.LookupEntry(titleId);
102 if (!titleInfo)
103 {
105 return false;
106 }
107
108 std::string tNameLink = handler->GetNameLink(target);
109 std::string titleNameStr = Acore::StringFormat(target->getGender() == GENDER_MALE ? titleInfo->nameMale[handler->GetSessionDbcLocale()] : titleInfo->nameFemale[handler->GetSessionDbcLocale()], target->GetName());
110
111 target->SetTitle(titleInfo);
112 handler->PSendSysMessage(LANG_TITLE_ADD_RES, uint32(titleId), titleNameStr, tNameLink);
113
114 return true;
115 }
std::uint32_t uint32
Definition: Define.h:107
@ GENDER_MALE
Definition: SharedDefines.h:61
@ LANG_TITLE_ADD_RES
Definition: Language.h:394
@ LANG_INVALID_TITLE_ID
Definition: Language.h:393
@ LANG_NO_CHAR_SELECTED
Definition: Language.h:148
DBCStorage< CharTitlesEntry > sCharTitlesStore(CharTitlesEntryfmt)
std::string StringFormat(FormatString< Args... > fmt, Args &&... args)
Default AC string format function.
Definition: StringFormat.h:34
virtual std::string GetNameLink() const
Definition: Chat.h:198
void PSendSysMessage(std::string_view str, bool escapeCharacters=false)
Definition: Chat.cpp:210
virtual LocaleConstant GetSessionDbcLocale() const
Definition: Chat.cpp:869
void SendErrorMessage(uint32 entry)
Definition: Chat.cpp:215
Player * getSelectedPlayer() const
Definition: Chat.cpp:373
bool HasLowerSecurity(Player *target, ObjectGuid guid=ObjectGuid::Empty, bool strong=false)
Definition: Chat.cpp:56
std::string const & GetName() const
Definition: Object.h:463
static ObjectGuid const Empty
Definition: ObjectGuid.h:120
Definition: Player.h:1081
void SetTitle(CharTitlesEntry const *title, bool lost=false)
Definition: Player.cpp:13370
uint8 getGender() const
Definition: Unit.h:805
Definition: DBCStructure.h:631
char const * nameMale[16]
Definition: DBCStructure.h:634
char const * nameFemale[16]
Definition: DBCStructure.h:636

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
58 {
59 Player* target = handler->getSelectedPlayer();
60 if (!target)
61 {
63 return false;
64 }
65
66 // check online security
67 if (handler->HasLowerSecurity(target, ObjectGuid::Empty))
68 return false;
69
70 CharTitlesEntry const* titleInfo = sCharTitlesStore.LookupEntry(titleId);
71 if (!titleInfo)
72 {
74 return false;
75 }
76
77 std::string tNameLink = handler->GetNameLink(target);
78 std::string titleNameStr = Acore::StringFormat(target->getGender() == GENDER_MALE ? titleInfo->nameMale[handler->GetSessionDbcLocale()] : titleInfo->nameFemale[handler->GetSessionDbcLocale()], target->GetName());
79
80 target->SetTitle(titleInfo);
81 target->SetUInt32Value(PLAYER_CHOSEN_TITLE, titleInfo->bit_index);
82
83 handler->PSendSysMessage(LANG_TITLE_CURRENT_RES, uint32(titleId), titleNameStr, tNameLink);
84
85 return true;
86 }
@ LANG_TITLE_CURRENT_RES
Definition: Language.h:396
@ PLAYER_CHOSEN_TITLE
Definition: UpdateFields.h:324
void SetUInt32Value(uint16 index, uint32 value)
Definition: Unit.cpp:21316
uint32 bit_index
Definition: DBCStructure.h:638

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(), Unit::SetUInt32Value(), and Acore::StringFormat().

Referenced by GetCommands().

◆ HandleTitlesRemoveCommand()

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

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(), Unit::SetUInt32Value(), and Acore::StringFormat().

Referenced by GetCommands().

◆ HandleTitlesSetMaskCommand()

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

Referenced by GetCommands().