1+ import { LandscapeObject } from '@runejs/filestore' ;
12import { activeWorld , Position } from '@engine/world' ;
23import { Actor } from '@engine/world/actor' ;
3- import { LandscapeObject } from '@runejs/filestore' ;
44import { ActorWalkToTask } from './actor-walk-to-task' ;
55
66/**
@@ -11,8 +11,9 @@ import { ActorWalkToTask } from './actor-walk-to-task';
1111 *
1212 * @author jameskmonger
1313 */
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 > {
1515 private _landscapeObject : LandscapeObject ;
16+ private _objectPosition : Position ;
1617
1718 /**
1819 * Gets the {@link LandscapeObject} that this task is interacting with.
@@ -37,6 +38,19 @@ export abstract class ActorLandscapeObjectInteractionTask<TActor extends Actor =
3738 return this . _landscapeObject ;
3839 }
3940
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+
4054 /**
4155 * @param actor The actor executing this task.
4256 * @param landscapeObject The landscape object to interact with.
@@ -51,7 +65,7 @@ export abstract class ActorLandscapeObjectInteractionTask<TActor extends Actor =
5165 ) {
5266 super (
5367 actor ,
54- new Position ( landscapeObject . x , landscapeObject . y , landscapeObject . level ) ,
68+ landscapeObject ,
5569 Math . max ( sizeX , sizeY )
5670 ) ;
5771
@@ -60,6 +74,8 @@ export abstract class ActorLandscapeObjectInteractionTask<TActor extends Actor =
6074 return ;
6175 }
6276
77+ // create the Position here to prevent instantiating a new Position every tick
78+ this . _objectPosition = new Position ( landscapeObject . x , landscapeObject . y , landscapeObject . level ) ;
6379 this . _landscapeObject = landscapeObject ;
6480 }
6581
@@ -80,7 +96,7 @@ export abstract class ActorLandscapeObjectInteractionTask<TActor extends Actor =
8096 return ;
8197 }
8298
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 ) ;
84100
85101 if ( ! worldObject ) {
86102 this . stop ( ) ;
0 commit comments