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

Public Member Functions

 instance_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 HandleInstanceListBindsCommand (ChatHandler *handler)
 
static bool HandleInstanceUnbindCommand (ChatHandler *handler, Variant< uint16, EXACT_SEQUENCE("all")> mapArg, Optional< uint8 > difficultyArg)
 
static bool HandleInstanceStatsCommand (ChatHandler *handler)
 
static bool HandleInstanceSaveDataCommand (ChatHandler *handler)
 
static bool HandleInstanceSetBossStateCommand (ChatHandler *handler, uint32 encounterId, uint32 state, Optional< PlayerIdentifier > player)
 
static bool HandleInstanceGetBossStateCommand (ChatHandler *handler, uint32 encounterId, Optional< PlayerIdentifier > player)
 

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

◆ instance_commandscript()

instance_commandscript::instance_commandscript ( )
inline
39: CommandScript("instance_commandscript") { }
Definition: CommandScript.h:25

Member Function Documentation

◆ GetCommands()

ChatCommandTable instance_commandscript::GetCommands ( ) const
inlineoverridevirtual

Implements CommandScript.

42 {
43 static ChatCommandTable instanceCommandTable =
44 {
45 { "listbinds", HandleInstanceListBindsCommand, SEC_MODERATOR, Console::No },
46 { "unbind", HandleInstanceUnbindCommand, SEC_GAMEMASTER, Console::No },
47 { "stats", HandleInstanceStatsCommand, SEC_MODERATOR, Console::Yes },
48 { "savedata", HandleInstanceSaveDataCommand, SEC_ADMINISTRATOR, Console::No },
49 { "setbossstate", HandleInstanceSetBossStateCommand, SEC_GAMEMASTER, Console::Yes },
50 { "getbossstate", HandleInstanceGetBossStateCommand, SEC_MODERATOR, Console::Yes },
51 };
52
53 static ChatCommandTable commandTable =
54 {
55 { "instance", instanceCommandTable },
56 };
57
58 return commandTable;
59 }
@ SEC_ADMINISTRATOR
Definition: Common.h:60
@ SEC_GAMEMASTER
Definition: Common.h:59
@ SEC_MODERATOR
Definition: Common.h:58
std::vector< ChatCommandBuilder > ChatCommandTable
Definition: ChatCommand.h:46
static bool HandleInstanceGetBossStateCommand(ChatHandler *handler, uint32 encounterId, Optional< PlayerIdentifier > player)
Definition: cs_instance.cpp:209
static bool HandleInstanceSaveDataCommand(ChatHandler *handler)
Definition: cs_instance.cpp:144
static bool HandleInstanceUnbindCommand(ChatHandler *handler, Variant< uint16, EXACT_SEQUENCE("all")> mapArg, Optional< uint8 > difficultyArg)
Definition: cs_instance.cpp:88
static bool HandleInstanceStatsCommand(ChatHandler *handler)
Definition: cs_instance.cpp:130
static bool HandleInstanceListBindsCommand(ChatHandler *handler)
Definition: cs_instance.cpp:61
static bool HandleInstanceSetBossStateCommand(ChatHandler *handler, uint32 encounterId, uint32 state, Optional< PlayerIdentifier > player)
Definition: cs_instance.cpp:165

References HandleInstanceGetBossStateCommand(), HandleInstanceListBindsCommand(), HandleInstanceSaveDataCommand(), HandleInstanceSetBossStateCommand(), HandleInstanceStatsCommand(), HandleInstanceUnbindCommand(), SEC_ADMINISTRATOR, SEC_GAMEMASTER, and SEC_MODERATOR.

◆ HandleInstanceGetBossStateCommand()

