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

Public Member Functions

 mmaps_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 HandleMmapPathCommand (ChatHandler *handler, Optional< std::string > param)
 
static bool HandleMmapLocCommand (ChatHandler *handler)
 
static bool HandleMmapLoadedTilesCommand (ChatHandler *handler)
 
static bool HandleMmapStatsCommand (ChatHandler *handler)
 
static bool HandleMmapTestArea (ChatHandler *handler)
 

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

◆ mmaps_commandscript()

mmaps_commandscript::mmaps_commandscript ( )
inline
42: CommandScript("mmaps_commandscript") { }
Definition CommandScript.h:25

Member Function Documentation

◆ GetCommands()

ChatCommandTable mmaps_commandscript::GetCommands ( ) const
inlineoverridevirtual

Implements CommandScript.

45 {
46 static ChatCommandTable mmapCommandTable =
47 {
48 { "loadedtiles", HandleMmapLoadedTilesCommand, SEC_ADMINISTRATOR, Console::No },
49 { "loc", HandleMmapLocCommand, SEC_ADMINISTRATOR, Console::No },
50 { "path", HandleMmapPathCommand, SEC_ADMINISTRATOR, Console::No },
51 { "stats", HandleMmapStatsCommand, SEC_ADMINISTRATOR, Console::No },
52 { "testarea", HandleMmapTestArea, SEC_ADMINISTRATOR, Console::No }
53 };
54
55 static ChatCommandTable commandTable =
56 {
57 { "mmap", mmapCommandTable }
58 };
59 return commandTable;
60 }
@ SEC_ADMINISTRATOR
Definition Common.h:60
static bool HandleMmapPathCommand(ChatHandler *handler, Optional< std::string > param)
Definition cs_mmaps.cpp:62
static bool HandleMmapLoadedTilesCommand(ChatHandler *handler)
Definition cs_mmaps.cpp:191
static bool HandleMmapStatsCommand(ChatHandler *handler)
Definition cs_mmaps.cpp:216
static bool HandleMmapLocCommand(ChatHandler *handler)
Definition cs_mmaps.cpp:129
static bool HandleMmapTestArea(ChatHandler *handler)
Definition cs_mmaps.cpp:262
std::vector< ChatCommandBuilder > ChatCommandTable
Definition ChatCommand.h:46

References HandleMmapLoadedTilesCommand(), HandleMmapLocCommand(), HandleMmapPathCommand(), HandleMmapStatsCommand(), HandleMmapTestArea(), and SEC_ADMINISTRATOR.

◆ HandleMmapLoadedTilesCommand()

static bool mmaps_commandscript::HandleMmapLoadedTilesCommand ( ChatHandler handler)
inlinestatic
192 {
193 uint32 mapid = handler->GetSession()->GetPlayer()->GetMapId();
194 dtNavMesh const* navmesh = MMAP::MMapFactory::createOrGetMMapMgr()->GetNavMesh(mapid);
195 dtNavMeshQuery const* navmeshquery = MMAP::MMapFactory::createOrGetMMapMgr()->GetNavMeshQuery(mapid, handler->GetSession()->GetPlayer()->GetInstanceId());
196 if (!navmesh || !navmeshquery)
197 {
198 handler->PSendSysMessage("NavMesh not loaded for current map.");
199 return true;
200 }
201
202 handler->PSendSysMessage("mmap loadedtiles:");
203
204 for (int32 i = 0; i < navmesh->getMaxTiles(); ++i)
205 {
206 dtMeshTile const* tile = navmesh->getTile(i);
207 if (!tile || !tile->header)
208 continue;
209
210 handler->PSendSysMessage("[{}, {}]", tile->header->x, tile->header->y);
211 }
212
213 return true;
214 }
std::int32_t int32
Definition Define.h:103
std::uint32_t uint32
Definition Define.h:107
void PSendSysMessage(std::string_view str, bool escapeCharacters=false)
Definition Chat.cpp:211
WorldSession * GetSession()
Definition Chat.h:242
static MMapMgr * createOrGetMMapMgr()
Definition MMapFactory.cpp:27
dtNavMesh const * GetNavMesh(uint32 mapId)
Definition MMapMgr.cpp:306
dtNavMeshQuery const * GetNavMeshQuery(uint32 mapId, uint32 instanceId)
Definition MMapMgr.cpp:317
uint32 GetMapId() const
Definition Position.h:280
uint32 GetInstanceId() const
Definition Object.h:448
Player * GetPlayer() const
Definition WorldSession.h:376

