Class: CoopAl::State
- Inherits:
-
Object
- Object
- CoopAl::State
- Defined in:
- lib/coop_al/state.rb
Overview
State
Instance Attribute Summary collapse
-
#current_path ⇒ Object
Returns the value of attribute current_path.
-
#items ⇒ Object
readonly
Returns the value of attribute items.
-
#loot ⇒ Object
readonly
Returns the value of attribute loot.
-
#xp ⇒ Object
readonly
Returns the value of attribute xp.
Instance Method Summary collapse
- #add_items(items) ⇒ Object
- #add_loot(loot) ⇒ Object
- #add_xp(xp) ⇒ Object
- #all_available_paths(library) ⇒ Object
- #apply_path(path) ⇒ Object
- #available_paths(library) ⇒ Object
- #downtime_if_available(chapter) ⇒ Object
- #history_includes?(path) ⇒ Boolean
- #in_downtime? ⇒ Boolean
-
#initialize ⇒ State
constructor
A new instance of State.
- #path_depth ⇒ Object
- #treasure_value ⇒ Object
Constructor Details
Instance Attribute Details
#current_path ⇒ Object
Returns the value of attribute current_path.
7 8 9 |
# File 'lib/coop_al/state.rb', line 7 def current_path @current_path end |
#items ⇒ Object (readonly)
Returns the value of attribute items.
6 7 8 |
# File 'lib/coop_al/state.rb', line 6 def items @items end |
#loot ⇒ Object (readonly)
Returns the value of attribute loot.
6 7 8 |
# File 'lib/coop_al/state.rb', line 6 def loot @loot end |
#xp ⇒ Object (readonly)
Returns the value of attribute xp.
6 7 8 |
# File 'lib/coop_al/state.rb', line 6 def xp @xp end |
Instance Method Details
#add_items(items) ⇒ Object
73 74 75 |
# File 'lib/coop_al/state.rb', line 73 def add_items(items) @items.concat(items) end |
#add_loot(loot) ⇒ Object
69 70 71 |
# File 'lib/coop_al/state.rb', line 69 def add_loot(loot) @loot += loot end |
#add_xp(xp) ⇒ Object
65 66 67 |
# File 'lib/coop_al/state.rb', line 65 def add_xp(xp) @xp += xp end |
#all_available_paths(library) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 |
# 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) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 |
# 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) ⇒ Object
28 29 30 |
# 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) ⇒ Object
46 47 48 49 |
# 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) ⇒ Boolean
81 82 83 |
# File 'lib/coop_al/state.rb', line 81 def history_includes?(path) @visited_paths.include?(path) end |
#in_downtime? ⇒ Boolean
24 25 26 |
# File 'lib/coop_al/state.rb', line 24 def in_downtime? current_path.root? end |
#path_depth ⇒ Object
20 21 22 |
# File 'lib/coop_al/state.rb', line 20 def path_depth @path_stack.size end |