Class: BCDice::GameSystem::BeginningIdol::WorkWithChanceTable

Inherits:
DiceTable::D66Table show all
Defined in:
lib/bcdice/game_system/beginning_idol/work_table.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from DiceTable::D66Table

#choice

Constructor Details

#initialize(name, sort_type, items, locale) ⇒ WorkWithChanceTable

Returns a new instance of WorkWithChanceTable.



14
15
16
17
18
# File 'lib/bcdice/game_system/beginning_idol/work_table.rb', line 14

def initialize(name, sort_type, items, locale)
  super(name, sort_type, items)
  @regexp = Regexp.new(I18n.t("BeginningIdol.with_chance.regexp", locale: locale))
  @off = I18n.t("BeginningIdol.with_chance.off_text", locale: locale)
end

Class Method Details

.from_i18n(key, locale) ⇒ Object



7
8
9
10
11
12
# File 'lib/bcdice/game_system/beginning_idol/work_table.rb', line 7

def self.from_i18n(key, locale)
  table = I18n.t(key, locale: locale)
  sort_type = D66SortType.const_get(table[:d66_sort_type])

  new(table[:name], sort_type, table[:items], locale)
end

Instance Method Details

#roll(randomizer, chance = nil) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/bcdice/game_system/beginning_idol/work_table.rb', line 29

def roll(randomizer, chance = nil)
  chosen = super(randomizer)
  unless chance
    return chosen
  end

  m = @regexp.match(chosen.body)
  if m && m[1].to_i >= chance
    DiceTable::RollResult.new(chosen.table_name, chosen.value, @off)
  elsif m
    DiceTable::RollResult.new(chosen.table_name, chosen.value, chosen.body.sub(@regexp, ""))
  else
    chosen
  end
end

#roll_command(randomizer, command) ⇒ Object



20
21
22
23
24
25
26
27
# File 'lib/bcdice/game_system/beginning_idol/work_table.rb', line 20

def roll_command(randomizer, command)
  m = /^LO([1-6]{1,2})?$/.match(command)
  unless m
    return nil
  end

  roll(randomizer, m[1]&.to_i)
end