mirror of
				https://github.com/unanmed/HumanBreak.git
				synced 2025-11-01 04:42:58 +08:00 
			
		
		
		
	fix: 循环式地图的自动寻路
This commit is contained in:
		
							parent
							
								
									0039c0d65b
								
							
						
					
					
						commit
						6e562627d1
					
				| @ -644,9 +644,17 @@ actions.prototype._sys_ondown = function (x, y, px, py) { | |||||||
|     core.status.downTime = new Date(); |     core.status.downTime = new Date(); | ||||||
|     core.deleteCanvas('route'); |     core.deleteCanvas('route'); | ||||||
|     var pos = { |     var pos = { | ||||||
|         x: parseInt((px + core.bigmap.offsetX) / 32), |         x: Math.floor((px + core.bigmap.offsetX) / 32), | ||||||
|         y: parseInt((py + core.bigmap.offsetY) / 32) |         y: Math.floor((py + core.bigmap.offsetY) / 32) | ||||||
|     }; |     }; | ||||||
|  | 
 | ||||||
|  |     const loopMaps = Mota.require('module', 'Mechanism').MiscData.loopMaps; | ||||||
|  |     if (loopMaps.has(core.status.floorId)) { | ||||||
|  |         const floor = core.status.thisMap; | ||||||
|  |         if (pos.x < 0) pos.x += floor.width; | ||||||
|  |         if (pos.x >= floor.width) pos.x -= floor.width; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|     core.status.stepPostfix = []; |     core.status.stepPostfix = []; | ||||||
|     core.status.stepPostfix.push(pos); |     core.status.stepPostfix.push(pos); | ||||||
|     core.fillRect( |     core.fillRect( | ||||||
|  | |||||||
| @ -806,6 +806,8 @@ maps.prototype.generateMovableArray = function (floorId) { | |||||||
|     for (var x = 0; x < width; ++x) { |     for (var x = 0; x < width; ++x) { | ||||||
|         array[x] = Array(height).fill([]); |         array[x] = Array(height).fill([]); | ||||||
|     } |     } | ||||||
|  |     const loopMaps = Mota.require('module', 'Mechanism').MiscData.loopMaps; | ||||||
|  |     const isLoop = loopMaps.has(floorId); | ||||||
|     var v2 = floorId == core.status.floorId && core.bigmap.v2; |     var v2 = floorId == core.status.floorId && core.bigmap.v2; | ||||||
|     var startX = v2 ? Math.max(0, core.bigmap.posX - core.bigmap.extend) : 0; |     var startX = v2 ? Math.max(0, core.bigmap.posX - core.bigmap.extend) : 0; | ||||||
|     var endX = v2 |     var endX = v2 | ||||||
| @ -822,6 +824,11 @@ maps.prototype.generateMovableArray = function (floorId) { | |||||||
|           ) |           ) | ||||||
|         : height; |         : height; | ||||||
| 
 | 
 | ||||||
|  |     if (isLoop) { | ||||||
|  |         startX = 0; | ||||||
|  |         endX = core.status.maps[floorId].width; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|     for (var x = startX; x < endX; x++) { |     for (var x = startX; x < endX; x++) { | ||||||
|         for (var y = startY; y < endY; y++) { |         for (var y = startY; y < endY; y++) { | ||||||
|             array[x][y] = ['left', 'down', 'up', 'right'].filter(function ( |             array[x][y] = ['left', 'down', 'up', 'right'].filter(function ( | ||||||
| @ -875,6 +882,12 @@ maps.prototype._canMoveHero_checkPoint = function ( | |||||||
| 
 | 
 | ||||||
|     var nx = x + core.utils.scan[direction].x, |     var nx = x + core.utils.scan[direction].x, | ||||||
|         ny = y + core.utils.scan[direction].y; |         ny = y + core.utils.scan[direction].y; | ||||||
|  | 
 | ||||||
|  |     const loopMaps = Mota.require('module', 'Mechanism').MiscData.loopMaps; | ||||||
|  |     if (loopMaps.has(floorId)) { | ||||||
|  |         if (nx < 0) nx = floor.width - 1; | ||||||
|  |         if (nx >= floor.width) nx = 0; | ||||||
|  |     } | ||||||
|     if ( |     if ( | ||||||
|         nx < 0 || |         nx < 0 || | ||||||
|         ny < 0 || |         ny < 0 || | ||||||
| @ -1110,6 +1123,9 @@ maps.prototype.automaticRoute = function (destX, destY) { | |||||||
|     // BFS找寻最短路径
 |     // BFS找寻最短路径
 | ||||||
|     var route = this._automaticRoute_bfs(startX, startY, destX, destY); |     var route = this._automaticRoute_bfs(startX, startY, destX, destY); | ||||||
|     if (route[destX + ',' + destY] == null) return []; |     if (route[destX + ',' + destY] == null) return []; | ||||||
|  |     const floor = core.status.thisMap; | ||||||
|  |     const loopMaps = Mota.require('module', 'Mechanism').MiscData.loopMaps; | ||||||
|  | 
 | ||||||
|     // 路径数组转换
 |     // 路径数组转换
 | ||||||
|     var ans = [], |     var ans = [], | ||||||
|         nowX = destX, |         nowX = destX, | ||||||
| @ -1119,6 +1135,10 @@ maps.prototype.automaticRoute = function (destX, destY) { | |||||||
|         ans.push({ direction: dir, x: nowX, y: nowY }); |         ans.push({ direction: dir, x: nowX, y: nowY }); | ||||||
|         nowX -= core.utils.scan[dir].x; |         nowX -= core.utils.scan[dir].x; | ||||||
|         nowY -= core.utils.scan[dir].y; |         nowY -= core.utils.scan[dir].y; | ||||||
|  |         if (loopMaps.has(core.status.floorId)) { | ||||||
|  |             if (nowX < 0) nowX += floor.width; | ||||||
|  |             if (nowX >= floor.width) nowX -= floor.width; | ||||||
|  |         } | ||||||
|     } |     } | ||||||
|     ans.reverse(); |     ans.reverse(); | ||||||
|     return ans; |     return ans; | ||||||
| @ -1136,6 +1156,9 @@ maps.prototype._automaticRoute_bfs = function (startX, startY, destX, destY) { | |||||||
|     route[startX + ',' + startY] = ''; |     route[startX + ',' + startY] = ''; | ||||||
|     queue.queue({ depth: 0, x: startX, y: startY }); |     queue.queue({ depth: 0, x: startX, y: startY }); | ||||||
|     var blocks = core.getMapBlocksObj(); |     var blocks = core.getMapBlocksObj(); | ||||||
|  |     const floor = core.status.thisMap; | ||||||
|  |     const loopMaps = Mota.require('module', 'Mechanism').MiscData.loopMaps; | ||||||
|  | 
 | ||||||
|     while (queue.length != 0) { |     while (queue.length != 0) { | ||||||
|         var curr = queue.dequeue(), |         var curr = queue.dequeue(), | ||||||
|             deep = curr.depth, |             deep = curr.depth, | ||||||
| @ -1145,6 +1168,13 @@ maps.prototype._automaticRoute_bfs = function (startX, startY, destX, destY) { | |||||||
|             if (!core.inArray(canMoveArray[nowX][nowY], direction)) continue; |             if (!core.inArray(canMoveArray[nowX][nowY], direction)) continue; | ||||||
|             var nx = nowX + core.utils.scan[direction].x; |             var nx = nowX + core.utils.scan[direction].x; | ||||||
|             var ny = nowY + core.utils.scan[direction].y; |             var ny = nowY + core.utils.scan[direction].y; | ||||||
|  |             if (loopMaps.has(core.status.floorId)) { | ||||||
|  |                 if (nx < 0) nx = floor.width - 1; | ||||||
|  |                 if (nx >= floor.width) nx = 0; | ||||||
|  |                 if (route[nx + ',' + ny] || ny < 0 || ny >= floor.height) { | ||||||
|  |                     continue; | ||||||
|  |                 } | ||||||
|  |             } else { | ||||||
|                 if ( |                 if ( | ||||||
|                     nx < 0 || |                     nx < 0 || | ||||||
|                     nx >= core.bigmap.width || |                     nx >= core.bigmap.width || | ||||||
| @ -1153,6 +1183,7 @@ maps.prototype._automaticRoute_bfs = function (startX, startY, destX, destY) { | |||||||
|                     route[nx + ',' + ny] != null |                     route[nx + ',' + ny] != null | ||||||
|                 ) |                 ) | ||||||
|                     continue; |                     continue; | ||||||
|  |             } | ||||||
|             // 重点
 |             // 重点
 | ||||||
|             if (nx == destX && ny == destY) { |             if (nx == destX && ny == destY) { | ||||||
|                 route[nx + ',' + ny] = direction; |                 route[nx + ',' + ny] = direction; | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user