TrinityCore
cs_reset.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: reset_commandscript
20%Complete: 100
21Comment: All reset related commands
22Category: commandscripts
23EndScriptData */
24
25#include "ScriptMgr.h"
26#include "AchievementMgr.h"
27#include "Chat.h"
28#include "ChatCommand.h"
29#include "DatabaseEnv.h"
30#include "DB2Stores.h"
31#include "Language.h"
32#include "Log.h"
33#include "ObjectAccessor.h"
34#include "Pet.h"
35#include "Player.h"
36#include "RBAC.h"
37#include "World.h"
38#include "WorldSession.h"
39
40#if TRINITY_COMPILER == TRINITY_COMPILER_GNU
41#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
42#endif
43
45{
46public:
47 reset_commandscript() : CommandScript("reset_commandscript") { }
48
49 std::vector<ChatCommand> GetCommands() const override
50 {
51 static std::vector<ChatCommand> resetCommandTable =
52 {
60 };
61 static std::vector<ChatCommand> commandTable =
62 {
63 { "reset", rbac::RBAC_PERM_COMMAND_RESET, true, nullptr, "", resetCommandTable },
64 };
65 return commandTable;
66 }
67
68 static bool HandleResetAchievementsCommand(ChatHandler* handler, char const* args)
69 {
70 Player* target;
71 ObjectGuid targetGuid;
72 if (!handler->extractPlayerTarget((char*)args, &target, &targetGuid))
73 return false;
74
75 if (target)
76 target->ResetAchievements();
77 else
79
80 return true;
81 }
82
83 static bool HandleResetHonorCommand(ChatHandler* handler, char const* args)
84 {
85 Player* target;
86 if (!handler->extractPlayerTarget((char*)args, &target))
87 return false;
88
89 target->ResetHonorStats();
91
92 return true;
93 }
94
96 {
97 ChrClassesEntry const* classEntry = sChrClassesStore.LookupEntry(player->GetClass());
98 if (!classEntry)
99 {
100 TC_LOG_ERROR("misc", "Class {} not found in DBC (Wrong DBC files?)", player->GetClass());
101 return false;
102 }
103
104 uint8 powerType = classEntry->DisplayPower;
105
106 // reset m_form if no aura
109
110 player->SetFactionForRace(player->GetRace());
111 player->SetPowerType(Powers(powerType));
112
113 // reset only if player not in some form;
114 if (player->GetShapeshiftForm() == FORM_NONE)
115 player->InitDisplayIds();
116
118
120
121 //-1 is default value
122 player->SetWatchedFactionIndex(-1);
123 return true;
124 }
125
126 static bool HandleResetLevelCommand(ChatHandler* handler, char const* args)
127 {
128 Player* target;
129 if (!handler->extractPlayerTarget((char*)args, &target))
130 return false;
131
133 return false;
134
135 uint8 oldLevel = target->GetLevel();
136
137 // set starting level
138 uint8 startLevel = target->GetStartLevel(target->GetRace(), target->GetClass(), {});
139
140 target->_ApplyAllLevelScaleItemMods(false);
141 target->SetLevel(startLevel);
142 target->InitRunes();
143 target->InitStatsForLevel(true);
144 target->InitTaxiNodesForLevel();
145 target->InitTalentForLevel();
146 target->SetXP(0);
147
148 target->_ApplyAllLevelScaleItemMods(true);
149
150 // reset level for pet
151 if (Pet* pet = target->GetPet())
152 pet->SynchronizeLevelWithOwner();
153
154 sScriptMgr->OnPlayerLevelChanged(target, oldLevel);
155
156 return true;
157 }
158
159 static bool HandleResetSpellsCommand(ChatHandler* handler, char const* args)
160 {
161 Player* target;
162 ObjectGuid targetGuid;
163 std::string targetName;
164 if (!handler->extractPlayerTarget((char*)args, &target, &targetGuid, &targetName))
165 return false;
166
167 if (target)
168 {
169 target->ResetSpells(/* bool myClassOnly */);
170
172 if (!handler->GetSession() || handler->GetSession()->GetPlayer() != target)
173 handler->PSendSysMessage(LANG_RESET_SPELLS_ONLINE, handler->GetNameLink(target).c_str());
174 }
175 else
176 {
179 stmt->setUInt64(1, targetGuid.GetCounter());
180 CharacterDatabase.Execute(stmt);
181
182 handler->PSendSysMessage(LANG_RESET_SPELLS_OFFLINE, targetName.c_str());
183 }
184
185 return true;
186 }
187
188 static bool HandleResetStatsCommand(ChatHandler* handler, char const* args)
189 {
190 Player* target;
191 if (!handler->extractPlayerTarget((char*)args, &target))
192 return false;
193
195 return false;
196
197 target->InitRunes();
198 target->InitStatsForLevel(true);
199 target->InitTaxiNodesForLevel();
200 target->InitTalentForLevel();
201
202 return true;
203 }
204
205 static bool HandleResetTalentsCommand(ChatHandler* handler, char const* args)
206 {
207 Player* target;
208 ObjectGuid targetGuid;
209 std::string targetName;
210
211 if (!handler->extractPlayerTarget((char*)args, &target, &targetGuid, &targetName))
212 {
213 /* TODO: 6.x remove/update pet talents
214 // Try reset talents as Hunter Pet
215 Creature* creature = handler->getSelectedCreature();
216 if (!*args && creature && creature->IsPet())
217 {
218 Unit* owner = creature->GetOwner();
219 if (owner && owner->GetTypeId() == TYPEID_PLAYER && creature->ToPet()->IsPermanentPetFor(owner->ToPlayer()))
220 {
221 creature->ToPet()->resetTalents();
222 owner->ToPlayer()->SendTalentsInfoData(true);
223
224 ChatHandler(owner->ToPlayer()->GetSession()).SendSysMessage(LANG_RESET_PET_TALENTS);
225 if (!handler->GetSession() || handler->GetSession()->GetPlayer() != owner->ToPlayer())
226 handler->PSendSysMessage(LANG_RESET_PET_TALENTS_ONLINE, handler->GetNameLink(owner->ToPlayer()).c_str());
227 }
228 return true;
229 }
230 */
231
233 handler->SetSentErrorMessage(true);
234 return false;
235 }
236
237 if (target)
238 {
239 target->ResetTalents(true);
241 target->SendTalentsInfoData();
243 if (!handler->GetSession() || handler->GetSession()->GetPlayer() != target)
244 handler->PSendSysMessage(LANG_RESET_TALENTS_ONLINE, handler->GetNameLink(target).c_str());
245
246 /* TODO: 6.x remove/update pet talents
247 Pet* pet = target->GetPet();
248 Pet::resetTalentsForAllPetsOf(target, pet);
249 if (pet)
250 target->SendTalentsInfoData(true);
251 */
252 return true;
253 }
254 else if (!targetGuid.IsEmpty())
255 {
258 stmt->setUInt64(1, targetGuid.GetCounter());
259 CharacterDatabase.Execute(stmt);
260
261 std::string nameLink = handler->playerLink(targetName);
262 handler->PSendSysMessage(LANG_RESET_TALENTS_OFFLINE, nameLink.c_str());
263 return true;
264 }
265
267 handler->SetSentErrorMessage(true);
268 return false;
269 }
270
271 static bool HandleResetAllCommand(ChatHandler* handler, char const* args)
272 {
273 if (!*args)
274 return false;
275
276 std::string caseName = args;
277
278 AtLoginFlags atLogin;
279
280 // Command specially created as single command to prevent using short case names
281 if (caseName == "spells")
282 {
283 atLogin = AT_LOGIN_RESET_SPELLS;
284 sWorld->SendWorldText(LANG_RESETALL_SPELLS);
285 if (!handler->GetSession())
287 }
288 else if (caseName == "talents")
289 {
291 sWorld->SendWorldText(LANG_RESETALL_TALENTS);
292 if (!handler->GetSession())
294 }
295 else
296 {
298 handler->SetSentErrorMessage(true);
299 return false;
300 }
301
303 stmt->setUInt16(0, uint16(atLogin));
304 CharacterDatabase.Execute(stmt);
305
306 std::shared_lock<std::shared_mutex> lock(*HashMapHolder<Player>::GetLock());
308 for (HashMapHolder<Player>::MapType::const_iterator itr = plist.begin(); itr != plist.end(); ++itr)
309 itr->second->SetAtLoginFlag(atLogin);
310
311 return true;
312 }
313};
314
316{
318}
@ CHAR_UPD_ADD_AT_LOGIN_FLAG
@ CHAR_UPD_ALL_AT_LOGIN_FLAGS
DB2Storage< ChrClassesEntry > sChrClassesStore("ChrClasses.db2", &ChrClassesLoadInfo::Instance)
DatabaseWorkerPool< CharacterDatabaseConnection > CharacterDatabase
Accessor to the character database.
Definition: DatabaseEnv.cpp:21
uint8_t uint8
Definition: Define.h:144
uint16_t uint16
Definition: Define.h:143
@ LANG_RESETALL_TALENTS
Definition: Language.h:266
@ LANG_RESET_SPELLS_ONLINE
Definition: Language.h:257
@ LANG_RESET_TALENTS_OFFLINE
Definition: Language.h:260
@ LANG_RESET_SPELLS_OFFLINE
Definition: Language.h:258
@ LANG_RESETALL_UNKNOWN_CASE
Definition: Language.h:264
@ LANG_RESET_TALENTS_ONLINE
Definition: Language.h:259
@ LANG_RESET_SPELLS
Definition: Language.h:261
@ LANG_RESET_TALENTS
Definition: Language.h:262
@ LANG_NO_CHAR_SELECTED
Definition: Language.h:150
@ LANG_RESETALL_SPELLS
Definition: Language.h:265
#define TC_LOG_ERROR(filterType__,...)
Definition: Log.h:165
AtLoginFlags
Definition: Player.h:536
@ AT_LOGIN_RESET_TALENTS
Definition: Player.h:540
@ AT_LOGIN_RESET_SPELLS
Definition: Player.h:539
@ AT_LOGIN_NONE
Definition: Player.h:537
@ AT_LOGIN_RESET_PET_TALENTS
Definition: Player.h:542
Role Based Access Control related classes definition.
#define sScriptMgr
Definition: ScriptMgr.h:1418
Powers
@ SPELL_AURA_MOD_SHAPESHIFT
@ FORM_NONE
@ UNIT_BYTE2_FLAG_PVP
Definition: UnitDefines.h:93
@ UNIT_FLAG_PLAYER_CONTROLLED
Definition: UnitDefines.h:147
std::string playerLink(std::string const &name) const
Definition: Chat.cpp:602
WorldSession * GetSession()
Definition: Chat.h:42
virtual std::string GetNameLink() const
Definition: Chat.cpp:58
void PSendSysMessage(const char *fmt, Args &&... args)
Definition: Chat.h:57
void SetSentErrorMessage(bool val)
Definition: Chat.h:114
virtual void SendSysMessage(std::string_view str, bool escapeCharacters=false)
Definition: Chat.cpp:113
bool extractPlayerTarget(char *args, Player **player, ObjectGuid *player_guid=nullptr, std::string *player_name=nullptr)
Definition: Chat.cpp:489
std::unordered_map< ObjectGuid, T * > MapType
LowType GetCounter() const
Definition: ObjectGuid.h:293
bool IsEmpty() const
Definition: ObjectGuid.h:319
Definition: Pet.h:40
static void DeleteFromDB(ObjectGuid const &guid)
uint8 GetStartLevel(uint8 race, uint8 playerClass, Optional< int32 > characterTemplateId) const
Definition: Player.cpp:23690
void SetWatchedFactionIndex(int32 index)
Definition: Player.h:2840
void _ApplyAllLevelScaleItemMods(bool apply)
Definition: Player.cpp:8986
void ResetSpells(bool myClassOnly=false)
Definition: Player.cpp:24491
void InitTalentForLevel()
Definition: Player.cpp:2370
void SendTalentsInfoData()
Definition: Player.cpp:27287
Pet * GetPet() const
Definition: Player.cpp:21513
void InitDisplayIds()
Definition: Player.cpp:22796
WorldSession * GetSession() const
Definition: Player.h:2101
void ResetHonorStats()
Definition: Player.cpp:6882
void ResetTalentSpecialization()
Definition: Player.cpp:26884
void UpdateCriteria(CriteriaType type, uint64 miscValue1=0, uint64 miscValue2=0, uint64 miscValue3=0, WorldObject *ref=nullptr)
Definition: Player.cpp:26767
void InitTaxiNodesForLevel()
Definition: Player.h:1167
void InitStatsForLevel(bool reapplyMods=false)
Definition: Player.cpp:2404
void SetXP(uint32 xp)
Definition: Player.cpp:2197
void InitRunes()
Definition: Player.cpp:26376
void SetFactionForRace(uint8 race)
Definition: Player.cpp:6489
bool ResetTalents(bool noCost=false)
Definition: Player.cpp:3529
void ResetAchievements()
Definition: Player.cpp:26731
void setUInt16(const uint8 index, const uint16 value)
void setUInt64(const uint8 index, const uint64 value)
void ReplaceAllPvpFlags(UnitPVPStateFlags flags)
Definition: Unit.h:870
uint8 GetClass() const
Definition: Unit.h:752
ShapeshiftForm GetShapeshiftForm() const
Definition: Unit.h:1463
void ReplaceAllUnitFlags(UnitFlags flags)
Definition: Unit.h:835
bool HasAuraType(AuraType auraType) const
Definition: Unit.cpp:4674
void SetPowerType(Powers power, bool sendUpdate=true)
Definition: Unit.cpp:5534
void SetLevel(uint8 lvl, bool sendUpdate=true)
Definition: Unit.cpp:9329
void SetShapeshiftForm(ShapeshiftForm form)
Definition: Unit.cpp:8904
uint8 GetLevel() const
Definition: Unit.h:746
uint8 GetRace() const
Definition: Unit.h:749
Player * GetPlayer() const
std::vector< ChatCommand > GetCommands() const override
Definition: cs_reset.cpp:49
static bool HandleResetHonorCommand(ChatHandler *handler, char const *args)
Definition: cs_reset.cpp:83
static bool HandleResetAllCommand(ChatHandler *handler, char const *args)
Definition: cs_reset.cpp:271
static bool HandleResetTalentsCommand(ChatHandler *handler, char const *args)
Definition: cs_reset.cpp:205
static bool HandleResetStatsCommand(ChatHandler *handler, char const *args)
Definition: cs_reset.cpp:188
static bool HandleResetStatsOrLevelHelper(Player *player)
Definition: cs_reset.cpp:95
static bool HandleResetLevelCommand(ChatHandler *handler, char const *args)
Definition: cs_reset.cpp:126
static bool HandleResetAchievementsCommand(ChatHandler *handler, char const *args)
Definition: cs_reset.cpp:68
static bool HandleResetSpellsCommand(ChatHandler *handler, char const *args)
Definition: cs_reset.cpp:159
void AddSC_reset_commandscript()
Definition: cs_reset.cpp:315
#define sWorld
Definition: World.h:931
TC_GAME_API HashMapHolder< Player >::MapType const & GetPlayers()
@ RBAC_PERM_COMMAND_RESET_STATS
Definition: RBAC.h:587
@ RBAC_PERM_COMMAND_RESET_LEVEL
Definition: RBAC.h:585
@ RBAC_PERM_COMMAND_RESET_HONOR
Definition: RBAC.h:584
@ RBAC_PERM_COMMAND_RESET_ALL
Definition: RBAC.h:589
@ RBAC_PERM_COMMAND_RESET
Definition: RBAC.h:582
@ RBAC_PERM_COMMAND_RESET_SPELLS
Definition: RBAC.h:586
@ RBAC_PERM_COMMAND_RESET_TALENTS
Definition: RBAC.h:588
@ RBAC_PERM_COMMAND_RESET_ACHIEVEMENTS
Definition: RBAC.h:583