TrinityCore
cs_deserter.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
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 "SpellAuras.h"
32
33using namespace Trinity::ChatCommands;
34
36{
38 BG_SPELL_DESERTER = 26013
39};
40
42{
43public:
44 deserter_commandscript() : CommandScript("deserter_commandscript") { }
45
51 {
52 static ChatCommandTable deserterInstanceCommandTable =
53 {
56 };
57 static ChatCommandTable deserterBGCommandTable =
58 {
61 };
62
63 static ChatCommandTable deserterCommandTable =
64 {
65 { "instance", deserterInstanceCommandTable },
66 { "bg", deserterBGCommandTable },
67 };
68 static ChatCommandTable commandTable =
69 {
70 { "deserter", deserterCommandTable },
71 };
72 return commandTable;
73 }
74
95 static bool HandleDeserterAdd(ChatHandler* handler, uint32 time, bool isInstance)
96 {
97 Player* player = handler->getSelectedPlayer();
98 if (!player)
99 {
101 handler->SetSentErrorMessage(true);
102 return false;
103 }
104
105 if (!time)
106 {
108 handler->SetSentErrorMessage(true);
109 return false;
110 }
111
112 Aura* aura = player->AddAura(isInstance ? LFG_SPELL_DUNGEON_DESERTER : BG_SPELL_DESERTER, player);
113
114 if (!aura)
115 {
117 handler->SetSentErrorMessage(true);
118 return false;
119 }
120 aura->SetDuration(time * IN_MILLISECONDS);
121
122 return true;
123 }
124
144 static bool HandleDeserterRemove(ChatHandler* handler, bool isInstance)
145 {
146 Player* player = handler->getSelectedPlayer();
147 if (!player)
148 {
150 handler->SetSentErrorMessage(true);
151 return false;
152 }
153
155
156 return true;
157 }
158
160 static bool HandleDeserterInstanceAdd(ChatHandler* handler, uint32 time)
161 {
162 return HandleDeserterAdd(handler, time, true);
163 }
164
166 static bool HandleDeserterBGAdd(ChatHandler* handler, uint32 time)
167 {
168 return HandleDeserterAdd(handler, time, false);
169 }
170
173 {
174 return HandleDeserterRemove(handler, true);
175 }
176
179 {
180 return HandleDeserterRemove(handler, false);
181 }
182};
183
185{
187}
@ IN_MILLISECONDS
Definition: Common.h:35
uint32_t uint32
Definition: Define.h:142
@ LANG_NO_CHAR_SELECTED
Definition: Language.h:150
@ LANG_BAD_VALUE
Definition: Language.h:149
Spells
Definition: PlayerAI.cpp:32
Role Based Access Control related classes definition.
void SetDuration(int32 duration, bool withMods=false)
Definition: SpellAuras.cpp:892
Player * getSelectedPlayer()
Definition: Chat.cpp:200
void SetSentErrorMessage(bool val)
Definition: Chat.h:114
virtual void SendSysMessage(std::string_view str, bool escapeCharacters=false)
Definition: Chat.cpp:113
void RemoveAura(AuraApplicationMap::iterator &i, AuraRemoveMode mode=AURA_REMOVE_BY_DEFAULT)
Definition: Unit.cpp:3685
Aura * AddAura(uint32 spellId, Unit *target)
Definition: Unit.cpp:11618
static bool HandleDeserterInstanceRemove(ChatHandler *handler)
ChatCommandTable GetCommands() const override
Returns the command structure for the system.
Definition: cs_deserter.cpp:50
static bool HandleDeserterAdd(ChatHandler *handler, uint32 time, bool isInstance)
Applies the Deserter Debuff to a player.
Definition: cs_deserter.cpp:95
static bool HandleDeserterRemove(ChatHandler *handler, bool isInstance)
Removes the Deserter Debuff from a player.
static bool HandleDeserterBGRemove(ChatHandler *handler)
static bool HandleDeserterBGAdd(ChatHandler *handler, uint32 time)
static bool HandleDeserterInstanceAdd(ChatHandler *handler, uint32 time)
void AddSC_deserter_commandscript()
@ LFG_SPELL_DUNGEON_DESERTER
Definition: cs_deserter.cpp:37
@ BG_SPELL_DESERTER
Definition: cs_deserter.cpp:38
std::vector< ChatCommandBuilder > ChatCommandTable
Definition: ChatCommand.h:49
@ RBAC_PERM_COMMAND_DESERTER_BG_REMOVE
Definition: RBAC.h:217
@ RBAC_PERM_COMMAND_DESERTER_INSTANCE_REMOVE
Definition: RBAC.h:220
@ RBAC_PERM_COMMAND_DESERTER_INSTANCE_ADD
Definition: RBAC.h:219
@ RBAC_PERM_COMMAND_DESERTER_BG_ADD
Definition: RBAC.h:216