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

[StellarKnights] アタック判定のダイス数指定において加算・除算をあつかえるように #465

25 changes: 19 additions & 6 deletions lib/bcdice/game_system/StellarKnights.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ class StellarKnights < Base
d省略時はダイスを振った結果のみ表示。(nSKはnB6と同じ)

4SK: ダイスを4個振って、その結果を表示
4+2SK: ダイスを4+2 (=6) 個振って、その結果を表示
5/2SK: ダイスを5個の半分 (=2) 個振って、その結果を表示
(5+3)/2SK: ダイスを(5+3)個の半分 (=4) 個振って、その結果を表示
5SK3: 【アタック判定:5ダイス】、対象の防御力を3として成功数を表示
3SK,1>6: ダイスを3個振り、出目が1のダイスを全て6に変更し、その結果を表示
6SK4,1>6,2>6: 【アタック判定:6ダイス】、出目が1と2のダイスを全て6に変更、対象の防御力を4として成功数を表示
Expand Down Expand Up @@ -75,8 +78,12 @@ def eval_game_system_specific_command(command)

if (table = self.class::TABLES[command])
table.roll(@randomizer)
elsif (m = /(\d+)SK(\d)?((,\d>\d)+)?/.match(command))
resolute_action(m[1].to_i, m[2] && m[2].to_i, m[3], command)
elsif (m = %r{([()+/\d]+)SK(\d)?((,\d>\d)+)?}.match(command))
num_dices = Arithmetic.eval(m[1], round_type: RoundType::FLOOR)

unless num_dices.nil?
resolute_action(num_dices, m[2] && m[2].to_i, m[3])
end
elsif command == 'STB2'
roll_all_situation_b2_tables
elsif command == 'ALLS'
Expand All @@ -94,13 +101,12 @@ def eval_game_system_specific_command(command)
# @param [Integer] num_dices
# @param [Integer | nil] defence
# @param [String] dice_change_text
# @param [String] command
# @return [Result, String]
def resolute_action(num_dices, defence, dice_change_text, command)
def resolute_action(num_dices, defence, dice_change_text)
dices = @randomizer.roll_barabara(num_dices, 6).sort
dice_text = dices.join(",")

output = "(#{command}) > #{dice_text}"
output = "(#{remake_command(num_dices, defence, dice_change_text)}) > #{dice_text}"
if dices.empty?
return output + translate("StellarKnights.SK.no_dice_error")
end
Expand Down Expand Up @@ -132,6 +138,13 @@ def resolute_action(num_dices, defence, dice_change_text, command)
end
end

def remake_command(num_dices, defence, dice_change_text)
command = "#{num_dices}SK"
command += defence.to_s unless defence.nil?
command += dice_change_text unless dice_change_text.nil?
command
end

def parse_dice_change_rules(text)
return [] if text.nil?

Expand Down Expand Up @@ -213,7 +226,7 @@ def translate_tables(locale)

TABLES = translate_tables(:ja_jp)

register_prefix('\d+SK', 'STB2', 'ALLS', 'PET', 'FT', TABLES.keys)
register_prefix('[()+\/\d]+SK', 'STB2', 'ALLS', 'PET', 'FT', TABLES.keys)
end
end
end
3 changes: 3 additions & 0 deletions lib/bcdice/game_system/StellarKnights_Korean.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ class StellarKnights_Korean < StellarKnights
d 생략 시 다이스를 굴린 결과만 표시. (nSK는 nB6과 동일)

4SK: 다이스 4개를 굴린 결과 표시.
4+2SK: ダイスを4+2 (=6) 個振って、その結果を表示
5/2SK: ダイスを5個の半分 (=2) 個振って、その結果を表示
(5+3)/2SK: ダイスを(5+3)個の半分 (=4) 個振って、その結果を表示
5SK3: 【공격 판정: 5다이스】, 대상의 방어력을 3으로 계산해 성공 수 표시.
3SK,1>6: 다이스 3개 굴림, 1이 나오면 전부 6으로 변경, 대상의 방어력을 4로 계산해 성공 수 표시.
6SK4,1>6,2>6: 【공격 판정: 6다이스】, 1과 2가 나오면 전부 6으로 변경, 대상의 방어력을 4로 계산해 성공 수 표시.
Expand Down
60 changes: 60 additions & 0 deletions test/data/StellarKnights.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,66 @@ input = "0SK"
output = "(0SK) > ダイスが 0 個です(アタック判定が発生しません)"
rands = []