References MMAP::MMapFactory::createOrGetMMapMgr(), WorldObject::GetInstanceId(), WorldLocation::GetMapId(), MMAP::MMapMgr::GetNavMesh(), MMAP::MMapMgr::GetNavMeshQuery(), WorldSession::GetPlayer(), ChatHandler::GetSession(), and ChatHandler::PSendSysMessage().

Referenced by GetCommands().

◆ HandleMmapLocCommand()

static bool mmaps_commandscript::HandleMmapLocCommand ( ChatHandler handler)
inlinestatic
130 {
131 handler->PSendSysMessage("mmap tileloc:");
132
133 // grid tile location
134 Player* player = handler->GetSession()->GetPlayer();
135
136 GridCoord const gridCoord = Acore::ComputeGridCoord(player->GetPositionX(), player->GetPositionY());
137
138 handler->PSendSysMessage("{}{}{}.mmtile", player->GetMapId(), gridCoord.x_coord, gridCoord.y_coord);
139 handler->PSendSysMessage("gridloc [{}, {}]", gridCoord.x_coord, gridCoord.y_coord);
140
141 // calculate navmesh tile location
142 dtNavMesh const* navmesh = MMAP::MMapFactory::createOrGetMMapMgr()->GetNavMesh(handler->GetSession()->GetPlayer()->GetMapId());
143 dtNavMeshQuery const* navmeshquery = MMAP::MMapFactory::createOrGetMMapMgr()->GetNavMeshQuery(handler->GetSession()->GetPlayer()->GetMapId(), player->GetInstanceId());
144 if (!navmesh || !navmeshquery)
145 {
146 handler->PSendSysMessage("NavMesh not loaded for current map.");
147 return true;
148 }
149
150 float const* min = navmesh->getParams()->orig;
151 float x, y, z;
152 player->GetPosition(x, y, z);
153 float location[VERTEX_SIZE] = {y, z, x};
154 float extents[VERTEX_SIZE] = {3.0f, 5.0f, 3.0f};
155
156 int32 tilex = int32((y - min[0]) / SIZE_OF_GRIDS);
157 int32 tiley = int32((x - min[2]) / SIZE_OF_GRIDS);
158
159 handler->PSendSysMessage("Calc [{}, {}]", tilex, tiley);
160
161 // navmesh poly -> navmesh tile location
163 dtPolyRef polyRef = INVALID_POLYREF;
164 if (dtStatusFailed(navmeshquery->findNearestPoly(location, extents, &filter, &polyRef, nullptr)))
165 {
166 handler->PSendSysMessage("Dt [??,??] (invalid poly, probably no tile loaded)");
167 return true;
168 }
169
170 if (polyRef == INVALID_POLYREF)
171 handler->PSendSysMessage("Dt [??, ??] (invalid poly, probably no tile loaded)");
172 else
173 {
174 dtMeshTile const* tile;
175 dtPoly const* poly;
176 if (dtStatusSucceed(navmesh->getTileAndPolyByRef(polyRef, &tile, &poly)))
177 {
178 if (tile)
179 {
180 handler->PSendSysMessage("Dt [{},{}]", tile->header->x, tile->header->y);
181 return false;
182 }
183 }
184
185 handler->PSendSysMessage("Dt [??,??] (no tile loaded)");
186 }
187
188 return true;
189 }
#define SIZE_OF_GRIDS
Definition MapDefines.h:26
#define VERTEX_SIZE
Definition PathGenerator.h:41
#define INVALID_POLYREF
Definition PathGenerator.h:42
Definition Player.h:1081
Definition DetourExtended.h:11
GridCoord ComputeGridCoord(float x, float y)
Definition GridDefines.h:181
Definition GridDefines.h:84
uint32 x_coord
Definition GridDefines.h:151
uint32 y_coord
Definition GridDefines.h:152
float GetPositionX() const
Definition Position.h:121
void GetPosition(float &x, float &y) const
Definition Position.h:126
float GetPositionY() const
Definition Position.h:122

References Acore::ComputeGridCoord(), MMAP::MMapFactory::createOrGetMMapMgr(), WorldObject::GetInstanceId(), WorldLocation::GetMapId(), MMAP::MMapMgr::GetNavMesh(), MMAP::MMapMgr::GetNavMeshQuery(), WorldSession::GetPlayer(), Position::GetPosition(), Position::GetPositionX(), Position::GetPositionY(), ChatHandler::GetSession(), INVALID_POLYREF, ChatHandler::PSendSysMessage(), SIZE_OF_GRIDS, VERTEX_SIZE, CoordPair< LIMIT >::x_coord, and CoordPair< LIMIT >::y_coord.

Referenced by GetCommands().

