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

ダンジョンズ&ドラゴンス第5版、武器の両手持ちのダメージに対応 #612

Merged
merged 10 commits into from
Mar 25, 2023
54 changes: 50 additions & 4 deletions lib/bcdice/game_system/DungeonsAndDragons5.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,18 @@ class DungeonsAndDragons5 < Base
 t:敵のアーマークラス。>=を含めて省略可。
 ファンブル/失敗/成功/クリティカル を自動判定。
 例)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

・能力値判定 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+)?[AD]?', 'AR([+-]\d+)?(>=\d+)?[AD]?', '2H(\d+)D(\d+)([+-]\d+)?')

def initialize(command)
super(command)
Expand All @@ -36,7 +40,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,6 +53,7 @@ def number_with_sign_from_int(number)
end
end

# 攻撃ロール
def attack_roll(command)
m = /^AT([-+]\d+)?(>=(\d+))?([AD]?)/.match(command)
unless m
Expand Down Expand Up @@ -124,6 +129,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 +197,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
if new_dice.!empty?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if new_dice.!empty?
if new_dice.empty?

記述ミスかと思いますので修正お願いします

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if じゃなくて unless を使った方が良いということでしょうか?
実は素では「if new_dice.length > 0」と書いていたらrubocop先生に「そこは .!empty? だろ」と訂正されたのでしたw

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

いえ、単に文法上 .!empty? という記法がないです。そのためテストも全て失敗しています。

if !new_dice.empty?が正しかったんですね。 unlessif ! のどちらでも問題ないです、

Copy link
Contributor Author

@Faceless192x Faceless192x Mar 22, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

なんと!文法上存在しないものがrubocopから提示されるとは考えてもみなかったですね。
そういうこともあるんだなぁ。

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
64 changes: 64 additions & 0 deletions test/data/DungeonsAndDragons5.toml
Original file line number Diff line number Diff line change
Expand Up @@ -406,3 +406,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 },
]