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
31: CommandScript("bf_commandscript") { }
Definition CommandScript.h:25

Member Function Documentation

◆ GetCommands()

ChatCommandTable bf_commandscript::GetCommands ( ) const
inlineoverridevirtual

Implements CommandScript.

34 {
35 static ChatCommandTable battlefieldcommandTable =
36 {
37 { "start", HandleBattlefieldStart, SEC_ADMINISTRATOR, Console::Yes },
38 { "stop", HandleBattlefieldEnd, SEC_ADMINISTRATOR, Console::Yes },
39 { "switch", HandleBattlefieldSwitch, SEC_ADMINISTRATOR, Console::Yes },
40 { "timer", HandleBattlefieldTimer, SEC_ADMINISTRATOR, Console::Yes },
41 { "enable", HandleBattlefieldEnable, SEC_ADMINISTRATOR, Console::Yes },
42 { "queue", HandleBattlefieldQueue, SEC_GAMEMASTER, Console::Yes }
43 };
44 static ChatCommandTable commandTable =
45 {
46 { "bf", battlefieldcommandTable }
47 };
48 return commandTable;
49 }
@ SEC_ADMINISTRATOR
Definition Common.h:60
@ SEC_GAMEMASTER
Definition Common.h:59
static bool HandleBattlefieldEnable(ChatHandler *handler, uint32 battleId)
Definition cs_bf.cpp:87
static bool HandleBattlefieldQueue(ChatHandler *handler, uint32 battleId)
Definition cs_bf.cpp:175
static bool HandleBattlefieldStart(ChatHandler *handler, uint32 battleId)
Definition cs_bf.cpp:51
static bool HandleBattlefieldTimer(ChatHandler *handler, uint32 battleId, std::string timeStr)
Definition cs_bf.cpp:133
static bool HandleBattlefieldSwitch(ChatHandler *handler, uint32 battleId)
Definition cs_bf.cpp:115
static bool HandleBattlefieldEnd(ChatHandler *handler, uint32 battleId)
Definition cs_bf.cpp:69
std::vector< ChatCommandBuilder > ChatCommandTable
Definition ChatCommand.h:46

References HandleBattlefieldEnable(), HandleBattlefieldEnd(), HandleBattlefieldQueue(), HandleBattlefieldStart(), HandleBattlefieldSwitch(), HandleBattlefieldTimer(), SEC_ADMINISTRATOR, and SEC_GAMEMASTER.

◆ HandleBattlefieldEnable()

