Skip to content

Commit

Permalink
Merge pull request #612 from Faceless192x/update/dnd5ed
Browse files Browse the repository at this point in the history
ダンジョンズ&ドラゴンス第5版、武器の両手持ちのダメージに対応
  • Loading branch information
ysakasin authored Mar 25, 2023
2 parents a43102c + 232e67d commit 5cbb3f3
Show file tree
Hide file tree
Showing 2 changed files with 188 additions and 10 deletions.
74 changes: 64 additions & 10 deletions lib/bcdice/game_system/DungeonsAndDragons5.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,26 @@ class DungeonsAndDragons5 < Base

# ダイスボットの使い方
HELP_MESSAGE = <<~INFO_MESSAGE_TEXT
・攻撃ロール AT[x][>=t][y]
・攻撃ロール AT[x][@c][>=t][y]
 x:+-修正。省略可。
 y:有利(A), 不利(D)。省略可。
 c:クリティカル値。省略可。
 t:敵のアーマークラス。>=を含めて省略可。
 y:有利(A), 不利(D)。省略可。
 ファンブル/失敗/成功/クリティカル を自動判定。
 例)AT AT>=10 AT+5>=18 AT-3>=16 ATA AT>=10A AT+3>=18A AT-3>=16 ATD AT>=10D AT+5>=18D AT-5>=16D
  AT@19 AT+5@18 AT-2@19>=15
・能力値判定 AR[x][>=t][y]
 攻撃ロールと同様。失敗/成功を自動判定。
 例)AR AR>=10 AR+5>=18 AR-3>=16 ARA AR>=10A AR+3>=18A AR-3>=16 ARD AR>=10D AR+5>=18D AR-5>=16D
・両手持ちのダメージ 2HnDx[m]
 n:ダイスの個数
 x:ダイスの面数
 m:+-修正。省略可。
 パラディンとファイターの武器の両手持ちによるダメージダイスの1,2の出目の振り直しを行います。
 例)2H3D6 2H1D10+3 2H2D8-1
INFO_MESSAGE_TEXT

register_prefix('AT([+-]\d+)?(>=\d+)?[AD]?', 'AR([+-]\d+)?(>=\d+)?[AD]?')
register_prefix('AT([+-]\d+)?(@\d+)?(>=\d+)?[AD]?', 'AR([+-]\d+)?(>=\d+)?[AD]?', '2H(\d+)D(\d+)([+-]\d+)?')

def initialize(command)
super(command)
Expand All @@ -36,7 +42,7 @@ def initialize(command)
end

def eval_game_system_specific_command(command)
attack_roll(command) || ability_roll(command)
attack_roll(command) || ability_roll(command) || twohands_damage_roll(command)
end

def number_with_sign_from_int(number)
Expand All @@ -49,20 +55,27 @@ def number_with_sign_from_int(number)
end
end

# 攻撃ロール
def attack_roll(command)
m = /^AT([-+]\d+)?(>=(\d+))?([AD]?)/.match(command)
m = /^AT([-+]\d+)?(@(\d+))?(>=(\d+))?([AD]?)/.match(command)
unless m
return nil
end

modify = m[1].to_i
difficulty = m[3].to_i
advantage = m[4]
critical_no = m[3].to_i
difficulty = m[5].to_i
advantage = m[6]

usedie = 0
roll_die = ""

dice_command = "AT#{number_with_sign_from_int(modify)}"
if critical_no > 0
dice_command += "@#{critical_no}"
else
critical_no = 20
end
if difficulty > 0
dice_command += ">=#{difficulty}"
end
Expand Down Expand Up @@ -96,7 +109,7 @@ def attack_roll(command)
end

result = Result.new
if usedie == 20
if usedie >= critical_no
result.critical = true
result.success = true
output.push("クリティカル")
Expand Down Expand Up @@ -124,6 +137,7 @@ def attack_roll(command)
end
end

# 能力値ロール
def ability_roll(command)
m = /^AR([-+]\d+)?(>=(\d+))?([AD]?)/.match(command)
unless m
Expand Down Expand Up @@ -191,6 +205,46 @@ def ability_roll(command)
end
end
end

# 武器の両手持ちダメージ
def twohands_damage_roll(command)
m = /^2H(\d+)D(\d+)([+-]\d+)?/.match(command)
unless m
return nil
end

dice_count = m[1].to_i
dice_number = m[2].to_i
modify = m[3].to_i
mod_str = number_with_sign_from_int(modify)
output = ["(2H#{dice_count}D#{dice_number}#{mod_str})"]

dice = @randomizer.roll_barabara(dice_count, dice_number)
roll_dice = "[" + dice.join(",") + "]"
output.push("#{roll_dice}#{mod_str}")

ex_dice = []
new_dice = []
sum_dice = 0
dice.each do |num|
if num.to_i > 2
sum_dice += num.to_i
ex_dice.push(num)
else
one_die = @randomizer.roll_once(dice_number)
sum_dice += one_die.to_i
new_dice.push(one_die)
end
end
unless new_dice.empty?
output.push("[" + ex_dice.join(",") + "][" + new_dice.join(",") + "]#{mod_str}")
end
output.push((sum_dice + modify).to_s)

Result.new.tap do |r|
r.text = output.join(" > ")
end
end
end
end
end
124 changes: 124 additions & 0 deletions test/data/DungeonsAndDragons5.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,36 @@ rands = [
{ sides = 20, value = 20 },
]

[[ test ]]
game_system = "DungeonsAndDragons5"
input = "AT@19 クリティカル"
output = "(AT@19) > 19 > クリティカル"
critical = true
success = true
rands = [
{ sides = 20, value = 19 },
]

[[ test ]]
game_system = "DungeonsAndDragons5"
input = "AT@18 クリティカル"
output = "(AT@18) > 18 > クリティカル"
critical = true
success = true
rands = [
{ sides = 20, value = 18 },
]

[[ test ]]
game_system = "DungeonsAndDragons5"
input = "AT@18 クリティカル"
output = "(AT@18) > 19 > クリティカル"
critical = true
success = true
rands = [
{ sides = 20, value = 19 },
]

[[ test ]]
game_system = "DungeonsAndDragons5"
input = "AT ファンブル"
Expand Down Expand Up @@ -64,6 +94,16 @@ rands = [
{ sides = 20, value = 20 },
]

[[ test ]]
game_system = "DungeonsAndDragons5"
input = "AT@18>=10 クリティカルの表示確認"
output = "(AT@18>=10) > 18 > クリティカル"
success = true
critical = true
rands = [
{ sides = 20, value = 18 },
]

[[ test ]]
game_system = "DungeonsAndDragons5"
input = "AT>=10 ファンブルの表示確認"
Expand Down Expand Up @@ -145,6 +185,16 @@ rands = [
{ sides = 20, value = 20 },
]

[[ test ]]
game_system = "DungeonsAndDragons5"
input = "AT+3@18>=10 クリティカルの表示確認"
output = "(AT+3@18>=10) > 18+3 > 21 > クリティカル"
success = true
critical = true
rands = [
{ sides = 20, value = 18 },
]

[[ test ]]
game_system = "DungeonsAndDragons5"
input = "AT-3>=10 クリティカルの表示確認"
Expand All @@ -155,6 +205,16 @@ rands = [
{ sides = 20, value = 20 },
]

[[ test ]]
game_system = "DungeonsAndDragons5"
input = "AT-3@18>=10 クリティカルの表示確認"
output = "(AT-3@18>=10) > 18-3 > 15 > クリティカル"
success = true
critical = true
rands = [
{ sides = 20, value = 18 },
]

[[ test ]]
game_system = "DungeonsAndDragons5"
input = "AT+3>=10 ファンブルの表示確認"
Expand Down Expand Up @@ -406,3 +466,67 @@ rands = [
{ sides = 20, value = 3 },
]


[[ test ]]
game_system = "DungeonsAndDragons5"
input = "2H3D6 両手持ちダメージ、振り直しなし、修正なし"
output = "(2H3D6) > [5,4,3] > 12"
rands = [
{ sides = 6, value = 5 },
{ sides = 6, value = 4 },
{ sides = 6, value = 3 },
]

[[ test ]]
game_system = "DungeonsAndDragons5"
input = "2H3D6+3 振り直しなし、+修正"
output = "(2H3D6+3) > [3,4,5]+3 > 15"
rands = [
{ sides = 6, value = 3 },
{ sides = 6, value = 4 },
{ sides = 6, value = 5 },
]

[[ test ]]
game_system = "DungeonsAndDragons5"
input = "2H3D6-5 振り直しなし、-修正"
output = "(2H3D6-5) > [5,4,3]-5 > 7"
rands = [
{ sides = 6, value = 5 },
{ sides = 6, value = 4 },
{ sides = 6, value = 3 },
]

[[ test ]]
game_system = "DungeonsAndDragons5"
input = "2H3D6 振り直しあり、修正なし"
output = "(2H3D6) > [5,4,2] > [5,4][4] > 13"
rands = [
{ sides = 6, value = 5 },
{ sides = 6, value = 4 },
{ sides = 6, value = 2 },
{ sides = 6, value = 4 },
]

[[ test ]]
game_system = "DungeonsAndDragons5"
input = "2H3D6+5 振り直しあり、+修正"
output = "(2H3D6+5) > [5,2,4]+5 > [5,4][4]+5 > 18"
rands = [
{ sides = 6, value = 5 },
{ sides = 6, value = 2 },
{ sides = 6, value = 4 },
{ sides = 6, value = 4 },
]

[[ test ]]
game_system = "DungeonsAndDragons5"
input = "2H3D6-3 振り直しあり、-修正"
output = "(2H3D6-3) > [5,4,2]-3 > [5,4][6]-3 > 12"
rands = [
{ sides = 6, value = 5 },
{ sides = 6, value = 4 },
{ sides = 6, value = 2 },
{ sides = 6, value = 6 },
]

0 comments on commit 5cbb3f3

Please sign in to comment.