TrinityCore
Loading...
Searching...
No Matches
cs_titles.cpp
Go to the documentation of this file.
1/*
2 * This file is part of the TrinityCore Project. See AUTHORS file for Copyright information
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by the
6 * Free Software Foundation; either version 2 of the License, or (at your
7 * option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18/* ScriptData
19Name: titles_commandscript
20%Complete: 100
21Comment: All titles related commands
22Category: commandscripts
23EndScriptData */
24
25#include "ScriptMgr.h"
26#include "Chat.h"
27#include "DBCStores.h"
28#include "Language.h"
29#include "Player.h"
30#include "RBAC.h"
31
32using namespace Trinity::ChatCommands;
33
35{
36public:
37 titles_commandscript() : CommandScript("titles_commandscript") { }
38
40 {
41 static ChatCommandTable titlesSetCommandTable =
42 {
44 };
45 static ChatCommandTable titlesCommandTable =
46 {
50 { "set", titlesSetCommandTable },
51 };
52 static ChatCommandTable commandTable =
53 {
54 { "titles", titlesCommandTable },
55 };
56 return commandTable;
57 }
58
60 {
61 Player* target = handler->getSelectedPlayer();
62 if (!target)
63 {
65 handler->SetSentErrorMessage(true);
66 return false;
67 }
68
69 // check online security
70 if (handler->HasLowerSecurity(target, ObjectGuid::Empty))
71 return false;
72
73 CharTitlesEntry const* titleInfo = sCharTitlesStore.LookupEntry(titleId);
74 if (!titleInfo)
75 {
76 handler->PSendSysMessage(LANG_INVALID_TITLE_ID, *titleId);
77 handler->SetSentErrorMessage(true);
78 return false;
79 }
80
81 std::string tNameLink = handler->GetNameLink(target);
82 std::string titleNameStr = ChatHandler::PGetParseString(target->GetNativeGender() == GENDER_MALE ? titleInfo->Name[handler->GetSessionDbcLocale()] : titleInfo->Name1[handler->GetSessionDbcLocale()], target->GetName());
83
84 target->SetTitle(titleInfo);
85 target->SetUInt32Value(PLAYER_CHOSEN_TITLE, titleInfo->MaskID);
86
87 handler->PSendSysMessage(LANG_TITLE_CURRENT_RES, *titleId, titleNameStr, tNameLink);
88
89 return true;
90 }
91
93 {
94 Player* target = handler->getSelectedPlayer();
95 if (!target)
96 {
98 handler->SetSentErrorMessage(true);
99 return false;
100 }
101
102 // check online security
103 if (handler->HasLowerSecurity(target, ObjectGuid::Empty))
104 return false;
105
106 CharTitlesEntry const* titleInfo = sCharTitlesStore.LookupEntry(titleId);
107 if (!titleInfo)
108 {
109 handler->PSendSysMessage(LANG_INVALID_TITLE_ID, *titleId);
110 handler->SetSentErrorMessage(true);
111 return false;
112 }
113
114 std::string tNameLink = handler->GetNameLink(target);
115 std::string titleNameStr = ChatHandler::PGetParseString(target->GetNativeGender() == GENDER_MALE ? titleInfo->Name[handler->GetSessionDbcLocale()] : titleInfo->Name1[handler->GetSessionDbcLocale()], target->GetName());
116
117 target->SetTitle(titleInfo);
118 handler->PSendSysMessage(LANG_TITLE_ADD_RES, *titleId, titleNameStr, tNameLink);
119
120 return true;
121 }
122
124 {
125 Player* target = handler->getSelectedPlayer();
126 if (!target)
127 {
129 handler->SetSentErrorMessage(true);
130 return false;
131 }
132
133 // check online security
134 if (handler->HasLowerSecurity(target, ObjectGuid::Empty))
135 return false;
136
137 CharTitlesEntry const* titleInfo = sCharTitlesStore.LookupEntry(titleId);
138 if (!titleInfo)
139 {
140 handler->PSendSysMessage(LANG_INVALID_TITLE_ID, *titleId);
141 handler->SetSentErrorMessage(true);
142 return false;
143 }
144
145 target->SetTitle(titleInfo, true);
146
147 std::string tNameLink = handler->GetNameLink(target);
148 std::string titleNameStr = ChatHandler::PGetParseString(target->GetNativeGender() == GENDER_MALE ? titleInfo->Name[handler->GetSessionDbcLocale()] : titleInfo->Name1[handler->GetSessionDbcLocale()], target->GetName());
149
150 handler->PSendSysMessage(LANG_TITLE_REMOVE_RES, *titleId, titleNameStr, tNameLink);
151
152 if (!target->HasTitle(target->GetInt32Value(PLAYER_CHOSEN_TITLE)))
153 {
155 handler->PSendSysMessage(LANG_CURRENT_TITLE_RESET, tNameLink);
156 }
157
158 return true;
159 }
160
161 //Edit Player KnownTitles
163 {
164 Player* target = handler->getSelectedPlayer();
165 if (!target)
166 {
168 handler->SetSentErrorMessage(true);
169 return false;
170 }
171
172 // check online security
173 if (handler->HasLowerSecurity(target, ObjectGuid::Empty))
174 return false;
175
176 uint64 titles2 = mask;
177
178 for (uint32 i = 1; i < sCharTitlesStore.GetNumRows(); ++i)
179 if (CharTitlesEntry const* tEntry = sCharTitlesStore.LookupEntry(i))
180 titles2 &= ~(uint64(1) << tEntry->MaskID);
181
182 mask &= ~titles2; // remove non-existing titles
183
185 handler->SendSysMessage(LANG_DONE);
186
187 if (!target->HasTitle(target->GetInt32Value(PLAYER_CHOSEN_TITLE)))
188 {
190 handler->PSendSysMessage(LANG_CURRENT_TITLE_RESET, handler->GetNameLink(target));
191 }
192
193 return true;
194 }
195};
196
DBCStorage< CharTitlesEntry > sCharTitlesStore(CharTitlesEntryfmt)
uint64_t uint64
Definition Define.h:132
uint16_t uint16
Definition Define.h:134
uint32_t uint32
Definition Define.h:133
@ LANG_TITLE_CURRENT_RES
Definition Language.h:410
@ LANG_TITLE_REMOVE_RES
Definition Language.h:409
@ LANG_TITLE_ADD_RES
Definition Language.h:408
@ LANG_CURRENT_TITLE_RESET
Definition Language.h:411
@ LANG_INVALID_TITLE_ID
Definition Language.h:407
@ LANG_NO_CHAR_SELECTED
Definition Language.h:150
@ LANG_DONE
Definition Language.h:75
Role Based Access Control related classes definition.
@ GENDER_MALE
@ PLAYER_CHOSEN_TITLE
@ PLAYER__FIELD_KNOWN_TITLES
static std::string PGetParseString(std::string_view fmt, Args &&... args)
Definition Chat.h:81
Player * getSelectedPlayer()
Definition Chat.cpp:302
virtual LocaleConstant GetSessionDbcLocale() const
Definition Chat.cpp:692
virtual std::string GetNameLink() const
Definition Chat.cpp:46
bool HasLowerSecurity(Player *target, ObjectGuid guid, bool strong=false)
Definition Chat.cpp:51
void SetSentErrorMessage(bool val)
Definition Chat.h:134
void PSendSysMessage(char const *fmt, Args &&... args)
Definition Chat.h:69
virtual void SendSysMessage(std::string_view str, bool escapeCharacters=false)
Definition Chat.cpp:101
static ObjectGuid const Empty
Definition ObjectGuid.h:140
int32 GetInt32Value(uint16 index) const
Definition Object.cpp:243
void SetUInt32Value(uint16 index, uint32 value)
Definition Object.cpp:585
void SetUInt64Value(uint16 index, uint64 value)
Definition Object.cpp:606
Gender GetNativeGender() const override
Definition Player.h:1039
bool HasTitle(uint32 bitIndex) const
Definition Player.cpp:24301
void SetTitle(CharTitlesEntry const *title, bool lost=false)
Definition Player.cpp:24316
std::string const & GetName() const
Definition Object.h:382
static bool HandleTitlesRemoveCommand(ChatHandler *handler, Variant< Hyperlink< title >, uint16 > titleId)
static bool HandleTitlesAddCommand(ChatHandler *handler, Variant< Hyperlink< title >, uint16 > titleId)
Definition cs_titles.cpp:92
static bool HandleTitlesSetMaskCommand(ChatHandler *handler, uint64 mask)
static bool HandleTitlesCurrentCommand(ChatHandler *handler, Variant< Hyperlink< title >, uint16 > titleId)
Definition cs_titles.cpp:59
ChatCommandTable GetCommands() const override
Definition cs_titles.cpp:39
void AddSC_titles_commandscript()
std::vector< ChatCommandBuilder > ChatCommandTable
Definition ChatCommand.h:50
@ RBAC_PERM_COMMAND_TITLES_CURRENT
Definition RBAC.h:633
@ RBAC_PERM_COMMAND_TITLES_ADD
Definition RBAC.h:632
@ RBAC_PERM_COMMAND_TITLES_SET_MASK
Definition RBAC.h:636
@ RBAC_PERM_COMMAND_TITLES_REMOVE
Definition RBAC.h:634
char const * Name[16]
char const * Name1[16]