TrinityCore
cs_cheat.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: cheat_commandscript
20%Complete: 100
21Comment: All cheat related commands
22Category: commandscripts
23EndScriptData */
24
25#include "ScriptMgr.h"
26#include "Chat.h"
27#include "ChatCommand.h"
28#include "Language.h"
29#include "Player.h"
30#include "RBAC.h"
31#include "WorldSession.h"
32
33using namespace Trinity::ChatCommands;
34
36{
37public:
38 cheat_commandscript() : CommandScript("cheat_commandscript") { }
39
41 {
42 static ChatCommandTable cheatCommandTable =
43 {
52
53 };
54
55 static ChatCommandTable commandTable =
56 {
57 { "cheat", cheatCommandTable },
58 };
59 return commandTable;
60 }
61
62 static bool HandleGodModeCheatCommand(ChatHandler* handler, Optional<bool> enableArg)
63 {
64 bool enable = !handler->GetSession()->GetPlayer()->GetCommandStatus(CHEAT_GOD);
65 if (enableArg)
66 enable = *enableArg;
67
68 if (enable)
69 {
71 handler->SendSysMessage("Godmode is ON. You won't take damage.");
72 }
73 else
74 {
76 handler->SendSysMessage("Godmode is OFF. You can take damage.");
77 }
78
79 return true;
80 }
81
82 static bool HandleCasttimeCheatCommand(ChatHandler* handler, Optional<bool> enableArg)
83 {
84 bool enable = !handler->GetSession()->GetPlayer()->GetCommandStatus(CHEAT_CASTTIME);
85 if (enableArg)
86 enable = *enableArg;
87
88 if (enable)
89 {
91 handler->SendSysMessage("CastTime Cheat is ON. Your spells won't have a casttime.");
92 }
93 else
94 {
96 handler->SendSysMessage("CastTime Cheat is OFF. Your spells will have a casttime.");
97 }
98
99 return true;
100 }
101
103 {
104 bool enable = !handler->GetSession()->GetPlayer()->GetCommandStatus(CHEAT_COOLDOWN);
105 if (enableArg)
106 enable = *enableArg;
107
108 if (enable)
109 {
111 handler->SendSysMessage("Cooldown Cheat is ON. You are not on the global cooldown.");
112 }
113 else
114 {
116 handler->SendSysMessage("Cooldown Cheat is OFF. You are on the global cooldown.");
117 }
118
119 return true;
120 }
121
122 static bool HandlePowerCheatCommand(ChatHandler* handler, Optional<bool> enableArg)
123 {
124 bool enable = !handler->GetSession()->GetPlayer()->GetCommandStatus(CHEAT_POWER);
125 if (enableArg)
126 enable = *enableArg;
127
128 if (enable)
129 {
130 Player* player = handler->GetSession()->GetPlayer();
131 // Set max power to all powers
132 for (uint32 i = 0; i < MAX_POWERS; ++i)
133 player->SetFullPower(Powers(i));
135 handler->SendSysMessage("Power Cheat is ON. You don't need mana/rage/energy to use spells.");
136 }
137 else
138 {
140 handler->SendSysMessage("Power Cheat is OFF. You need mana/rage/energy to use spells.");
141 }
142
143 return true;
144 }
145
147 {
148 Player* player = handler->GetSession()->GetPlayer();
149
150 char const* enabled = "ON";
151 char const* disabled = "OFF";
152
154 handler->PSendSysMessage(LANG_COMMAND_CHEAT_GOD, player->GetCommandStatus(CHEAT_GOD) ? enabled : disabled);
155 handler->PSendSysMessage(LANG_COMMAND_CHEAT_CD, player->GetCommandStatus(CHEAT_COOLDOWN) ? enabled : disabled);
156 handler->PSendSysMessage(LANG_COMMAND_CHEAT_CT, player->GetCommandStatus(CHEAT_CASTTIME) ? enabled : disabled);
157 handler->PSendSysMessage(LANG_COMMAND_CHEAT_POWER, player->GetCommandStatus(CHEAT_POWER) ? enabled : disabled);
158 handler->PSendSysMessage(LANG_COMMAND_CHEAT_WW, player->GetCommandStatus(CHEAT_WATERWALK) ? enabled : disabled);
159 handler->PSendSysMessage(LANG_COMMAND_CHEAT_TAXINODES, player->isTaxiCheater() ? enabled : disabled);
160 return true;
161 }
162
164 {
165 bool enable = !handler->GetSession()->GetPlayer()->GetCommandStatus(CHEAT_WATERWALK);
166 if (enableArg)
167 enable = *enableArg;
168
169 if (enable)
170 {
172 handler->GetSession()->GetPlayer()->SetWaterWalking(true); // ON
173 handler->SendSysMessage("Waterwalking is ON. You can walk on water.");
174 }
175 else
176 {
178 handler->GetSession()->GetPlayer()->SetWaterWalking(false); // OFF
179 handler->SendSysMessage("Waterwalking is OFF. You can't walk on water.");
180 }
181
182 return true;
183 }
184
185 static bool HandleTaxiCheatCommand(ChatHandler* handler, Optional<bool> enableArg)
186 {
187 Player* chr = handler->getSelectedPlayer();
188
189 if (!chr)
190 chr = handler->GetSession()->GetPlayer();
191 else if (handler->HasLowerSecurity(chr, ObjectGuid::Empty)) // check online security
192 return false;
193
194 bool enable = !chr->isTaxiCheater();
195 if (enableArg)
196 enable = *enableArg;
197
198 if (enable)
199 {
200 chr->SetTaxiCheater(true);
201 handler->PSendSysMessage(LANG_YOU_GIVE_TAXIS, handler->GetNameLink(chr).c_str());
202 if (handler->needReportToTarget(chr))
204 }
205 else
206 {
207 chr->SetTaxiCheater(false);
208 handler->PSendSysMessage(LANG_YOU_REMOVE_TAXIS, handler->GetNameLink(chr).c_str());
209 if (handler->needReportToTarget(chr))
211 }
212
213 return true;
214 }
215
216 static bool HandleExploreCheatCommand(ChatHandler* handler, bool reveal)
217 {
218 Player* chr = handler->getSelectedPlayer();
219 if (!chr)
220 {
222 handler->SetSentErrorMessage(true);
223 return false;
224 }
225
226 if (reveal)
227 {
228 handler->PSendSysMessage(LANG_YOU_SET_EXPLORE_ALL, handler->GetNameLink(chr).c_str());
229 if (handler->needReportToTarget(chr))
231 }
232 else
233 {
234 handler->PSendSysMessage(LANG_YOU_SET_EXPLORE_NOTHING, handler->GetNameLink(chr).c_str());
235 if (handler->needReportToTarget(chr))
237 }
238
239 for (uint16 i = 0; i < PLAYER_EXPLORED_ZONES_SIZE; ++i)
240 {
241 if (reveal)
242 handler->GetSession()->GetPlayer()->AddExploredZones(i, 0xFFFFFFFFFFFFFFFF);
243 else
244 handler->GetSession()->GetPlayer()->RemoveExploredZones(i, 0xFFFFFFFFFFFFFFFF);
245 }
246
247 return true;
248 }
249};
250
252{
254}
constexpr size_t PLAYER_EXPLORED_ZONES_SIZE
Definition: DBCEnums.h:166
uint16_t uint16
Definition: Define.h:143
uint32_t uint32
Definition: Define.h:142
@ LANG_YOU_SET_EXPLORE_NOTHING
Definition: Language.h:629
@ LANG_YOURS_TAXIS_REMOVED
Definition: Language.h:172
@ LANG_COMMAND_CHEAT_CT
Definition: Language.h:415
@ LANG_YOURS_TAXIS_ADDED
Definition: Language.h:171
@ LANG_COMMAND_CHEAT_WW
Definition: Language.h:418
@ LANG_COMMAND_CHEAT_POWER
Definition: Language.h:417
@ LANG_COMMAND_CHEAT_GOD
Definition: Language.h:414
@ LANG_YOU_REMOVE_TAXIS
Definition: Language.h:170
@ LANG_COMMAND_CHEAT_CD
Definition: Language.h:416
@ LANG_YOURS_EXPLORE_SET_ALL
Definition: Language.h:630
@ LANG_NO_CHAR_SELECTED
Definition: Language.h:150
@ LANG_YOU_SET_EXPLORE_ALL
Definition: Language.h:628
@ LANG_YOURS_EXPLORE_SET_NOTHING
Definition: Language.h:631
@ LANG_YOU_GIVE_TAXIS
Definition: Language.h:169
@ LANG_COMMAND_CHEAT_STATUS
Definition: Language.h:413
@ LANG_COMMAND_CHEAT_TAXINODES
Definition: Language.h:420
std::optional< T > Optional
Optional helper class to wrap optional values within.
Definition: Optional.h:25
@ CHEAT_COOLDOWN
Definition: Player.h:951
@ CHEAT_POWER
Definition: Player.h:952
@ CHEAT_GOD
Definition: Player.h:949
@ CHEAT_WATERWALK
Definition: Player.h:953
@ CHEAT_CASTTIME
Definition: Player.h:950
Role Based Access Control related classes definition.
Powers
@ MAX_POWERS
Player * getSelectedPlayer()
Definition: Chat.cpp:200
WorldSession * GetSession()
Definition: Chat.h:42
virtual std::string GetNameLink() const
Definition: Chat.cpp:58
void PSendSysMessage(const char *fmt, Args &&... args)
Definition: Chat.h:57
bool HasLowerSecurity(Player *target, ObjectGuid guid, bool strong=false)
Definition: Chat.cpp:63
void SetSentErrorMessage(bool val)
Definition: Chat.h:114
virtual void SendSysMessage(std::string_view str, bool escapeCharacters=false)
Definition: Chat.cpp:113
virtual bool needReportToTarget(Player *chr) const
Definition: Chat.cpp:586
static ObjectGuid const Empty
Definition: ObjectGuid.h:274
bool GetCommandStatus(uint32 command) const
Definition: Player.h:1206
WorldSession * GetSession() const
Definition: Player.h:2101
void SetCommandStatusOn(uint32 command)
Definition: Player.h:1207
void AddExploredZones(uint32 pos, uint64 mask)
Definition: Player.cpp:6421
void SetCommandStatusOff(uint32 command)
Definition: Player.h:1208
void RemoveExploredZones(uint32 pos, uint64 mask)
Definition: Player.cpp:6429
void SetTaxiCheater(bool on)
Definition: Player.h:1185
bool isTaxiCheater() const
Definition: Player.h:1184
void SetFullPower(Powers power)
Definition: Unit.h:812
bool SetWaterWalking(bool enable)
Definition: Unit.cpp:12863
Player * GetPlayer() const
static bool HandleCasttimeCheatCommand(ChatHandler *handler, Optional< bool > enableArg)
Definition: cs_cheat.cpp:82
static bool HandleExploreCheatCommand(ChatHandler *handler, bool reveal)
Definition: cs_cheat.cpp:216
ChatCommandTable GetCommands() const override
Definition: cs_cheat.cpp:40
static bool HandleWaterWalkCheatCommand(ChatHandler *handler, Optional< bool > enableArg)
Definition: cs_cheat.cpp:163
static bool HandleCoolDownCheatCommand(ChatHandler *handler, Optional< bool > enableArg)
Definition: cs_cheat.cpp:102
static bool HandleTaxiCheatCommand(ChatHandler *handler, Optional< bool > enableArg)
Definition: cs_cheat.cpp:185
static bool HandleGodModeCheatCommand(ChatHandler *handler, Optional< bool > enableArg)
Definition: cs_cheat.cpp:62
static bool HandleCheatStatusCommand(ChatHandler *handler)
Definition: cs_cheat.cpp:146
static bool HandlePowerCheatCommand(ChatHandler *handler, Optional< bool > enableArg)
Definition: cs_cheat.cpp:122
void AddSC_cheat_commandscript()
Definition: cs_cheat.cpp:251
std::vector< ChatCommandBuilder > ChatCommandTable
Definition: ChatCommand.h:49
@ RBAC_PERM_COMMAND_CHEAT_POWER
Definition: RBAC.h:210
@ RBAC_PERM_COMMAND_CHEAT_TAXI
Definition: RBAC.h:212
@ RBAC_PERM_COMMAND_CHEAT_GOD
Definition: RBAC.h:209
@ RBAC_PERM_COMMAND_CHEAT_COOLDOWN
Definition: RBAC.h:207
@ RBAC_PERM_COMMAND_CHEAT_CASTTIME
Definition: RBAC.h:206
@ RBAC_PERM_COMMAND_CHEAT_WATERWALK
Definition: RBAC.h:213
@ RBAC_PERM_COMMAND_CHEAT_STATUS
Definition: RBAC.h:211
@ RBAC_PERM_COMMAND_CHEAT_EXPLORE
Definition: RBAC.h:208