Class: BCDice::GameSystem::Dracurouge::YearTable
- Inherits:
-
Object
- Object
- BCDice::GameSystem::Dracurouge::YearTable
- Defined in:
- lib/bcdice/game_system/Dracurouge.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(name, year_title, items) ⇒ YearTable
constructor
A new instance of YearTable.
- #roll(randomizer) ⇒ String
Constructor Details
#initialize(name, year_title, items) ⇒ YearTable
Returns a new instance of YearTable.
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
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
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.(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 |