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 player->SetPowerType(Powers(powerType), false);
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
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 uint32 startLevel = target->GetClass() != CLASS_DEATH_KNIGHT
141 ? sWorld->getIntConfig(CONFIG_START_PLAYER_LEVEL)
143
144 target->_ApplyAllLevelScaleItemMods(false);
145 target->SetLevel(startLevel);
146 target->InitRunes();
147 target->InitStatsForLevel(true);
148 target->InitTaxiNodesForLevel();
149 target->InitGlyphsForLevel();
150 target->InitTalentForLevel();
151 target->SetXP(0);
152
153 target->_ApplyAllLevelScaleItemMods(true);
154
155 // reset level for pet
156 if (Pet* pet = target->GetPet())
157 pet->SynchronizeLevelWithOwner();
158
159 sScriptMgr->OnPlayerLevelChanged(target, oldLevel);
160
161 return true;
162 }
163
164 static bool HandleResetSpellsCommand(ChatHandler* handler, char const* args)
165 {
166 Player* target;
167 ObjectGuid targetGuid;
168 std::string targetName;
169 if (!handler->extractPlayerTarget((char*)args, &target, &targetGuid, &targetName))
170 return false;
171
172 if (target)
173 {
174 target->ResetSpells(/* bool myClassOnly */);
175
177 if (!handler->GetSession() || handler->GetSession()->GetPlayer() != target)
178 handler->PSendSysMessage(LANG_RESET_SPELLS_ONLINE, handler->GetNameLink(target).c_str());
179 }
180 else
181 {
184 stmt->setUInt32(1, targetGuid.GetCounter());
185 CharacterDatabase.Execute(stmt);
186
187 handler->PSendSysMessage(LANG_RESET_SPELLS_OFFLINE, targetName.c_str());
188 }
189
190 return true;
191 }
192
193 static bool HandleResetStatsCommand(ChatHandler* handler, char const* args)
194 {
195 Player* target;
196 if (!handler->extractPlayerTarget((char*)args, &target))
197 return false;
198
200 return false;
201
202 target->InitRunes();
203 target->InitStatsForLevel(true);
204 target->InitTaxiNodesForLevel();
205 target->InitGlyphsForLevel();
206 target->InitTalentForLevel();
207
208 return true;
209 }
210
211 static bool HandleResetTalentsCommand(ChatHandler* handler, char const* args)
212 {
213 Player* target;
214 ObjectGuid targetGuid;
215 std::string targetName;
216 if (!handler->extractPlayerTarget((char*)args, &target, &targetGuid, &targetName))
217 {
218 // Try reset talents as Hunter Pet
219 Creature* creature = handler->getSelectedCreature();
220 if (!*args && creature && creature->IsPet())
221 {
222 Unit* owner = creature->GetOwner();
223 if (owner && owner->GetTypeId() == TYPEID_PLAYER && creature->ToPet()->IsPermanentPetFor(owner->ToPlayer()))
224 {
225 creature->ToPet()->resetTalents(true);
226 owner->ToPlayer()->SendTalentsInfoData(true);
227
228 if (!handler->GetSession() || handler->GetSession()->GetPlayer() != owner->ToPlayer())
229 handler->PSendSysMessage(LANG_RESET_PET_TALENTS_ONLINE, handler->GetNameLink(owner->ToPlayer()).c_str());
230 }
231 return true;
232 }
233
235 handler->SetSentErrorMessage(true);
236 return false;
237 }
238
239 if (target)
240 {
241 target->ResetTalents(true);
242 target->SendTalentsInfoData(false);
243 if (!handler->GetSession() || handler->GetSession()->GetPlayer() != target)
244 handler->PSendSysMessage(LANG_RESET_TALENTS_ONLINE, handler->GetNameLink(target).c_str());
245
246 Pet* pet = target->GetPet();
247 Pet::resetTalentsForAllPetsOf(target, pet, true);
248 if (pet)
249 target->SendTalentsInfoData(true);
250 return true;
251 }
252 else if (!targetGuid.IsEmpty())
253 {
256 stmt->setUInt32(1, targetGuid.GetCounter());
257 CharacterDatabase.Execute(stmt);
258
259 std::string nameLink = handler->playerLink(targetName);
260 handler->PSendSysMessage(LANG_RESET_TALENTS_OFFLINE, nameLink.c_str());
261 return true;
262 }
263
265 handler->SetSentErrorMessage(true);
266 return false;
267 }
268
269 static bool HandleResetAllCommand(ChatHandler* handler, char const* args)
270 {
271 if (!*args)
272 return false;
273
274 std::string caseName = args;
275
276 AtLoginFlags atLogin;
277
278 // Command specially created as single command to prevent using short case names
279 if (caseName == "spells")
280 {
281 atLogin = AT_LOGIN_RESET_SPELLS;
282 sWorld->SendWorldText(LANG_RESETALL_SPELLS);
283 if (!handler->GetSession())
285 }
286 else if (caseName == "talents")
287 {
289 sWorld->SendWorldText(LANG_RESETALL_TALENTS);
290 if (!handler->GetSession())
292 }
293 else
294 {
296 handler->SetSentErrorMessage(true);
297 return false;
298 }
299
301 stmt->setUInt16(0, uint16(atLogin));
302 CharacterDatabase.Execute(stmt);
303
304 std::shared_lock<std::shared_mutex> lock(*HashMapHolder<Player>::GetLock());
306 for (HashMapHolder<Player>::MapType::const_iterator itr = plist.begin(); itr != plist.end(); ++itr)
307 itr->second->SetAtLoginFlag(atLogin);
308
309 return true;
310 }
311};
312
@ 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:479
@ AT_LOGIN_RESET_TALENTS
Definition Player.h:483
@ AT_LOGIN_RESET_SPELLS
Definition Player.h:482
@ AT_LOGIN_NONE
Definition Player.h:480
@ AT_LOGIN_RESET_PET_TALENTS
Definition Player.h:485
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:119
WorldSession * GetSession()
Definition Chat.h:46
virtual std::string GetNameLink() const
Definition Chat.cpp:47
Creature * getSelectedCreature()
Definition Chat.cpp:230
void SetSentErrorMessage(bool val)
Definition Chat.h:126
void PSendSysMessage(char const *fmt, Args &&... args)
Definition Chat.h:61
virtual void SendSysMessage(std::string_view str, bool escapeCharacters=false)
Definition Chat.cpp:102
bool extractPlayerTarget(char *args, Player **player, ObjectGuid *player_guid=nullptr, std::string *player_name=nullptr)
Definition Chat.cpp:481
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:577
static Player * ToPlayer(Object *o)
Definition Object.h:183
Definition Pet.h:40
static void resetTalentsForAllPetsOf(Player *owner, Pet *online_pet=nullptr, bool involuntarily=false)
Definition Pet.cpp:1717
bool IsPermanentPetFor(Player *owner) const
Definition Pet.cpp:1850
bool resetTalents(bool involuntarily=false)
Definition Pet.cpp:1640
void _ApplyAllLevelScaleItemMods(bool apply)
Definition Player.cpp:7964
void ResetSpells(bool myClassOnly=false)
Definition Player.cpp:22642
void SendTalentsInfoData(bool pet)
Definition Player.cpp:25337
void InitTalentForLevel()
Definition Player.cpp:2542
void InitGlyphsForLevel()
Definition Player.cpp:24231
void UpdateAchievementCriteria(AchievementCriteriaTypes type, uint32 miscValue1=0, uint32 miscValue2=0, WorldObject *ref=nullptr)
Definition Player.cpp:24914
Pet * GetPet() const
Definition Player.cpp:20284
void InitDisplayIds()
Definition Player.cpp:21310
WorldSession * GetSession() const
Definition Player.h:1705
void SetHonorPoints(uint32 value)
Definition Player.cpp:6662
void InitTaxiNodesForLevel()
Definition Player.h:964
void InitStatsForLevel(bool reapplyMods=false)
Definition Player.cpp:2582
void SetXP(uint32 xp)
Definition Player.h:998
bool ResetTalents(bool involuntarily=false)
Definition Player.cpp:3735
void InitRunes()
Definition Player.cpp:24470
void SetFactionForRace(uint8 race)
Definition Player.cpp:6297
void ResetAchievements()
Definition Player.cpp:24884
void setUInt16(uint8 index, uint16 value)
void setUInt32(uint8 index, uint32 value)
Definition Unit.h:783
Pet * ToPet()
Definition Unit.h:1804
void ReplaceAllPvpFlags(UnitPVPStateFlags flags)
Definition Unit.h:999
uint8 GetClass() const
Definition Unit.h:909
ShapeshiftForm GetShapeshiftForm() const
Definition Unit.h:1503
void ReplaceAllUnitFlags(UnitFlags flags)
Definition Unit.h:970
bool IsPet() const
Definition Unit.h:898
bool HasAuraType(AuraType auraType) const
Definition Unit.cpp:4565
void SetPowerType(Powers power, bool sendUpdate=true)
Definition Unit.cpp:5350
void SetLevel(uint8 lvl, bool sendUpdate=true)
Definition Unit.cpp:9321
void SetShapeshiftForm(ShapeshiftForm form)
Definition Unit.cpp:8904
uint8 GetLevel() const
Definition Unit.h:903
uint8 GetRace() const
Definition Unit.h:906
Unit * GetOwner() const
Definition Object.cpp:2181
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:269
static bool HandleResetTalentsCommand(ChatHandler *handler, char const *args)
Definition cs_reset.cpp:211
static bool HandleResetStatsCommand(ChatHandler *handler, char const *args)
Definition cs_reset.cpp:193
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:66
static bool HandleResetSpellsCommand(ChatHandler *handler, char const *args)
Definition cs_reset.cpp:164
void AddSC_reset_commandscript()
Definition cs_reset.cpp:313
#define sWorld
Definition World.h:901
@ CONFIG_START_DEATH_KNIGHT_PLAYER_LEVEL
Definition World.h:240
@ CONFIG_START_PLAYER_LEVEL
Definition World.h:239
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