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

Public Member Functions

 arena_commandscript ()
 
ChatCommandTable GetCommands () const override
 
virtual std::vector< Acore::ChatCommands::ChatCommandBuilderGetCommands () const =0
 
- 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 HandleArenaCreateCommand (ChatHandler *handler, Optional< PlayerIdentifier > captain, QuotedString name, ArenaTeamTypes type)
 
static bool HandleArenaDisbandCommand (ChatHandler *handler, uint32 teamId)
 
static bool HandleArenaRenameCommand (ChatHandler *handler, QuotedString oldName, QuotedString newName)
 
static bool HandleArenaCaptainCommand (ChatHandler *handler, uint32 teamId, Optional< PlayerIdentifier > target)
 
static bool HandleArenaInfoCommand (ChatHandler *handler, uint32 teamId)
 
static bool HandleArenaLookupCommand (ChatHandler *handler, Tail needle)
 

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

◆ arena_commandscript()

arena_commandscript::arena_commandscript ( )
inline
35: CommandScript("arena_commandscript") { }
Definition: CommandScript.h:25

Member Function Documentation

◆ GetCommands()

ChatCommandTable arena_commandscript::GetCommands ( ) const
inlineoverridevirtual

Implements CommandScript.

38 {
39 static ChatCommandTable arenaCommandTable =
40 {
41 { "create", HandleArenaCreateCommand, SEC_ADMINISTRATOR, Console::Yes },
42 { "disband", HandleArenaDisbandCommand, SEC_ADMINISTRATOR, Console::Yes },
43 { "rename", HandleArenaRenameCommand, SEC_ADMINISTRATOR, Console::Yes },
44 { "captain", HandleArenaCaptainCommand, SEC_ADMINISTRATOR, Console::No },
45 { "info", HandleArenaInfoCommand, SEC_GAMEMASTER, Console::Yes },
46 { "lookup", HandleArenaLookupCommand, SEC_GAMEMASTER, Console::No },
47 };
48
49 static ChatCommandTable commandTable =
50 {
51 { "arena", arenaCommandTable }
52 };
53
54 return commandTable;
55 }
@ SEC_ADMINISTRATOR
Definition: Common.h:60
@ SEC_GAMEMASTER
Definition: Common.h:59
std::vector< ChatCommandBuilder > ChatCommandTable
Definition: ChatCommand.h:46
static bool HandleArenaDisbandCommand(ChatHandler *handler, uint32 teamId)
Definition: cs_arena.cpp:92
static bool HandleArenaCreateCommand(ChatHandler *handler, Optional< PlayerIdentifier > captain, QuotedString name, ArenaTeamTypes type)
Definition: cs_arena.cpp:57
static bool HandleArenaRenameCommand(ChatHandler *handler, QuotedString oldName, QuotedString newName)
Definition: cs_arena.cpp:117
static bool HandleArenaLookupCommand(ChatHandler *handler, Tail needle)
Definition: cs_arena.cpp:208
static bool HandleArenaCaptainCommand(ChatHandler *handler, uint32 teamId, Optional< PlayerIdentifier > target)
Definition: cs_arena.cpp:149
static bool HandleArenaInfoCommand(ChatHandler *handler, uint32 teamId)
Definition: cs_arena.cpp:191

References HandleArenaCaptainCommand(), HandleArenaCreateCommand(), HandleArenaDisbandCommand(), HandleArenaInfoCommand(), HandleArenaLookupCommand(), HandleArenaRenameCommand(), SEC_ADMINISTRATOR, and SEC_GAMEMASTER.

◆ HandleArenaCaptainCommand()

