import { Task } from '../Task' ; export type dropTargetType = { pos : RoomPosition ; } | RoomPosition ; export class TaskDrop extends Task { static taskName = 'drop' ; target : null ; data : { resourceType : ResourceConstant ; amount : number | undefined ; } ; constructor ( target , resourceType = RESOURCE_ENERGY , amount = undefined , options = { } as TaskOptions ) { if ( target instanceof RoomPosition ) { super ( TaskDrop . taskName , { ref : '' , pos : target } , options ) ; } else { super ( TaskDrop . taskName , { ref : '' , pos : target . pos } , options ) ; } this . settings . oneShot = true ; this . settings . targetRange = 0 ; this . data . resourceType = resourceType ; this . data . amount = amount ; } isValidTask ( ) { let amount = this . data . amount || 1 ; let resourcesInCarry = this . creep . carry [ this . data . resourceType ] || 0 ; return resourcesInCarry >= amount ; } 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 this . creep . drop ( this . data . resourceType , this . data . amount ) ; } }