class CoopAl::State
Attributes
current_path[RW]
items[R]
loot[R]
xp[R]
Public Class Methods
new()
click to toggle source
# File lib/coop_al/state.rb, line 9 def initialize @path_stack = [Path.root] @xp = 0 @loot = Loot.empty @visited_paths = [] end
Public Instance Methods
add_items(items)
click to toggle source
# File lib/coop_al/state.rb, line 73 def add_items(items) @items.concat(items) end
add_loot(loot)
click to toggle source
# File lib/coop_al/state.rb, line 69 def add_loot(loot) @loot += loot end
add_xp(xp)
click to toggle source
# File lib/coop_al/state.rb, line 65 def add_xp(xp) @xp += xp end
all_available_paths(library)
click to toggle source
# File lib/coop_al/state.rb, line 32 def all_available_paths(library) if path_depth == 1 if in_downtime? library.all_entries else chapter = library.resolve(current_path) chapter.links + downtime_if_available(chapter) end else chapter = library.resolve(@path_stack[0]) library.all_entries + chapter.links + downtime_if_available(chapter) end end
apply_path(path)
click to toggle source
# File lib/coop_al/state.rb, line 51 def apply_path(path) if path_depth == 1 if path.root? @path_stack.push(path) else @path_stack = [current_path + path] @visited_paths << current_path end else @path_stack = [path] @visited_paths << path end end
available_paths(library)
click to toggle source
# File lib/coop_al/state.rb, line 28 def available_paths(library) all_available_paths(library).select { |p| !@visited_paths.include?(p) } end
downtime_if_available(chapter)
click to toggle source
# File lib/coop_al/state.rb, line 46 def downtime_if_available(chapter) return [Path.root] if chapter.links_to_downtime? && !in_downtime? [] end
history_includes?(path)
click to toggle source
# File lib/coop_al/state.rb, line 81 def history_includes?(path) @visited_paths.include?(path) end
in_downtime?()
click to toggle source
# File lib/coop_al/state.rb, line 24 def in_downtime? current_path.root? end
path_depth()
click to toggle source
# File lib/coop_al/state.rb, line 20 def path_depth @path_stack.size end
treasure_value()
click to toggle source
# File lib/coop_al/state.rb, line 77 def treasure_value @treasure.inject(Value.new) { |a, e| a + e.value } end