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

[GoblinSlayer] 判定に大成功と大失敗の閾値変更オプションを追加 #562

Merged
merged 1 commit into from
Oct 17, 2022
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
38 changes: 30 additions & 8 deletions lib/bcdice/game_system/GoblinSlayer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@ class GoblinSlayer < Base

# ダイスボットの使い方
HELP_MESSAGE = <<~MESSAGETEXT
・判定 GS(x)>=y
・判定 GS(x)@c#f>=y
 2d6の判定を行い、達成値を出力します。
 xは基準値、yは目標値です。いずれも省略可能です。
 xは基準値、yは目標値、cは大成功の下限、fは大失敗の上限です。いずれも省略可能です。
 cが未指定の場合には c=12 、fが未指定の場合には f=2 となります。
 yが設定されている場合、大成功/成功/失敗/大失敗を自動判定します。
 例)GS>=12 GS>10 GS(10)>14 GS+10>=15 GS10>=15 GS(10) GS+10 GS10 GS
   GS@10 GS@10#3 GS#3@10

・祈念 MCPI(n)$m
 祈念を行います。
Expand Down Expand Up @@ -62,24 +64,35 @@ def eval_game_system_specific_command(command)
end

def getCheckResult(command)
m = /^GS([-+]?\d+)?((>=?)(\d+))?$/i.match(command)
m = /^GS([-+]?\d+)?(?:(?:([@#])([-+]?\d+))(?:([@#])([-+]?\d+))?)?(?:(>=?)(\d+))?$/i.match(command)
unless m
return nil
end

basis = m[1].to_i # 基準値
target = m[4].to_i
without_compare = m[2].nil? || target <= 0
cmp_op = m[3]
target = m[7].to_i
cmp_op = m[6]
without_compare = cmp_op.nil?

option1 = m[2]
option1_value = m[3]
option2 = m[4]
option2_param = m[5]

if option1 && option1 == option2
return nil
end

threshold_critical, threshold_fumble = calc_threshold(option1, option1_value, option2, option2_param)

dice_list = @randomizer.roll_barabara(2, 6)
total = dice_list.sum()
diceText = dice_list.join(",")

achievement = basis + total # 達成値

fumble = diceText == "1,1"
critical = diceText == "6,6"
fumble = total <= threshold_fumble
critical = total >= threshold_critical

result = " > #{resultStr(achievement, target, cmp_op, fumble, critical)}"
if without_compare && !fumble && !critical
Expand All @@ -90,6 +103,15 @@ def getCheckResult(command)
return "(#{command}) > #{basis_str}#{total}[#{diceText}] > #{achievement}#{result}"
end

CRITICAL = 12
FUMBLE = 2

def calc_threshold(option1, option1_value, _option2, option2_value)
critical, fumble = option1 == "@" ? [option1_value, option2_value] : [option2_value, option1_value]

return [critical&.to_i || CRITICAL, fumble&.to_i || FUMBLE]
end

def murmurChantPrayInvoke(command)
m = /^MCPI(\+?\d+)?\$(\d+)$/i.match(command)
unless m
Expand Down
99 changes: 99 additions & 0 deletions test/data/GoblinSlayer.toml
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,105 @@ rands = [
{ sides = 6, value = 1 },
]

[[ test ]]
game_system = "GoblinSlayer"
input = "GS@10"
output = "(GS@10) > 10[5,5] > 10 > 大成功"
rands = [
{ sides = 6, value = 5 },
{ sides = 6, value = 5 },
]

[[ test ]]
game_system = "GoblinSlayer"
input = "GS@10>=9"
output = "(GS@10>=9) > 10[5,5] > 10 > 大成功"
rands = [
{ sides = 6, value = 5 },
{ sides = 6, value = 5 },
]

[[ test ]]
game_system = "GoblinSlayer"
input = "GS@10"
output = "(GS@10) > 9[4,5] > 9"
rands = [
{ sides = 6, value = 4 },
{ sides = 6, value = 5 },
]

[[ test ]]
game_system = "GoblinSlayer"
input = "GS@10>=9"
output = "(GS@10>=9) > 9[4,5] > 9 > 成功"
rands = [
{ sides = 6, value = 4 },
{ sides = 6, value = 5 },
]

[[ test ]]
game_system = "GoblinSlayer"
input = "GS+1@10"
output = "(GS+1@10) > 1 + 9[4,5] > 10"
rands = [
{ sides = 6, value = 4 },
{ sides = 6, value = 5 },
]

[[ test ]]
game_system = "GoblinSlayer"
input = "GS#3"
output = "(GS#3) > 3[1,2] > 3 > 大失敗"
rands = [
{ sides = 6, value = 1 },
{ sides = 6, value = 2 },
]

[[ test ]]
game_system = "GoblinSlayer"
input = "GS#3"
output = "(GS#3) > 4[2,2] > 4"
rands = [
{ sides = 6, value = 2 },
{ sides = 6, value = 2 },
]

[[ test ]]
game_system = "GoblinSlayer"
input = "GS1#3"
output = "(GS1#3) > 1 + 3[1,2] > 4 > 大失敗"
rands = [
{ sides = 6, value = 1 },
{ sides = 6, value = 2 },
]

[[ test ]]
game_system = "GoblinSlayer"
input = "GS@9#4"
output = "(GS@9#4) > 9[4,5] > 9 > 大成功"
rands = [
{ sides = 6, value = 4 },
{ sides = 6, value = 5 },
]

[[ test ]]
game_system = "GoblinSlayer"
input = "GS@9#4"
output = "(GS@9#4) > 4[2,2] > 4 > 大失敗"
rands = [
{ sides = 6, value = 2 },
{ sides = 6, value = 2 },
]

[[ test ]]
game_system = "GoblinSlayer"
input = "GS#4@9"
output = "(GS#4@9) > 4[2,2] > 4 > 大失敗"
rands = [
{ sides = 6, value = 2 },
{ sides = 6, value = 2 },
]

[[ test ]]
game_system = "GoblinSlayer"
input = "GS>5"
Expand Down