TrinityCore
Loading...
Searching...
No Matches
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
44using namespace Trinity::ChatCommands;
45
47{
48public:
49 reset_commandscript() : CommandScript("reset_commandscript") { }
50
51 std::span<ChatCommandBuilder const> GetCommands() const override
52 {
53 static ChatCommandTable resetCommandTable =
54 {
62 };
63 static ChatCommandTable commandTable =
64 {
65 { "reset", rbac::RBAC_PERM_COMMAND_RESET, true, nullptr, "", resetCommandTable },
66 };
67 return commandTable;
68 }
69
70 static bool HandleResetAchievementsCommand(ChatHandler* handler, char const* args)
71 {
72 Player* target;
73 ObjectGuid targetGuid;
74 if (!handler->extractPlayerTarget((char*)args, &target, &targetGuid))
75 return false;
76
77 if (target)
78 target->ResetAchievements();
79 else
81
82 return true;
83 }
84
85 static bool HandleResetHonorCommand(ChatHandler* handler, char const* args)
86 {
87 Player* target;
88 if (!handler->extractPlayerTarget((char*)args, &target))
89 return false;
90
91 target->ResetHonorStats();
93
94 return true;
95 }
96
98 {
99 ChrClassesEntry const* classEntry = sChrClassesStore.LookupEntry(player->GetClass());
100 if (!classEntry)
101 {
102 TC_LOG_ERROR("misc", "Class {} not found in DBC (Wrong DBC files?)", player->GetClass());
103 return false;
104 }
105
106 uint8 powerType = classEntry->DisplayPower;
107
108 // reset m_form if no aura
111
112 player->SetFactionForRace(player->GetRace());
113 player->SetPowerType(Powers(powerType));
114
115 // reset only if player not in some form;
116 if (player->GetShapeshiftForm() == FORM_NONE)
117 player->InitDisplayIds();
118
120
122
123 //-1 is default value
124 player->SetWatchedFactionIndex(-1);
125 return true;
126 }
127
128 static bool HandleResetLevelCommand(ChatHandler* handler, char const* args)
129 {
130 Player* target;
131 if (!handler->extractPlayerTarget((char*)args, &target))
132 return false;
133
135 return false;
136
137 uint8 oldLevel = target->GetLevel();
138
139 // set starting level
140 uint8 startLevel = target->GetStartLevel(target->GetRace(), target->GetClass(), {});
141
142 target->_ApplyAllLevelScaleItemMods(false);
143 target->SetLevel(startLevel);
144 target->InitRunes();
145 target->InitStatsForLevel(true);
146 target->InitTaxiNodesForLevel();
147 target->InitTalentForLevel();
148 target->SetXP(0);
149
150 target->_ApplyAllLevelScaleItemMods(true);
151
152 // reset level for pet
153 if (Pet* pet = target->GetPet())
154 pet->SynchronizeLevelWithOwner();
155
156 sScriptMgr->OnPlayerLevelChanged(target, oldLevel);
157
158 return true;
159 }
160
161 static bool HandleResetSpellsCommand(ChatHandler* handler, char const* args)
162 {
163 Player* target;
164 ObjectGuid targetGuid;
165 std::string targetName;
166 if (!handler->extractPlayerTarget((char*)args, &target, &targetGuid, &targetName))
167 return false;
168
169 if (target)
170 {
171 target->ResetSpells(/* bool myClassOnly */);
172
174 if (!handler->GetSession() || handler->GetSession()->GetPlayer() != target)
175 handler->PSendSysMessage(LANG_RESET_SPELLS_ONLINE, handler->GetNameLink(target).c_str());
176 }
177 else
178 {
181 stmt->setUInt64(1, targetGuid.GetCounter());
182 CharacterDatabase.Execute(stmt);
183
184 handler->PSendSysMessage(LANG_RESET_SPELLS_OFFLINE, targetName.c_str());
185 }
186
187 return true;
188 }
189
190 static bool HandleResetStatsCommand(ChatHandler* handler, char const* args)
191 {
192 Player* target;
193 if (!handler->extractPlayerTarget((char*)args, &target))
194 return false;
195
197 return false;
198
199 target->InitRunes();
200 target->InitStatsForLevel(true);
201 target->InitTaxiNodesForLevel();
202 target->InitTalentForLevel();
203
204 return true;
205 }
206
207 static bool HandleResetTalentsCommand(ChatHandler* handler, char const* args)
208 {
209 Player* target;
210 ObjectGuid targetGuid;
211 std::string targetName;
212
213 if (!handler->extractPlayerTarget((char*)args, &target, &targetGuid, &targetName))
214 {
215 /* TODO: 6.x remove/update pet talents
216 // Try reset talents as Hunter Pet
217 Creature* creature = handler->getSelectedCreature();
218 if (!*args && creature && creature->IsPet())
219 {
220 Unit* owner = creature->GetOwner();
221 if (owner && owner->GetTypeId() == TYPEID_PLAYER && creature->ToPet()->IsPermanentPetFor(owner->ToPlayer()))
222 {
223 creature->ToPet()->resetTalents();
224 owner->ToPlayer()->SendTalentsInfoData(true);
225
226 ChatHandler(owner->ToPlayer()->GetSession()).SendSysMessage(LANG_RESET_PET_TALENTS);
227 if (!handler->GetSession() || handler->GetSession()->GetPlayer() != owner->ToPlayer())
228 handler->PSendSysMessage(LANG_RESET_PET_TALENTS_ONLINE, handler->GetNameLink(owner->ToPlayer()).c_str());
229 }
230 return true;
231 }
232 */
233
235 handler->SetSentErrorMessage(true);
236 return false;
237 }
238
239 if (target)
240 {
241 target->ResetTalents(true);
243 target->SendTalentsInfoData();
245 if (!handler->GetSession() || handler->GetSession()->GetPlayer() != target)
246 handler->PSendSysMessage(LANG_RESET_TALENTS_ONLINE, handler->GetNameLink(target).c_str());
247
248 /* TODO: 6.x remove/update pet talents
249 Pet* pet = target->GetPet();
250 Pet::resetTalentsForAllPetsOf(target, pet);
251 if (pet)
252 target->SendTalentsInfoData(true);
253 */
254 return true;
255 }
256 else if (!targetGuid.IsEmpty())
257 {
260 stmt->setUInt64(1, targetGuid.GetCounter());
261 CharacterDatabase.Execute(stmt);
262
263 std::string nameLink = handler->playerLink(targetName);
264 handler->PSendSysMessage(LANG_RESET_TALENTS_OFFLINE, nameLink.c_str());
265 return true;
266 }
267
269 handler->SetSentErrorMessage(true);
270 return false;
271 }
272
273 static bool HandleResetAllCommand(ChatHandler* handler, char const* args)
274 {
275 if (!*args)
276 return false;
277
278 std::string caseName = args;
279
280 AtLoginFlags atLogin;
281
282 // Command specially created as single command to prevent using short case names
283 if (caseName == "spells")
284 {
285 atLogin = AT_LOGIN_RESET_SPELLS;
286 sWorld->SendWorldText(LANG_RESETALL_SPELLS);
287 if (!handler->GetSession())
289 }
290 else if (caseName == "talents")
291 {
293 sWorld->SendWorldText(LANG_RESETALL_TALENTS);
294 if (!handler->GetSession())
296 }
297 else
298 {
300 handler->SetSentErrorMessage(true);
301 return false;
302 }
303
305 stmt->setUInt16(0, uint16(atLogin));
306 CharacterDatabase.Execute(stmt);
307
308 std::shared_lock<std::shared_mutex> lock(*HashMapHolder<Player>::GetLock());
310 for (HashMapHolder<Player>::MapType::const_iterator itr = plist.begin(); itr != plist.end(); ++itr)
311 itr->second->SetAtLoginFlag(atLogin);
312
313 return true;
314 }
315};
316
@ 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.
uint8_t uint8
Definition Define.h:156
uint16_t uint16
Definition Define.h:155
@ LANG_RESETALL_TALENTS
Definition Language.h:265
@ LANG_RESET_SPELLS_ONLINE
Definition Language.h:256
@ LANG_RESET_TALENTS_OFFLINE
Definition Language.h:259
@ LANG_RESET_SPELLS_OFFLINE
Definition Language.h:257
@ LANG_RESETALL_UNKNOWN_CASE
Definition Language.h:263
@ LANG_RESET_TALENTS_ONLINE
Definition Language.h:258
@ LANG_RESET_SPELLS
Definition Language.h:260
@ LANG_RESET_TALENTS
Definition Language.h:261
@ LANG_NO_CHAR_SELECTED
Definition Language.h:150
@ LANG_RESETALL_SPELLS
Definition Language.h:264
#define TC_LOG_ERROR(filterType__, message__,...)
Definition Log.h:190
AtLoginFlags
Definition Player.h:636
@ AT_LOGIN_RESET_TALENTS
Definition Player.h:640
@ AT_LOGIN_RESET_SPELLS
Definition Player.h:639
@ AT_LOGIN_NONE
Definition Player.h:637
@ AT_LOGIN_RESET_PET_TALENTS
Definition Player.h:642
Role Based Access Control related classes definition.
#define sScriptMgr
Definition ScriptMgr.h:1449
Powers
@ SPELL_AURA_MOD_SHAPESHIFT
@ FORM_NONE
@ UNIT_BYTE2_FLAG_PVP
Definition UnitDefines.h:93
@ UNIT_FLAG_PLAYER_CONTROLLED
std::string playerLink(std::string const &name) const
Definition Chat.cpp:603
WorldSession * GetSession()
Definition Chat.h:42
virtual std::string GetNameLink() const
Definition Chat.cpp:56
void SetSentErrorMessage(bool val)
Definition Chat.h:127
void PSendSysMessage(char const *fmt, Args &&... args)
Definition Chat.h:62
virtual void SendSysMessage(std::string_view str, bool escapeCharacters=false)
Definition Chat.cpp:111
bool extractPlayerTarget(char *args, Player **player, ObjectGuid *player_guid=nullptr, std::string *player_name=nullptr)
Definition Chat.cpp:490
std::unordered_map< ObjectGuid, T * > MapType
LowType GetCounter() const
Definition ObjectGuid.h:336
bool IsEmpty() const
Definition ObjectGuid.h:362
Definition Pet.h:40
static void DeleteFromDB(ObjectGuid const &guid)
uint8 GetStartLevel(uint8 race, uint8 playerClass, Optional< int32 > characterTemplateId) const
Definition Player.cpp:24439
void SetWatchedFactionIndex(int32 index)
Definition Player.h:3015
void _ApplyAllLevelScaleItemMods(bool apply)
Definition Player.cpp:9029
void ResetSpells(bool myClassOnly=false)
Definition Player.cpp:25247
void InitTalentForLevel()
Definition Player.cpp:2361
void SendTalentsInfoData()
Definition Player.cpp:28107
Pet * GetPet() const
Definition Player.cpp:22060
void InitDisplayIds()
Definition Player.cpp:23458
WorldSession * GetSession() const
Definition Player.h:2272
void ResetHonorStats()
Definition Player.cpp:6920
void ResetTalentSpecialization()
Definition Player.cpp:27705
void UpdateCriteria(CriteriaType type, uint64 miscValue1=0, uint64 miscValue2=0, uint64 miscValue3=0, WorldObject *ref=nullptr)
Definition Player.cpp:27588
void InitTaxiNodesForLevel()
Definition Player.h:1294
void InitStatsForLevel(bool reapplyMods=false)
Definition Player.cpp:2395
void SetXP(uint32 xp)
Definition Player.cpp:2186
void InitRunes()
Definition Player.cpp:27160
void SetFactionForRace(uint8 race)
Definition Player.cpp:6497
bool ResetTalents(bool noCost=false)
Definition Player.cpp:3508
void ResetAchievements()
Definition Player.cpp:27552
void setUInt16(uint8 index, uint16 value)
void setUInt64(uint8 index, uint64 value)
void ReplaceAllPvpFlags(UnitPVPStateFlags flags)
Definition Unit.h:883
uint8 GetClass() const
Definition Unit.h:764
ShapeshiftForm GetShapeshiftForm() const
Definition Unit.h:1504
void ReplaceAllUnitFlags(UnitFlags flags)
Definition Unit.h:848
bool HasAuraType(AuraType auraType) const
Definition Unit.cpp:4814
void SetLevel(uint8 lvl, bool sendUpdate=true)
Definition Unit.cpp:9956
void SetShapeshiftForm(ShapeshiftForm form)
Definition Unit.cpp:9494
void SetPowerType(Powers power, bool sendUpdate=true, bool onInit=false)
Definition Unit.cpp:5697
uint8 GetLevel() const
Definition Unit.h:757
uint8 GetRace() const
Definition Unit.h:761
Player * GetPlayer() const
static bool HandleResetHonorCommand(ChatHandler *handler, char const *args)
Definition cs_reset.cpp:85
std::span< ChatCommandBuilder const > GetCommands() const override
Definition cs_reset.cpp:51
static bool HandleResetAllCommand(ChatHandler *handler, char const *args)
Definition cs_reset.cpp:273
static bool HandleResetTalentsCommand(ChatHandler *handler, char const *args)
Definition cs_reset.cpp:207
static bool HandleResetStatsCommand(ChatHandler *handler, char const *args)
Definition cs_reset.cpp:190
static bool HandleResetStatsOrLevelHelper(Player *player)
Definition cs_reset.cpp:97
static bool HandleResetLevelCommand(ChatHandler *handler, char const *args)
Definition cs_reset.cpp:128
static bool HandleResetAchievementsCommand(ChatHandler *handler, char const *args)
Definition cs_reset.cpp:70
static bool HandleResetSpellsCommand(ChatHandler *handler, char const *args)
Definition cs_reset.cpp:161
void AddSC_reset_commandscript()
Definition cs_reset.cpp:317
#define sWorld
Definition World.h:916
TC_GAME_API HashMapHolder< Player >::MapType const & GetPlayers()
ChatCommandBuilder const [] ChatCommandTable
Definition ChatCommand.h:49
@ 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