Class: BCDice::GameSystem::CthulhuTech::Test
- Inherits:
-
Object
- Object
- BCDice::GameSystem::CthulhuTech::Test
- Defined in:
- lib/bcdice/game_system/CthulhuTech.rb
Overview
行為判定のノード
Direct Known Subclasses
Constant Summary collapse
- COMPARE_OP =
判定で用いる比較演算子
対抗判定で変えられるように定数で定義する。
:>=
Instance Method Summary collapse
-
#execute(randomizer) ⇒ String
判定を行う.
-
#initialize(num, modifier, difficulty) ⇒ Test
constructor
ノードを初期化する.
Constructor Details
#initialize(num, modifier, difficulty) ⇒ Test
ノードを初期化する
43 44 45 46 47 |
# File 'lib/bcdice/game_system/CthulhuTech.rb', line 43 def initialize(num, modifier, difficulty) @num = num @modifier = modifier @difficulty = difficulty end |
Instance Method Details
#execute(randomizer) ⇒ String
判定を行う
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/bcdice/game_system/CthulhuTech.rb', line 52 def execute(randomizer) dice_values = randomizer.(@num, 10) # ファンブル:出目の半分(小数点以下切り上げ)以上が1の場合 fumble = dice_values.count(1) >= (dice_values.length + 1) / 2 sorted_dice_values = dice_values.sort roll_result = calculate_roll_result(sorted_dice_values) test_value = roll_result + @modifier diff = test_value - @difficulty # diff と @difficulty との比較の演算子が変わるので、send で対応 # 例:COMPARE_OP が :>= ならば、diff >= 0 と同じ success = !fumble && diff.send(self.class::COMPARE_OP, 0) critical = diff >= 10 output_parts = [ "(#{expression()})", test_value_expression(sorted_dice_values, roll_result), test_value, result_str(success, fumble, critical, diff) ] return output_parts.join(' > ') end |