@@ -2,8 +2,6 @@ import { Actor } from './actor';
2
2
import { Position } from '../position' ;
3
3
import { Player } from './player/player' ;
4
4
import { world } from '@server/game-server' ;
5
- import { Chunk } from '../map/chunk' ;
6
- import { Tile } from '@runejs/cache-parser' ;
7
5
import { Npc } from './npc/npc' ;
8
6
9
7
/**
@@ -59,7 +57,7 @@ export class WalkingQueue {
59
57
60
58
const newPosition = new Position ( lastX , lastY , this . actor . position . level ) ;
61
59
62
- if ( this . canMoveTo ( lastPosition , newPosition ) ) {
60
+ if ( this . actor . pathfinding . canMoveTo ( lastPosition , newPosition ) ) {
63
61
lastPosition = newPosition ;
64
62
newPosition . metadata = positionMetadata ;
65
63
this . queue . push ( newPosition ) ;
@@ -72,7 +70,7 @@ export class WalkingQueue {
72
70
if ( lastX !== x || lastY !== y && this . valid ) {
73
71
const newPosition = new Position ( x , y , this . actor . position . level ) ;
74
72
75
- if ( this . canMoveTo ( lastPosition , newPosition ) ) {
73
+ if ( this . actor . pathfinding . canMoveTo ( lastPosition , newPosition ) ) {
76
74
newPosition . metadata = positionMetadata ;
77
75
this . queue . push ( newPosition ) ;
78
76
} else {
@@ -85,7 +83,7 @@ export class WalkingQueue {
85
83
const position = this . actor . position ;
86
84
const newPosition = new Position ( position . x + xDiff , position . y + yDiff , position . level ) ;
87
85
88
- if ( this . canMoveTo ( position , newPosition ) ) {
86
+ if ( this . actor . pathfinding . canMoveTo ( position , newPosition ) ) {
89
87
this . clear ( ) ;
90
88
this . valid = true ;
91
89
this . add ( newPosition . x , newPosition . y , { ignoreWidgets : true } ) ;
@@ -95,134 +93,6 @@ export class WalkingQueue {
95
93
return false ;
96
94
}
97
95
98
- public canMoveTo ( origin : Position , destination : Position ) : boolean {
99
- let destinationChunk : Chunk = world . chunkManager . getChunkForWorldPosition ( destination ) ;
100
- const positionAbove : Position = new Position ( destination . x , destination . y , destination . level + 1 ) ;
101
- const chunkAbove : Chunk = world . chunkManager . getChunkForWorldPosition ( positionAbove ) ;
102
- let tile : Tile = chunkAbove . getTile ( positionAbove ) ;
103
-
104
- if ( ! tile || ! tile . bridge ) {
105
- tile = destinationChunk . getTile ( destination ) ;
106
- } else {
107
- // Destination is a bridge, so we need to check the chunk above to get the bridge tiles instead of the level we're currently on
108
- destinationChunk = chunkAbove ;
109
- }
110
-
111
- if ( tile ) {
112
- if ( tile . nonWalkable ) {
113
- return false ;
114
- }
115
- }
116
-
117
- const initialX : number = origin . x ;
118
- const initialY : number = origin . y ;
119
- const destinationAdjacency : number [ ] [ ] = destinationChunk . collisionMap . adjacency ;
120
- const destinationLocalX : number = destination . x - destinationChunk . collisionMap . insetX ;
121
- const destinationLocalY : number = destination . y - destinationChunk . collisionMap . insetY ;
122
-
123
- // @TODO check objects moving from bridge tile to non bridge tile
124
- // ^ currently possible to clip through some bridge walls thanks to this issue
125
- // not the most important thing since you still can't walk on water or anything
126
-
127
- // West
128
- if ( destination . x < initialX && destination . y == initialY ) {
129
- if ( ( destinationAdjacency [ destinationLocalX ] [ destinationLocalY ] & 0x1280108 ) != 0 ) {
130
- // logger.warn(`${this.actor instanceof Player ? this.actor.username + ' c' : 'C'}an not move west.`);
131
- return false ;
132
- }
133
- }
134
-
135
- // East
136
- if ( destination . x > initialX && destination . y == initialY ) {
137
- if ( ( destinationAdjacency [ destinationLocalX ] [ destinationLocalY ] & 0x1280180 ) != 0 ) {
138
- // logger.warn(`${this.actor instanceof Player ? this.actor.username + ' c' : 'C'}an not move east.`);
139
- return false ;
140
- }
141
- }
142
-
143
- // South
144
- if ( destination . y < initialY && destination . x == initialX ) {
145
- if ( ( destinationAdjacency [ destinationLocalX ] [ destinationLocalY ] & 0x1280102 ) != 0 ) {
146
- // logger.warn(`${this.actor instanceof Player ? this.actor.username + ' c' : 'C'}an not move south.`);
147
- return false ;
148
- }
149
- }
150
-
151
- // North
152
- if ( destination . y > initialY && destination . x == initialX ) {
153
- if ( ( destinationAdjacency [ destinationLocalX ] [ destinationLocalY ] & 0x1280120 ) != 0 ) {
154
- // logger.warn(`${this.actor instanceof Player ? this.actor.username + ' c' : 'C'}an not move north.`);
155
- return false ;
156
- }
157
- }
158
-
159
- // South-West
160
- if ( destination . x < initialX && destination . y < initialY ) {
161
- if ( ! this . canMoveDiagonally ( origin , destinationAdjacency , destinationLocalX , destinationLocalY , initialX , initialY , - 1 , - 1 ,
162
- 0x128010e , 0x1280108 , 0x1280102 ) ) {
163
- // logger.warn(`${this.actor instanceof Player ? this.actor.username + ' c' : 'C'}an not move south-west.`);
164
- return false ;
165
- }
166
- }
167
-
168
- // South-East
169
- if ( destination . x > initialX && destination . y < initialY ) {
170
- if ( ! this . canMoveDiagonally ( origin , destinationAdjacency , destinationLocalX , destinationLocalY , initialX , initialY , 1 , - 1 ,
171
- 0x1280183 , 0x1280180 , 0x1280102 ) ) {
172
- // logger.warn(`${this.actor instanceof Player ? this.actor.username + ' c' : 'C'}an not move south-east.`);
173
- return false ;
174
- }
175
- }
176
-
177
- // North-West
178
- if ( destination . x < initialX && destination . y > initialY ) {
179
- if ( ! this . canMoveDiagonally ( origin , destinationAdjacency , destinationLocalX , destinationLocalY , initialX , initialY , - 1 , 1 ,
180
- 0x1280138 , 0x1280108 , 0x1280120 ) ) {
181
- // logger.warn(`${this.actor instanceof Player ? this.actor.username + ' c' : 'C'}an not move north-west.`);
182
- return false ;
183
- }
184
- }
185
-
186
- // North-East
187
- if ( destination . x > initialX && destination . y > initialY ) {
188
- if ( ! this . canMoveDiagonally ( origin , destinationAdjacency , destinationLocalX , destinationLocalY , initialX , initialY , 1 , 1 ,
189
- 0x12801e0 , 0x1280180 , 0x1280120 ) ) {
190
- // logger.warn(`${this.actor instanceof Player ? this.actor.username + ' c' : 'C'}an not move north-east.`);
191
- return false ;
192
- }
193
- }
194
-
195
- return true ;
196
- }
197
-
198
- private canMoveDiagonally ( origin : Position , destinationAdjacency : number [ ] [ ] , destinationLocalX : number , destinationLocalY : number ,
199
- initialX : number , initialY : number , offsetX : number , offsetY : number , destMask : number , cornerMask1 : number , cornerMask2 : number ) : boolean {
200
- const cornerX1 : number = initialX + offsetX ;
201
- const cornerY1 : number = initialY ;
202
- const cornerX2 : number = initialX ;
203
- const cornerY2 : number = initialY + offsetY ;
204
- const corner1 = this . calculateLocalCornerPosition ( cornerX1 , cornerY1 , origin ) ;
205
- const corner2 = this . calculateLocalCornerPosition ( cornerX2 , cornerY2 , origin ) ;
206
-
207
- return ( ( destinationAdjacency [ destinationLocalX ] [ destinationLocalY ] & destMask ) == 0 &&
208
- ( corner1 . chunk . collisionMap . adjacency [ corner1 . localX ] [ corner1 . localY ] & cornerMask1 ) == 0 &&
209
- ( corner2 . chunk . collisionMap . adjacency [ corner2 . localX ] [ corner2 . localY ] & cornerMask2 ) == 0 ) ;
210
- }
211
-
212
- private calculateLocalCornerPosition ( cornerX : number , cornerY : number , origin : Position ) : { localX : number , localY : number , chunk : Chunk } {
213
- const cornerPosition : Position = new Position ( cornerX , cornerY , origin . level + 1 ) ;
214
- let cornerChunk : Chunk = world . chunkManager . getChunkForWorldPosition ( cornerPosition ) ;
215
- const tileAbove : Tile = cornerChunk . getTile ( cornerPosition ) ;
216
- if ( ! tileAbove || ! tileAbove . bridge ) {
217
- cornerPosition . level = cornerPosition . level - 1 ;
218
- cornerChunk = world . chunkManager . getChunkForWorldPosition ( cornerPosition ) ;
219
- }
220
- const localX : number = cornerX - cornerChunk . collisionMap . insetX ;
221
- const localY : number = cornerY - cornerChunk . collisionMap . insetY ;
222
-
223
- return { localX, localY, chunk : cornerChunk } ;
224
- }
225
-
226
96
public resetDirections ( ) : void {
227
97
this . actor . walkDirection = - 1 ;
228
98
this . actor . runDirection = - 1 ;
@@ -286,7 +156,7 @@ export class WalkingQueue {
286
156
287
157
const currentPosition = this . actor . position ;
288
158
289
- if ( this . canMoveTo ( currentPosition , walkPosition ) ) {
159
+ if ( this . actor . pathfinding . canMoveTo ( currentPosition , walkPosition ) ) {
290
160
const oldChunk = world . chunkManager . getChunkForWorldPosition ( currentPosition ) ;
291
161
const lastMapRegionUpdatePosition = this . actor . lastMapRegionUpdatePosition ;
292
162
@@ -308,7 +178,7 @@ export class WalkingQueue {
308
178
if ( this . actor . settings . runEnabled && this . queue . length !== 0 ) {
309
179
const runPosition = this . queue . shift ( ) ;
310
180
311
- if ( this . canMoveTo ( walkPosition , runPosition ) ) {
181
+ if ( this . actor . pathfinding . canMoveTo ( walkPosition , runPosition ) ) {
312
182
const runDiffX = runPosition . x - walkPosition . x ;
313
183
const runDiffY = runPosition . y - walkPosition . y ;
314
184
runDir = this . calculateDirection ( runDiffX , runDiffY ) ;
0 commit comments