AzerothCore 3.3.5a
OpenSource WoW Emulator
Loading...
Searching...
No Matches
bf_commandscript Class Reference
Inheritance diagram for bf_commandscript:
CommandScript ScriptObject

Public Member Functions

 bf_commandscript ()
 
ChatCommandTable GetCommands () const override
 
- Public Member Functions inherited from ScriptObject
virtual bool IsDatabaseBound () const
 
virtual bool isAfterLoadScript () const
 
virtual void checkValidity ()
 
const std::string & GetName () const
 
uint16 GetTotalAvailableHooks ()
 

Static Public Member Functions

static bool HandleBattlefieldStart (ChatHandler *handler, uint32 battleId)
 
static bool HandleBattlefieldEnd (ChatHandler *handler, uint32 battleId)
 
static bool HandleBattlefieldEnable (ChatHandler *handler, uint32 battleId)
 
static bool HandleBattlefieldSwitch (ChatHandler *handler, uint32 battleId)
 
static bool HandleBattlefieldTimer (ChatHandler *handler, uint32 battleId, std::string timeStr)
 
static bool HandleBattlefieldQueue (ChatHandler *handler, uint32 battleId)
 

Additional Inherited Members

- Protected Member Functions inherited from CommandScript
 CommandScript (const char *name)
 
- Protected Member Functions inherited from ScriptObject
 ScriptObject (const char *name, uint16 totalAvailableHooks=0)
 
virtual ~ScriptObject ()=default
 

Detailed Description

Constructor & Destructor Documentation

◆ bf_commandscript()

bf_commandscript::bf_commandscript ( )
inline
32: CommandScript("bf_commandscript") { }
Definition CommandScript.h:25

Member Function Documentation

◆ GetCommands()

ChatCommandTable bf_commandscript::GetCommands ( ) const
inlineoverridevirtual

Implements CommandScript.

35 {
36 static ChatCommandTable battlefieldcommandTable =
37 {
44 };
45 static ChatCommandTable commandTable =
46 {
47 { "bf", battlefieldcommandTable }
48 };
49 return commandTable;
50 }
static bool HandleBattlefieldEnable(ChatHandler *handler, uint32 battleId)
Definition cs_bf.cpp:88
static bool HandleBattlefieldQueue(ChatHandler *handler, uint32 battleId)
Definition cs_bf.cpp:176
static bool HandleBattlefieldStart(ChatHandler *handler, uint32 battleId)
Definition cs_bf.cpp:52
static bool HandleBattlefieldTimer(ChatHandler *handler, uint32 battleId, std::string timeStr)
Definition cs_bf.cpp:134
static bool HandleBattlefieldSwitch(ChatHandler *handler, uint32 battleId)
Definition cs_bf.cpp:116
static bool HandleBattlefieldEnd(ChatHandler *handler, uint32 battleId)
Definition cs_bf.cpp:70
std::vector< ChatCommandBuilder > ChatCommandTable
Definition ChatCommand.h:46
@ RBAC_PERM_COMMAND_BF_TIMER
Definition RBAC.h:159
@ RBAC_PERM_COMMAND_BF_ENABLE
Definition RBAC.h:160
@ RBAC_PERM_COMMAND_BF_SWITCH
Definition RBAC.h:158
@ RBAC_PERM_COMMAND_BF_START
Definition RBAC.h:156
@ RBAC_PERM_COMMAND_BF_STOP
Definition RBAC.h:157
@ RBAC_PERM_COMMAND_BF_QUEUE
Definition RBAC.h:677

References HandleBattlefieldEnable(), HandleBattlefieldEnd(), HandleBattlefieldQueue(), HandleBattlefieldStart(), HandleBattlefieldSwitch(), HandleBattlefieldTimer(), rbac::RBAC_PERM_COMMAND_BF_ENABLE, rbac::RBAC_PERM_COMMAND_BF_QUEUE, rbac::RBAC_PERM_COMMAND_BF_START, rbac::RBAC_PERM_COMMAND_BF_STOP, rbac::RBAC_PERM_COMMAND_BF_SWITCH, and rbac::RBAC_PERM_COMMAND_BF_TIMER.

◆ HandleBattlefieldEnable()

