Skip to content

Commit

Permalink
Merge pull request #445 from bcdice/battletech-improve_cd
Browse files Browse the repository at this point in the history
BattleTech: CDxコマンドを改良する
  • Loading branch information
ysakasin authored May 8, 2021
2 parents 6f9acf6 + 35579e3 commit ab6d0c1
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 20 deletions.
64 changes: 46 additions & 18 deletions lib/bcdice/game_system/BattleTech.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class BattleTech < Base
 右側からPPC(ダメージ10)による攻撃を技能ベース3目標値10で2回判定
・CT:致命的命中表
・DW:転倒後の向き表
・CDx:メック戦士意識維持表。ダメージ値xで判定 例)CD3
・CDx:メック戦士意識維持ロール。ダメージ値x(1〜6)で判定 例)CD3
MESSAGETEXT

register_prefix('\d*SRM', '\d*LRM', '\d*BT', '\d*PPC', 'CT', 'DW', 'CD')
Expand Down Expand Up @@ -78,9 +78,9 @@ def eval_game_system_specific_command(command)
debug('executeCommandCatched command', command)

case command
when /^CD(\d+)$/
when /\ACD([1-6])\z/
damage = Regexp.last_match(1).to_i
return getCheckDieResult(damage)
return consciousness_roll(damage)
when /^((S|L)RM\d+)(.+)/
tail = Regexp.last_match(3)
type = Regexp.last_match(1)
Expand Down Expand Up @@ -304,26 +304,54 @@ def getHitResultOne(damage_text, hit_part_table)
return result_parts.join(' > '), hit_part.name, criticalText
end

def getCheckDieResult(damage)
if damage >= 6
return "死亡"
# メック戦士意識維持ロールを行う
#
# damageが6の場合は死亡。
# damageが5以下の場合は、2d6の結果が意識維持表の値以上かの成功判定。
#
# @param damage [Integer] メック戦士へのダメージ(1〜6)
# @return [Result]
# @see 「BattleTech: A Game of Armored Combat」ルールブックp. 44
def consciousness_roll(damage)
unless (1..6).include?(damage)
return nil
end

table = [[1, 3],
[2, 5],
[3, 7],
[4, 10],
[5, 11]]
command = "CD#{damage}"

target = get_table_by_number(damage, table, nil)
if damage == 6
return Result.fumble("#{command} > 死亡")
end

dice1 = @randomizer.roll_once(6)
dice2 = @randomizer.roll_once(6)
total = dice1 + dice2
result = total >= target ? "成功" : "失敗"
text = "#{total}[#{dice1},#{dice2}]>=#{target}#{result}"
consciousness_table = {
1 => 3,
2 => 5,
3 => 7,
4 => 10,
5 => 11,
}

target = consciousness_table[damage]
expr = "(2D6>=#{target})"

values = @randomizer.roll_barabara(2, 6)
sum = values.sum
values_str = @randomizer.rand_results.map(&:first).join(",")
sum_and_values = "#{sum}[#{values_str}]"

success = sum >= target
result = success ? "成功" : "失敗"

parts = [
command,
expr,
sum_and_values,
sum,
result,
]
text = parts.join(" > ")

return text
return success ? Result.success(text) : Result.failure(text)
end

# PPCコマンドを実行する
Expand Down
29 changes: 27 additions & 2 deletions test/data/BattleTech.toml
Original file line number Diff line number Diff line change
Expand Up @@ -425,14 +425,39 @@ rands = [
[[ test ]]
game_system = "BattleTech"
input = "CD6"
output = "死亡"
output = "CD6 > 死亡"
failure = true
fumble = true
rands = []

[[ test ]]
game_system = "BattleTech"
input = "CD3"
output = "7[5,2]>=7 > 成功"
output = "CD3 > (2D6>=7) > 7[5,2] > 7 > 成功"
success = true
rands = [
{ sides = 6, value = 5 },
{ sides = 6, value = 2 },
]

[[ test ]]
game_system = "BattleTech"
input = "CD4"
output = "CD4 > (2D6>=10) > 8[3,5] > 8 > 失敗"
failure = true
rands = [
{ sides = 6, value = 3 },
{ sides = 6, value = 5 },
]

[[ test ]]
game_system = "BattleTech"
input = "CD0 範囲外"
output = ""
rands = []

[[ test ]]
game_system = "BattleTech"
input = "CD7 範囲外"
output = ""
rands = []

0 comments on commit ab6d0c1

Please sign in to comment.