TrinityCore
Loading...
Searching...
No Matches
cs_bf.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: bf_commandscript
20%Complete: 100
21Comment: All bf related commands
22Category: commandscripts
23EndScriptData */
24
25#include "ScriptMgr.h"
26#include "BattlefieldMgr.h"
27#include "Chat.h"
28#include "ChatCommand.h"
29#include "Player.h"
30#include "RBAC.h"
31
32using namespace Trinity::ChatCommands;
33
35{
36public:
37 bf_commandscript() : CommandScript("bf_commandscript") { }
38
39 std::span<ChatCommandBuilder const> GetCommands() const override
40 {
41 static ChatCommandTable battlefieldcommandTable =
42 {
48 };
49 static ChatCommandTable commandTable =
50 {
51 { "bf", battlefieldcommandTable },
52 };
53 return commandTable;
54 }
55
56 static bool HandleBattlefieldStart(ChatHandler* handler, uint32 battleId)
57 {
58 Battlefield* bf = sBattlefieldMgr->GetBattlefieldByBattleId(handler->GetPlayer()->GetMap(), battleId);
59
60 if (!bf)
61 return false;
62
63 bf->StartBattle();
64
65 if (battleId == 1)
66 handler->SendGlobalGMSysMessage("Wintergrasp (Command start used)");
67
68 return true;
69 }
70
71 static bool HandleBattlefieldEnd(ChatHandler* handler, uint32 battleId)
72 {
73 Battlefield* bf = sBattlefieldMgr->GetBattlefieldByBattleId(handler->GetPlayer()->GetMap(), battleId);
74
75 if (!bf)
76 return false;
77
78 bf->EndBattle(true);
79
80 if (battleId == 1)
81 handler->SendGlobalGMSysMessage("Wintergrasp (Command stop used)");
82
83 return true;
84 }
85
86 static bool HandleBattlefieldEnable(ChatHandler* handler, uint32 battleId)
87 {
88 Battlefield* bf = sBattlefieldMgr->GetBattlefieldByBattleId(handler->GetPlayer()->GetMap(), battleId);
89
90 if (!bf)
91 return false;
92
93 if (bf->IsEnabled())
94 {
95 bf->ToggleBattlefield(false);
96 if (battleId == 1)
97 handler->SendGlobalGMSysMessage("Wintergrasp is disabled");
98 }
99 else
100 {
101 bf->ToggleBattlefield(true);
102 if (battleId == 1)
103 handler->SendGlobalGMSysMessage("Wintergrasp is enabled");
104 }
105
106 return true;
107 }
108
109 static bool HandleBattlefieldSwitch(ChatHandler* handler, uint32 battleId)
110 {
111 Battlefield* bf = sBattlefieldMgr->GetBattlefieldByBattleId(handler->GetPlayer()->GetMap(), battleId);
112
113 if (!bf)
114 return false;
115
116 bf->EndBattle(false);
117 if (battleId == 1)
118 handler->SendGlobalGMSysMessage("Wintergrasp (Command switch used)");
119
120 return true;
121 }
122
123 static bool HandleBattlefieldTimer(ChatHandler* handler, uint32 battleId, uint32 time)
124 {
125 Battlefield* bf = sBattlefieldMgr->GetBattlefieldByBattleId(handler->GetPlayer()->GetMap(), battleId);
126
127 if (!bf)
128 return false;
129
130 bf->SetTimer(time * IN_MILLISECONDS);
131 if (battleId == 1)
132 handler->SendGlobalGMSysMessage("Wintergrasp (Command timer used)");
133
134 return true;
135 }
136};
137
139{
140 new bf_commandscript();
141}
#define sBattlefieldMgr
@ IN_MILLISECONDS
Definition Common.h:38
uint32_t uint32
Definition Define.h:154
Role Based Access Control related classes definition.
void SetTimer(uint32 timer)
void EndBattle(bool endByTimer)
void StartBattle()
void ToggleBattlefield(bool enable)
Enable or Disable battlefield.
bool IsEnabled() const
Return if battlefield is enable.
void SendGlobalGMSysMessage(const char *str)
Definition Chat.cpp:137
Player * GetPlayer() const
Definition Chat.cpp:37
Map * GetMap() const
Definition Object.h:411
static bool HandleBattlefieldEnable(ChatHandler *handler, uint32 battleId)
Definition cs_bf.cpp:86
static bool HandleBattlefieldStart(ChatHandler *handler, uint32 battleId)
Definition cs_bf.cpp:56
static bool HandleBattlefieldSwitch(ChatHandler *handler, uint32 battleId)
Definition cs_bf.cpp:109
static bool HandleBattlefieldTimer(ChatHandler *handler, uint32 battleId, uint32 time)
Definition cs_bf.cpp:123
std::span< ChatCommandBuilder const > GetCommands() const override
Definition cs_bf.cpp:39
static bool HandleBattlefieldEnd(ChatHandler *handler, uint32 battleId)
Definition cs_bf.cpp:71
void AddSC_bf_commandscript()
Definition cs_bf.cpp:138
ChatCommandBuilder const [] ChatCommandTable
Definition ChatCommand.h:49
@ RBAC_PERM_COMMAND_BF_TIMER
Definition RBAC.h:175
@ RBAC_PERM_COMMAND_BF_ENABLE
Definition RBAC.h:176
@ RBAC_PERM_COMMAND_BF_SWITCH
Definition RBAC.h:174
@ RBAC_PERM_COMMAND_BF_START
Definition RBAC.h:172
@ RBAC_PERM_COMMAND_BF_STOP
Definition RBAC.h:173