class Core::Game::NPC::Task
Public Class Methods
new(parameters)
click to toggle source
action: proc to execute wait: stall later tasks until this one finished remove_after: delete task when finished
# File lib/game/npc/task.rb, line 8 def initialize(parameters) @array = parameters @finished = false @current = 0 end
Public Instance Methods
empty?()
click to toggle source
# File lib/game/npc/task.rb, line 20 def empty? return @array.empty? end
execute(npc, other=nil)
click to toggle source
# File lib/game/npc/task.rb, line 14 def execute(npc, other=nil) if !@array.empty? and !@finished send(@array[@current].first, @array[@current], npc, other) end end
finished?()
click to toggle source
# File lib/game/npc/task.rb, line 24 def finished? return @finished end
next_subtask(npc, other)
click to toggle source
# File lib/game/npc/task.rb, line 32 def next_subtask(npc, other) if @array[@current].include?(:remove) @array.delete_at(@current) else @current += 1 end if @current >= @array.size @current = 0 return end if !@array[@current-1].include?(:wait) execute(npc, other) end end
reset()
click to toggle source
# File lib/game/npc/task.rb, line 28 def reset @finished = false end
Private Instance Methods
msg(parms, npc, other)
click to toggle source
# File lib/game/npc/task.rb, line 66 def msg(parms, npc, other) Core.window.state.map.message(parms[1]) next_subtask(npc, other) end
particles(parms, npc, other)
click to toggle source
# File lib/game/npc/task.rb, line 49 def particles(parms, npc, other) npc.children.push(Core::Game::MapParticle.new(parms[1].x, parms[1].y, parms[2])) npc.children.last.xoff = npc.children.last.yoff = 16 if parms.include?(:follow) npc.children.last.follow = true end next_subtask(npc, other) end
path_to(parms, npc, other)
click to toggle source
# File lib/game/npc/task.rb, line 58 def path_to(parms, npc, other) if npc.goal.state != :progress next_subtask(npc, other) npc.find_path_to(parms[1].x, parms[1].y) npc.goal.start end end