local PathSystem = {} local pathResult = {} local FP=FP local BattleExt=BattleExt local ipairs=ipairs --[[ 寻路 --]] function PathSystem.FindPath(entity, endPos, needSmooth, priorityWall) local pathComponent = entity.components.path local startPos = entity.components.move.LogicPos local startX,startZ = LuaShoveManager.ConvertPosToGrid(startPos) local endX,endZ = LuaShoveManager.ConvertPosToGrid(endPos) pathComponent.CurFindPathCount = pathComponent.CurFindPathCount + 1 local limitByBorder = true local pathList = pathComponent.Path for i, pos in ipairs(pathList) do FP.releaseV2(pos) pathList[i] = nil end if pathComponent.TargetPos then FP.releaseV2(pathComponent.TargetPos) end pathComponent.TargetPos = endPos:cloneV2() pathComponent.CurPathPosIndex = 1 local count = BattleExt.GridFindPath(startX, startZ, endX, endZ, entity._logicInitData.EntityID, pathComponent.CurFindPathCount, limitByBorder, needSmooth, not priorityWall, pathResult) for i = 1, count do local x, z = pathResult[i * 2 - 1], pathResult[i * 2] pathList[i] = LuaShoveManager.GetPosByGrid(x, z) end end --[[ 寻路 (给-表现寻路path2 赋值) --]] function PathSystem.FindPath2(entity, endPos, needSmooth, priorityWall) local pathComponent = entity.components.path local startPos = entity.components.move.LogicPos local startX,startZ = LuaShoveManager.ConvertPosToGrid(startPos) local endX,endZ = LuaShoveManager.ConvertPosToGrid(endPos) pathComponent.CurFindPathCount = pathComponent.CurFindPathCount + 1 local limitByBorder = true local pathList = pathComponent.Path2 for i, pos in ipairs(pathList) do FP.releaseV2(pos) pathList[i] = nil end local count = BattleExt.GridFindPath(startX, startZ, endX, endZ, entity._logicInitData.EntityID, pathComponent.CurFindPathCount, limitByBorder, needSmooth, not priorityWall, pathResult) for i = 1, count do local x, z = pathResult[i * 2 - 1], pathResult[i * 2] pathList[i] = LuaShoveManager.GetPosByGrid(x, z) end end return PathSystem