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, :success, :regular_success, :hard_success, :extreme_success, :critical, ].freeze
- LEVEL_TO_S =
{ critical: "クリティカル", extreme_success: "イクストリーム成功", hard_success: "ハード成功", regular_success: "レギュラー成功", success: "成功", fumble: "ファンブル", failure: "失敗", }.freeze
Class Method Summary collapse
- .from_values(total, difficulty, fumbleable = false) ⇒ Object
- .with_difficulty_level(total, difficulty) ⇒ Object
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.
135 136 137 138 139 |
# 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 |
Class Method Details
.from_values(total, difficulty, fumbleable = false) ⇒ Object
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 |
# 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 |
.with_difficulty_level(total, difficulty) ⇒ Object
103 104 105 106 107 108 109 110 111 112 113 114 115 |
# 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 |
Instance Method Details
#critical? ⇒ Boolean
149 150 151 |
# File 'lib/bcdice/game_system/Cthulhu7th.rb', line 149 def critical? @level == :critical end |
#failure? ⇒ Boolean
145 146 147 |
# File 'lib/bcdice/game_system/Cthulhu7th.rb', line 145 def failure? @level_index <= LEVEL.index(:failure) end |
#fumble? ⇒ Boolean
153 154 155 |
# File 'lib/bcdice/game_system/Cthulhu7th.rb', line 153 def fumble? @level == :fumble end |
#success? ⇒ Boolean
141 142 143 |
# File 'lib/bcdice/game_system/Cthulhu7th.rb', line 141 def success? @level_index >= LEVEL.index(:success) end |
#to_s ⇒ Object
157 158 159 |
# File 'lib/bcdice/game_system/Cthulhu7th.rb', line 157 def to_s LEVEL_TO_S[@level] end |