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

[Emoklore] Result対応 #459

Merged
merged 1 commit into from
May 14, 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
39 changes: 22 additions & 17 deletions lib/bcdice/game_system/Emoklore.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def eval_game_system_specific_command(command)
# ダイスロールの共通処理
# @param [Integer] num_dice
# @param [Integer] success_threshold
# @return [String]
# @return [Result]
def dice_roll(num_dice, success_threshold)
# ダイスを振った結果を配列として取得
values = @randomizer.roll_barabara(num_dice, 10)
Expand All @@ -65,33 +65,35 @@ def dice_roll(num_dice, success_threshold)

# 成功値
success_value = 2 * critical + success - fumble
result = compare_result(success_value)

"#{values} > #{success_value} > #{result_text(success_value)}"
result.text = "#{values} > #{success_value} > #{result.text}"
return result
end

# @param [Integer] success
# @return [String]
def result_text(success)
# @return [Result]
def compare_result(success)
if success < 0
"ファンブル!"
Result.fumble("ファンブル!")
elsif success == 0
"失敗!"
Result.failure("失敗!")
elsif success == 1
"成功!"
Result.success("成功!")
elsif success == 2
"ダブル!"
Result.critical("ダブル!")
elsif success == 3
"トリプル!"
Result.critical("トリプル!")
elsif success <= 9
"ミラクル!"
Result.critical("ミラクル!")
else
"カタストロフ!"
Result.critical("カタストロフ!")
end
end

# 技能判定
# @param [String] command コマンド
# @return [String, nil] コマンドの結果
# @return [Result, nil] コマンドの結果
def roll_dm(command)
m = /^(\d+)?DM<=(\d+)$/.match(command)
unless m
Expand All @@ -105,14 +107,15 @@ def roll_dm(command)
end

# ダイスロール本体
ret_str = dice_roll(num_dice, success_threshold)
result = dice_roll(num_dice, success_threshold)

return "(#{num_dice}DM<=#{success_threshold}) > #{ret_str}"
result.text = "(#{num_dice}DM<=#{success_threshold}) > #{result.text}"
return result
end

# 取得技能判定
# @param [String] command コマンド
# @return [String, nil] コマンドの結果
# @return [Result, nil] コマンドの結果
def roll_da(command)
m = /^(B|\d+)?DA(\d+)(\+\d+)?$/.match(command)
unless m
Expand All @@ -123,8 +126,10 @@ def roll_da(command)
num_dice = (m[1] == "B" ? 1 : (m[1]&.to_i || 1)) + bonus
success_threshold = m[1].to_i + m[2].to_i

ret_str = dice_roll(num_dice, success_threshold)
"(#{command}) > (#{num_dice}DM<=#{success_threshold}) > #{ret_str}"
result = dice_roll(num_dice, success_threshold)

