<commit_before>require_relative 'pool'

module Tabletop
  
  class Conditional
    attr_reader :outcomes, :conditions
    
    def initialize(outcomes, conditions)
      @outcomes = outcomes
      @conditions = conditions
    end
  end
    
  class Roll
    attr_reader :pool, :conditionals
    
    def initialize(pool=nil, &block)
      if pool
        raise ArgumentError if pool.class != Tabletop::Pool
      end
      @pool = pool
      @conditionals = []
      @die_sides = nil
      @static_modifier = 0
      @roll_modifier = 0
      @result_set = false
      instance_eval(&block)
      unless @result_set
        set_result(:sum)
      end
    end
    
    def effects
      results = []
      
      if @difficulty
        results << "Success" if result >= @difficulty
      end
      
      @conditionals.each do |cond|
        if meets?(cond)
          cond.outcomes.each do |outcome|
            if Roll === outcome
              results << outcome.roll
            else
              results << outcome
            end
          end
        end
      end
      
          
      if results.empty?
        results << nil 
      end
      
      results.unshift(result)
    end
    
    def roll(opts={})
      @roll_modifier = opts[:modifier] ? opts[:modifier] : 0
      if @die_sides
        if opts[:pool] 
          @pool = opts[:pool].dX(@die_sides)
        else
          raise ArgumentError
        end
      end
      if opts[:difficulty]
        @difficulty = opts[:difficulty]
      end
      @pool.roll 
    end
    
    def meets?(c)
      answer = true
      if c.conditions[:>=]
        if c.conditions[:>=] > sum
          answer = false
        end
      end
      if c.conditions[:==]
        answer = false if c.conditions[:==] != sum
      end
      answer
    end
    
    def sum
      @pool.sum + @static_modifier + @roll_modifier
    end
    
    # instance_eval methods
    
    ## Conditional-creating methods
    def at_least(value, *outcomes)
      @conditionals << Conditional.new(outcomes, :>= => value)
    end
    
    def equals(values, *outcomes)
      if values.class == Range
        values.each do |val|
          @conditionals << Conditional.new(outcomes, :== => val)
        end
      else
        @conditionals << Conditional.new(outcomes, :== => values)
      end
    end
    <commit_msg>you know what, conditionals is a dumb name<commit_after>require_relative 'pool'

module Tabletop
  
  class Possibility
    attr_reader :outcomes, :conditions
    
    def initialize(outcomes, conditions)
      @outcomes = outcomes
      @conditions = conditions
    end
  end
    
  class Roll
    attr_reader :pool, :possibilities
    
    def initialize(pool=nil, &block)
      if pool
        raise ArgumentError if pool.class != Tabletop::Pool
      end
      @pool = pool
      @possibilities = []
      @die_sides = nil
      @static_modifier = 0
      @roll_modifier = 0
      @result_set = false
      instance_eval(&block)
      unless @result_set
        set_result(:sum)
      end
    end
    
    def effects
      results = []
      
      if @difficulty
        results << "Success" if result >= @difficulty
      end
      
      @possibilities.each do |poss|
        if meets?(poss)
          poss.outcomes.each do |outcome|
            if Roll === outcome
              results << outcome.roll
            else
              results << outcome
            end
          end
        end
      end
      
          
      if results.empty?
        results << nil 
      end
      
      results.unshift(result)
    end
    
    def roll(opts={})
      @roll_modifier = opts[:modifier] ? opts[:modifier] : 0
      if @die_sides
        if opts[:pool] 
          @pool = opts[:pool].dX(@die_sides)
        else
          raise ArgumentError
        end
      end
      if opts[:difficulty]
        @difficulty = opts[:difficulty]
      end
      @pool.roll 
    end
    
    def meets?(p)
      answer = true
      if p.conditions[:>=]
        if p.conditions[:>=] > sum
          answer = false
        end
      end
      if p.conditions[:==]
        answer = false if p.conditions[:==] != sum
      end
      answer
    end
    
    def sum
      @pool.sum + @static_modifier + @roll_modifier
    end
    
    # instance_eval methods
    
    ## Possibility-creating methods
    def at_least(value, *outcomes)
      @possibilities << Possibility.new(outcomes, :>= => value)
    end
    
    def equals(values, *outcomes)
      if values.class == Range
        values.each do |val|
          @possibilities << Possibility.new(outcomes, :== => val)
        end
      else
        @possibilities << Possibility.new(outcomes, :== => values)
      end
    end
    
{'fraction_non_alphanumeric': 0.09221963112147552, 'fraction_numerical': 0.0012719949120203519, 'mean_word_length': 1.6095132743362832, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '727697', 'n_tokens_mistral': 1394, 'n_tokens_neox': 1373, 'n_words': 351}