static bool arena_commandscript::HandleArenaCaptainCommand ( ChatHandler handler,
uint32  teamId,
Optional< PlayerIdentifier target 
)
inlinestatic
150 {
151 ArenaTeam* arena = sArenaTeamMgr->GetArenaTeamById(teamId);
152 if (!arena)
153 {
155 return false;
156 }
157
158 if (arena->IsFighting())
159 {
161 return false;
162 }
163
164 if (!target)
165 target = PlayerIdentifier::FromTargetOrSelf(handler);
166
167 if (!target)
168 return false;
169
170 if (!arena->IsMember(target->GetGUID()))
171 {
172 handler->SendErrorMessage(LANG_ARENA_ERROR_NOT_MEMBER, target->GetName(), arena->GetName());
173 return false;
174 }
175
176 if (arena->GetCaptain() == target->GetGUID())
177 {
178 handler->SendErrorMessage(LANG_ARENA_ERROR_CAPTAIN, target->GetName(), arena->GetName());
179 return false;
180 }
181
182 std::string oldCaptainName;
183 sCharacterCache->GetCharacterNameByGuid(arena->GetCaptain(), oldCaptainName);
184 arena->SetCaptain(target->GetGUID());
185
186 handler->PSendSysMessage(LANG_ARENA_CAPTAIN, arena->GetName(), arena->GetId(), oldCaptainName, target->GetName());
187
188 return true;
189 }
@ LANG_ARENA_CAPTAIN
Definition: Language.h:824
@ LANG_ARENA_ERROR_CAPTAIN
Definition: Language.h:820
@ LANG_ARENA_ERROR_NOT_MEMBER
Definition: Language.h:819
@ LANG_ARENA_ERROR_NOT_FOUND
Definition: Language.h:814
@ LANG_ARENA_ERROR_COMBAT
Definition: Language.h:817
#define sArenaTeamMgr
Definition: ArenaTeamMgr.h:67
#define sCharacterCache
Definition: CharacterCache.h:83
Definition: ArenaTeam.h:137
ObjectGuid GetCaptain() const
Definition: ArenaTeam.h:153
bool IsMember(ObjectGuid guid) const
Definition: ArenaTeam.cpp:643
void SetCaptain(ObjectGuid guid)
Definition: ArenaTeam.cpp:295
bool IsFighting() const
Definition: ArenaTeam.cpp:997
std::string const & GetName() const
Definition: ArenaTeam.h:154
uint32 GetId() const
Definition: ArenaTeam.h:148
void PSendSysMessage(std::string_view str, bool escapeCharacters=false)
Definition: Chat.cpp:210
void SendErrorMessage(uint32 entry)
Definition: Chat.cpp:215
static Optional< PlayerIdentifier > FromTargetOrSelf(ChatHandler *handler)
Definition: ChatCommandTags.h:184

References Acore::ChatCommands::PlayerIdentifier::FromTargetOrSelf(), ArenaTeam::GetCaptain(), ArenaTeam::GetId(), ArenaTeam::GetName(), ArenaTeam::IsFighting(), ArenaTeam::IsMember(), LANG_ARENA_CAPTAIN, LANG_ARENA_ERROR_CAPTAIN, LANG_ARENA_ERROR_COMBAT, LANG_ARENA_ERROR_NOT_FOUND, LANG_ARENA_ERROR_NOT_MEMBER, ChatHandler::PSendSysMessage(), sArenaTeamMgr, sCharacterCache, ChatHandler::SendErrorMessage(), and ArenaTeam::SetCaptain().

Referenced by GetCommands().

◆ HandleArenaCreateCommand()

