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_IS_GCC
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(true);
224 owner->ToPlayer()->SendTalentsInfoData(true);
225
226 if (!handler->GetSession() || handler->GetSession()->GetPlayer() != owner->ToPlayer())
227 handler->PSendSysMessage(LANG_RESET_PET_TALENTS_ONLINE, handler->GetNameLink(owner->ToPlayer()).c_str());
228 }
229 return true;
230 }
231 */
232
234 handler->SetSentErrorMessage(true);
235 return false;
236 }
237
238 if (target)
239 {
240 target->ResetTalents(true);
242 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, true);
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
@ 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_NO_CHAR_SELECTED
Definition Language.h:150
@ LANG_RESETALL_SPELLS
Definition Language.h:264
#define TC_LOG_ERROR(filterType__, message__,...)
Definition Log.h:182
AtLoginFlags
Definition Player.h:619
@ AT_LOGIN_RESET_TALENTS
Definition Player.h:623
@ AT_LOGIN_RESET_SPELLS
Definition Player.h:622
@ AT_LOGIN_NONE
Definition Player.h:620
@ AT_LOGIN_RESET_PET_TALENTS
Definition Player.h:625
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:24362
void SetWatchedFactionIndex(int32 index)
Definition Player.h:2999
void _ApplyAllLevelScaleItemMods(bool apply)
Definition Player.cpp:8937
void ResetSpells(bool myClassOnly=false)
Definition Player.cpp:25182
void InitTalentForLevel()
Definition Player.cpp:2272
void SendTalentsInfoData()
Definition Player.cpp:28051
Pet * GetPet() const
Definition Player.cpp:22007
void InitDisplayIds()
Definition Player.cpp:23404
WorldSession * GetSession() const
Definition Player.h:2256
void ResetHonorStats()
Definition Player.cpp:6810
void ResetTalentSpecialization()
Definition Player.cpp:27649
void UpdateCriteria(CriteriaType type, uint64 miscValue1=0, uint64 miscValue2=0, uint64 miscValue3=0, WorldObject *ref=nullptr)
Definition Player.cpp:27532
void InitTaxiNodesForLevel()
Definition Player.h:1278
void InitStatsForLevel(bool reapplyMods=false)
Definition Player.cpp:2306
void SetXP(uint32 xp)
Definition Player.cpp:2097
void InitRunes()
Definition Player.cpp:27104
void SetFactionForRace(uint8 race)
Definition Player.cpp:6407
bool ResetTalents(bool noCost=false)
Definition Player.cpp:3427
void ResetAchievements()
Definition Player.cpp:27496
void setUInt16(uint8 index, uint16 value)
void setUInt64(uint8 index, uint64 value)
void ReplaceAllPvpFlags(UnitPVPStateFlags flags)
Definition Unit.h:898
uint8 GetClass() const
Definition Unit.h:776
ShapeshiftForm GetShapeshiftForm() const
Definition Unit.h:1527
void ReplaceAllUnitFlags(UnitFlags flags)
Definition Unit.h:863
bool HasAuraType(AuraType auraType) const
Definition Unit.cpp:4832
void SetLevel(uint8 lvl, bool sendUpdate=true)
Definition Unit.cpp:10019
void SetShapeshiftForm(ShapeshiftForm form)
Definition Unit.cpp:9521
void SetPowerType(Powers power, bool sendUpdate=true, bool onInit=false)
Definition Unit.cpp:5716
uint8 GetLevel() const
Definition Unit.h:769
uint8 GetRace() const
Definition Unit.h:773
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:271
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:315
#define sWorld
Definition World.h:919
TC_GAME_API HashMapHolder< Player >::MapType const & GetPlayers()
ChatCommandBuilder const [] ChatCommandTable
Definition ChatCommand.h:49
@ RBAC_PERM_COMMAND_RESET_STATS
Definition RBAC.h:589
@ RBAC_PERM_COMMAND_RESET_LEVEL
Definition RBAC.h:587
@ RBAC_PERM_COMMAND_RESET_HONOR
Definition RBAC.h:586
@ RBAC_PERM_COMMAND_RESET_ALL
Definition RBAC.h:591
@ RBAC_PERM_COMMAND_RESET
Definition RBAC.h:584
@ RBAC_PERM_COMMAND_RESET_SPELLS
Definition RBAC.h:588
@ RBAC_PERM_COMMAND_RESET_TALENTS
Definition RBAC.h:590
@ RBAC_PERM_COMMAND_RESET_ACHIEVEMENTS
Definition RBAC.h:585