class Tablescript::RollAndIgnoreDuplicatesStrategy

RollAndIgnoreDuplicatesStrategy

Public Class Methods

new(table, roll_count, ignore = nil) click to toggle source
# File lib/tablescript/roll_and_ignore_duplicates_strategy.rb, line 23
def initialize(table, roll_count, ignore = nil)
  @table = table
  @roll_count = roll_count
  @roll_history = ignore || RpgLib::RollSet.new
  @entry_ids = Set.new
  @rolls = []
  @values = []
end

Public Instance Methods

rolls() click to toggle source
# File lib/tablescript/roll_and_ignore_duplicates_strategy.rb, line 32
def rolls
  evaluate
  @rolls
end
values() click to toggle source
# File lib/tablescript/roll_and_ignore_duplicates_strategy.rb, line 37
def values
  evaluate
  @values
end

Private Instance Methods

evaluate() click to toggle source
# File lib/tablescript/roll_and_ignore_duplicates_strategy.rb, line 44
def evaluate
  loop do
    roll_next_value
    break if @values.size == @roll_count
  end
end
next_roll(dice) click to toggle source
# File lib/tablescript/roll_and_ignore_duplicates_strategy.rb, line 65
def next_roll(dice)
  RpgLib::DiceRoller.instance.roll_and_ignore(dice, @roll_history)
end
record(roll, entry) click to toggle source
# File lib/tablescript/roll_and_ignore_duplicates_strategy.rb, line 58
def record(roll, entry)
  @entry_ids.add(entry.id)
  @roll_history.add(entry.roll)
  @rolls << roll
  @values << entry.evaluate(roll, @table)
end
roll_next_value() click to toggle source
# File lib/tablescript/roll_and_ignore_duplicates_strategy.rb, line 51
def roll_next_value
  roll = next_roll(@table.dice_to_roll)
  entry = @table.entries.lookup(roll)
  return if @entry_ids.include?(entry.id)
  record(roll, entry)
end