Class: BCDice::GameSystem::Cthulhu7th_ChineseTraditional::ResultLevel
- Inherits:
-
Object
- Object
- BCDice::GameSystem::Cthulhu7th_ChineseTraditional::ResultLevel
- Defined in:
- lib/bcdice/game_system/Cthulhu7th_ChineseTraditional.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.
133 134 135 136 137 |
# File 'lib/bcdice/game_system/Cthulhu7th_ChineseTraditional.rb', line 133 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
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
# File 'lib/bcdice/game_system/Cthulhu7th_ChineseTraditional.rb', line 115 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
101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/bcdice/game_system/Cthulhu7th_ChineseTraditional.rb', line 101 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
147 148 149 |
# File 'lib/bcdice/game_system/Cthulhu7th_ChineseTraditional.rb', line 147 def critical? @level == :critical end |
#failure? ⇒ Boolean
143 144 145 |
# File 'lib/bcdice/game_system/Cthulhu7th_ChineseTraditional.rb', line 143 def failure? @level_index <= LEVEL.index(:failure) end |
#fumble? ⇒ Boolean
151 152 153 |
# File 'lib/bcdice/game_system/Cthulhu7th_ChineseTraditional.rb', line 151 def fumble? @level == :fumble end |
#success? ⇒ Boolean
139 140 141 |
# File 'lib/bcdice/game_system/Cthulhu7th_ChineseTraditional.rb', line 139 def success? @level_index >= LEVEL.index(:success) end |
#to_s ⇒ Object
155 156 157 |
# File 'lib/bcdice/game_system/Cthulhu7th_ChineseTraditional.rb', line 155 def to_s LEVEL_TO_S[@level] end |