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 ()
 
std::string const & 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< uint32 > difficultyArg, Optional< PlayerIdentifier > target)
 
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)
 

Static Private Member Functions

static std::unordered_map< uint32, char const * > GetEncounterNames (InstanceMap const *map)
 
static std::string GetBossName (std::unordered_map< uint32, char const * > const &encounterNames, uint32 encounterId)
 

Additional Inherited Members

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

Detailed Description

Constructor & Destructor Documentation

◆ instance_commandscript()

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

Member Function Documentation

◆ GetBossName()

static std::string instance_commandscript::GetBossName ( std::unordered_map< uint32, char const * > const &  encounterNames,
uint32  encounterId 
)
inlinestaticprivate
318 {
319 auto it = encounterNames.find(encounterId);
320 return (it != encounterNames.end() && it->second) ? it->second : "Unknown";
321 }

Referenced by HandleInstanceGetBossStateCommand(), and HandleInstanceSetBossStateCommand().

◆ GetCommands()

ChatCommandTable instance_commandscript::GetCommands ( ) const
inlineoverridevirtual

Implements CommandScript.

39 {
40 static ChatCommandTable instanceCommandTable =
41 {
48 };
49
50 static ChatCommandTable commandTable =
51 {
52 { "instance", instanceCommandTable },
53 };
54
55 return commandTable;
56 }
static bool HandleInstanceGetBossStateCommand(ChatHandler *handler, Optional< PlayerIdentifier > player)
Definition cs_instance.cpp:231
static bool HandleInstanceSaveDataCommand(ChatHandler *handler)
Definition cs_instance.cpp:165
static bool HandleInstanceUnbindCommand(ChatHandler *handler, Variant< uint16, EXACT_SEQUENCE("all")> mapArg, Optional< uint32 > difficultyArg, Optional< PlayerIdentifier > target)
Definition cs_instance.cpp:86
static bool HandleInstanceStatsCommand(ChatHandler *handler)
Definition cs_instance.cpp:151
static bool HandleInstanceListBindsCommand(ChatHandler *handler)
Definition cs_instance.cpp:58
static bool HandleInstanceSetBossStateCommand(ChatHandler *handler, uint32 encounterId, uint32 state, Optional< PlayerIdentifier > player)
Definition cs_instance.cpp:186
std::vector< ChatCommandBuilder > ChatCommandTable
Definition ChatCommand.h:46
@ RBAC_PERM_COMMAND_INSTANCE_LISTBINDS
Definition RBAC.h:247
@ RBAC_PERM_COMMAND_INSTANCE_SET_BOSS_STATE
Definition RBAC.h:617
@ RBAC_PERM_COMMAND_INSTANCE_GET_BOSS_STATE
Definition RBAC.h:618
@ RBAC_PERM_COMMAND_INSTANCE_STATS
Definition RBAC.h:249
@ RBAC_PERM_COMMAND_INSTANCE_UNBIND
Definition RBAC.h:248
@ RBAC_PERM_COMMAND_INSTANCE_SAVEDATA
Definition RBAC.h:250

References HandleInstanceGetBossStateCommand(), HandleInstanceListBindsCommand(), HandleInstanceSaveDataCommand(), HandleInstanceSetBossStateCommand(), HandleInstanceStatsCommand(), HandleInstanceUnbindCommand(), rbac::RBAC_PERM_COMMAND_INSTANCE_GET_BOSS_STATE, rbac::RBAC_PERM_COMMAND_INSTANCE_LISTBINDS, rbac::RBAC_PERM_COMMAND_INSTANCE_SAVEDATA, rbac::RBAC_PERM_COMMAND_INSTANCE_SET_BOSS_STATE, rbac::RBAC_PERM_COMMAND_INSTANCE_STATS, and rbac::RBAC_PERM_COMMAND_INSTANCE_UNBIND.

◆ GetEncounterNames()

