Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BattleTech: CDxコマンドを改良する #445

Merged
merged 3 commits into from
May 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 46 additions & 18 deletions lib/bcdice/game_system/BattleTech.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class BattleTech < Base
  左上半身にSRM6連を技能ベース5目標値8で3回判定
・CT:致命的命中表
・DW:転倒後の向き表
・CDx:メック戦士意識維持表。ダメージ値xで判定 例)CD3
・CDx:メック戦士意識維持ロール。ダメージ値x(1〜6)で判定 例)CD3
MESSAGETEXT

register_prefix('\d*SRM', '\d*LRM', '\d*BT', 'PPC', 'CT', 'DW', 'CD')
Expand All @@ -55,9 +55,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 @@ -272,26 +272,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(",")
ysakasin marked this conversation as resolved.
Show resolved Hide resolved
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

# 表の集合
Expand Down
29 changes: 27 additions & 2 deletions test/data/BattleTech.toml
Original file line number Diff line number Diff line change
Expand Up @@ -338,14 +338,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 = []