Project SkyFire Core
SkyFire 5.4.8 server core API documentation
Loading...
Searching...
No Matches
cs_reset.cpp
Go to the documentation of this file.
1/*
2* This file is part of Project SkyFire https://www.projectskyfire.org.
3* See LICENSE.md file for Copyright information
4*/
5
6/* ScriptData
7Name: reset_commandscript
8%Complete: 100
9Comment: All reset related commands
10Category: commandscripts
11EndScriptData */
12
13#include "AchievementMgr.h"
14#include "Chat.h"
15#include "Language.h"
16#include "ObjectAccessor.h"
17#include "Pet.h"
18#include "Player.h"
19#include "ScriptMgr.h"
20
22{
23public:
24 reset_commandscript() : CommandScript("reset_commandscript") { }
25
26 std::vector<ChatCommand> GetCommands() const OVERRIDE
27 {
28 static std::vector<ChatCommand> resetCommandTable =
29 {
37 };
38 static std::vector<ChatCommand> commandTable =
39 {
40 { "reset", rbac::RBAC_PERM_COMMAND_RESET, true, NULL, "", resetCommandTable },
41 };
42 return commandTable;
43 }
44
45 static bool HandleResetAchievementsCommand(ChatHandler* handler, char const* args)
46 {
47 Player* target;
48 uint64 targetGuid;
49 if (!handler->extractPlayerTarget((char*)args, &target, &targetGuid))
50 return false;
51
52 if (target)
53 target->ResetAchievements();
54 else
56
57 return true;
58 }
59
60 static bool HandleResetHonorCommand(ChatHandler* handler, char const* args)
61 {
62 Player* target;
63 if (!handler->extractPlayerTarget((char*)args, &target))
64 return false;
65
69
70 return true;
71 }
72
74 {
75 ChrClassesEntry const* classEntry = sChrClassesStore.LookupEntry(player->getClass());
76 if (!classEntry)
77 {
78 SF_LOG_ERROR("misc", "Class %u not found in DBC (Wrong DBC files?)", player->getClass());
79 return false;
80 }
81
82 uint8 powerType = classEntry->powerType;
83
84 // reset m_form if no aura
87
88 player->setFactionForRace(player->getRace());
89
90 player->SetRace(player->getRace());
91 player->SetClass(player->getClass());
92 player->SetGender(player->getGender());
93
94 player->SetFieldPowerType(powerType);
95
96 // reset only if player not in some form;
97 if (player->GetShapeshiftForm() == FORM_NONE)
98 player->InitDisplayIds();
99
101
103
104 //-1 is default value
106 return true;
107 }
108
109 static bool HandleResetLevelCommand(ChatHandler* handler, char const* args)
110 {
111 Player* target;
112 if (!handler->extractPlayerTarget((char*)args, &target))
113 return false;
114
116 return false;
117
118 uint8 oldLevel = target->getLevel();
119
120 // set starting level
121 uint32 startLevel = target->getClass() != CLASS_DEATH_KNIGHT
124
125 target->_ApplyAllLevelScaleItemMods(false);
126 target->SetLevel(startLevel);
127 target->InitRunes();
128 target->InitStatsForLevel(true);
129 target->InitTaxiNodesForLevel();
130 target->InitGlyphsForLevel();
131 target->InitTalentForLevel();
133
134 target->_ApplyAllLevelScaleItemMods(true);
135
136 // reset level for pet
137 if (Pet* pet = target->GetPet())
138 pet->SynchronizeLevelWithOwner();
139
140 sScriptMgr->OnPlayerLevelChanged(target, oldLevel);
141
142 return true;
143 }
144
145 static bool HandleResetSpellsCommand(ChatHandler* handler, char const* args)
146 {
147 Player* target;
148 uint64 targetGuid;
149 std::string targetName;
150 if (!handler->extractPlayerTarget((char*)args, &target, &targetGuid, &targetName))
151 return false;
152
153 if (target)
154 {
155 target->resetSpells(/* bool myClassOnly */);
156
158 if (!handler->GetSession() || handler->GetSession()->GetPlayer() != target)
159 handler->PSendSysMessage(LANG_RESET_SPELLS_ONLINE, handler->GetNameLink(target).c_str());
160 }
161 else
162 {
165 stmt->setUInt32(1, GUID_LOPART(targetGuid));
166 CharacterDatabase.Execute(stmt);
167
168 handler->PSendSysMessage(LANG_RESET_SPELLS_OFFLINE, targetName.c_str());
169 }
170
171 return true;
172 }
173
174 static bool HandleResetStatsCommand(ChatHandler* handler, char const* args)
175 {
176 Player* target;
177 if (!handler->extractPlayerTarget((char*)args, &target))
178 return false;
179
181 return false;
182
183 target->InitRunes();
184 target->InitStatsForLevel(true);
185 target->InitTaxiNodesForLevel();
186 target->InitGlyphsForLevel();
187 target->InitTalentForLevel();
188
189 return true;
190 }
191
192 static bool HandleResetTalentsCommand(ChatHandler* handler, char const* args)
193 {
194 Player* target;
195 uint64 targetGuid;
196 std::string targetName;
197 if (!handler->extractPlayerTarget((char*)args, &target, &targetGuid, &targetName))
198 {
199 // Try reset talents as Hunter Pet
200 Creature* creature = handler->getSelectedCreature();
201 if (!*args && creature && creature->IsPet())
202 {
203 Unit* owner = creature->GetOwner();
204 if (owner && owner->GetTypeId() == TypeID::TYPEID_PLAYER && creature->ToPet()->IsPermanentPetFor(owner->ToPlayer()))
205 {
206 creature->ToPet()->resetTalents();
207
209 if (!handler->GetSession() || handler->GetSession()->GetPlayer() != owner->ToPlayer())
210 handler->PSendSysMessage(LANG_RESET_PET_TALENTS_ONLINE, handler->GetNameLink(owner->ToPlayer()).c_str());
211 }
212 return true;
213 }
214
216 handler->SetSentErrorMessage(true);
217 return false;
218 }
219
220 if (target)
221 {
222 target->ResetTalents(true);
223 target->SendTalentsInfoData();
225 if (!handler->GetSession() || handler->GetSession()->GetPlayer() != target)
226 handler->PSendSysMessage(LANG_RESET_TALENTS_ONLINE, handler->GetNameLink(target).c_str());
227
228 return true;
229 }
230 else if (targetGuid)
231 {
234 stmt->setUInt32(1, GUID_LOPART(targetGuid));
235 CharacterDatabase.Execute(stmt);
236
237 std::string nameLink = handler->playerLink(targetName);
238 handler->PSendSysMessage(LANG_RESET_TALENTS_OFFLINE, nameLink.c_str());
239 return true;
240 }
241
243 handler->SetSentErrorMessage(true);
244 return false;
245 }
246
247 static bool HandleResetAllCommand(ChatHandler* handler, char const* args)
248 {
249 if (!*args)
250 return false;
251
252 std::string caseName = args;
253
254 AtLoginFlags atLogin;
255
256 // Command specially created as single command to prevent using short case names
257 if (caseName == "spells")
258 {
259 atLogin = AT_LOGIN_RESET_SPELLS;
260 sWorld->SendWorldText(LANG_RESETALL_SPELLS);
261 if (!handler->GetSession())
263 }
264 else if (caseName == "talents")
265 {
267 sWorld->SendWorldText(LANG_RESETALL_TALENTS);
268 if (!handler->GetSession())
270 }
271 else
272 {
274 handler->SetSentErrorMessage(true);
275 return false;
276 }
277
279 stmt->setUInt16(0, uint16(atLogin));
280 CharacterDatabase.Execute(stmt);
281
283 HashMapHolder<Player>::MapType const& plist = sObjectAccessor->GetPlayers();
284 for (HashMapHolder<Player>::MapType::const_iterator itr = plist.begin(); itr != plist.end(); ++itr)
285 itr->second->SetAtLoginFlag(atLogin);
286
287 return true;
288 }
289};
290
@ CHAR_UPD_ADD_AT_LOGIN_FLAG
@ CHAR_UPD_ALL_AT_LOGIN_FLAGS
@ ACHIEVEMENT_CRITERIA_TYPE_EARN_HONORABLE_KILL
Definition DBCEnums.h:267
DBCStorage< ChrClassesEntry > sChrClassesStore(ChrClassesEntryfmt)
std::uint8_t uint8
Definition Define.h:79
std::uint32_t uint32
Definition Define.h:77
#define OVERRIDE
Definition Define.h:60
std::uint64_t uint64
Definition Define.h:76
std::uint16_t uint16
Definition Define.h:78
@ LANG_RESETALL_TALENTS
Definition Language.h:221
@ LANG_RESET_SPELLS_ONLINE
Definition Language.h:212
@ LANG_RESET_TALENTS_OFFLINE
Definition Language.h:215
@ LANG_RESET_SPELLS_OFFLINE
Definition Language.h:213
@ LANG_RESETALL_UNKNOWN_CASE
Definition Language.h:219
@ LANG_RESET_TALENTS_ONLINE
Definition Language.h:214
@ LANG_RESET_SPELLS
Definition Language.h:216
@ LANG_RESET_TALENTS
Definition Language.h:217
@ LANG_RESET_PET_TALENTS_ONLINE
Definition Language.h:917
@ LANG_NO_CHAR_SELECTED
Definition Language.h:118
@ LANG_RESET_PET_TALENTS
Definition Language.h:916
@ LANG_RESETALL_SPELLS
Definition Language.h:220
#define SF_LOG_ERROR(filterType__,...)
Definition Log.h:143
@ TYPEID_PLAYER
Definition Object.h:55
#define sObjectAccessor
uint32 GUID_LOPART(uint64 x)
AtLoginFlags
Definition Player.h:615
@ AT_LOGIN_RESET_TALENTS
Definition Player.h:619
@ AT_LOGIN_RESET_SPELLS
Definition Player.h:618
@ AT_LOGIN_NONE
Definition Player.h:616
@ AT_LOGIN_RESET_PET_TALENTS
Definition Player.h:621
#define sScriptMgr
Definition ScriptMgr.h:764
@ CLASS_DEATH_KNIGHT
#define SF_SHARED_GUARD
Definition SharedMutex.h:17
@ SPELL_AURA_MOD_SHAPESHIFT
@ FORM_NONE
Definition Unit.h:207
@ UNIT_BYTE2_FLAG_PVP
Definition Unit.h:255
@ UNIT_FLAG_PVP_ATTACKABLE
Definition Unit.h:628
@ UNIT_FIELD_SHAPESHIFT_FORM
@ UNIT_FIELD_FLAGS
@ PLAYER_FIELD_YESTERDAY_HONORABLE_KILLS
@ PLAYER_FIELD_XP
@ PLAYER_FIELD_WATCHED_FACTION_INDEX
@ PLAYER_FIELD_LIFETIME_HONORABLE_KILLS
static void DeleteFromDB(uint32 lowguid)
virtual std::string GetNameLink() const
Definition Chat.h:79
std::string playerLink(std::string const &name) const
Definition Chat.h:108
WorldSession * GetSession()
Definition Chat.h:43
Creature * getSelectedCreature()
Definition Chat.cpp:865
void PSendSysMessage(const char *format,...) ATTR_PRINTF(2
Definition Chat.cpp:221
void SetSentErrorMessage(bool val)
Definition Chat.h:114
bool extractPlayerTarget(char *args, Player **player, uint64 *player_guid=NULL, std::string *player_name=NULL)
Definition Chat.cpp:1184
virtual void SendSysMessage(const char *str)
Definition Chat.cpp:153
CommandScript(const char *name)
static SF_SHARED_MUTEX * GetLock()
UNORDERED_MAP< uint64, T * > MapType
void SetByteValue(uint16 index, uint8 offset, uint8 value)
Definition Object.cpp:1158
Player * ToPlayer()
Definition Object.h:204
TypeID GetTypeId() const
Definition Object.h:131
void SetUInt32Value(uint16 index, uint32 value)
Definition Object.cpp:1038
Definition Pet.h:28
bool IsPermanentPetFor(Player *owner) const
Definition Pet.cpp:1899
bool resetTalents()
Definition Pet.cpp:1679
void setFactionForRace(uint8 race)
Definition Player.cpp:7090
void _ApplyAllLevelScaleItemMods(bool apply)
Definition Player.cpp:9262
void InitTalentForLevel()
Definition Player.cpp:3283
void InitGlyphsForLevel()
Definition Player.cpp:20384
void SendTalentsInfoData()
Definition Player.cpp:21306
Pet * GetPet() const
Definition Player.cpp:15640
void InitDisplayIds()
Definition Player.cpp:16925
WorldSession * GetSession() const
Definition Player.h:2417
bool ResetTalents(bool noCost=false, bool resetTalents=true, bool resetSpecialization=true)
Definition Player.cpp:4497
void InitTaxiNodesForLevel()
Definition Player.h:1352
void InitStatsForLevel(bool reapplyMods=false)
Definition Player.cpp:3323
void UpdateAchievementCriteria(AchievementCriteriaTypes type, uint64 miscValue1=0, uint64 miscValue2=0, uint64 miscValue3=0, Unit *unit=NULL)
Definition Player.cpp:21033
void InitRunes()
Definition Player.cpp:20622
void resetSpells(bool myClassOnly=false)
Definition Player.cpp:18782
void ResetAchievements()
Definition Player.cpp:20998
void setUInt16(const uint8 index, const uint16 value)
void setUInt32(const uint8 index, const uint32 value)
Definition Unit.h:1367
uint8 getGender() const
Definition Unit.h:1551
Unit * GetOwner() const
Definition Unit.cpp:2339
Pet * ToPet()
Definition Unit.h:2803
void SetRace(uint8 race)
Definition Unit.h:1560
ShapeshiftForm GetShapeshiftForm() const
Definition Unit.h:2377
bool IsPet() const
Definition Unit.h:1511
uint8 getClass() const
Definition Unit.h:1543
void SetClass(uint8 newClass)
Definition Unit.h:1564
void SetGender(uint8 gender)
Definition Unit.h:1568
bool HasAuraType(AuraType auraType) const
uint8 getLevel() const
Definition Unit.h:1528
void SetLevel(uint8 lvl)
Definition Unit.cpp:5150
void SetFieldPowerType(uint32 powerType)
Definition Unit.h:1655
void SetShapeshiftForm(ShapeshiftForm form)
Definition Unit.cpp:4931
uint8 getRace() const
Definition Unit.h:1535
Player * GetPlayer() const
static bool HandleResetHonorCommand(ChatHandler *handler, char const *args)
Definition cs_reset.cpp:60
static bool HandleResetAllCommand(ChatHandler *handler, char const *args)
Definition cs_reset.cpp:247
static bool HandleResetTalentsCommand(ChatHandler *handler, char const *args)
Definition cs_reset.cpp:192
std::vector< ChatCommand > GetCommands() const OVERRIDE
Definition cs_reset.cpp:26
static bool HandleResetStatsCommand(ChatHandler *handler, char const *args)
Definition cs_reset.cpp:174
static bool HandleResetStatsOrLevelHelper(Player *player)
Definition cs_reset.cpp:73
static bool HandleResetLevelCommand(ChatHandler *handler, char const *args)
Definition cs_reset.cpp:109
static bool HandleResetAchievementsCommand(ChatHandler *handler, char const *args)
Definition cs_reset.cpp:45
static bool HandleResetSpellsCommand(ChatHandler *handler, char const *args)
Definition cs_reset.cpp:145
void AddSC_reset_commandscript()
Definition cs_reset.cpp:291
CharacterDatabaseWorkerPool CharacterDatabase
Accessor to the character database.
Definition Main.cpp:41
#define sWorld
Definition World.h:910
@ CONFIG_START_HEROIC_PLAYER_LEVEL
Definition World.h:228
@ CONFIG_START_PLAYER_LEVEL
Definition World.h:227
@ RBAC_PERM_COMMAND_RESET_STATS
Definition RBAC.h:603
@ RBAC_PERM_COMMAND_RESET_LEVEL
Definition RBAC.h:601
@ RBAC_PERM_COMMAND_RESET_HONOR
Definition RBAC.h:600
@ RBAC_PERM_COMMAND_RESET_ALL
Definition RBAC.h:605
@ RBAC_PERM_COMMAND_RESET
Definition RBAC.h:598
@ RBAC_PERM_COMMAND_RESET_SPELLS
Definition RBAC.h:602
@ RBAC_PERM_COMMAND_RESET_TALENTS
Definition RBAC.h:604
@ RBAC_PERM_COMMAND_RESET_ACHIEVEMENTS
Definition RBAC.h:599
uint32 powerType