static bool bf_commandscript::HandleBattlefieldEnable ( ChatHandler handler,
uint32  battleId 
)
inlinestatic
89 {
90 Battlefield* bf = sBattlefieldMgr->GetBattlefieldByBattleId(battleId);
91
92 if (!bf)
93 {
94 handler->SendErrorMessage(LANG_BF_NOT_FOUND, battleId);
95 return false;
96 }
97
98 if (bf->IsEnabled())
99 {
100 bf->ToggleBattlefield(false);
101 handler->SendWorldText(LANG_BF_DISABLED, battleId);
102 if (handler->IsConsole())
103 handler->PSendSysMessage(LANG_BF_DISABLED, battleId);
104 }
105 else
106 {
107 bf->ToggleBattlefield(true);
108 handler->SendWorldText(LANG_BF_ENABLED, battleId);
109 if (handler->IsConsole())
110 handler->PSendSysMessage(LANG_BF_ENABLED, battleId);
111 }
112
113 return true;
114 }
#define sBattlefieldMgr
Definition BattlefieldMgr.h:76
@ LANG_BF_NOT_FOUND
Definition Language.h:1191
@ LANG_BF_ENABLED
Definition Language.h:1196
@ LANG_BF_DISABLED
Definition Language.h:1197
Definition Battlefield.h:208
void ToggleBattlefield(bool enable)
Enable or Disable battlefield.
Definition Battlefield.h:254
bool IsEnabled() const
Return if battlefield is enabled.
Definition Battlefield.h:256
void PSendSysMessage(std::string_view str, bool escapeCharacters=false)
Definition Chat.cpp:219
void SendErrorMessage(uint32 entry)
Definition Chat.cpp:224
void SendWorldText(std::string_view str)
Definition Chat.cpp:139
bool IsConsole() const
Definition Chat.h:240

References ChatHandler::IsConsole(), Battlefield::IsEnabled(), LANG_BF_DISABLED, LANG_BF_ENABLED, LANG_BF_NOT_FOUND, ChatHandler::PSendSysMessage(), sBattlefieldMgr, ChatHandler::SendErrorMessage(), ChatHandler::SendWorldText(), and Battlefield::ToggleBattlefield().

Referenced by GetCommands().

◆ HandleBattlefieldEnd()

static bool bf_commandscript::HandleBattlefieldEnd ( ChatHandler handler,
uint32  battleId 
)
inlinestatic
71 {
72 Battlefield* bf = sBattlefieldMgr->GetBattlefieldByBattleId(battleId);
73
74 if (!bf)
75 {
76 handler->SendErrorMessage(LANG_BF_NOT_FOUND, battleId);
77 return false;
78 }
79
80 bf->EndBattle(true);
81 handler->SendWorldText(LANG_BF_STOPPED, battleId);
82 if (handler->IsConsole())
83 handler->PSendSysMessage(LANG_BF_STOPPED, battleId);
84
85 return true;
86 }
@ LANG_BF_STOPPED
Definition Language.h:1193
void EndBattle(bool endByTimer)
Definition Battlefield.cpp:347

References Battlefield::EndBattle(), ChatHandler::IsConsole(), LANG_BF_NOT_FOUND, LANG_BF_STOPPED, ChatHandler::PSendSysMessage(), sBattlefieldMgr, ChatHandler::SendErrorMessage(), and ChatHandler::SendWorldText().

Referenced by GetCommands().

◆ HandleBattlefieldQueue()

