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 "DatabaseEnv.h"
29#include "Language.h"
30#include "Log.h"
31#include "ObjectAccessor.h"
32#include "Pet.h"
33#include "Player.h"
34#include "RBAC.h"
35#include "World.h"
36#include "WorldSession.h"
37
38#if TRINITY_COMPILER == TRINITY_COMPILER_GNU
39#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
40#endif
41
43{
44public:
45 reset_commandscript() : CommandScript("reset_commandscript") { }
46
47 std::vector<ChatCommand> GetCommands() const override
48 {
49 static std::vector<ChatCommand> resetCommandTable =
50 {
58 };
59 static std::vector<ChatCommand> commandTable =
60 {
61 { "reset", rbac::RBAC_PERM_COMMAND_RESET, true, nullptr, "", resetCommandTable },
62 };
63 return commandTable;
64 }
65
66 static bool HandleResetAchievementsCommand(ChatHandler* handler, char const* args)
67 {
68 Player* target;
69 ObjectGuid targetGuid;
70 if (!handler->extractPlayerTarget((char*)args, &target, &targetGuid))
71 return false;
72
73 if (target)
74 target->ResetAchievements();
75 else
77
78 return true;
79 }
80
81 static bool HandleResetHonorCommand(ChatHandler* handler, char const* args)
82 {
83 Player* target;
84 if (!handler->extractPlayerTarget((char*)args, &target))
85 return false;
86
87 target->SetHonorPoints(0);
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
114 player->SetPowerType(Powers(powerType), false);
115
116 // reset only if player not in some form;
117 if (player->GetShapeshiftForm() == FORM_NONE)
118 player->InitDisplayIds();
119
121
123
124 //-1 is default value
126 return true;
127 }
128
129 static bool HandleResetLevelCommand(ChatHandler* handler, char const* args)
130 {
131 Player* target;
132 if (!handler->extractPlayerTarget((char*)args, &target))
133 return false;
134
136 return false;
137
138 uint8 oldLevel = target->GetLevel();
139
140 // set starting level
141 uint32 startLevel = target->GetClass() != CLASS_DEATH_KNIGHT
142 ? sWorld->getIntConfig(CONFIG_START_PLAYER_LEVEL)
144
145 target->_ApplyAllLevelScaleItemMods(false);
146 target->SetLevel(startLevel);
147 target->InitRunes();
148 target->InitStatsForLevel(true);
149 target->InitTaxiNodesForLevel();
150 target->InitGlyphsForLevel();
151 target->InitTalentForLevel();
152 target->SetXP(0);
153
154 target->_ApplyAllLevelScaleItemMods(true);
155
156 // reset level for pet
157 if (Pet* pet = target->GetPet())
158 pet->SynchronizeLevelWithOwner();
159
160 sScriptMgr->OnPlayerLevelChanged(target, oldLevel);
161
162 return true;
163 }
164
165 static bool HandleResetSpellsCommand(ChatHandler* handler, char const* args)
166 {
167 Player* target;
168 ObjectGuid targetGuid;
169 std::string targetName;
170 if (!handler->extractPlayerTarget((char*)args, &target, &targetGuid, &targetName))
171 return false;
172
173 if (target)
174 {
175 target->ResetSpells(/* bool myClassOnly */);
176
178 if (!handler->GetSession() || handler->GetSession()->GetPlayer() != target)
179 handler->PSendSysMessage(LANG_RESET_SPELLS_ONLINE, handler->GetNameLink(target).c_str());
180 }
181 else
182 {
185 stmt->setUInt32(1, targetGuid.GetCounter());
186 CharacterDatabase.Execute(stmt);
187
188 handler->PSendSysMessage(LANG_RESET_SPELLS_OFFLINE, targetName.c_str());
189 }
190
191 return true;
192 }
193
194 static bool HandleResetStatsCommand(ChatHandler* handler, char const* args)
195 {
196 Player* target;
197 if (!handler->extractPlayerTarget((char*)args, &target))
198 return false;
199
201 return false;
202
203 target->InitRunes();
204 target->InitStatsForLevel(true);
205 target->InitTaxiNodesForLevel();
206 target->InitGlyphsForLevel();
207 target->InitTalentForLevel();
208
209 return true;
210 }
211
212 static bool HandleResetTalentsCommand(ChatHandler* handler, char const* args)
213 {
214 Player* target;
215 ObjectGuid targetGuid;
216 std::string targetName;
217 if (!handler->extractPlayerTarget((char*)args, &target, &targetGuid, &targetName))
218 {
219 // Try reset talents as Hunter Pet
220 Creature* creature = handler->getSelectedCreature();
221 if (!*args && creature && creature->IsPet())
222 {
223 Unit* owner = creature->GetOwner();
224 if (owner && owner->GetTypeId() == TYPEID_PLAYER && creature->ToPet()->IsPermanentPetFor(owner->ToPlayer()))
225 {
226 creature->ToPet()->resetTalents(true);
227 owner->ToPlayer()->SendTalentsInfoData(true);
228
229 if (!handler->GetSession() || handler->GetSession()->GetPlayer() != owner->ToPlayer())
230 handler->PSendSysMessage(LANG_RESET_PET_TALENTS_ONLINE, handler->GetNameLink(owner->ToPlayer()).c_str());
231 }
232 return true;
233 }
234
236 handler->SetSentErrorMessage(true);
237 return false;
238 }
239
240 if (target)
241 {
242 target->ResetTalents(true);
243 target->SendTalentsInfoData(false);
244 if (!handler->GetSession() || handler->GetSession()->GetPlayer() != target)
245 handler->PSendSysMessage(LANG_RESET_TALENTS_ONLINE, handler->GetNameLink(target).c_str());
246
247 Pet* pet = target->GetPet();
248 Pet::resetTalentsForAllPetsOf(target, pet, true);
249 if (pet)
250 target->SendTalentsInfoData(true);
251 return true;
252 }
253 else if (!targetGuid.IsEmpty())
254 {
257 stmt->setUInt32(1, targetGuid.GetCounter());
258 CharacterDatabase.Execute(stmt);
259
260 std::string nameLink = handler->playerLink(targetName);
261 handler->PSendSysMessage(LANG_RESET_TALENTS_OFFLINE, nameLink.c_str());
262 return true;
263 }
264
266 handler->SetSentErrorMessage(true);
267 return false;
268 }
269
270 static bool HandleResetAllCommand(ChatHandler* handler, char const* args)
271 {
272 if (!*args)
273 return false;
274
275 std::string caseName = args;
276
277 AtLoginFlags atLogin;
278
279 // Command specially created as single command to prevent using short case names
280 if (caseName == "spells")
281 {
282 atLogin = AT_LOGIN_RESET_SPELLS;
283 sWorld->SendWorldText(LANG_RESETALL_SPELLS);
284 if (!handler->GetSession())
286 }
287 else if (caseName == "talents")
288 {
290 sWorld->SendWorldText(LANG_RESETALL_TALENTS);
291 if (!handler->GetSession())
293 }
294 else
295 {
297 handler->SetSentErrorMessage(true);
298 return false;
299 }
300
302 stmt->setUInt16(0, uint16(atLogin));
303 CharacterDatabase.Execute(stmt);
304
305 std::shared_lock<std::shared_mutex> lock(*HashMapHolder<Player>::GetLock());
307 for (HashMapHolder<Player>::MapType::const_iterator itr = plist.begin(); itr != plist.end(); ++itr)
308 itr->second->SetAtLoginFlag(atLogin);
309
310 return true;
311 }
312};
313
@ CHAR_UPD_ADD_AT_LOGIN_FLAG
@ CHAR_UPD_ALL_AT_LOGIN_FLAGS
@ ACHIEVEMENT_CRITERIA_TYPE_EARN_HONORABLE_KILL
Definition DBCEnums.h:232
DBCStorage< ChrClassesEntry > sChrClassesStore(ChrClassesEntryfmt)
DatabaseWorkerPool< CharacterDatabaseConnection > CharacterDatabase
Accessor to the character database.
uint8_t uint8
Definition Define.h:135
uint16_t uint16
Definition Define.h:134
uint32_t uint32
Definition Define.h:133
@ 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_PET_TALENTS_ONLINE
Definition Language.h:903
@ LANG_NO_CHAR_SELECTED
Definition Language.h:150
@ LANG_RESETALL_SPELLS
Definition Language.h:264
#define TC_LOG_ERROR(filterType__,...)
Definition Log.h:165
@ TYPEID_PLAYER
Definition ObjectGuid.h:39
AtLoginFlags
Definition Player.h:471
@ AT_LOGIN_RESET_TALENTS
Definition Player.h:475
@ AT_LOGIN_RESET_SPELLS
Definition Player.h:474
@ AT_LOGIN_NONE
Definition Player.h:472
@ AT_LOGIN_RESET_PET_TALENTS
Definition Player.h:477
Role Based Access Control related classes definition.
#define sScriptMgr
Definition ScriptMgr.h:1168
@ CLASS_DEATH_KNIGHT
Powers
@ SPELL_AURA_MOD_SHAPESHIFT
@ FORM_NONE
@ UNIT_BYTE2_FLAG_PVP
@ UNIT_FLAG_PLAYER_CONTROLLED
@ PLAYER_FIELD_TODAY_CONTRIBUTION
@ PLAYER_FIELD_KILLS
@ PLAYER_FIELD_YESTERDAY_CONTRIBUTION
@ PLAYER_FIELD_WATCHED_FACTION_INDEX
@ PLAYER_FIELD_LIFETIME_HONORABLE_KILLS
static void DeleteFromDB(ObjectGuid lowguid)
std::string playerLink(std::string const &name) const
Definition Chat.h:127
WorldSession * GetSession()
Definition Chat.h:46
virtual std::string GetNameLink() const
Definition Chat.cpp:46
Creature * getSelectedCreature()
Definition Chat.cpp:338
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
bool extractPlayerTarget(char *args, Player **player, ObjectGuid *player_guid=nullptr, std::string *player_name=nullptr)
Definition Chat.cpp:589
std::unordered_map< ObjectGuid, T * > MapType
LowType GetCounter() const
Definition ObjectGuid.h:156
bool IsEmpty() const
Definition ObjectGuid.h:172
TypeID GetTypeId() const
Definition Object.h:93
void SetUInt32Value(uint16 index, uint32 value)
Definition Object.cpp:585
static Player * ToPlayer(Object *o)
Definition Object.h:180
Definition Pet.h:40
static void resetTalentsForAllPetsOf(Player *owner, Pet *online_pet=nullptr, bool involuntarily=false)
Definition Pet.cpp:1720
bool IsPermanentPetFor(Player *owner) const
Definition Pet.cpp:1853
bool resetTalents(bool involuntarily=false)
Definition Pet.cpp:1643
void _ApplyAllLevelScaleItemMods(bool apply)
Definition Player.cpp:7963
void ResetSpells(bool myClassOnly=false)
Definition Player.cpp:22666
void SendTalentsInfoData(bool pet)
Definition Player.cpp:25366
void InitTalentForLevel()
Definition Player.cpp:2506
void InitGlyphsForLevel()
Definition Player.cpp:24256
void UpdateAchievementCriteria(AchievementCriteriaTypes type, uint32 miscValue1=0, uint32 miscValue2=0, WorldObject *ref=nullptr)
Definition Player.cpp:24940
Pet * GetPet() const
Definition Player.cpp:20286
void InitDisplayIds()
Definition Player.cpp:21313
WorldSession * GetSession() const
Definition Player.h:1719
void SetHonorPoints(uint32 value)
Definition Player.cpp:6661
void InitTaxiNodesForLevel()
Definition Player.h:986
void InitStatsForLevel(bool reapplyMods=false)
Definition Player.cpp:2546
void SetXP(uint32 xp)
Definition Player.h:1020
bool ResetTalents(bool involuntarily=false)
Definition Player.cpp:3707
void InitRunes()
Definition Player.cpp:24495
void SetFactionForRace(uint8 race)
Definition Player.cpp:6295
void ResetAchievements()
Definition Player.cpp:24910
void setUInt16(uint8 index, uint16 value)
void setUInt32(uint8 index, uint32 value)
Definition Unit.h:769
Pet * ToPet()
Definition Unit.h:1788
void ReplaceAllPvpFlags(UnitPVPStateFlags flags)
Definition Unit.h:985
uint8 GetClass() const
Definition Unit.h:895
ShapeshiftForm GetShapeshiftForm() const
Definition Unit.h:1490
void ReplaceAllUnitFlags(UnitFlags flags)
Definition Unit.h:956
bool IsPet() const
Definition Unit.h:884
bool HasAuraType(AuraType auraType) const
Definition Unit.cpp:4542
void SetPowerType(Powers power, bool sendUpdate=true)
Definition Unit.cpp:5408
void SetLevel(uint8 lvl, bool sendUpdate=true)
Definition Unit.cpp:9344
void SetShapeshiftForm(ShapeshiftForm form)
Definition Unit.cpp:8964
uint8 GetLevel() const
Definition Unit.h:889
uint8 GetRace() const
Definition Unit.h:892
Unit * GetOwner() const
Definition Object.cpp:2180
Player * GetPlayer() const
std::vector< ChatCommand > GetCommands() const override
Definition cs_reset.cpp:47
static bool HandleResetHonorCommand(ChatHandler *handler, char const *args)
Definition cs_reset.cpp:81
static bool HandleResetAllCommand(ChatHandler *handler, char const *args)
Definition cs_reset.cpp:270
static bool HandleResetTalentsCommand(ChatHandler *handler, char const *args)
Definition cs_reset.cpp:212
static bool HandleResetStatsCommand(ChatHandler *handler, char const *args)
Definition cs_reset.cpp:194
static bool HandleResetStatsOrLevelHelper(Player *player)
Definition cs_reset.cpp:97
static bool HandleResetLevelCommand(ChatHandler *handler, char const *args)
Definition cs_reset.cpp:129
static bool HandleResetAchievementsCommand(ChatHandler *handler, char const *args)
Definition cs_reset.cpp:66
static bool HandleResetSpellsCommand(ChatHandler *handler, char const *args)
Definition cs_reset.cpp:165
void AddSC_reset_commandscript()
Definition cs_reset.cpp:314
#define sWorld
Definition World.h:900
@ CONFIG_START_DEATH_KNIGHT_PLAYER_LEVEL
Definition World.h:239
@ CONFIG_START_PLAYER_LEVEL
Definition World.h:238
TC_GAME_API HashMapHolder< Player >::MapType const & GetPlayers()
@ RBAC_PERM_COMMAND_RESET_STATS
Definition RBAC.h:585
@ RBAC_PERM_COMMAND_RESET_LEVEL
Definition RBAC.h:583
@ RBAC_PERM_COMMAND_RESET_HONOR
Definition RBAC.h:582
@ RBAC_PERM_COMMAND_RESET_ALL
Definition RBAC.h:587
@ RBAC_PERM_COMMAND_RESET
Definition RBAC.h:580
@ RBAC_PERM_COMMAND_RESET_SPELLS
Definition RBAC.h:584
@ RBAC_PERM_COMMAND_RESET_TALENTS
Definition RBAC.h:586
@ RBAC_PERM_COMMAND_RESET_ACHIEVEMENTS
Definition RBAC.h:581