Class: BCDice::GameSystem::DoubleCross::DX

Inherits:
Object
  • Object
show all
Includes:
Translate
Defined in:
lib/bcdice/game_system/DoubleCross.rb

Overview

成功判定コマンドのノード

Instance Method Summary collapse

Methods included from Translate

#translate

Constructor Details

#initialize(num, critical_value, modifier, target_value) ⇒ DX

ノードを初期化する

Parameters:

  • ダイス数

  • クリティカル値

  • 修正値

  • 目標値



52
53
54
55
56
57
58
59
60
61
62
# File 'lib/bcdice/game_system/DoubleCross.rb', line 52

def initialize(num, critical_value, modifier, target_value)
  @num = num
  @critical_value = critical_value
  @modifier = modifier
  @target_value = target_value

  @modifier_str = Format.modifier(@modifier)
  @expression = node_expression()

  @locale = :ja_jp
end

Instance Method Details

#execute(randomizer) ⇒ Result

成功判定を行う

Parameters:

Returns:

  • 判定結果



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/bcdice/game_system/DoubleCross.rb', line 67

def execute(randomizer)
  if @critical_value < 2
    return Result.new("(#{@expression}) > #{translate('DoubleCross.DX.invalid_critical')}")
  end

  if @num < 1
    return Result.failure("(#{@expression}) > #{translate('DoubleCross.DX.auto_failure')}")
  end

  # 出目のグループの配列
  value_groups = []
  # 次にダイスロールを行う際のダイス数
  num_of_dice = @num
  # 回転数
  loop_count = 0

  while num_of_dice > 0 && loop_count < CommonCommand::RerollDice::REROLL_LIMIT
    values = randomizer.roll_barabara(num_of_dice, 10)

    value_group = ValueGroup.new(values, @critical_value)
    value_groups.push(value_group)

    # 次回はクリティカル発生数と等しい個数のダイスを振る
    # [3rd ルールブック1 p. 185]
    num_of_dice = value_group.num_of_critical_occurrences

    loop_count += 1
  end

  return result(value_groups)
end