static bool instance_commandscript::HandleInstanceGetBossStateCommand ( ChatHandler handler,
uint32  encounterId,
Optional< PlayerIdentifier player 
)
inlinestatic
210 {
211 // Character name must be provided when using this from console.
212 if (!player && !handler->GetSession())
213 {
215 return false;
216 }
217
218 if (!player)
219 player = PlayerIdentifier::FromSelf(handler);
220
221 if (!player->IsConnected())
222 {
224 return false;
225 }
226
227 InstanceMap* map = player->GetConnectedPlayer()->GetMap()->ToInstanceMap();
228 if (!map)
229 {
231 return false;
232 }
233
234 if (!map->GetInstanceScript())
235 {
237 return false;
238 }
239
240 if (encounterId > map->GetInstanceScript()->GetEncounterCount())
241 {
243 return false;
244 }
245
246 uint32 state = map->GetInstanceScript()->GetBossState(encounterId);
247 std::string stateName = InstanceScript::GetBossStateName(state);
248 handler->PSendSysMessage(LANG_COMMAND_INST_GET_BOSS_STATE, encounterId, state, stateName);
249 return true;
250 }
std::uint32_t uint32
Definition: Define.h:107
@ LANG_COMMAND_INST_GET_BOSS_STATE
Definition: Language.h:1107
@ LANG_NOT_DUNGEON
Definition: Language.h:1104
@ LANG_NO_INSTANCE_DATA
Definition: Language.h:1105
@ LANG_CMD_SYNTAX
Definition: Language.h:42
@ LANG_PLAYER_NOT_FOUND
Definition: Language.h:539
@ LANG_BAD_VALUE
Definition: Language.h:147
void PSendSysMessage(std::string_view str, bool escapeCharacters=false)
Definition: Chat.cpp:210
WorldSession * GetSession()
Definition: Chat.h:242
void SendErrorMessage(uint32 entry)
Definition: Chat.cpp:215
static Optional< PlayerIdentifier > FromSelf(ChatHandler *handler)
Definition: ChatCommandTags.cpp:147
EncounterState GetBossState(uint32 id) const
Definition: InstanceScript.h:235
static std::string GetBossStateName(uint8 state)
Definition: InstanceScript.cpp:808
uint32 GetEncounterCount() const
Definition: InstanceScript.h:259
InstanceMap * ToInstanceMap()
Definition: Map.h:544
Definition: Map.h:817
InstanceScript * GetInstanceScript()
Definition: Map.h:829

References Acore::ChatCommands::PlayerIdentifier::FromSelf(), InstanceScript::GetBossState(), InstanceScript::GetBossStateName(), InstanceScript::GetEncounterCount(), InstanceMap::GetInstanceScript(), ChatHandler::GetSession(), LANG_BAD_VALUE, LANG_CMD_SYNTAX, LANG_COMMAND_INST_GET_BOSS_STATE, LANG_NO_INSTANCE_DATA, LANG_NOT_DUNGEON, LANG_PLAYER_NOT_FOUND, ChatHandler::PSendSysMessage(), ChatHandler::SendErrorMessage(), and Map::ToInstanceMap().

Referenced by GetCommands().

◆ HandleInstanceListBindsCommand()

static bool instance_commandscript::HandleInstanceListBindsCommand ( ChatHandler handler)
inlinestatic
62 {
63 Player* player = handler->getSelectedPlayer();
64 if (!player)
65 player = handler->GetSession()->GetPlayer();
66
67 uint32 counter = 0;
68
69 for (uint8 i = 0; i < MAX_DIFFICULTY; ++i)
70 {
71 for (auto const& [mapId, bind] : sInstanceSaveMgr->PlayerGetBoundInstances(player->GetGUID(), Difficulty(i)))
72 {
73 InstanceSave const* save = bind.save;
74 uint32 resetTime = bind.extended ? save->GetExtendedResetTime() : save->GetResetTime();
75 uint32 ttr = (resetTime >= GameTime::GetGameTime().count() ? resetTime - GameTime::GetGameTime().count() : 0);
76 std::string timeleft = secsToTimeString(ttr);
77 handler->PSendSysMessage("map: {}, inst: {}, perm: {}, diff: {}, canReset: {}, TTR: {}{}",
78 mapId, save->GetInstanceId(), bind.perm ? "yes" : "no", save->GetDifficulty(), save->CanReset() ? "yes" : "no", timeleft, (bind.extended ? " (extended)" : ""));
79 counter++;
80 }
81 }
82
83 handler->PSendSysMessage("player binds: {}", counter);
84
85 return true;
86 }
std::string secsToTimeString(uint64 timeInSecs, bool shortText)
Definition: Util.cpp:73
std::uint8_t uint8
Definition: Define.h:109
Difficulty
Definition: DBCEnums.h:266
#define MAX_DIFFICULTY
Definition: DBCEnums.h:283
#define sInstanceSaveMgr
Definition: InstanceSaveMgr.h:202
Seconds GetGameTime()
Definition: GameTime.cpp:38
Player * getSelectedPlayer() const
Definition: Chat.cpp:373
static ObjectGuid GetGUID(Object const *o)
Definition: Object.h:109
Definition: Player.h:1064
Definition: InstanceSaveMgr.h:56
time_t GetExtendedResetTime() const
Definition: InstanceSaveMgr.h:76
uint32 GetInstanceId() const
Definition: InstanceSaveMgr.h:61
Difficulty GetDifficulty() const
Definition: InstanceSaveMgr.h:63
bool CanReset() const
Definition: InstanceSaveMgr.h:81
time_t GetResetTime() const
Definition: InstanceSaveMgr.h:75
Player * GetPlayer() const
Definition: WorldSession.h:362