◆ HandleMmapPathCommand()

static bool mmaps_commandscript::HandleMmapPathCommand ( ChatHandler handler,
Optional< std::string >  param 
)
inlinestatic
63 {
64 if (!MMAP::MMapFactory::createOrGetMMapMgr()->GetNavMesh(handler->GetSession()->GetPlayer()->GetMapId()))
65 {
66 handler->PSendSysMessage("NavMesh not loaded for current map.");
67 return true;
68 }
69
70 handler->PSendSysMessage("mmap path:");
71
72 // units
73 Player* player = handler->GetSession()->GetPlayer();
74 Unit* target = handler->getSelectedUnit();
75 if (!player || !target)
76 {
77 handler->PSendSysMessage("Invalid target/source selection.");
78 return true;
79 }
80
81 bool useStraightPath = false;
82 bool useRaycast = false;
83 if (param)
84 {
85 auto paramValue = param.value();
86 if (paramValue.starts_with("true"))
87 {
88 useStraightPath = true;
89 }
90
91 if (paramValue.starts_with("line") || paramValue.starts_with("ray") || paramValue.starts_with("raycast"))
92 {
93 useRaycast = true;
94 }
95 }
96
97 // unit locations
98 float x, y, z;
99 player->GetPosition(x, y, z);
100
101 // path
102 PathGenerator path(target);
103 path.SetUseStraightPath(useStraightPath);
104 path.SetUseRaycast(useRaycast);
105 bool result = path.CalculatePath(x, y, z, false);
106
107 Movement::PointsArray const& pointPath = path.GetPath();
108 handler->PSendSysMessage("{}'s path to {}:", target->GetName(), player->GetName());
109 handler->PSendSysMessage("Building: {}", useStraightPath ? "StraightPath" : useRaycast ? "Raycast" : "SmoothPath");
110 handler->PSendSysMessage("Result: {} - Length: {} - Type: {}", (result ? "true" : "false"), pointPath.size(), path.GetPathType());
111
112 G3D::Vector3 const& start = path.GetStartPosition();
113 G3D::Vector3 const& end = path.GetEndPosition();
114 G3D::Vector3 const& actualEnd = path.GetActualEndPosition();
115
116 handler->PSendSysMessage("StartPosition ({}, {}, {})", start.x, start.y, start.z);
117 handler->PSendSysMessage("EndPosition ({}, {}, {})", end.x, end.y, end.z);
118 handler->PSendSysMessage("ActualEndPosition ({}, {}, {})", actualEnd.x, actualEnd.y, actualEnd.z);
119
120 if (!player->IsGameMaster())
121 handler->PSendSysMessage("Enable GM mode to see the path points.");
122
123 for (auto i : pointPath)
124 player->SummonCreature(VISUAL_WAYPOINT, i.x, i.y, i.z, 0, TEMPSUMMON_TIMED_DESPAWN, 9000);
125
126 return true;
127 }
#define VISUAL_WAYPOINT
Definition MotionMaster.h:34
@ TEMPSUMMON_TIMED_DESPAWN
Definition Object.h:48
Unit * getSelectedUnit() const
Definition Chat.cpp:386
Definition PathGenerator.h:59
bool IsGameMaster() const
Definition Player.h:1175
Definition Unit.h:636
std::string const & GetName() const
Definition Object.h:463
std::vector< Vector3 > PointsArray
Definition MoveSplineInitArgs.h:28

References PathGenerator::CalculatePath(), MMAP::MMapFactory::createOrGetMMapMgr(), PathGenerator::GetActualEndPosition(), PathGenerator::GetEndPosition(), WorldLocation::GetMapId(), WorldObject::GetName(), PathGenerator::GetPath(), PathGenerator::GetPathType(), WorldSession::GetPlayer(), Position::GetPosition(), ChatHandler::getSelectedUnit(), ChatHandler::GetSession(), PathGenerator::GetStartPosition(), Player::IsGameMaster(), ChatHandler::PSendSysMessage(), PathGenerator::SetUseRaycast(), PathGenerator::SetUseStraightPath(), WorldObject::SummonCreature(), TEMPSUMMON_TIMED_DESPAWN, and VISUAL_WAYPOINT.

Referenced by GetCommands().

◆ HandleMmapStatsCommand()

