Class: BCDice::GameSystem::KamitsubakiCityUnderConstructionNarrative::KumiDice

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

Constant Summary collapse

CRITICAL =
"M"
FUMBLE =
"Q"

Instance Method Summary collapse

Constructor Details

#initialize(items) ⇒ KumiDice

Returns a new instance of KumiDice.



74
75
76
# File 'lib/bcdice/game_system/KamitsubakiCityUnderConstructionNarrative.rb', line 74

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

Instance Method Details

#roll(randomizer) ⇒ Object



81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/bcdice/game_system/KamitsubakiCityUnderConstructionNarrative.rb', line 81

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

  fumble = chosen == FUMBLE
  critical = chosen == CRITICAL

  result_tail =
    if fumble
      "ファンブル"
    elsif critical
      "マジック"
    elsif !chosen.empty?
      "成功"
    else
      "失敗"
    end

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