static bool bf_commandscript::HandleBattlefieldQueue ( ChatHandler handler,
uint32  battleId 
)
inlinestatic
177 {
178 Battlefield* bf = sBattlefieldMgr->GetBattlefieldByBattleId(battleId);
179
180 if (!bf)
181 {
182 handler->SendErrorMessage(LANG_BF_NOT_FOUND, battleId);
183 return false;
184 }
185
187 battleId, bf->GetTimer() / IN_MILLISECONDS);
188
189 static char const* teamNames[PVP_TEAMS_COUNT] = { "Alliance", "Horde" };
190
191 std::string offlineSuffix = handler->GetAcoreString(LANG_OFFLINE);
192
193 auto nameOf = [offlineSuffix](ObjectGuid guid) -> std::string
194 {
195 if (Player* p = ObjectAccessor::FindPlayer(guid))
196 return p->GetName();
197 return std::to_string(guid.GetCounter()) + offlineSuffix;
198 };
199
200 for (uint8 i = 0; i < PVP_TEAMS_COUNT; ++i)
201 {
202 TeamId team = TeamId(i);
203
204 GuidUnorderedSet const& inQueue = bf->GetPlayersQueueSet(team);
205 PlayerTimerMap const& invited = bf->GetInvitedPlayersMap(team);
206 GuidUnorderedSet const& inWar = bf->GetPlayersInWarSet(team);
207
209 teamNames[i],
210 static_cast<uint32>(inQueue.size()),
211 static_cast<uint32>(invited.size()),
212 static_cast<uint32>(inWar.size()));
213
214 for (ObjectGuid const& guid : inQueue)
215 handler->PSendSysMessage(LANG_BF_QUEUE_PLAYER_QUEUE, nameOf(guid));
216
218 for (auto const& [guid, expiry] : invited)
219 {
220 SystemTimePoint expiryPoint = std::chrono::system_clock::from_time_t(expiry);
221 int32 secsLeft = std::max(int32(0), static_cast<int32>(
222 std::chrono::duration_cast<Seconds>(expiryPoint - now).count()));
223 handler->PSendSysMessage(LANG_BF_QUEUE_PLAYER_INVITED, nameOf(guid), secsLeft);
224 }
225
226 for (ObjectGuid const& guid : inWar)
227 handler->PSendSysMessage(LANG_BF_QUEUE_PLAYER_WAR, nameOf(guid));
228 }
229
230 return true;
231 }
std::map< ObjectGuid, time_t > PlayerTimerMap
Definition Battlefield.h:83
constexpr auto IN_MILLISECONDS
Definition Common.h:53
std::int32_t int32
Definition Define.h:103
std::uint8_t uint8
Definition Define.h:109
std::uint32_t uint32
Definition Define.h:107
std::chrono::system_clock::time_point SystemTimePoint
Definition Duration.h:70
@ LANG_BF_QUEUE_PLAYER_QUEUE
Definition Language.h:1206
@ LANG_OFFLINE
Definition Language.h:69
@ LANG_BF_QUEUE_TEAM_HDR
Definition Language.h:1205
@ LANG_BF_QUEUE_PLAYER_INVITED
Definition Language.h:1207
@ LANG_BF_QUEUE_HDR_WAIT
Definition Language.h:1204
@ LANG_BF_QUEUE_HDR_WAR
Definition Language.h:1203
@ LANG_BF_QUEUE_PLAYER_WAR
Definition Language.h:1208
std::unordered_set< ObjectGuid > GuidUnorderedSet
Definition ObjectGuid.h:257
uint8 constexpr PVP_TEAMS_COUNT
Definition SharedDefines.h:3701
TeamId
Definition SharedDefines.h:747
PlayerTimerMap const & GetInvitedPlayersMap(TeamId teamId) const
Definition Battlefield.h:371
bool IsWarTime() const
Return true if battle is started, false if battle is not started.
Definition Battlefield.h:251
GuidUnorderedSet const & GetPlayersQueueSet(TeamId teamId) const
Returns the set of players waiting in the pre-battle queue (per team, read-only).
Definition Battlefield.h:368
GuidUnorderedSet const & GetPlayersInWarSet(TeamId teamId) const
Returns the set of players actively fighting in the war (per team, read-only).
Definition Battlefield.h:373
virtual std::string GetAcoreString(uint32 entry) const
Definition Chat.cpp:42
Definition ObjectGuid.h:118
Definition Player.h:1084
SystemTimePoint GetSystemTime()
Current chrono system_clock time point.
Definition GameTime.cpp:48
Player * FindPlayer(ObjectGuid const guid)
Definition ObjectAccessor.cpp:245

References ObjectAccessor::FindPlayer(), ChatHandler::GetAcoreString(), Battlefield::GetInvitedPlayersMap(), Battlefield::GetPlayersInWarSet(), Battlefield::GetPlayersQueueSet(), GameTime::GetSystemTime(), Battlefield::GetTimer(), IN_MILLISECONDS, Battlefield::IsWarTime(), LANG_BF_NOT_FOUND, LANG_BF_QUEUE_HDR_WAIT, LANG_BF_QUEUE_HDR_WAR, LANG_BF_QUEUE_PLAYER_INVITED, LANG_BF_QUEUE_PLAYER_QUEUE, LANG_BF_QUEUE_PLAYER_WAR, LANG_BF_QUEUE_TEAM_HDR, LANG_OFFLINE, ChatHandler::PSendSysMessage(), PVP_TEAMS_COUNT, sBattlefieldMgr, and ChatHandler::SendErrorMessage().

