Class: BCDice::GameSystem::OneWayHeroics::DungeonTable

Inherits:
Object
  • Object
show all
Defined in:
lib/bcdice/game_system/one_way_heroics/dungeon_table.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, key, type, items) ⇒ DungeonTable

Returns a new instance of DungeonTable.



9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/bcdice/game_system/one_way_heroics/dungeon_table.rb', line 9

def initialize(name, key, type, items)
  @name = name
  @key = key
  @items = items.freeze

  m = /(\d+)D(\d+)/i.match(type)
  unless m
    raise ArgumentError, "Unexpected table type: #{type}"
  end

  @times = m[1].to_i
  @sides = m[2].to_i
end

Instance Attribute Details

#keyObject (readonly)

Returns the value of attribute key.



7
8
9
# File 'lib/bcdice/game_system/one_way_heroics/dungeon_table.rb', line 7

def key
  @key
end

Instance Method Details

#roll_with_day(day, randomizer) ⇒ Object



23
24
25
26
27
28
29
# File 'lib/bcdice/game_system/one_way_heroics/dungeon_table.rb', line 23

def roll_with_day(day, randomizer)
  value = randomizer.roll_sum(@times, @sides)
  value += @times if day >= 4

  index = value - @times
  return "#{@name}(#{value}) > #{@items[index]}"
end