Class: BCDice::GameSystem::Dracurouge::YearTable

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, year_title, items) ⇒ YearTable

Returns a new instance of YearTable.

Parameters:

  • name (String)
  • year_title (String)
  • items (Array<Array<(String, String)>>)


243
244
245
246
247
# File 'lib/bcdice/game_system/Dracurouge.rb', line 243

def initialize(name, year_title, items)
  @name = name
  @year_title = year_title
  @items = items.freeze
end

Class Method Details

.from_i18n(key, locale, years) ⇒ YearTable

Parameters:

  • key (String)
  • locale (Symbol)
  • years (Array<String>)

Returns:



234
235
236
237
238
# File 'lib/bcdice/game_system/Dracurouge.rb', line 234

def self.from_i18n(key, locale, years)
  table = I18n.translate(key, locale: locale, raise: true)
  items = table[:items].zip(years)
  return new(table[:name], table[:year_title], items)
end

Instance Method Details

#roll(randomizer) ⇒ String

Parameters:

Returns:

  • (String)


251
252
253
254
255
256
257
258
259
260
# File 'lib/bcdice/game_system/Dracurouge.rb', line 251

def roll(randomizer)
  tens, ones = randomizer.roll_barabara(2, 6)
  index = (tens - 1) * 6 + (ones - 1)

  text, year_expr = @items[index]
  interim_expr = year_expr.gsub(/\d+D6+/) { |expr| roll_d6x(expr, randomizer) }
  year = ArithmeticEvaluator.eval(interim_expr.gsub("×", "*"))

  "#{@name}(#{tens}#{ones}) > #{text}#{@year_title}#{year_expr} > (#{interim_expr}) > #{@year_title}#{year}"
end