Referenced by GetCommands().

◆ HandleBattlefieldStart()

static bool bf_commandscript::HandleBattlefieldStart ( ChatHandler handler,
uint32  battleId 
)
inlinestatic
53 {
54 Battlefield* bf = sBattlefieldMgr->GetBattlefieldByBattleId(battleId);
55
56 if (!bf)
57 {
58 handler->SendErrorMessage(LANG_BF_NOT_FOUND, battleId);
59 return false;
60 }
61
62 bf->StartBattle();
63 handler->SendWorldText(LANG_BF_STARTED, battleId);
64 if (handler->IsConsole())
65 handler->PSendSysMessage(LANG_BF_STARTED, battleId);
66
67 return true;
68 }
@ LANG_BF_STARTED
Definition Language.h:1192
void StartBattle()
Definition Battlefield.cpp:299

References ChatHandler::IsConsole(), LANG_BF_NOT_FOUND, LANG_BF_STARTED, ChatHandler::PSendSysMessage(), sBattlefieldMgr, ChatHandler::SendErrorMessage(), ChatHandler::SendWorldText(), and Battlefield::StartBattle().

Referenced by GetCommands().

◆ HandleBattlefieldSwitch()

static bool bf_commandscript::HandleBattlefieldSwitch ( ChatHandler handler,
uint32  battleId 
)
inlinestatic
117 {
118 Battlefield* bf = sBattlefieldMgr->GetBattlefieldByBattleId(battleId);
119
120 if (!bf)
121 {
122 handler->SendErrorMessage(LANG_BF_NOT_FOUND, battleId);
123 return false;
124 }
125
126 bf->EndBattle(false);
127 handler->SendWorldText(LANG_BF_SWITCHED, battleId);
128 if (handler->IsConsole())
129 handler->PSendSysMessage(LANG_BF_SWITCHED, battleId);
130
131 return true;
132 }
@ LANG_BF_SWITCHED
Definition Language.h:1194

References Battlefield::EndBattle(), ChatHandler::IsConsole(), LANG_BF_NOT_FOUND, LANG_BF_SWITCHED, ChatHandler::PSendSysMessage(), sBattlefieldMgr, ChatHandler::SendErrorMessage(), and ChatHandler::SendWorldText().

Referenced by GetCommands().

◆ HandleBattlefieldTimer()

static bool bf_commandscript::HandleBattlefieldTimer ( ChatHandler handler,
uint32  battleId,
std::string  timeStr 
)
inlinestatic
135 {
136 if (timeStr.empty())
137 {
138 return false;
139 }
140
141 if (Acore::StringTo<int32>(timeStr).value_or(0) < 0)
142 {
144 return false;
145 }
146
147 int32 time = TimeStringToSecs(timeStr);
148 if (time <= 0)
149 {
150 time = Acore::StringTo<int32>(timeStr).value_or(0);
151 }
152
153 if (time <= 0)
154 {
156 return false;
157 }
158
159 Battlefield* bf = sBattlefieldMgr->GetBattlefieldByBattleId(battleId);
160
161 if (!bf)
162 {
163 handler->SendErrorMessage(LANG_BF_NOT_FOUND, battleId);
164 return false;
165 }
166
167 bf->SetTimer(time * IN_MILLISECONDS);
169 handler->SendWorldText(LANG_BF_TIMER_SET, battleId, time);
170 if (handler->IsConsole())
171 handler->PSendSysMessage(LANG_BF_TIMER_SET, battleId, time);
172
173 return true;
174 }
@ LANG_BAD_VALUE
Definition Language.h:151
@ LANG_BF_TIMER_SET
Definition Language.h:1195
uint32 TimeStringToSecs(const std::string &timestring)
Definition Util.cpp:163
void SetTimer(uint32 timer)
Definition Battlefield.h:356
virtual void SendInitWorldStatesToAll()=0
Send all worldstate data to all players in zone.

References IN_MILLISECONDS, ChatHandler::IsConsole(), LANG_BAD_VALUE, LANG_BF_NOT_FOUND, LANG_BF_TIMER_SET, ChatHandler::PSendSysMessage(), sBattlefieldMgr, ChatHandler::SendErrorMessage(), Battlefield::SendInitWorldStatesToAll(), ChatHandler::SendWorldText(), Battlefield::SetTimer(), and TimeStringToSecs().

Referenced by GetCommands().


The documentation for this class was generated from the following file: