Skip to content

Commit

Permalink
[KillDeathBusiness] 修正値が前処理で負数になっても動くように
Browse files Browse the repository at this point in the history
Fix #272
  • Loading branch information
ysakasin committed Dec 28, 2020
1 parent e4c4fe1 commit 5b081b7
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 16 deletions.
40 changes: 24 additions & 16 deletions lib/bcdice/game_system/KillDeathBusiness.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class KillDeathBusiness < Base
# ダイスボットの使い方
HELP_MESSAGE = <<~INFO_MESSAGE_TEXT
・判定
 JDx or JDx+y or JDx-y or JDx,z or JDx+y,z JDx-y,z
 JDx or JDx±y or JDx,z JDx#z or JDx±y,z JDx±y#z
 (x=難易度、y=補正、z=ファンブル率(リスク))
・履歴表 (HST)
・願い事表 (-WT)
Expand Down Expand Up @@ -70,28 +70,29 @@ def check_2D6(total, dice_total, _dice_list, cmp_op, target)
def eval_game_system_specific_command(command)
debug("eval_game_system_specific_command command", command)

# 判定チェックは先に処理
case command
when JUDGE_DICE_REG
result = judgeDice(command)
text = translate("KillDeathBusiness.JD.name") + result
return text
if command.start_with?("JD")
judgeDice(command)
else
rollTableCommand(command)
end

# 判定以外なら表コマンドの処理に
return rollTableCommand(command)
end

JUDGE_DICE_REG = /(^|\s)JD(\d+)([+\-]\d+)?(,(\d+))?($|\s)/i.freeze
private

def judgeDice(command)
unless command.match(JUDGE_DICE_REG)
fumble_match = /,(\d+)$/.match(command)

parser = CommandParser.new(/^JD(\d+)$/).allow_cmp_op(nil)
cmd = parser.parse(fumble_match&.pre_match || command)
unless cmd
return nil
end

target = Regexp.last_match(2).to_i
modify = Regexp.last_match(3).to_i
fumble = Regexp.last_match(5).to_i
target = cmd.command.delete_prefix("JD").to_i
modify = cmd.modify_number
fumble = fumble_match ? fumble_match[1].to_i : cmd.fumble.to_i

command = judge_expr(target, modify, fumble)

result = ""

Expand Down Expand Up @@ -138,7 +139,14 @@ def judgeDice(command)
end
end

return result
return translate("KillDeathBusiness.JD.name") + result
end

def judge_expr(target, modifier, fumble)
modifier = Format.modifier(modifier)
fumble = ",#{fumble}" if fumble > 0

"JD#{target}#{modifier}#{fumble}"
end

def rollTableCommand(command)
Expand Down
18 changes: 18 additions & 0 deletions test/data/KillDeathBusiness.toml
Original file line number Diff line number Diff line change
Expand Up @@ -897,6 +897,15 @@ rands = [
{ sides = 6, value = 1 },
]

[[ test ]]
game_system = "KillDeathBusiness"
input = "JD5#4"
output = "判定【難易度5、補正0、ファンブル率4】 > 出目(4,1) > 達成値5、難易度以上なので判定成功!"
rands = [
{ sides = 6, value = 4 },
{ sides = 6, value = 1 },
]

[[ test ]]
game_system = "KillDeathBusiness"
input = "JD6,5"
Expand Down Expand Up @@ -933,6 +942,15 @@ rands = [
{ sides = 6, value = 1 },
]

[[ test ]]
game_system = "KillDeathBusiness"
input = "JD5+(1-2),4"
output = "判定【難易度5、補正-1、ファンブル率4】 > 出目(4,1) > 達成値4、難易度未満なので判定失敗!"
rands = [
{ sides = 6, value = 4 },
{ sides = 6, value = 1 },
]

[[ test ]]
game_system = "KillDeathBusiness"
input = "JD5-1,5"
Expand Down

0 comments on commit 5b081b7

Please sign in to comment.