@@ -69,6 +69,38 @@ export class Pathfinding {
69
69
public constructor ( private actor : Actor ) {
70
70
}
71
71
72
+ public static canMoveNSEW ( destinationAdjacency : number [ ] [ ] , destinationLocalX : number , destinationLocalY : number , i : number ) : boolean {
73
+ return ( destinationAdjacency [ destinationLocalX ] [ destinationLocalY ] & i ) === 0 ;
74
+ }
75
+
76
+ public static canMoveDiagonally ( origin : Position , destinationAdjacency : number [ ] [ ] , destinationLocalX : number , destinationLocalY : number ,
77
+ initialX : number , initialY : number , offsetX : number , offsetY : number , destMask : number , cornerMask1 : number , cornerMask2 : number ) : boolean {
78
+ const cornerX1 : number = initialX + offsetX ;
79
+ const cornerY1 : number = initialY ;
80
+ const cornerX2 : number = initialX ;
81
+ const cornerY2 : number = initialY + offsetY ;
82
+ const corner1 = Pathfinding . calculateLocalCornerPosition ( cornerX1 , cornerY1 , origin ) ;
83
+ const corner2 = Pathfinding . calculateLocalCornerPosition ( cornerX2 , cornerY2 , origin ) ;
84
+
85
+ return ( ( destinationAdjacency [ destinationLocalX ] [ destinationLocalY ] & destMask ) == 0 &&
86
+ ( corner1 . chunk . collisionMap . adjacency [ corner1 . localX ] [ corner1 . localY ] & cornerMask1 ) == 0 &&
87
+ ( corner2 . chunk . collisionMap . adjacency [ corner2 . localX ] [ corner2 . localY ] & cornerMask2 ) == 0 ) ;
88
+ }
89
+
90
+ private static calculateLocalCornerPosition ( cornerX : number , cornerY : number , origin : Position ) : { localX : number , localY : number , chunk : Chunk } {
91
+ const cornerPosition : Position = new Position ( cornerX , cornerY , origin . level + 1 ) ;
92
+ let cornerChunk : Chunk = world . chunkManager . getChunkForWorldPosition ( cornerPosition ) ;
93
+ const tileAbove : Tile = cornerChunk . getTile ( cornerPosition ) ;
94
+ if ( ! tileAbove || ! tileAbove . bridge ) {
95
+ cornerPosition . level = cornerPosition . level - 1 ;
96
+ cornerChunk = world . chunkManager . getChunkForWorldPosition ( cornerPosition ) ;
97
+ }
98
+ const localX : number = cornerX - cornerChunk . collisionMap . insetX ;
99
+ const localY : number = cornerY - cornerChunk . collisionMap . insetY ;
100
+
101
+ return { localX, localY, chunk : cornerChunk } ;
102
+ }
103
+
72
104
public async walkTo ( position : Position , options : PathingOptions ) : Promise < void > {
73
105
if ( ! options . pathingDiameter ) {
74
106
options . pathingDiameter = 16 ;
@@ -141,8 +173,8 @@ export class Pathfinding {
141
173
this . openPoints . splice ( this . openPoints . indexOf ( this . currentPoint ) , 1 ) ;
142
174
this . closedPoints . push ( this . currentPoint ) ;
143
175
144
- let level = this . actor . position . level ;
145
- let { x, y, indexX, indexY } = this . currentPoint ;
176
+ const level = this . actor . position . level ;
177
+ const { x, y, indexX, indexY } = this . currentPoint ;
146
178
let canPath = false ;
147
179
148
180
try {
@@ -404,36 +436,4 @@ export class Pathfinding {
404
436
return true ;
405
437
}
406
438
407
- public static canMoveNSEW ( destinationAdjacency : number [ ] [ ] , destinationLocalX : number , destinationLocalY : number , i : number ) : boolean {
408
- return ( destinationAdjacency [ destinationLocalX ] [ destinationLocalY ] & i ) === 0 ;
409
- }
410
-
411
- public static canMoveDiagonally ( origin : Position , destinationAdjacency : number [ ] [ ] , destinationLocalX : number , destinationLocalY : number ,
412
- initialX : number , initialY : number , offsetX : number , offsetY : number , destMask : number , cornerMask1 : number , cornerMask2 : number ) : boolean {
413
- const cornerX1 : number = initialX + offsetX ;
414
- const cornerY1 : number = initialY ;
415
- const cornerX2 : number = initialX ;
416
- const cornerY2 : number = initialY + offsetY ;
417
- const corner1 = Pathfinding . calculateLocalCornerPosition ( cornerX1 , cornerY1 , origin ) ;
418
- const corner2 = Pathfinding . calculateLocalCornerPosition ( cornerX2 , cornerY2 , origin ) ;
419
-
420
- return ( ( destinationAdjacency [ destinationLocalX ] [ destinationLocalY ] & destMask ) == 0 &&
421
- ( corner1 . chunk . collisionMap . adjacency [ corner1 . localX ] [ corner1 . localY ] & cornerMask1 ) == 0 &&
422
- ( corner2 . chunk . collisionMap . adjacency [ corner2 . localX ] [ corner2 . localY ] & cornerMask2 ) == 0 ) ;
423
- }
424
-
425
- private static calculateLocalCornerPosition ( cornerX : number , cornerY : number , origin : Position ) : { localX : number , localY : number , chunk : Chunk } {
426
- const cornerPosition : Position = new Position ( cornerX , cornerY , origin . level + 1 ) ;
427
- let cornerChunk : Chunk = world . chunkManager . getChunkForWorldPosition ( cornerPosition ) ;
428
- const tileAbove : Tile = cornerChunk . getTile ( cornerPosition ) ;
429
- if ( ! tileAbove || ! tileAbove . bridge ) {
430
- cornerPosition . level = cornerPosition . level - 1 ;
431
- cornerChunk = world . chunkManager . getChunkForWorldPosition ( cornerPosition ) ;
432
- }
433
- const localX : number = cornerX - cornerChunk . collisionMap . insetX ;
434
- const localY : number = cornerY - cornerChunk . collisionMap . insetY ;
435
-
436
- return { localX, localY, chunk : cornerChunk } ;
437
- }
438
-
439
439
}
0 commit comments