static bool arena_commandscript::HandleArenaCreateCommand ( ChatHandler handler,
Optional< PlayerIdentifier captain,
QuotedString  name,
ArenaTeamTypes  type 
)
inlinestatic
58 {
59 if (sArenaTeamMgr->GetArenaTeamByName(name))
60 {
62 return false;
63 }
64
65 if (!captain)
66 captain = PlayerIdentifier::FromTargetOrSelf(handler);
67
68 if (!captain)
69 return false;
70
71 if (Player::GetArenaTeamIdFromDB(captain->GetGUID(), type) != 0)
72 {
73 handler->SendErrorMessage(LANG_ARENA_ERROR_SIZE, captain->GetName());
74 return false;
75 }
76
77 ArenaTeam* arena = new ArenaTeam();
78
79 if (!arena->Create(captain->GetGUID(), type, name, 4293102085, 101, 4293253939, 4, 4284049911))
80 {
81 delete arena;
83 return false;
84 }
85
86 sArenaTeamMgr->AddArenaTeam(arena);
87 handler->PSendSysMessage(LANG_ARENA_CREATE, arena->GetName(), arena->GetId(), arena->GetType(), arena->GetCaptain().ToString());
88
89 return true;
90 }
@ LANG_ARENA_ERROR_NAME_EXISTS
Definition: Language.h:815
@ LANG_ARENA_CREATE
Definition: Language.h:821
@ LANG_ARENA_ERROR_SIZE
Definition: Language.h:816
@ LANG_BAD_VALUE
Definition: Language.h:147
bool Create(ObjectGuid captainGuid, uint8 type, std::string const &teamName, uint32 backgroundColor, uint8 emblemStyle, uint32 emblemColor, uint8 borderStyle, uint32 borderColor)
Definition: ArenaTeam.cpp:47
uint32 GetType() const
Definition: ArenaTeam.h:149
std::string ToString() const
Definition: ObjectGuid.cpp:47
static uint32 GetArenaTeamIdFromDB(ObjectGuid guid, uint8 slot)
Definition: Player.cpp:6334

References ArenaTeam::Create(), Acore::ChatCommands::PlayerIdentifier::FromTargetOrSelf(), Player::GetArenaTeamIdFromDB(), ArenaTeam::GetCaptain(), ArenaTeam::GetId(), ArenaTeam::GetName(), ArenaTeam::GetType(), LANG_ARENA_CREATE, LANG_ARENA_ERROR_NAME_EXISTS, LANG_ARENA_ERROR_SIZE, LANG_BAD_VALUE, ChatHandler::PSendSysMessage(), sArenaTeamMgr, ChatHandler::SendErrorMessage(), and ObjectGuid::ToString().

Referenced by GetCommands().

◆ HandleArenaDisbandCommand()

static bool arena_commandscript::HandleArenaDisbandCommand ( ChatHandler handler,
uint32  teamId 
)
inlinestatic
93 {
94 ArenaTeam* arena = sArenaTeamMgr->GetArenaTeamById(teamId);
95
96 if (!arena)
97 {
99 return false;
100 }
101
102 if (arena->IsFighting())
103 {
105 return false;
106 }
107
108 std::string name = arena->GetName();
109 arena->Disband();
110
111 delete(arena);
112
113 handler->PSendSysMessage(LANG_ARENA_DISBAND, name, teamId);
114 return true;
115 }
@ LANG_ARENA_DISBAND
Definition: Language.h:822
void Disband(WorldSession *session)
Definition: ArenaTeam.cpp:383

References ArenaTeam::Disband(), ArenaTeam::GetName(), ArenaTeam::IsFighting(), LANG_ARENA_DISBAND, LANG_ARENA_ERROR_COMBAT, LANG_ARENA_ERROR_NOT_FOUND, ChatHandler::PSendSysMessage(), sArenaTeamMgr, and ChatHandler::SendErrorMessage().

Referenced by GetCommands().

◆ HandleArenaInfoCommand()

static bool arena_commandscript::HandleArenaInfoCommand ( ChatHandler handler,
uint32  teamId 
)
inlinestatic
192 {
193 ArenaTeam* arena = sArenaTeamMgr->GetArenaTeamById(teamId);
194 if (!arena)
195 {
197 return false;
198 }
199
200 handler->PSendSysMessage(LANG_ARENA_INFO_HEADER, arena->GetName(), arena->GetId(), arena->GetRating(), arena->GetType(), arena->GetType());
201
202 for (auto const& itr : arena->GetMembers())
203 handler->PSendSysMessage(LANG_ARENA_INFO_MEMBERS, itr.Name, itr.Guid.ToString(), itr.PersonalRating, (arena->GetCaptain() == itr.Guid ? "- Captain" : ""));
204
205 return true;
206 }
@ LANG_ARENA_INFO_HEADER
Definition: Language.h:825
@ LANG_ARENA_INFO_MEMBERS
Definition: Language.h:826
uint32 GetRating() const
Definition: ArenaTeam.h:158
MemberList & GetMembers()
Definition: ArenaTeam.h:173