static bool mmaps_commandscript::HandleMmapStatsCommand ( ChatHandler handler)
inlinestatic
217 {
218 handler->PSendSysMessage("mmap stats:");
219 //handler->PSendSysMessage(" global mmap pathfinding is {}abled", sDisableMgr->IsPathfindingEnabled(mapId) ? "en" : "dis");
221 handler->PSendSysMessage(" {} maps loaded with {} tiles overall", manager->getLoadedMapsCount(), manager->getLoadedTilesCount());
222
223 dtNavMesh const* navmesh = manager->GetNavMesh(handler->GetSession()->GetPlayer()->GetMapId());
224 if (!navmesh)
225 {
226 handler->PSendSysMessage("NavMesh not loaded for current map.");
227 return true;
228 }
229
230 uint32 tileCount = 0;
231 uint32 nodeCount = 0;
232 uint32 polyCount = 0;
233 uint32 vertCount = 0;
234 uint32 triCount = 0;
235 uint32 triVertCount = 0;
236 uint32 dataSize = 0;
237 for (int32 i = 0; i < navmesh->getMaxTiles(); ++i)
238 {
239 dtMeshTile const* tile = navmesh->getTile(i);
240 if (!tile || !tile->header)
241 continue;
242
243 tileCount++;
244 nodeCount += tile->header->bvNodeCount;
245 polyCount += tile->header->polyCount;
246 vertCount += tile->header->vertCount;
247 triCount += tile->header->detailTriCount;
248 triVertCount += tile->header->detailVertCount;
249 dataSize += tile->dataSize;
250 }
251
252 handler->PSendSysMessage("Navmesh stats:");
253 handler->PSendSysMessage(" {} tiles loaded", tileCount);
254 handler->PSendSysMessage(" {} BVTree nodes", nodeCount);
255 handler->PSendSysMessage(" {} polygons ({} vertices)", polyCount, vertCount);
256 handler->PSendSysMessage(" {} triangles ({} vertices)", triCount, triVertCount);
257 handler->PSendSysMessage(" {} MB of data (not including pointers)", ((float)dataSize / sizeof(unsigned char)) / 1048576);
258
259 return true;
260 }
Definition MMapMgr.h:74
uint32 getLoadedTilesCount() const
Definition MMapMgr.h:89
uint32 getLoadedMapsCount() const
Definition MMapMgr.h:90

References MMAP::MMapFactory::createOrGetMMapMgr(), MMAP::MMapMgr::getLoadedMapsCount(), MMAP::MMapMgr::getLoadedTilesCount(), WorldLocation::GetMapId(), MMAP::MMapMgr::GetNavMesh(), WorldSession::GetPlayer(), ChatHandler::GetSession(), and ChatHandler::PSendSysMessage().

Referenced by GetCommands().

◆ HandleMmapTestArea()

static bool mmaps_commandscript::HandleMmapTestArea ( ChatHandler handler)
inlinestatic
263 {
264 float radius = 40.0f;
265 WorldObject* object = handler->GetSession()->GetPlayer();
266
267 // Get Creatures
268 std::list<Creature*> creatureList;
269 Acore::AnyUnitInObjectRangeCheck go_check(object, radius);
270 Acore::CreatureListSearcher<Acore::AnyUnitInObjectRangeCheck> go_search(object, creatureList, go_check);
271 Cell::VisitGridObjects(object, go_search, radius);
272
273 if (!creatureList.empty())
274 {
275 handler->PSendSysMessage("Found {} Creatures.", creatureList.size());
276
277 uint32 paths = 0;
278 uint32 uStartTime = getMSTime();
279
280 float gx, gy, gz;
281 object->GetPosition(gx, gy, gz);
282 for (std::list<Creature*>::iterator itr = creatureList.begin(); itr != creatureList.end(); ++itr)
283 {
284 PathGenerator path(*itr);
285 path.CalculatePath(gx, gy, gz);
286 ++paths;
287 }
288
289 uint32 uPathLoadTime = getMSTimeDiff(uStartTime, getMSTime());
290 handler->PSendSysMessage("Generated {} paths in {} ms", paths, uPathLoadTime);
291 }
292 else
293 handler->PSendSysMessage("No creatures in {} yard range.", radius);
294
295 return true;
296 }
uint32 getMSTime()
Definition Timer.h:103
uint32 getMSTimeDiff(uint32 oldMSTime, uint32 newMSTime)
Definition Timer.h:110
Definition GridNotifiers.h:1036
Definition Object.h:410
Definition GridNotifiers.h:473
static void VisitGridObjects(WorldObject const *obj, T &visitor, float radius)
Definition CellImpl.h:165

References PathGenerator::CalculatePath(), getMSTime(), getMSTimeDiff(), WorldSession::GetPlayer(), ChatHandler::GetSession(), ChatHandler::PSendSysMessage(), and Cell::VisitGridObjects().

Referenced by GetCommands().


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