References InstanceSave::CanReset(), InstanceSave::GetDifficulty(), InstanceSave::GetExtendedResetTime(), GameTime::GetGameTime(), Object::GetGUID(), InstanceSave::GetInstanceId(), WorldSession::GetPlayer(), InstanceSave::GetResetTime(), ChatHandler::getSelectedPlayer(), ChatHandler::GetSession(), MAX_DIFFICULTY, ChatHandler::PSendSysMessage(), secsToTimeString(), and sInstanceSaveMgr.

Referenced by GetCommands().

◆ HandleInstanceSaveDataCommand()

static bool instance_commandscript::HandleInstanceSaveDataCommand ( ChatHandler handler)
inlinestatic
145 {
146 Player* player = handler->GetSession()->GetPlayer();
147 Map* map = player->GetMap();
148 if (!map->IsDungeon())
149 {
150 handler->SendErrorMessage("Map is not a dungeon.");
151 return false;
152 }
153
154 if (!map->ToInstanceMap()->GetInstanceScript())
155 {
156 handler->SendErrorMessage("Map has no instance data.");
157 return false;
158 }
159
161
162 return true;
163 }
Map * GetMap() const
Definition: Object.h:531
void SaveToDB()
Definition: InstanceScript.cpp:41
Definition: Map.h:311
bool IsDungeon() const
Definition: Map.h:446

References InstanceMap::GetInstanceScript(), WorldObject::GetMap(), WorldSession::GetPlayer(), ChatHandler::GetSession(), Map::IsDungeon(), InstanceScript::SaveToDB(), ChatHandler::SendErrorMessage(), and Map::ToInstanceMap().

Referenced by GetCommands().

◆ HandleInstanceSetBossStateCommand()

static bool instance_commandscript::HandleInstanceSetBossStateCommand ( ChatHandler handler,
uint32  encounterId,
uint32  state,
Optional< PlayerIdentifier player 
)
inlinestatic
166 {
167 // Character name must be provided when using this from console.
168 if (!player && !handler->GetSession())
169 {
171 return false;
172 }
173
174 if (!player)
175 player = PlayerIdentifier::FromSelf(handler);
176
177 if (!player->IsConnected())
178 {
180 return false;
181 }
182
183 InstanceMap* map = player->GetConnectedPlayer()->GetMap()->ToInstanceMap();
184 if (!map)
185 {
187 return false;
188 }
189
190 if (!map->GetInstanceScript())
191 {
193 return false;
194 }
195
196 // Reject improper values.
197 if (encounterId > map->GetInstanceScript()->GetEncounterCount())
198 {
200 return false;
201 }
202
203 map->GetInstanceScript()->SetBossState(encounterId, EncounterState(state));
204 std::string stateName = InstanceScript::GetBossStateName(state);
205 handler->PSendSysMessage(LANG_COMMAND_INST_SET_BOSS_STATE, encounterId, state, stateName);
206 return true;
207 }
EncounterState
Definition: InstanceScript.h:56
@ LANG_COMMAND_INST_SET_BOSS_STATE
Definition: Language.h:1106
virtual bool SetBossState(uint32 id, EncounterState state)
Definition: InstanceScript.cpp:373

References Acore::ChatCommands::PlayerIdentifier::FromSelf(), InstanceScript::GetBossStateName(), InstanceScript::GetEncounterCount(), InstanceMap::GetInstanceScript(), ChatHandler::GetSession(), LANG_BAD_VALUE, LANG_CMD_SYNTAX, LANG_COMMAND_INST_SET_BOSS_STATE, LANG_NO_INSTANCE_DATA, LANG_NOT_DUNGEON, LANG_PLAYER_NOT_FOUND, ChatHandler::PSendSysMessage(), ChatHandler::SendErrorMessage(), InstanceScript::SetBossState(), and Map::ToInstanceMap().