static bool bf_commandscript::HandleBattlefieldEnable ( ChatHandler handler,
uint32  battleId 
)
inlinestatic
88 {
89 Battlefield* bf = sBattlefieldMgr->GetBattlefieldByBattleId(battleId);
90
91 if (!bf)
92 {
93 handler->SendErrorMessage(LANG_BF_NOT_FOUND, battleId);
94 return false;
95 }
96
97 if (bf->IsEnabled())
98 {
99 bf->ToggleBattlefield(false);
100 handler->SendWorldText(LANG_BF_DISABLED, battleId);
101 if (handler->IsConsole())
102 handler->PSendSysMessage(LANG_BF_DISABLED, battleId);
103 }
104 else
105 {
106 bf->ToggleBattlefield(true);
107 handler->SendWorldText(LANG_BF_ENABLED, battleId);
108 if (handler->IsConsole())
109 handler->PSendSysMessage(LANG_BF_ENABLED, battleId);
110 }
111
112 return true;
113 }
#define sBattlefieldMgr
Definition BattlefieldMgr.h:76
@ LANG_BF_NOT_FOUND
Definition Language.h:1188
@ LANG_BF_ENABLED
Definition Language.h:1193
@ LANG_BF_DISABLED
Definition Language.h:1194
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:211
void SendErrorMessage(uint32 entry)
Definition Chat.cpp:216
void SendWorldText(std::string_view str)
Definition Chat.cpp:131
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
70 {
71 Battlefield* bf = sBattlefieldMgr->GetBattlefieldByBattleId(battleId);
72
73 if (!bf)
74 {
75 handler->SendErrorMessage(LANG_BF_NOT_FOUND, battleId);
76 return false;
77 }
78
79 bf->EndBattle(true);
80 handler->SendWorldText(LANG_BF_STOPPED, battleId);
81 if (handler->IsConsole())
82 handler->PSendSysMessage(LANG_BF_STOPPED, battleId);
83
84 return true;
85 }
@ LANG_BF_STOPPED
Definition Language.h:1190
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
176 {
177 Battlefield* bf = sBattlefieldMgr->GetBattlefieldByBattleId(battleId);
178
179 if (!bf)
180 {
181 handler->SendErrorMessage(LANG_BF_NOT_FOUND, battleId);
182 return false;
183 }
184
186 battleId, bf->GetTimer() / IN_MILLISECONDS);
187
188 static char const* teamNames[PVP_TEAMS_COUNT] = { "Alliance", "Horde" };
189
190 std::string offlineSuffix = handler->GetAcoreString(LANG_OFFLINE);
191
192 auto nameOf = [offlineSuffix](ObjectGuid guid) -> std::string
193 {
194 if (Player* p = ObjectAccessor::FindPlayer(guid))
195 return p->GetName();
196 return std::to_string(guid.GetCounter()) + offlineSuffix;
197 };
198
199 for (uint8 i = 0; i < PVP_TEAMS_COUNT; ++i)
200 {
201 TeamId team = TeamId(i);
202
203 GuidUnorderedSet const& inQueue = bf->GetPlayersQueueSet(team);
204 PlayerTimerMap const& invited = bf->GetInvitedPlayersMap(team);
205 GuidUnorderedSet const& inWar = bf->GetPlayersInWarSet(team);
206
208 teamNames[i],
209 static_cast<uint32>(inQueue.size()),
210 static_cast<uint32>(invited.size()),
211 static_cast<uint32>(inWar.size()));
212
213 for (ObjectGuid const& guid : inQueue)
214 handler->PSendSysMessage(LANG_BF_QUEUE_PLAYER_QUEUE, nameOf(guid));
215
217 for (auto const& [guid, expiry] : invited)
218 {
219 SystemTimePoint expiryPoint = std::chrono::system_clock::from_time_t(expiry);
220 int32 secsLeft = std::max(int32(0), static_cast<int32>(
221 std::chrono::duration_cast<Seconds>(expiryPoint - now).count()));
222 handler->PSendSysMessage(LANG_BF_QUEUE_PLAYER_INVITED, nameOf(guid), secsLeft);
223 }
224
225 for (ObjectGuid const& guid : inWar)
226 handler->PSendSysMessage(LANG_BF_QUEUE_PLAYER_WAR, nameOf(guid));
227 }
228
229 return true;
230 }
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:1203
@ LANG_OFFLINE
Definition Language.h:69
@ LANG_BF_QUEUE_TEAM_HDR
Definition Language.h:1202
@ LANG_BF_QUEUE_PLAYER_INVITED
Definition Language.h:1204
@ LANG_BF_QUEUE_HDR_WAIT
Definition Language.h:1201
@ LANG_BF_QUEUE_HDR_WAR
Definition Language.h:1200
@ LANG_BF_QUEUE_PLAYER_WAR
Definition Language.h:1205
std::unordered_set< ObjectGuid > GuidUnorderedSet
Definition ObjectGuid.h:257
uint8 constexpr PVP_TEAMS_COUNT
Definition SharedDefines.h:3703
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:41
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
52 {
53 Battlefield* bf = sBattlefieldMgr->GetBattlefieldByBattleId(battleId);
54
55 if (!bf)
56 {
57 handler->SendErrorMessage(LANG_BF_NOT_FOUND, battleId);
58 return false;
59 }
60
61 bf->StartBattle();
62 handler->SendWorldText(LANG_BF_STARTED, battleId);
63 if (handler->IsConsole())
64 handler->PSendSysMessage(LANG_BF_STARTED, battleId);
65
66 return true;
67 }
@ LANG_BF_STARTED
Definition Language.h:1189
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
116 {
117 Battlefield* bf = sBattlefieldMgr->GetBattlefieldByBattleId(battleId);
118
119 if (!bf)
120 {
121 handler->SendErrorMessage(LANG_BF_NOT_FOUND, battleId);
122 return false;
123 }
124
125 bf->EndBattle(false);
126 handler->SendWorldText(LANG_BF_SWITCHED, battleId);
127 if (handler->IsConsole())
128 handler->PSendSysMessage(LANG_BF_SWITCHED, battleId);
129
130 return true;
131 }
@ LANG_BF_SWITCHED
Definition Language.h:1191

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
134 {
135 if (timeStr.empty())
136 {
137 return false;
138 }
139
140 if (Acore::StringTo<int32>(timeStr).value_or(0) < 0)
141 {
143 return false;
144 }
145
146 int32 time = TimeStringToSecs(timeStr);
147 if (time <= 0)
148 {
149 time = Acore::StringTo<int32>(timeStr).value_or(0);
150 }
151
152 if (time <= 0)
153 {
155 return false;
156 }
157
158 Battlefield* bf = sBattlefieldMgr->GetBattlefieldByBattleId(battleId);
159
160 if (!bf)
161 {
162 handler->SendErrorMessage(LANG_BF_NOT_FOUND, battleId);
163 return false;
164 }
165
166 bf->SetTimer(time * IN_MILLISECONDS);
168 handler->SendWorldText(LANG_BF_TIMER_SET, battleId, time);
169 if (handler->IsConsole())
170 handler->PSendSysMessage(LANG_BF_TIMER_SET, battleId, time);
171
172 return true;
173 }
@ LANG_BAD_VALUE
Definition Language.h:148
@ LANG_BF_TIMER_SET
Definition Language.h:1192
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: