class Core::Game::CompositeGoal

Attributes

state[R]

Public Class Methods

new(policy=:abort) click to toggle source
Calls superclass method
# File lib/game/npc/goal.rb, line 39
def initialize(policy=:abort)
  super()
  @current = 0
  @policy = policy
  @state = :progress
end

Public Instance Methods

advance() click to toggle source
# File lib/game/npc/goal.rb, line 73
def advance
  @current += 1
  if @current == self.size
    @state = :finished
    @current = 0
  end
end
current() click to toggle source
# File lib/game/npc/goal.rb, line 53
def current
  return self[@current]
end
reset() click to toggle source
# File lib/game/npc/goal.rb, line 45
def reset
  self.clear
  @current = 0
  @state = :reset
end
start() click to toggle source
# File lib/game/npc/goal.rb, line 50
def start
  @state = :progress
end
update() click to toggle source
# File lib/game/npc/goal.rb, line 56
def update
  if @state == :progress
    awesome_print(self) if !current
    case current.state
    when :before
      if current.class != MotionGoal
        current.setup
      end
    when :progress
      return
    when :failed
      handle_failed
    when :finished
      advance
    end
  end
end

Private Instance Methods

handle_failed() click to toggle source
# File lib/game/npc/goal.rb, line 81
def handle_failed
  case @policy
  when :abort
    @state = :failed
  when :retry
    current.restart
  when :recalc
    current.recalc
  end
end