Referenced by GetCommands().

◆ HandleInstanceStatsCommand()

static bool instance_commandscript::HandleInstanceStatsCommand ( ChatHandler handler)
inlinestatic
131 {
132 uint32 dungeon = 0, battleground = 0, arena = 0, spectators = 0;
133 sMapMgr->GetNumInstances(dungeon, battleground, arena);
134 handler->PSendSysMessage("instances loaded: dungeons ({}), battlegrounds ({}), arenas ({})", dungeon, battleground, arena);
135 dungeon = 0;
136 battleground = 0;
137 arena = 0;
138 spectators = 0;
139 sMapMgr->GetNumPlayersInInstances(dungeon, battleground, arena, spectators);
140 handler->SendErrorMessage("players in instances: dungeons ({}), battlegrounds ({}), arenas ({} + {} spect)", dungeon, battleground, arena, spectators);
141 return false;
142 }
#define sMapMgr
Definition: MapMgr.h:219

References ChatHandler::PSendSysMessage(), ChatHandler::SendErrorMessage(), and sMapMgr.

Referenced by GetCommands().

◆ HandleInstanceUnbindCommand()

static bool instance_commandscript::HandleInstanceUnbindCommand ( ChatHandler handler,
Variant< uint16, EXACT_SEQUENCE("all")>  mapArg,
Optional< uint8 difficultyArg 
)
inlinestatic
89 {
90 Player* player = handler->getSelectedPlayer();
91 if (!player)
92 player = handler->GetSession()->GetPlayer();
93
94 uint16 counter = 0;
95 uint16 mapId = 0;
96
97 if (mapArg.holds_alternative<uint16>())
98 {
99 mapId = mapArg.get<uint16>();
100 if (!mapId)
101 return false;
102 }
103
104 for (uint8 i = 0; i < MAX_DIFFICULTY; ++i)
105 {
106 BoundInstancesMap const& m_boundInstances = sInstanceSaveMgr->PlayerGetBoundInstances(player->GetGUID(), Difficulty(i));
107 for (BoundInstancesMap::const_iterator itr = m_boundInstances.begin(); itr != m_boundInstances.end();)
108 {
109 InstanceSave const* save = itr->second.save;
110 if (itr->first != player->GetMapId() && (!mapId || mapId == itr->first) && (!difficultyArg || difficultyArg == save->GetDifficulty()))
111 {
112 uint32 resetTime = itr->second.extended ? save->GetExtendedResetTime() : save->GetResetTime();
113 uint32 ttr = (resetTime >= GameTime::GetGameTime().count() ? resetTime - GameTime::GetGameTime().count() : 0);
114 std::string timeleft = secsToTimeString(ttr);
115 handler->PSendSysMessage("unbinding map: {}, inst: {}, perm: {}, diff: {}, canReset: {}, TTR: {}{}", itr->first, save->GetInstanceId(), itr->second.perm ? "yes" : "no", save->GetDifficulty(), save->CanReset() ? "yes" : "no", timeleft, (itr->second.extended ? " (extended)" : ""));
116 sInstanceSaveMgr->PlayerUnbindInstance(player->GetGUID(), itr->first, Difficulty(i), true, player);
117 itr = m_boundInstances.begin();
118 counter++;
119 }
120 else
121 ++itr;
122 }
123 }
124
125 handler->PSendSysMessage("instances unbound: {}", counter);
126
127 return true;
128 }
std::uint16_t uint16
Definition: Define.h:108
std::unordered_map< uint32, InstancePlayerBind > BoundInstancesMap
Definition: InstanceSaveMgr.h:46
constexpr decltype(auto) get()
Definition: ChatCommandTags.h:284
constexpr bool holds_alternative() const
Definition: ChatCommandTags.h:298
uint32 GetMapId() const
Definition: Position.h:275

References InstanceSave::CanReset(), InstanceSave::GetDifficulty(), InstanceSave::GetExtendedResetTime(), GameTime::GetGameTime(), Object::GetGUID(), InstanceSave::GetInstanceId(), WorldLocation::GetMapId(), WorldSession::GetPlayer(), InstanceSave::GetResetTime(), ChatHandler::getSelectedPlayer(), ChatHandler::GetSession(), MAX_DIFFICULTY, ChatHandler::PSendSysMessage(), secsToTimeString(), and sInstanceSaveMgr.

Referenced by GetCommands().