Class: Core::Game::NPC::Task
Instance Method Summary collapse
- #empty? ⇒ Boolean
- #execute(npc, other = nil) ⇒ Object
- #finished? ⇒ Boolean
-
#initialize(parameters) ⇒ Task
constructor
action: proc to execute wait: stall later tasks until this one finished remove_after: delete task when finished.
- #next_subtask(npc, other) ⇒ Object
- #reset ⇒ Object
Constructor Details
#initialize(parameters) ⇒ Task
action: proc to execute wait: stall later tasks until this one finished remove_after: delete task when finished
8 9 10 11 12 |
# File 'lib/game/npc/task.rb', line 8 def initialize(parameters) @array = parameters @finished = false @current = 0 end |
Instance Method Details
#empty? ⇒ Boolean
20 21 22 |
# File 'lib/game/npc/task.rb', line 20 def empty? return @array.empty? end |
#execute(npc, other = nil) ⇒ Object
14 15 16 17 18 |
# 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? ⇒ Boolean
24 25 26 |
# File 'lib/game/npc/task.rb', line 24 def finished? return @finished end |
#next_subtask(npc, other) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# 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 ⇒ Object
28 29 30 |
# File 'lib/game/npc/task.rb', line 28 def reset @finished = false end |