static std::unordered_map< uint32, char const * > instance_commandscript::GetEncounterNames ( InstanceMap const *  map)
inlinestaticprivate
281 {
282 std::unordered_map<uint32, char const*> encounterNames;
283 Difficulty difficulty = map->GetDifficulty();
284
285 // For heroic ICC/Ruby Sanctum, encounters are only defined
286 // for normal difficulty in the DBC, use the same fallback
287 // pattern as Map::UpdateEncounterState
288 DungeonEncounterList const* encounters = nullptr;
289 if ((map->GetId() == 631 || map->GetId() == 724)
290 && map->IsHeroic())
291 {
292 encounters = sObjectMgr->GetDungeonEncounterList(
293 map->GetId(),
294 !map->Is25ManRaid()
297 }
298 else
299 {
300 Difficulty diffFixed = IsSharedDifficultyMap(map->GetId())
301 ? Difficulty(difficulty % 2)
302 : difficulty;
303 encounters = sObjectMgr->GetDungeonEncounterList(
304 map->GetId(), diffFixed);
305 }
306
307 if (encounters)
308 {
309 for (auto const* encounter : *encounters)
310 encounterNames[encounter->dbcEntry->encounterIndex]
311 = encounter->dbcEntry->encounterName[0];
312 }
313
314 return encounterNames;
315 }
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:846
#define sObjectMgr
Definition ObjectMgr.h:1731
std::list< DungeonEncounter const * > DungeonEncounterList
Definition ObjectMgr.h:716

References Map::GetDifficulty(), Map::GetId(), Map::Is25ManRaid(), Map::IsHeroic(), IsSharedDifficultyMap(), RAID_DIFFICULTY_10MAN_NORMAL, RAID_DIFFICULTY_25MAN_NORMAL, and sObjectMgr.

Referenced by HandleInstanceGetBossStateCommand(), and HandleInstanceSetBossStateCommand().

◆ HandleInstanceGetBossStateCommand()

static bool instance_commandscript::HandleInstanceGetBossStateCommand ( ChatHandler *  handler,
Optional< PlayerIdentifier >  player 
)
inlinestatic
232 {
233 // Character name must be provided when using this from console.
234 if (!player && !handler->GetSession())
235 {
237 return false;
238 }
239
240 if (!player)
241 player = PlayerIdentifier::FromSelf(handler);
242
243 if (!player->IsConnected())
244 {
246 return false;
247 }
248
249 InstanceMap* map = player->GetConnectedPlayer()->GetMap()->ToInstanceMap();
250 if (!map)
251 {
253 return false;
254 }
255
256 if (!map->GetInstanceScript())
257 {
259 return false;
260 }
261
262 std::unordered_map<uint32, char const*> encounterNames = GetEncounterNames(map);
263
264 for (uint8 i = 0; i < map->GetInstanceScript()->GetEncounterCount(); ++i)
265 {
266 uint32 state = map->GetInstanceScript()->GetBossState(i);
267 std::string stateName = InstanceScript::GetBossStateName(state);
268 std::string bossName = GetBossName(encounterNames, i);
269
270 handler->PSendSysMessage(
272 i, bossName, state, stateName);
273 }
274
275 return true;
276 }
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:1122
@ LANG_NOT_DUNGEON
Definition Language.h:1119
@ LANG_NO_INSTANCE_DATA
Definition Language.h:1120
@ LANG_CMD_SYNTAX
Definition Language.h:42
@ LANG_PLAYER_NOT_FOUND
Definition Language.h:548
void PSendSysMessage(std::string_view str, bool escapeCharacters=false)
Definition Chat.cpp:219
WorldSession * GetSession()
Definition Chat.h:242
void SendErrorMessage(uint32 entry)
Definition Chat.cpp:224
Definition Map.h:727
InstanceScript * GetInstanceScript()
Definition Map.h:739
EncounterState GetBossState(uint32 id) const
Definition InstanceScript.h:252
static std::string GetBossStateName(uint8 state)
Definition InstanceScript.cpp:850
InstanceMap * ToInstanceMap()
Definition Map.h:390
static std::string GetBossName(std::unordered_map< uint32, char const * > const &encounterNames, uint32 encounterId)
Definition cs_instance.cpp:317
static std::unordered_map< uint32, char const * > GetEncounterNames(InstanceMap const *map)
Definition cs_instance.cpp:280
static Optional< PlayerIdentifier > FromSelf(ChatHandler *handler)
Definition ChatCommandTags.cpp:147

References Acore::ChatCommands::PlayerIdentifier::FromSelf(), GetBossName(), InstanceScript::GetBossState(), InstanceScript::GetBossStateName(), GetEncounterNames(), InstanceMap::GetInstanceScript(), ChatHandler::GetSession(), 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
59 {
60 Player* player = handler->getSelectedPlayer();
61 if (!player)
62 player = handler->GetSession()->GetPlayer();
63
64 uint32 counter = 0;
65
66 for (uint8 i = 0; i < MAX_DIFFICULTY; ++i)
67 {
68 for (auto const& [mapId, bind] : sInstanceSaveMgr->PlayerGetBoundInstances(player->GetGUID(), Difficulty(i)))
69 {
70 InstanceSave const* save = bind.save;
71 uint32 resetTime = bind.extended ? save->GetExtendedResetTime() : save->GetResetTime();
72 uint32 ttr = (resetTime >= GameTime::GetGameTime().count() ? resetTime - GameTime::GetGameTime().count() : 0);
73 std::string timeleft = secsToTimeString(ttr);
74 handler->PSendSysMessage("map: {}, inst: {}, perm: {}, diff: {}, canReset: {}, TTR: {}{}",
75 mapId, save->GetInstanceId(), bind.perm ? "yes" : "no", save->GetDifficulty(), save->CanReset() ? "yes" : "no", timeleft, (bind.extended ? " (extended)" : ""));
76 counter++;
77 }
78 }
79
80 handler->PSendSysMessage("player binds: {}", counter);
81
82 return true;
83 }
#define MAX_DIFFICULTY
Definition DBCEnums.h:283
#define sInstanceSaveMgr
Definition InstanceSaveMgr.h:233
std::string secsToTimeString(uint64 timeInSecs, bool shortText)
Definition Util.cpp:73
Player * getSelectedPlayer() const
Definition Chat.cpp:382
Definition InstanceSaveMgr.h:57
time_t GetExtendedResetTime() const
Definition InstanceSaveMgr.h:77
uint32 GetInstanceId() const
Definition InstanceSaveMgr.h:62
time_t GetResetTime() const
Definition InstanceSaveMgr.h:76
Definition Player.h:1086
Player * GetPlayer() const
Definition WorldSession.h:503
Seconds GetGameTime()
Definition GameTime.cpp:39

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
166 {
167 Player* player = handler->GetSession()->GetPlayer();
168 Map* map = player->GetMap();
169 if (!map->IsDungeon())
170 {
171 handler->SendErrorMessage("Map is not a dungeon.");
172 return false;
173 }
174
175 if (!map->ToInstanceMap()->GetInstanceScript())
176 {
177 handler->SendErrorMessage("Map has no instance data.");
178 return false;
179 }
180
182
183 return true;
184 }
void SaveToDB()
Definition InstanceScript.cpp:43
Definition Map.h:168
bool IsDungeon() const
Definition Map.h:299
Map * GetMap() const
Definition Object.h:637

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
187 {
188 // Character name must be provided when using this from console.
189 if (!player && !handler->GetSession())
190 {
192 return false;
193 }
194
195 if (!player)
196 player = PlayerIdentifier::FromSelf(handler);
197
198 if (!player->IsConnected())
199 {
201 return false;
202 }
203
204 InstanceMap* map = player->GetConnectedPlayer()->GetMap()->ToInstanceMap();
205 if (!map)
206 {
208 return false;
209 }
210
211 if (!map->GetInstanceScript())
212 {
214 return false;
215 }
216
217 // Reject improper values.
218 if (encounterId > map->GetInstanceScript()->GetEncounterCount())
219 {
221 return false;
222 }
223
224 map->GetInstanceScript()->SetBossState(encounterId, EncounterState(state));
225 std::string stateName = InstanceScript::GetBossStateName(state);
226 std::string bossName = GetBossName(GetEncounterNames(map), encounterId);
227 handler->PSendSysMessage(LANG_COMMAND_INST_SET_BOSS_STATE, encounterId, bossName, state, stateName);
228 return true;
229 }
EncounterState
Definition InstanceScript.h:57
@ LANG_COMMAND_INST_SET_BOSS_STATE
Definition Language.h:1121
@ LANG_BAD_VALUE
Definition Language.h:151
virtual bool SetBossState(uint32 id, EncounterState state)
Definition InstanceScript.cpp:406
uint32 GetEncounterCount() const
Definition InstanceScript.h:281

References Acore::ChatCommands::PlayerIdentifier::FromSelf(), GetBossName(), InstanceScript::GetBossStateName(), InstanceScript::GetEncounterCount(), GetEncounterNames(), 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
152 {
153 uint32 dungeon = 0, battleground = 0, arena = 0, spectators = 0;
154 sMapMgr->GetNumInstances(dungeon, battleground, arena);
155 handler->PSendSysMessage("instances loaded: dungeons ({}), battlegrounds ({}), arenas ({})", dungeon, battleground, arena);
156 dungeon = 0;
157 battleground = 0;
158 arena = 0;
159 spectators = 0;
160 sMapMgr->GetNumPlayersInInstances(dungeon, battleground, arena, spectators);
161 handler->SendErrorMessage("players in instances: dungeons ({}), battlegrounds ({}), arenas ({} + {} spect)", dungeon, battleground, arena, spectators);
162 return false;
163 }
#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< uint32 >  difficultyArg,
Optional< PlayerIdentifier >  target 
)
inlinestatic
88 {
89 if (!target)
90 target = PlayerIdentifier::FromTargetOrSelf(handler);
91
92 if (!target)
93 {
95 return false;
96 }
97
98 Player* player = target->GetConnectedPlayer();
99 ObjectGuid const guid = target->GetGUID();
100
101 // Keep the bind of the map the character is on, or logged out on
102 uint32 currentMapId = 0;
103 if (player)
104 currentMapId = player->GetMapId();
105 else
106 {
108 CharacterDatabase.GetPreparedStatement(CHAR_SEL_CHAR_POSITION_XYZ);
109 stmt->SetData(0, guid.GetCounter());
110 if (PreparedQueryResult result = CharacterDatabase.Query(stmt))
111 currentMapId = (*result)[0].Get<uint16>();
112 }
113
114 uint16 counter = 0;
115 uint16 mapId = 0;
116
117 if (mapArg.holds_alternative<uint16>())
118 {
119 mapId = mapArg.get<uint16>();
120 if (!mapId)
121 return false;
122 }
123
124 for (uint8 i = 0; i < MAX_DIFFICULTY; ++i)
125 {
126 BoundInstancesMap const& m_boundInstances = sInstanceSaveMgr->PlayerGetBoundInstances(guid, Difficulty(i));
127 for (BoundInstancesMap::const_iterator itr = m_boundInstances.begin(); itr != m_boundInstances.end();)
128 {
129 InstanceSave const* save = itr->second.save;
130 if (itr->first != currentMapId && (!mapId || mapId == itr->first)
131 && (!difficultyArg || *difficultyArg == uint32(save->GetDifficulty())))
132 {
133 uint32 resetTime = itr->second.extended ? save->GetExtendedResetTime() : save->GetResetTime();
134 uint32 ttr = (resetTime >= GameTime::GetGameTime().count() ? resetTime - GameTime::GetGameTime().count() : 0);
135 std::string timeleft = secsToTimeString(ttr);
136 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)" : ""));
137 sInstanceSaveMgr->PlayerUnbindInstance(guid, itr->first, Difficulty(i), true, player);
138 itr = m_boundInstances.begin();
139 counter++;
140 }
141 else
142 ++itr;
143 }
144 }
145
146 handler->PSendSysMessage("instances unbound: {}", counter);
147
148 return true;
149 }
@ CHAR_SEL_CHAR_POSITION_XYZ
Definition CharacterDatabase.h:53
std::shared_ptr< PreparedResultSet > PreparedQueryResult
Definition DatabaseEnvFwd.h:45
DatabaseWorkerPool< CharacterDatabaseConnection > CharacterDatabase
Accessor to the character database.
Definition DatabaseEnv.cpp:21
std::uint16_t uint16
Definition Define.h:108
std::unordered_map< uint32, InstancePlayerBind > BoundInstancesMap
Definition InstanceSaveMgr.h:47
Difficulty GetDifficulty() const
Definition InstanceSaveMgr.h:64
Definition ObjectGuid.h:121
LowType GetCounter() const
Definition ObjectGuid.h:149
Acore::Types::is_default< T > SetData(const uint8 index, T value)
Definition PreparedStatement.h:77
Definition PreparedStatement.h:157
uint32 GetMapId() const
Definition Position.h:281
static Optional< PlayerIdentifier > FromTargetOrSelf(ChatHandler *handler)
Definition ChatCommandTags.h:189
constexpr decltype(auto) get()
Definition ChatCommandTags.h:289
constexpr bool holds_alternative() const
Definition ChatCommandTags.h:303

References InstanceSave::CanReset(), CHAR_SEL_CHAR_POSITION_XYZ, CharacterDatabase, Acore::ChatCommands::PlayerIdentifier::FromTargetOrSelf(), ObjectGuid::GetCounter(), InstanceSave::GetDifficulty(), InstanceSave::GetExtendedResetTime(), GameTime::GetGameTime(), InstanceSave::GetInstanceId(), WorldLocation::GetMapId(), InstanceSave::GetResetTime(), LANG_PLAYER_NOT_FOUND, MAX_DIFFICULTY, ChatHandler::PSendSysMessage(), secsToTimeString(), ChatHandler::SendErrorMessage(), PreparedStatementBase::SetData(), and sInstanceSaveMgr.

Referenced by GetCommands().


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