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
 
- 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, 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
34: CommandScript("instance_commandscript") { }
Definition CommandScript.h:25

Member Function Documentation

◆ GetCommands()

ChatCommandTable instance_commandscript::GetCommands ( ) const
inlineoverridevirtual

Implements CommandScript.

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

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

◆ HandleInstanceGetBossStateCommand()

static bool instance_commandscript::HandleInstanceGetBossStateCommand ( ChatHandler handler,
Optional< PlayerIdentifier player 
)
inlinestatic
205 {
206 // Character name must be provided when using this from console.
207 if (!player && !handler->GetSession())
208 {
210 return false;
211 }
212
213 if (!player)
214 player = PlayerIdentifier::FromSelf(handler);
215
216 if (!player->IsConnected())
217 {
219 return false;
220 }
221
222 InstanceMap* map = player->GetConnectedPlayer()->GetMap()->ToInstanceMap();
223 if (!map)
224 {
226 return false;
227 }
228
229 if (!map->GetInstanceScript())
230 {
232 return false;
233 }
234
235 // Build a map of encounterIndex -> encounterName from DBC data
236 std::unordered_map<uint32, char const*> encounterNames;
237 Difficulty difficulty = map->GetDifficulty();
238
239 // For heroic ICC/Ruby Sanctum, encounters are only defined
240 // for normal difficulty in the DBC, use the same fallback
241 // pattern as Map::UpdateEncounterState
242 DungeonEncounterList const* encounters = nullptr;
243 if ((map->GetId() == 631 || map->GetId() == 724)
244 && map->IsHeroic())
245 {
246 encounters = sObjectMgr->GetDungeonEncounterList(
247 map->GetId(),
248 !map->Is25ManRaid()
251 }
252 else
253 {
254 Difficulty diffFixed = IsSharedDifficultyMap(map->GetId())
255 ? Difficulty(difficulty % 2)
256 : difficulty;
257 encounters = sObjectMgr->GetDungeonEncounterList(
258 map->GetId(), diffFixed);
259 }
260
261 if (encounters)
262 {
263 for (auto const* encounter : *encounters)
264 encounterNames[encounter->dbcEntry->encounterIndex]
265 = encounter->dbcEntry->encounterName[0];
266 }
267
268 for (uint8 i = 0; i < map->GetInstanceScript()->GetEncounterCount(); ++i)
269 {
270 uint32 state = map->GetInstanceScript()->GetBossState(i);
271 std::string stateName = InstanceScript::GetBossStateName(state);
272
273 auto it = encounterNames.find(i);
274 std::string bossName = (it != encounterNames.end()
275 && it->second) ? it->second : "Unknown";
276
277 handler->PSendSysMessage(
279 i, bossName, state, stateName);
280 }
281
282 return true;
283 }
Difficulty
Definition DBCEnums.h:266
@ RAID_DIFFICULTY_10MAN_NORMAL
Definition DBCEnums.h:273
@ RAID_DIFFICULTY_25MAN_NORMAL
Definition DBCEnums.h:274
bool IsSharedDifficultyMap(uint32 mapid)
Definition DBCStores.cpp:829
std::uint8_t uint8
Definition Define.h:109
std::uint32_t uint32
Definition Define.h:107
@ LANG_COMMAND_INST_GET_BOSS_STATE
Definition Language.h:1119
@ LANG_NOT_DUNGEON
Definition Language.h:1116
@ LANG_NO_INSTANCE_DATA
Definition Language.h:1117
@ LANG_CMD_SYNTAX
Definition Language.h:42
@ LANG_PLAYER_NOT_FOUND
Definition Language.h:545
#define sObjectMgr
Definition ObjectMgr.h:1712
std::list< DungeonEncounter const * > DungeonEncounterList
Definition ObjectMgr.h:713
void PSendSysMessage(std::string_view str, bool escapeCharacters=false)
Definition Chat.cpp:211
WorldSession * GetSession()
Definition Chat.h:242
void SendErrorMessage(uint32 entry)
Definition Chat.cpp:216
Definition Map.h:648
InstanceScript * GetInstanceScript()
Definition Map.h:660
EncounterState GetBossState(uint32 id) const
Definition InstanceScript.h:252
static std::string GetBossStateName(uint8 state)
Definition InstanceScript.cpp:831
bool Is25ManRaid() const
Definition Map.h:300
uint32 GetId() const
Definition Map.h:230
InstanceMap * ToInstanceMap()
Definition Map.h:378
Difficulty GetDifficulty() const
Definition Map.h:290
bool IsHeroic() const
Definition Map.h:299
static Optional< PlayerIdentifier > FromSelf(ChatHandler *handler)
Definition ChatCommandTags.cpp:147

References Acore::ChatCommands::PlayerIdentifier::FromSelf(), InstanceScript::GetBossState(), InstanceScript::GetBossStateName(), Map::GetDifficulty(), Map::GetId(), InstanceMap::GetInstanceScript(), ChatHandler::GetSession(), Map::Is25ManRaid(), Map::IsHeroic(), IsSharedDifficultyMap(), LANG_CMD_SYNTAX, LANG_COMMAND_INST_GET_BOSS_STATE, LANG_NO_INSTANCE_DATA, LANG_NOT_DUNGEON, LANG_PLAYER_NOT_FOUND, ChatHandler::PSendSysMessage(), RAID_DIFFICULTY_10MAN_NORMAL, RAID_DIFFICULTY_25MAN_NORMAL, ChatHandler::SendErrorMessage(), sObjectMgr, and Map::ToInstanceMap().

Referenced by GetCommands().

◆ HandleInstanceListBindsCommand()

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

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
140 {
141 Player* player = handler->GetSession()->GetPlayer();
142 Map* map = player->GetMap();
143 if (!map->IsDungeon())
144 {
145 handler->SendErrorMessage("Map is not a dungeon.");
146 return false;
147 }
148
149 if (!map->ToInstanceMap()->GetInstanceScript())
150 {
151 handler->SendErrorMessage("Map has no instance data.");
152 return false;
153 }
154
156
157 return true;
158 }
void SaveToDB()
Definition InstanceScript.cpp:41
Definition Map.h:164
bool IsDungeon() const
Definition Map.h:295
Map * GetMap() const
Definition Object.h:625

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
161 {
162 // Character name must be provided when using this from console.
163 if (!player && !handler->GetSession())
164 {
166 return false;
167 }
168
169 if (!player)
170 player = PlayerIdentifier::FromSelf(handler);
171
172 if (!player->IsConnected())
173 {
175 return false;
176 }
177
178 InstanceMap* map = player->GetConnectedPlayer()->GetMap()->ToInstanceMap();
179 if (!map)
180 {
182 return false;
183 }
184
185 if (!map->GetInstanceScript())
186 {
188 return false;
189 }
190
191 // Reject improper values.
192 if (encounterId > map->GetInstanceScript()->GetEncounterCount())
193 {
195 return false;
196 }
197
198 map->GetInstanceScript()->SetBossState(encounterId, EncounterState(state));
199 std::string stateName = InstanceScript::GetBossStateName(state);
200 handler->PSendSysMessage(LANG_COMMAND_INST_SET_BOSS_STATE, encounterId, state, stateName);
201 return true;
202 }
EncounterState
Definition InstanceScript.h:57
@ LANG_COMMAND_INST_SET_BOSS_STATE
Definition Language.h:1118
@ LANG_BAD_VALUE
Definition Language.h:148
virtual bool SetBossState(uint32 id, EncounterState state)
Definition InstanceScript.cpp:390
uint32 GetEncounterCount() const
Definition InstanceScript.h:276

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
126 {
127 uint32 dungeon = 0, battleground = 0, arena = 0, spectators = 0;
128 sMapMgr->GetNumInstances(dungeon, battleground, arena);
129 handler->PSendSysMessage("instances loaded: dungeons ({}), battlegrounds ({}), arenas ({})", dungeon, battleground, arena);
130 dungeon = 0;
131 battleground = 0;
132 arena = 0;
133 spectators = 0;
134 sMapMgr->GetNumPlayersInInstances(dungeon, battleground, arena, spectators);
135 handler->SendErrorMessage("players in instances: dungeons ({}), battlegrounds ({}), arenas ({} + {} spect)", dungeon, battleground, arena, spectators);
136 return false;
137 }
#define sMapMgr
Definition MapMgr.h:220

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
84 {
85 Player* player = handler->getSelectedPlayer();
86 if (!player)
87 player = handler->GetSession()->GetPlayer();
88
89 uint16 counter = 0;
90 uint16 mapId = 0;
91
92 if (mapArg.holds_alternative<uint16>())
93 {
94 mapId = mapArg.get<uint16>();
95 if (!mapId)
96 return false;
97 }
98
99 for (uint8 i = 0; i < MAX_DIFFICULTY; ++i)
100 {
101 BoundInstancesMap const& m_boundInstances = sInstanceSaveMgr->PlayerGetBoundInstances(player->GetGUID(), Difficulty(i));
102 for (BoundInstancesMap::const_iterator itr = m_boundInstances.begin(); itr != m_boundInstances.end();)
103 {
104 InstanceSave const* save = itr->second.save;
105 if (itr->first != player->GetMapId() && (!mapId || mapId == itr->first) && (!difficultyArg || difficultyArg == save->GetDifficulty()))
106 {
107 uint32 resetTime = itr->second.extended ? save->GetExtendedResetTime() : save->GetResetTime();
108 uint32 ttr = (resetTime >= GameTime::GetGameTime().count() ? resetTime - GameTime::GetGameTime().count() : 0);
109 std::string timeleft = secsToTimeString(ttr);
110 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)" : ""));
111 sInstanceSaveMgr->PlayerUnbindInstance(player->GetGUID(), itr->first, Difficulty(i), true, player);
112 itr = m_boundInstances.begin();
113 counter++;
114 }
115 else
116 ++itr;
117 }
118 }
119
120 handler->PSendSysMessage("instances unbound: {}", counter);
121
122 return true;
123 }
std::uint16_t uint16
Definition Define.h:108
std::unordered_map< uint32, InstancePlayerBind > BoundInstancesMap
Definition InstanceSaveMgr.h:46
Difficulty GetDifficulty() const
Definition InstanceSaveMgr.h:63
static ObjectGuid GetGUID(Object const *o)
Definition Object.h:114
uint32 GetMapId() const
Definition Position.h:281
constexpr decltype(auto) get()
Definition ChatCommandTags.h:284
constexpr bool holds_alternative() const
Definition ChatCommandTags.h:298

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().


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