~jeremyf/twn

6c328bf83336fc2d984e3ef93ad9cab8b1b061a0 — Jeremy Friesen 9 months ago c444c5f
Updating Twn::TradeGoods
1 files changed, 15 insertions(+), 8 deletions(-)

M lib/twn/trade_goods.rb
M lib/twn/trade_goods.rb => lib/twn/trade_goods.rb +15 -8
@@ 13,28 13,35 @@ module Twn
    end

    class Roller
      def initialize(table:)
      def initialize(table:, supplier: :legal)
        @table = table
        @supplier = supplier
      end
      attr_reader :table, :supplier

      def roll
        common_goods
        common_goods + random_goods
      end

      private

      def random_goods
        (1..Utility.roll("1d6")).map do |i|
          random_good
        end.compact
      end

      def common_goods
        (11..16).map do |i|
          Result.new(row: @table.fetch(i))
          table.fetch(i)
        end
      end
    end

    class Result
      def initialize(row:)
        @row = row
      def random_good
        result = roll("d66")
        return nil if result > 60 && supplier == :legal
        table.fetch(result)
      end
      attr_reader :row
    end
  end
end