static bool LoadedTilesCommand(StringArguments args, CommandHandler handler) { Player player = handler.GetSession().GetPlayer(); uint terrainMapId = PhasingHandler.GetTerrainMapId(player.GetPhaseShift(), player.GetMap(), player.GetPositionX(), player.GetPositionY()); Detour.dtNavMesh navmesh = Global.MMapMgr.GetNavMesh(terrainMapId); Detour.dtNavMeshQuery navmeshquery = Global.MMapMgr.GetNavMeshQuery(terrainMapId, handler.GetPlayer().GetInstanceId()); if (navmesh == null || navmeshquery == null) { handler.SendSysMessage("NavMesh not loaded for current map."); return(true); } handler.SendSysMessage("mmap loadedtiles:"); for (int i = 0; i < navmesh.getMaxTiles(); ++i) { Detour.dtMeshTile tile = navmesh.getTile(i); if (tile.header == null) { continue; } handler.SendSysMessage("[{0:D2}, {1:D2}]", tile.header.x, tile.header.y); } return(true); }
void _setTargetLocation(T owner) { if (owner == null) { return; } if (owner.HasUnitState(UnitState.Root | UnitState.Stunned)) { return; } if (owner.IsMovementPreventedByCasting()) { owner.CastStop(); return; } owner.AddUnitState(UnitState.FleeingMove); float x, y, z; _getPoint(owner, out x, out y, out z); Position mypos = owner.GetPosition(); bool isInLOS = Global.VMapMgr.isInLineOfSight(PhasingHandler.GetTerrainMapId(owner.GetPhaseShift(), owner.GetMap(), mypos.posX, mypos.posY), mypos.posX, mypos.posY, mypos.posZ + 2.0f, x, y, z + 2.0f, ModelIgnoreFlags.Nothing); if (!isInLOS) { i_nextCheckTime.Reset(200); return; } PathGenerator path = new PathGenerator(owner); path.SetPathLengthLimit(30.0f); bool result = path.CalculatePath(x, y, z); if (!result || path.GetPathType().HasAnyFlag(PathType.NoPath)) { i_nextCheckTime.Reset(100); return; } MoveSplineInit init = new MoveSplineInit(owner); init.MovebyPath(path.GetPath()); init.SetWalk(false); int traveltime = init.Launch(); i_nextCheckTime.Reset(traveltime + RandomHelper.URand(800, 1500)); }
void SetTargetLocation(T owner) { if (owner == null) { return; } if (owner.HasUnitState(UnitState.NotMove) || owner.IsMovementPreventedByCasting()) { _interrupt = true; owner.StopMoving(); return; } owner.AddUnitState(UnitState.FleeingMove); Position destination = owner.GetPosition(); GetPoint(owner, ref destination); // Add LOS check for target point Position currentPosition = owner.GetPosition(); bool isInLOS = Global.VMapMgr.IsInLineOfSight(PhasingHandler.GetTerrainMapId(owner.GetPhaseShift(), owner.GetMap(), currentPosition.posX, currentPosition.posY), currentPosition.posX, currentPosition.posY, currentPosition.posZ + 2.0f, destination.GetPositionX(), destination.GetPositionY(), destination.GetPositionZ() + 2.0f, ModelIgnoreFlags.Nothing); if (!isInLOS) { _timer.Reset(200); return; } if (_path == null) { _path = new PathGenerator(owner); } _path.SetPathLengthLimit(30.0f); bool result = _path.CalculatePath(destination.GetPositionX(), destination.GetPositionY(), destination.GetPositionZ()); if (!result || _path.GetPathType().HasAnyFlag(PathType.NoPath)) { _timer.Reset(100); return; } MoveSplineInit init = new(owner); init.MovebyPath(_path.GetPath()); init.SetWalk(false); int traveltime = init.Launch(); _timer.Reset(traveltime + RandomHelper.URand(800, 1500)); }
static bool HandleMmapStatsCommand(StringArguments args, CommandHandler handler) { Player player = handler.GetSession().GetPlayer(); uint terrainMapId = PhasingHandler.GetTerrainMapId(player.GetPhaseShift(), player.GetMap(), player.GetPositionX(), player.GetPositionY()); handler.SendSysMessage("mmap stats:"); handler.SendSysMessage(" global mmap pathfinding is {0}abled", Global.DisableMgr.IsPathfindingEnabled(player.GetMapId()) ? "En" : "Dis"); handler.SendSysMessage(" {0} maps loaded with {1} tiles overall", Global.MMapMgr.getLoadedMapsCount(), Global.MMapMgr.getLoadedTilesCount()); Detour.dtNavMesh navmesh = Global.MMapMgr.GetNavMesh(terrainMapId); if (navmesh == null) { handler.SendSysMessage("NavMesh not loaded for current map."); return(true); } uint tileCount = 0; int nodeCount = 0; int polyCount = 0; int vertCount = 0; int triCount = 0; int triVertCount = 0; for (int i = 0; i < navmesh.getMaxTiles(); ++i) { Detour.dtMeshTile tile = navmesh.getTile(i); if (tile == null) { continue; } tileCount++; nodeCount += tile.header.bvNodeCount; polyCount += tile.header.polyCount; vertCount += tile.header.vertCount; triCount += tile.header.detailTriCount; triVertCount += tile.header.detailVertCount; } handler.SendSysMessage("Navmesh stats:"); handler.SendSysMessage(" {0} tiles loaded", tileCount); handler.SendSysMessage(" {0} BVTree nodes", nodeCount); handler.SendSysMessage(" {0} polygons ({1} vertices)", polyCount, vertCount); handler.SendSysMessage(" {0} triangles ({1} vertices)", triCount, triVertCount); return(true); }
public PathGenerator(Unit owner) { _polyLength = 0; pathType = PathType.Blank; _useStraightPath = false; _forceDestination = false; _pointPathLimit = 74; _endPosition = Vector3.Zero; _sourceUnit = owner; _navMesh = null; _navMeshQuery = null; Log.outDebug(LogFilter.Maps, "PathGenerator:PathGenerator for {0}", _sourceUnit.GetGUID().ToString()); uint mapId = PhasingHandler.GetTerrainMapId(_sourceUnit.GetPhaseShift(), _sourceUnit.GetMap(), _sourceUnit.GetPositionX(), _sourceUnit.GetPositionY()); if (Global.DisableMgr.IsPathfindingEnabled(_sourceUnit.GetMapId())) { _navMesh = Global.MMapMgr.GetNavMesh(mapId); _navMeshQuery = Global.MMapMgr.GetNavMeshQuery(mapId, _sourceUnit.GetInstanceId()); } CreateFilter(); }
static bool LocCommand(StringArguments args, CommandHandler handler) { handler.SendSysMessage("mmap tileloc:"); // grid tile location Player player = handler.GetPlayer(); int gx = (int)(32 - player.GetPositionX() / MapConst.SizeofGrids); int gy = (int)(32 - player.GetPositionY() / MapConst.SizeofGrids); float x, y, z; player.GetPosition(out x, out y, out z); handler.SendSysMessage("{0:D4}{1:D2}{2:D2}.mmtile", player.GetMapId(), gy, gx); handler.SendSysMessage("gridloc [{0}, {1}]", gx, gy); // calculate navmesh tile location uint terrainMapId = PhasingHandler.GetTerrainMapId(player.GetPhaseShift(), player.GetMap(), x, y); Detour.dtNavMesh navmesh = Global.MMapMgr.GetNavMesh(terrainMapId); Detour.dtNavMeshQuery navmeshquery = Global.MMapMgr.GetNavMeshQuery(terrainMapId, player.GetInstanceId()); if (navmesh == null || navmeshquery == null) { handler.SendSysMessage("NavMesh not loaded for current map."); return(true); } float[] min = navmesh.getParams().orig; float[] location = { y, z, x }; float[] extents = { 3.0f, 5.0f, 3.0f }; int tilex = (int)((y - min[0]) / MapConst.SizeofGrids); int tiley = (int)((x - min[2]) / MapConst.SizeofGrids); handler.SendSysMessage("Calc [{0:D2}, {1:D2}]", tilex, tiley); // navmesh poly . navmesh tile location Detour.dtQueryFilter filter = new Detour.dtQueryFilter(); float[] nothing = new float[3]; ulong polyRef = 0; if (Detour.dtStatusFailed(navmeshquery.findNearestPoly(location, extents, filter, ref polyRef, ref nothing))) { handler.SendSysMessage("Dt [??,??] (invalid poly, probably no tile loaded)"); return(true); } if (polyRef == 0) { handler.SendSysMessage("Dt [??, ??] (invalid poly, probably no tile loaded)"); } else { Detour.dtMeshTile tile = new Detour.dtMeshTile(); Detour.dtPoly poly = new Detour.dtPoly(); if (Detour.dtStatusSucceed(navmesh.getTileAndPolyByRef(polyRef, ref tile, ref poly))) { if (tile != null) { handler.SendSysMessage("Dt [{0:D2},{1:D2}]", tile.header.x, tile.header.y); return(false); } } handler.SendSysMessage("Dt [??,??] (no tile loaded)"); } return(true); }