Module: BCDice::GameSystem::BeginningIdol::WithAbnormality

Included in:
D66WithAbnormality, TableWithAbnormality
Defined in:
lib/bcdice/game_system/beginning_idol/with_abnormality.rb

Instance Method Summary collapse

Instance Method Details

#kanji_to_i(kanji) ⇒ Object



25
26
27
28
# File 'lib/bcdice/game_system/beginning_idol/with_abnormality.rb', line 25

def kanji_to_i(kanji)
  list = I18n.t("BeginningIdol.abnormality.num_map", locale: @locale)
  list.find_index(kanji)&.succ
end

#replace_abnormality(chosen, randomizer) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/bcdice/game_system/beginning_idol/with_abnormality.rb', line 7

def replace_abnormality(chosen, randomizer)
  reg = Regexp.new(I18n.t("BeginningIdol.abnormality.regexp", locale: @locale))
  m = reg.match(chosen.body)
  unless m
    return chosen
  end

  abno_count = kanji_to_i(m[1])
  unless abno_count
    return chosen
  end

  text = @bad_status_table.roll(randomizer, abno_count)
  new_body = chosen.body.sub(reg, text)

  return DiceTable::RollResult.new(chosen.table_name, chosen.value, new_body)
end