Class: BCDice::GameSystem::SwordWorld2_0::TranscendentTest

Inherits:
Object
  • Object
show all
Defined in:
lib/bcdice/game_system/sword_world/transcendent_test.rb

Overview

超越判定のノード

Constant Summary collapse

RESULT_STR =
{
  success: "成功",
  failure: "失敗",
  super_success: "超成功",
  critical: "自動的成功",
  fumble: "自動的失敗",
}.freeze

Instance Method Summary collapse

Constructor Details

#initialize(critical_value, modifier, cmp_op, target) ⇒ TranscendentTest

Returns a new instance of TranscendentTest.

Parameters:

  • critical_value (Integer)

    クリティカル値

  • modifier (Integer)

    修正値

  • cmp_op (String, nil)

    比較演算子(> または >=)

  • target (Integer, nil)

    目標値



20
21
22
23
24
25
26
27
28
# File 'lib/bcdice/game_system/sword_world/transcendent_test.rb', line 20

def initialize(critical_value, modifier, cmp_op, target)
  @critical_value = critical_value
  @modifier = modifier
  @cmp_op = cmp_op
  @target = target

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

Instance Method Details

#execute(randomizer) ⇒ String

超越判定を行う

Parameters:

Returns:

  • (String)


33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/bcdice/game_system/sword_world/transcendent_test.rb', line 33

def execute(randomizer)
  if @critical_value < 3
    return "(#{@expression}) > クリティカル値が小さすぎます。3以上を指定してください。"
  end

  first_value_group = randomizer.roll_barabara(2, 6)
  value_groups = [first_value_group]

  fumble = first_value_group == [1, 1]
  critical = first_value_group == [6, 6]

  if !fumble && !critical
    while sum_of_dice(value_groups.last) >= @critical_value
      value_groups.push(randomizer.roll_barabara(2, 6))
    end
  end

  sum = sum_of_dice(value_groups)
  total_sum = sum + @modifier

  result = result_status(total_sum, value_groups.length, fumble, critical)
  parts = [
    "(#{@expression})",
    "#{dice_str(value_groups, sum)}#{@modifier_str}",
    total_sum,
    RESULT_STR[result],
  ].compact

  return Result.new.tap do |r|
    r.text = parts.join(" > ")
    r.fumble = result == :fumble
    r.critical = result == :critical
    r.success = [:success, :super_success, :critical].include?(result)
    r.failure = [:failure, :fumble].include?(result)
  end
end