@@ -13,7 +13,8 @@ import { world } from '@engine/game-server';
13
13
import { WorldInstance } from '@engine/world/instances' ;
14
14
import { Player } from '@engine/world/actor/player/player' ;
15
15
import { ActionCancelType , ActionPipeline } from '@engine/world/action' ;
16
- import { LocationObject } from '@runejs/cache-parser' ;
16
+ import { LandscapeObject } from '@runejs/filestore' ;
17
+
17
18
18
19
/**
19
20
* Handles an actor within the game world.
@@ -84,20 +85,20 @@ export abstract class Actor {
84
85
* The promise will be rejected if the actor's walking queue changes or their movement is otherwise canceled.
85
86
* @param gameObject The game object to wait for the actor to reach.
86
87
*/
87
- public async waitForPathing ( gameObject : LocationObject ) : Promise < void > ;
88
+ public async waitForPathing ( gameObject : LandscapeObject ) : Promise < void > ;
88
89
89
90
/**
90
91
* Waits for the actor to reach the specified game object before resolving it's promise.
91
92
* The promise will be rejected if the actor's walking queue changes or their movement is otherwise canceled.
92
93
* @param target The position or game object that the actor needs to reach for the promise to resolve.
93
94
*/
94
- public async waitForPathing ( target : Position | LocationObject ) : Promise < void > ;
95
- public async waitForPathing ( target : Position | LocationObject ) : Promise < void > {
95
+ public async waitForPathing ( target : Position | LandscapeObject ) : Promise < void > ;
96
+ public async waitForPathing ( target : Position | LandscapeObject ) : Promise < void > {
96
97
if ( this . position . withinInteractionDistance ( target ) ) {
97
98
return ;
98
99
}
99
100
100
- await new Promise ( ( resolve , reject ) => {
101
+ await new Promise < void > ( ( resolve , reject ) => {
101
102
this . metadata . walkingTo = target instanceof Position ? target : new Position ( target . x , target . y , target . level ) ;
102
103
103
104
const inter = setInterval ( ( ) => {
@@ -130,6 +131,10 @@ export abstract class Actor {
130
131
}
131
132
132
133
public async moveBehind ( target : Actor ) : Promise < boolean > {
134
+ if ( this . position . level !== target . position . level ) {
135
+ return false ;
136
+ }
137
+
133
138
const distance = Math . floor ( this . position . distanceBetween ( target . position ) ) ;
134
139
if ( distance > 16 ) {
135
140
this . clearFaceActor ( ) ;
@@ -152,6 +157,10 @@ export abstract class Actor {
152
157
}
153
158
154
159
public async moveTo ( target : Actor ) : Promise < boolean > {
160
+ if ( this . position . level !== target . position . level ) {
161
+ return false ;
162
+ }
163
+
155
164
const distance = Math . floor ( this . position . distanceBetween ( target . position ) ) ;
156
165
if ( distance > 16 ) {
157
166
this . clearFaceActor ( ) ;
@@ -171,7 +180,11 @@ export abstract class Actor {
171
180
this . metadata [ 'following' ] = target ;
172
181
173
182
this . moveBehind ( target ) ;
174
- const subscription = target . walkingQueue . movementEvent . subscribe ( async ( ) => this . moveBehind ( target ) ) ;
183
+ const subscription = target . walkingQueue . movementEvent . subscribe ( async ( ) => {
184
+ if ( ! this . moveBehind ( target ) ) {
185
+ this . actionsCancelled . next ( null ) ;
186
+ }
187
+ } ) ;
175
188
176
189
this . actionsCancelled . pipe (
177
190
filter ( type => type !== 'pathing-movement' ) ,
0 commit comments