Class: BCDice::GameSystem::KamitsubakiCityUnderConstructionNarrative::QDice

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

Constant Summary collapse

CRITICAL =
"M"

Instance Method Summary collapse

Constructor Details

#initialize(items) ⇒ QDice

Returns a new instance of QDice.



150
151
152
# File 'lib/bcdice/game_system/KamitsubakiCityUnderConstructionNarrative.rb', line 150

def initialize(items)
  @items = items.freeze
end

Instance Method Details

#roll(randomizer) ⇒ Object



156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
# File 'lib/bcdice/game_system/KamitsubakiCityUnderConstructionNarrative.rb', line 156

def roll(randomizer)
  dice = randomizer.roll_once(@items.length)
  chosen = @items[dice - 1]

  critical = chosen == CRITICAL

  result_tail =
    if critical
      "マジック"
    elsif !chosen.empty?
      "成功"
    else
      "失敗"
    end

  Result.new.tap do |r|
    r.critical = critical
    r.condition = !chosen.empty?
    r.text = [
      "(D#{@items.length})",
      dice.to_s,
      chosen.empty? ? nil : chosen,
      result_tail,
    ].compact.join("")
  end
end