Class: BCDice::GameSystem::Cthulhu7th::ResultLevel
- Inherits:
-
Object
- Object
- BCDice::GameSystem::Cthulhu7th::ResultLevel
- Defined in:
- lib/bcdice/game_system/Cthulhu7th.rb
Constant Summary collapse
- LEVEL =
[ :fumble, :failure, :regular_success, :hard_success, :extreme_success, :critical, ].freeze
- LEVEL_TO_S =
{ critical: "クリティカル", extreme_success: "イクストリーム成功", hard_success: "ハード成功", regular_success: "レギュラー成功", fumble: "ファンブル", failure: "失敗", }.freeze
Class Method Summary collapse
Instance Method Summary collapse
- #critical? ⇒ Boolean
- #failure? ⇒ Boolean
- #fumble? ⇒ Boolean
-
#initialize(level) ⇒ ResultLevel
constructor
A new instance of ResultLevel.
- #success? ⇒ Boolean
- #to_s ⇒ Object
Constructor Details
#initialize(level) ⇒ ResultLevel
Returns a new instance of ResultLevel.
113 114 115 116 117 |
# File 'lib/bcdice/game_system/Cthulhu7th.rb', line 113 def initialize(level) @level = level @level_index = LEVEL.index(level) raise ArgumentError unless @level_index end |
Class Method Details
.from_values(total, difficulty, fumbleable = false) ⇒ Object
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/bcdice/game_system/Cthulhu7th.rb', line 95 def self.from_values(total, difficulty, fumbleable = false) fumble = difficulty < 50 || fumbleable ? 96 : 100 if total == 1 ResultLevel.new(:critical) elsif total <= (difficulty / 5) ResultLevel.new(:extreme_success) elsif total <= (difficulty / 2) ResultLevel.new(:hard_success) elsif total <= difficulty ResultLevel.new(:regular_success) elsif total >= fumble ResultLevel.new(:fumble) else ResultLevel.new(:failure) end end |
Instance Method Details
#critical? ⇒ Boolean
127 128 129 |
# File 'lib/bcdice/game_system/Cthulhu7th.rb', line 127 def critical? @level == :critical end |
#failure? ⇒ Boolean
123 124 125 |
# File 'lib/bcdice/game_system/Cthulhu7th.rb', line 123 def failure? @level_index <= LEVEL.index(:failure) end |
#fumble? ⇒ Boolean
131 132 133 |
# File 'lib/bcdice/game_system/Cthulhu7th.rb', line 131 def fumble? @level == :fumble end |
#success? ⇒ Boolean
119 120 121 |
# File 'lib/bcdice/game_system/Cthulhu7th.rb', line 119 def success? @level_index >= LEVEL.index(:regular_success) end |
#to_s ⇒ Object
135 136 137 |
# File 'lib/bcdice/game_system/Cthulhu7th.rb', line 135 def to_s LEVEL_TO_S[@level] end |