[[ test ]]
game_system = "StellarKnights"
input = "4+2SK"
output = "(6SK) > 1,1,3,4,5,6"
rands = [
{ sides = 6, value = 5 },
{ sides = 6, value = 1 },
{ sides = 6, value = 3 },
{ sides = 6, value = 4 },
{ sides = 6, value = 6 },
{ sides = 6, value = 1 },
]

[[ test ]]
game_system = "StellarKnights"
input = "(4+2)SK"
output = "(6SK) > 1,1,3,4,5,6"
rands = [
{ sides = 6, value = 5 },
{ sides = 6, value = 1 },
{ sides = 6, value = 3 },
{ sides = 6, value = 4 },
{ sides = 6, value = 6 },
{ sides = 6, value = 1 },
]

[[ test ]]
game_system = "StellarKnights"
input = "4/2SK"
output = "(2SK) > 1,5"
rands = [
{ sides = 6, value = 5 },
{ sides = 6, value = 1 },
]

[[ test ]]
game_system = "StellarKnights"
input = "5/2SK"
output = "(2SK) > 1,5"
rands = [
{ sides = 6, value = 5 },
{ sides = 6, value = 1 },
]

[[ test ]]
game_system = "StellarKnights"
input = "(4+2)/2SK"
output = "(3SK) > 1,3,5"
rands = [
{ sides = 6, value = 5 },
{ sides = 6, value = 1 },
{ sides = 6, value = 3 },
]

[[ test ]]
game_system = "StellarKnights"
input = "(4+2/2SK"
output = ""
rands = []

[[ test ]]
game_system = "StellarKnights"
input = "5SK3"
Expand Down
60 changes: 60 additions & 0 deletions test/data/StellarKnights_Korean.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,66 @@ rands = [
{ sides = 6, value = 4 },
]

[[ test ]]
game_system = "StellarKnights:Korean"
input = "4+2SK"
output = "(6SK) > 1,1,3,4,5,6"
rands = [
{ sides = 6, value = 5 },
{ sides = 6, value = 1 },
{ sides = 6, value = 3 },
{ sides = 6, value = 4 },
{ sides = 6, value = 6 },
{ sides = 6, value = 1 },
]

[[ test ]]
game_system = "StellarKnights:Korean"
input = "(4+2)SK"
output = "(6SK) > 1,1,3,4,5,6"
rands = [
{ sides = 6, value = 5 },
{ sides = 6, value = 1 },
{ sides = 6, value = 3 },
{ sides = 6, value = 4 },
{ sides = 6, value = 6 },
{ sides = 6, value = 1 },
]

[[ test ]]
game_system = "StellarKnights:Korean"
input = "4/2SK"
output = "(2SK) > 1,5"
rands = [
{ sides = 6, value = 5 },
{ sides = 6, value = 1 },
]

[[ test ]]
game_system = "StellarKnights:Korean"
input = "5/2SK"
output = "(2SK) > 1,5"
rands = [
{ sides = 6, value = 5 },
{ sides = 6, value = 1 },
]

[[ test ]]
game_system = "StellarKnights:Korean"
input = "(4+2)/2SK"
output = "(3SK) > 1,3,5"
rands = [
{ sides = 6, value = 5 },
{ sides = 6, value = 1 },
{ sides = 6, value = 3 },
]

[[ test ]]
game_system = "StellarKnights:Korean"
input = "(4+2/2SK"
output = ""
rands = []

[[ test ]]
game_system = "StellarKnights:Korean"
input = "5SK3"
Expand Down