abstract class AbstractHugbot : AbstractBot { @Attribute var deadly = false @Attribute var thief = false @Attribute var speed = 4 @CostumeAttribute var color = Color.white() var direction = EAST var allowReverse = true override fun begin() { super.speed = speed super.begin() actor.color = color } override fun isDeadly() = deadly override fun canMove( direction : int, other : LookedAt ) : boolean { return super.canMove( direction, other ) || ( deadly && other.isPlayer() ) || ( thief && other.collectable()) || other.canPush( direction, speed, strength ) } override fun myTurn() { val player = PlayDirector.instance.player if (player == null || player.square == null) return val dx = player.square.x - square.x val dy = player.square.y - square.y if ( dx * dx + dy * dy == 1 && ! isTalking() ) { speak( actor.costume.chooseString( "hug" ), 3, speechColor ) } myTurn( dx, dy ) } fun myTurn( dx : int, ty : int ) {} fun headingAway( direction : int ) : boolean { val player = PlayDirector.instance.player val dx = Item.getDeltaX( direction ) val dy = Item.getDeltaY( direction ) val tx = player.actor.x - actor.x val ty = player.actor.y - actor.y if (dx * tx > 0) return false if (dy * ty > 0) return false return true } fun tryToMove( direction : int ) : boolean { if (canMove( direction )) { makeMove( direction ) return true } return false } }