Core/Pathfinding: Allow using PathGenerator with any source location, not only objects current position
Port From (https://github.com/TrinityCore/TrinityCore/commit/e5beb25d2529cee9f7d83f227b06ce3d47f6d2c2)
This commit is contained in:
@@ -18,13 +18,14 @@ namespace Game.Movement
|
|||||||
_useStraightPath = false;
|
_useStraightPath = false;
|
||||||
_forceDestination = false;
|
_forceDestination = false;
|
||||||
_pointPathLimit = 74;
|
_pointPathLimit = 74;
|
||||||
|
_startPosition = owner;
|
||||||
_endPosition = Vector3.Zero;
|
_endPosition = Vector3.Zero;
|
||||||
_source = owner;
|
_source = owner;
|
||||||
_navMesh = null;
|
_navMesh = null;
|
||||||
_navMeshQuery = null;
|
_navMeshQuery = null;
|
||||||
Log.outDebug(LogFilter.Maps, "PathGenerator:PathGenerator for {0}", _source.GetGUID().ToString());
|
Log.outDebug(LogFilter.Maps, "PathGenerator:PathGenerator for {0}", _source.GetGUID().ToString());
|
||||||
|
|
||||||
uint mapId = PhasingHandler.GetTerrainMapId(_source.GetPhaseShift(), _source.GetMapId(), _source.GetMap().GetTerrain(), _source.GetPositionX(), _source.GetPositionY());
|
uint mapId = PhasingHandler.GetTerrainMapId(_source.GetPhaseShift(), _source.GetMapId(), _source.GetMap().GetTerrain(), _startPosition.X, _startPosition.Y);
|
||||||
if (Global.DisableMgr.IsPathfindingEnabled(_source.GetMapId()))
|
if (Global.DisableMgr.IsPathfindingEnabled(_source.GetMapId()))
|
||||||
{
|
{
|
||||||
_navMeshQuery = Global.MMapMgr.GetNavMeshQuery(mapId, _source.GetMapId(), _source.GetInstanceId());
|
_navMeshQuery = Global.MMapMgr.GetNavMeshQuery(mapId, _source.GetMapId(), _source.GetInstanceId());
|
||||||
@@ -33,18 +34,15 @@ namespace Game.Movement
|
|||||||
CreateFilter();
|
CreateFilter();
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool CalculatePath(float destX, float destY, float destZ, bool forceDest = false)
|
public bool CalculatePath(float srcX, float srcY, float srcZ, float destX, float destY, float destZ, bool forceDest = false)
|
||||||
{
|
{
|
||||||
float x, y, z;
|
if (!GridDefines.IsValidMapCoord(destX, destY, destZ) || !GridDefines.IsValidMapCoord(srcX, srcY, srcZ))
|
||||||
_source.GetPosition(out x, out y, out z);
|
|
||||||
|
|
||||||
if (!GridDefines.IsValidMapCoord(destX, destY, destZ) || !GridDefines.IsValidMapCoord(x, y, z))
|
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
Vector3 dest = new(destX, destY, destZ);
|
Vector3 dest = new(destX, destY, destZ);
|
||||||
SetEndPosition(dest);
|
SetEndPosition(dest);
|
||||||
|
|
||||||
Vector3 start = new(x, y, z);
|
Vector3 start = new(srcX, srcY, srcZ);
|
||||||
SetStartPosition(start);
|
SetStartPosition(start);
|
||||||
|
|
||||||
_forceDestination = forceDest;
|
_forceDestination = forceDest;
|
||||||
@@ -67,6 +65,12 @@ namespace Game.Movement
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool CalculatePath(float destX, float destY, float destZ, bool forceDest)
|
||||||
|
{
|
||||||
|
_source.GetPosition(out float x, out float y, out float z);
|
||||||
|
return CalculatePath(x, y, z, destX, destY, destZ, forceDest);
|
||||||
|
}
|
||||||
|
|
||||||
ulong GetPathPolyByPosition(ulong[] polyPath, uint polyPathSize, float[] point, ref float distance)
|
ulong GetPathPolyByPosition(ulong[] polyPath, uint polyPathSize, float[] point, ref float distance)
|
||||||
{
|
{
|
||||||
if (polyPath == null || polyPathSize == 0)
|
if (polyPath == null || polyPathSize == 0)
|
||||||
@@ -879,7 +883,7 @@ namespace Game.Movement
|
|||||||
if (_sourceUnit.IsInWater() || _sourceUnit.IsUnderWater())
|
if (_sourceUnit.IsInWater() || _sourceUnit.IsUnderWater())
|
||||||
{
|
{
|
||||||
NavTerrainFlag includedFlags = (NavTerrainFlag)_filter.getIncludeFlags();
|
NavTerrainFlag includedFlags = (NavTerrainFlag)_filter.getIncludeFlags();
|
||||||
includedFlags |= GetNavTerrain(_source.GetPositionX(), _source.GetPositionY(), _source.GetPositionZ());
|
includedFlags |= GetNavTerrain(_startPosition.X, _startPosition.Y, _startPosition.Z);
|
||||||
|
|
||||||
_filter.setIncludeFlags((ushort)includedFlags);
|
_filter.setIncludeFlags((ushort)includedFlags);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user