result.text = "(#{command}) > (#{num_dice}DM<=#{success_threshold}) > #{result.text}"
return result
end
end
end
Expand Down
36 changes: 36 additions & 0 deletions test/data/Emoklore.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ rands = [
game_system = "Emoklore"
input = "1DM<=5"
output = "(1DM<=5) > [6] > 0 > 失敗!"
failure = true
rands = [
{ sides = 10, value = 6 },
]
Expand All @@ -19,6 +20,7 @@ rands = [
game_system = "Emoklore"
input = "1DM<=5"
output = "(1DM<=5) > [5] > 1 > 成功!"
success = true
rands = [
{ sides = 10, value = 5 },
]
Expand All @@ -27,6 +29,8 @@ rands = [
game_system = "Emoklore"
input = "1DM<=5"
output = "(1DM<=5) > [1] > 2 > ダブル!"
success = true
critical = true
rands = [
{ sides = 10, value = 1 },
]
Expand All @@ -35,6 +39,8 @@ rands = [
game_system = "Emoklore"
input = "DM<=5"
output = "(1DM<=5) > [1] > 2 > ダブル!"
success = true
critical = true
rands = [
{ sides = 10, value = 1 },
]
Expand All @@ -43,6 +49,8 @@ rands = [
game_system = "Emoklore"
input = "2DM<=5"
output = "(2DM<=5) > [1, 6] > 2 > ダブル!"
success = true
critical = true
rands = [
{ sides = 10, value = 1 },
{ sides = 10, value = 6 },
Expand All @@ -52,6 +60,8 @@ rands = [
game_system = "Emoklore"
input = "2DM<=5"
output = "(2DM<=5) > [1, 1] > 4 > ミラクル!"
success = true
critical = true
rands = [
{ sides = 10, value = 1 },
{ sides = 10, value = 1 },
Expand All @@ -61,6 +71,8 @@ rands = [
game_system = "Emoklore"
input = "10DM<=3"
output = "(10DM<=3) > [4, 7, 10, 3, 6, 9, 2, 5, 8, 1] > 3 > トリプル!"
success = true
critical = true
rands = [
{ sides = 10, value = 4 },
{ sides = 10, value = 7 },
Expand All @@ -78,6 +90,8 @@ rands = [
game_system = "Emoklore"
input = "10DM<=3"
output = "(10DM<=3) > [10, 10, 10, 1, 1, 1, 1, 1, 1, 1] > 11 > カタストロフ!"
success = true
critical = true
rands = [
{ sides = 10, value = 10 },
{ sides = 10, value = 10 },
Expand All @@ -95,6 +109,8 @@ rands = [
game_system = "Emoklore"
input = "10DM<=3"
output = "(10DM<=3) > [10, 10, 5, 1, 1, 1, 1, 1, 1, 1] > 12 > カタストロフ!"
success = true
critical = true
rands = [
{ sides = 10, value = 10 },
{ sides = 10, value = 10 },
Expand All @@ -112,6 +128,8 @@ rands = [
game_system = "Emoklore"
input = "10DM<=3"
output = "(10DM<=3) > [10, 10, 10, 10, 1, 1, 1, 1, 1, 1] > 8 > ミラクル!"
success = true
critical = true
rands = [
{ sides = 10, value = 10 },
{ sides = 10, value = 10 },
Expand All @@ -129,6 +147,8 @@ rands = [
game_system = "Emoklore"
input = "10DM<=3"
output = "(10DM<=3) > [10, 10, 10, 10, 1, 4, 5, 6, 7, 8] > -2 > ファンブル!"
failure = true
fumble = true
rands = [
{ sides = 10, value = 10 },
{ sides = 10, value = 10 },
Expand All @@ -146,6 +166,7 @@ rands = [
game_system = "Emoklore"
input = "2DA3"
output = "(2DA3) > (2DM<=5) > [8, 5] > 1 > 成功!"
success = true
rands = [
{ sides = 10, value = 8 },
{ sides = 10, value = 5 },
Expand All @@ -155,6 +176,7 @@ rands = [
game_system = "Emoklore"
input = "2DA3+1"
output = "(2DA3+1) > (3DM<=5) > [8, 5, 6] > 1 > 成功!"
success = true
rands = [
{ sides = 10, value = 8 },
{ sides = 10, value = 5 },
Expand All @@ -165,6 +187,7 @@ rands = [
game_system = "Emoklore"
input = "DA3+1"
output = "(DA3+1) > (2DM<=3) > [8, 6] > 0 > 失敗!"
failure = true
rands = [
{ sides = 10, value = 8 },
{ sides = 10, value = 6 },
Expand All @@ -174,6 +197,7 @@ rands = [
game_system = "Emoklore"
input = "1DA3"
output = "(1DA3) > (1DM<=4) > [2] > 1 > 成功!"
success = true
rands = [
{ sides = 10, value = 2 },
]
Expand All @@ -182,6 +206,8 @@ rands = [
game_system = "Emoklore"
input = "1DA3"
output = "(1DA3) > (1DM<=4) > [1] > 2 > ダブル!"
success = true
critical = true
rands = [
{ sides = 10, value = 1 },
]
Expand All @@ -190,6 +216,8 @@ rands = [
game_system = "Emoklore"
input = "bDA3"
output = "(BDA3) > (1DM<=3) > [1] > 2 > ダブル!"
success = true
critical = true
rands = [
{ sides = 10, value = 1 },
]
Expand All @@ -198,6 +226,8 @@ rands = [
game_system = "Emoklore"
input = "bDA3+5"
output = "(BDA3+5) > (6DM<=3) > [1, 2, 3, 4, 7, 8] > 4 > ミラクル!"
success = true
critical = true
rands = [
{ sides = 10, value = 1 },
{ sides = 10, value = 2 },
Expand All @@ -211,6 +241,8 @@ rands = [
game_system = "Emoklore"
input = "3DA3+5"
output = "(3DA3+5) > (8DM<=6) > [1, 2, 3, 4, 7, 8, 9, 10] > 4 > ミラクル!"
success = true
critical = true
rands = [
{ sides = 10, value = 1 },
{ sides = 10, value = 2 },
Expand All @@ -226,6 +258,8 @@ rands = [
game_system = "Emoklore"
input = "3DA3+9"
output = "(3DA3+9) > (12DM<=6) > [10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10] > -12 > ファンブル!"
failure = true
fumble = true
rands = [
{ sides = 10, value = 10 },
{ sides = 10, value = 10 },
Expand All @@ -245,6 +279,8 @@ rands = [
game_system = "Emoklore"
input = "3DA3+4 (技能:調査)"
output = "(3DA3+4) > (7DM<=6) > [10, 10, 10, 10, 10, 10, 10] > -7 > ファンブル!"
failure = true
fumble = true
rands = [
{ sides = 10, value = 10 },
{ sides = 10, value = 10 },
Expand Down