class CoopAl::StateReporter

StateReporter

Public Class Methods

new(state, library, options = {}) click to toggle source
# File lib/coop_al/state_reporter.rb, line 6
def initialize(state, library, options = {})
  @state = state
  @library = library
  @party_size = options.key?(:party_size) ? options[:party_size] : 6
  @show_xp = options.key?(:show_xp) ? options[:show_xp] : true
  @show_loot = options.key?(:show_loot) ? options[:show_loot] : true
  @show_paths = options.key?(:show_paths) ? options[:show_paths] : true
end

Public Instance Methods

report(s) click to toggle source
# File lib/coop_al/state_reporter.rb, line 15
def report(s)
  report_xp(s) if @show_xp
  report_loot(s) if @show_loot
  report_paths(s) if @show_paths
end

Private Instance Methods

available_paths() click to toggle source
# File lib/coop_al/state_reporter.rb, line 65
def available_paths
  @state.available_paths(@library).map do |p|
    return ['Downtime'] if p.root?
    "#{@library.resolve(p).description} (#{p})"
  end
end
character_level() click to toggle source
# File lib/coop_al/state_reporter.rb, line 31
def character_level
  CoopAl::XpRequirementTable.new.level_from_xp(character_xp)
end
character_treasure() click to toggle source
# File lib/coop_al/state_reporter.rb, line 52
def character_treasure
  @state.loot.treasure_value / @party_size
end
character_xp() click to toggle source
# File lib/coop_al/state_reporter.rb, line 27
def character_xp
  @state.xp / @party_size
end
report_items(s) click to toggle source
# File lib/coop_al/state_reporter.rb, line 45
def report_items(s)
  items = @state.loot.items
  return if items.empty?
  s.puts 'Items:'
  s.puts items.map { |item| "  #{item.description_with_origin}" }
end
report_loot(s) click to toggle source
# File lib/coop_al/state_reporter.rb, line 35
def report_loot(s)
  report_treasure(s)
  report_items(s)
end
report_paths(s) click to toggle source
# File lib/coop_al/state_reporter.rb, line 56
def report_paths(s)
  s.puts 'Paths:'
  if available_paths.empty?
    s.puts '  None'
  else
    s.puts available_paths.map { |p| "  #{p}" }.join("\n")
  end
end
report_treasure(s) click to toggle source
# File lib/coop_al/state_reporter.rb, line 40
def report_treasure(s)
  return if @state.loot.treasures.empty?
  s.puts "Treasure: #{character_treasure} (#{@state.loot.treasure_value} total)"
end
report_xp(s) click to toggle source
# File lib/coop_al/state_reporter.rb, line 23
def report_xp(s)
  s.puts "Character Level: #{character_level} (#{character_xp} XP - #{@state.xp} XP total)"
end