1
+ import { LandscapeObject } from '@runejs/filestore' ;
1
2
import { activeWorld , Position } from '@engine/world' ;
2
3
import { Actor } from '@engine/world/actor' ;
3
- import { LandscapeObject } from '@runejs/filestore' ;
4
4
import { ActorWalkToTask } from './actor-walk-to-task' ;
5
5
6
6
/**
@@ -11,8 +11,9 @@ import { ActorWalkToTask } from './actor-walk-to-task';
11
11
*
12
12
* @author jameskmonger
13
13
*/
14
- export abstract class ActorLandscapeObjectInteractionTask < TActor extends Actor = Actor > extends ActorWalkToTask < TActor > {
14
+ export abstract class ActorLandscapeObjectInteractionTask < TActor extends Actor = Actor > extends ActorWalkToTask < TActor , LandscapeObject > {
15
15
private _landscapeObject : LandscapeObject ;
16
+ private _objectPosition : Position ;
16
17
17
18
/**
18
19
* Gets the {@link LandscapeObject} that this task is interacting with.
@@ -37,6 +38,19 @@ export abstract class ActorLandscapeObjectInteractionTask<TActor extends Actor =
37
38
return this . _landscapeObject ;
38
39
}
39
40
41
+ /**
42
+ * Get the position of this task's landscape object
43
+ *
44
+ * @returns The position of this task's landscape object, or null if the landscape object is not present
45
+ */
46
+ protected get landscapeObjectPosition ( ) : Position {
47
+ if ( ! this . _landscapeObject ) {
48
+ return null ;
49
+ }
50
+
51
+ return this . _objectPosition ;
52
+ }
53
+
40
54
/**
41
55
* @param actor The actor executing this task.
42
56
* @param landscapeObject The landscape object to interact with.
@@ -51,7 +65,7 @@ export abstract class ActorLandscapeObjectInteractionTask<TActor extends Actor =
51
65
) {
52
66
super (
53
67
actor ,
54
- new Position ( landscapeObject . x , landscapeObject . y , landscapeObject . level ) ,
68
+ landscapeObject ,
55
69
Math . max ( sizeX , sizeY )
56
70
) ;
57
71
@@ -60,6 +74,8 @@ export abstract class ActorLandscapeObjectInteractionTask<TActor extends Actor =
60
74
return ;
61
75
}
62
76
77
+ // create the Position here to prevent instantiating a new Position every tick
78
+ this . _objectPosition = new Position ( landscapeObject . x , landscapeObject . y , landscapeObject . level ) ;
63
79
this . _landscapeObject = landscapeObject ;
64
80
}
65
81
@@ -80,7 +96,7 @@ export abstract class ActorLandscapeObjectInteractionTask<TActor extends Actor =
80
96
return ;
81
97
}
82
98
83
- const { object : worldObject } = activeWorld . findObjectAtLocation ( this . actor , this . _landscapeObject . objectId , this . destination ) ;
99
+ const { object : worldObject } = activeWorld . findObjectAtLocation ( this . actor , this . _landscapeObject . objectId , this . _objectPosition ) ;
84
100
85
101
if ( ! worldObject ) {
86
102
this . stop ( ) ;
0 commit comments