class BCDice::GameSystem::Cthulhu7th::ResultLevel

Constants

LEVEL
LEVEL_TO_S

Public Class Methods

from_values(total, difficulty, fumbleable = false) click to toggle source
# File lib/bcdice/game_system/Cthulhu7th.rb, line 117
def self.from_values(total, difficulty, fumbleable = false)
  fumble = difficulty < 50 || fumbleable ? 96 : 100

  if total == 1
    ResultLevel.new(:critical)
  elsif total >= fumble
    ResultLevel.new(:fumble)
  elsif total <= (difficulty / 5)
    ResultLevel.new(:extreme_success)
  elsif total <= (difficulty / 2)
    ResultLevel.new(:hard_success)
  elsif total <= difficulty
    ResultLevel.new(:regular_success)
  else
    ResultLevel.new(:failure)
  end
end
new(level) click to toggle source
# File lib/bcdice/game_system/Cthulhu7th.rb, line 135
def initialize(level)
  @level = level
  @level_index = LEVEL.index(level)
  raise ArgumentError unless @level_index
end
with_difficulty_level(total, difficulty) click to toggle source
# File lib/bcdice/game_system/Cthulhu7th.rb, line 103
def self.with_difficulty_level(total, difficulty)
  fumble = difficulty < 50 ? 96 : 100

  if total == 1
    ResultLevel.new(:critical)
  elsif total >= fumble
    ResultLevel.new(:fumble)
  elsif total <= difficulty
    ResultLevel.new(:success)
  else
    ResultLevel.new(:failure)
  end
end

Public Instance Methods

critical?() click to toggle source
# File lib/bcdice/game_system/Cthulhu7th.rb, line 149
def critical?
  @level == :critical
end
failure?() click to toggle source
# File lib/bcdice/game_system/Cthulhu7th.rb, line 145
def failure?
  @level_index <= LEVEL.index(:failure)
end
fumble?() click to toggle source
# File lib/bcdice/game_system/Cthulhu7th.rb, line 153
def fumble?
  @level == :fumble
end
success?() click to toggle source
# File lib/bcdice/game_system/Cthulhu7th.rb, line 141
def success?
  @level_index >= LEVEL.index(:success)
end
to_s() click to toggle source
# File lib/bcdice/game_system/Cthulhu7th.rb, line 157
def to_s
  LEVEL_TO_S[@level]
end