import { Task } from '../Task' ; export type goToTargetType = { pos : RoomPosition ; } | RoomPosition ; function hasPos ( obj ) { return ( < { pos : RoomPosition ; } > obj ) . pos != undefined ; } export class TaskGoTo extends Task { static taskName = 'goTo' ; target : null ; constructor ( target , options = { } as TaskOptions ) { if ( hasPos ( target ) ) { super ( TaskGoTo . taskName , { ref : '' , pos : target . pos } , options ) ; } else { super ( TaskGoTo . taskName , { ref : '' , pos : target } , options ) ; } this . settings . targetRange = 1 ; } isValidTask ( ) { return ! this . creep . pos . inRangeTo ( this . targetPos , this . settings . targetRange ) ; } isValidTarget ( ) { return true ; } isValid ( ) { let validTask = false ; if ( this . creep ) { validTask = this . isValidTask ( ) ; } if ( validTask ) { return true ; } else { let isValid = false ; if ( this . parent ) { isValid = this . parent . isValid ( ) ; } this . finish ( ) ; return isValid ; } } work ( ) { return OK ; } }