References ArenaTeam::GetCaptain(), ArenaTeam::GetId(), ArenaTeam::GetMembers(), ArenaTeam::GetName(), ArenaTeam::GetRating(), ArenaTeam::GetType(), LANG_ARENA_ERROR_NOT_FOUND, LANG_ARENA_INFO_HEADER, LANG_ARENA_INFO_MEMBERS, ChatHandler::PSendSysMessage(), sArenaTeamMgr, and ChatHandler::SendErrorMessage().

Referenced by GetCommands().

◆ HandleArenaLookupCommand()

static bool arena_commandscript::HandleArenaLookupCommand ( ChatHandler handler,
Tail  needle 
)
inlinestatic
209 {
210 if (needle.empty())
211 return false;
212
213 bool found = false;
214 for (auto [teamId, team] : sArenaTeamMgr->GetArenaTeams())
215 {
216 if (StringContainsStringI(team->GetName(), needle))
217 {
218 if (handler->GetSession())
219 {
220 handler->PSendSysMessage(LANG_ARENA_LOOKUP, team->GetName(), team->GetId(), team->GetType(), team->GetType());
221 found = true;
222 continue;
223 }
224 }
225 }
226
227 if (!found)
228 handler->PSendSysMessage(LANG_ARENA_ERROR_NAME_NOT_FOUND, std::string(needle));
229
230 return true;
231 }
bool StringContainsStringI(std::string_view haystack, std::string_view needle)
Definition: Util.cpp:597
@ LANG_ARENA_ERROR_NAME_NOT_FOUND
Definition: Language.h:818
@ LANG_ARENA_LOOKUP
Definition: Language.h:827
WorldSession * GetSession()
Definition: Chat.h:242

References ChatHandler::GetSession(), LANG_ARENA_ERROR_NAME_NOT_FOUND, LANG_ARENA_LOOKUP, ChatHandler::PSendSysMessage(), sArenaTeamMgr, and StringContainsStringI().

Referenced by GetCommands().

◆ HandleArenaRenameCommand()

static bool arena_commandscript::HandleArenaRenameCommand ( ChatHandler handler,
QuotedString  oldName,
QuotedString  newName 
)
inlinestatic
118 {
119 ArenaTeam* arena = sArenaTeamMgr->GetArenaTeamByName(oldName);
120 if (!arena)
121 {
123 return false;
124 }
125
126 if (sArenaTeamMgr->GetArenaTeamByName(newName))
127 {
129 return false;
130 }
131
132 if (arena->IsFighting())
133 {
135 return false;
136 }
137
138 if (!arena->SetName(newName))
139 {
141 return false;
142 }
143
144 handler->PSendSysMessage(LANG_ARENA_RENAME, arena->GetId(), oldName, newName);
145
146 return true;
147 }
@ LANG_ARENA_RENAME
Definition: Language.h:823
bool SetName(std::string const &name)
Definition: ArenaTeam.cpp:282

References ArenaTeam::GetId(), ArenaTeam::IsFighting(), LANG_ARENA_ERROR_COMBAT, LANG_ARENA_ERROR_NAME_EXISTS, LANG_ARENA_ERROR_NAME_NOT_FOUND, LANG_ARENA_RENAME, LANG_BAD_VALUE, ChatHandler::PSendSysMessage(), sArenaTeamMgr, ChatHandler::SendErrorMessage(), and ArenaTeam::SetName().

Referenced by GetCommands().