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

SW2.5のモンストラスロアで追加された森羅魔法のダメージ算出ダイスに対応 #372

Merged
merged 11 commits into from
Feb 13, 2021
Merged
48 changes: 47 additions & 1 deletion lib/bcdice/game_system/SwordWorld2_5.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,31 @@ class SwordWorld2_5 < SwordWorld2_0

・絡み効果表 (TT)
 絡み効果表を出すことができます。

・ドルイドの物理魔法用表 (Dru[2-6の値,7-9の値,10-12の値])
 例)Dru[0,3,6]+10-3
INFO_MESSAGE_TEXT

register_prefix('H?K\d+.*', 'Gr(\d+)?', '2D6?@\d+.*', 'FT', 'TT')
register_prefix('H?K\d+.*', 'Gr(\d+)?', '2D6?@\d+.*', 'FT', 'TT', 'Dru\[\d+,\d+,\d+\].*')

DRUID_DICE_RE = /^dru\[(\d+),(\d+),(\d+)\]/i.freeze

def eval_game_system_specific_command(command)
case command
when DRUID_DICE_RE
Copy link
Member

Choose a reason for hiding this comment

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

Command::Parser で使いまわさないため、定数で使いまわさずにリテラルを直接指定してください

power_list = Regexp.last_match.captures.map(&:to_i)
druid_parser = Command::Parser.new(DRUID_DICE_RE, round_type: BCDice::RoundType::CEIL)
Copy link
Member

Choose a reason for hiding this comment

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

Command::Parserに渡す正規表現で ^ を使うのは想定していないため、使いまわさずにリテラルで指定してください。


cmd = druid_parser.parse(command)
unless cmd
return nil
end

druid_dice(cmd, power_list)
else
super(command)
end
end

# コマンド実行前にメッセージを置換する
# @param [String] string 受信したメッセージ
Expand All @@ -82,6 +104,30 @@ def replace_text(string)
end
end

def druid_dice(command, power_list)
dice_list = @randomizer.roll_barabara(2, 6)
dice_total = dice_list.sum()
offset =
case dice_total
when 2..6
0
when 7..9
1
when 10..12
2
end
power = power_list[offset]
total = power + command.modify_number
sequence = [
"(#{command.command.capitalize}#{Format.modifier(command.modify_number)})",
"2D[#{dice_list.join(',')}]=#{dice_total}",
"#{power}#{Format.modifier(command.modify_number)}",
total
]

return sequence.join(" > ")
end

def getRatingCommandStrings
super + "aA"
end
Expand Down
81 changes: 81 additions & 0 deletions test/data/SwordWorld2_5.toml
Original file line number Diff line number Diff line change
Expand Up @@ -731,3 +731,84 @@ output = "絡み効果表(6) → 特殊:尻尾や翼などに命中。絡め
rands = [
{ sides = 6, value = 6 },
]

[[ test ]]
game_system = "SwordWorld2.5"
input = "Dru[4,7,13]+10"
output = "(Dru[4,7,13]+10) > 2D[6,5]=11 > 13+10 > 23"
rands = [
{ sides = 6, value = 6 },
{ sides = 6, value = 5 },
]

[[ test ]]
game_system = "SwordWorld2.5"
input = "Dru[4,7,13]+10"
output = "(Dru[4,7,13]+10) > 2D[6,6]=12 > 13+10 > 23"
rands = [
{ sides = 6, value = 6 },
{ sides = 6, value = 6 },
]

[[ test ]]
game_system = "SwordWorld2.5"
input = "Dru[4,7,13]+10"
output = "(Dru[4,7,13]+10) > 2D[4,6]=10 > 13+10 > 23"
rands = [
{ sides = 6, value = 4 },
{ sides = 6, value = 6 },
]

[[ test ]]
game_system = "SwordWorld2.5"
input = "Dru[4,7,13]+10"
output = "(Dru[4,7,13]+10) > 2D[4,5]=9 > 7+10 > 17"
rands = [
{ sides = 6, value = 4 },
{ sides = 6, value = 5 },
]

[[ test ]]
game_system = "SwordWorld2.5"
input = "dru[0,3,6]+10+4-5"
output = "(Dru[0,3,6]+9) > 2D[2,3]=5 > 0+9 > 9"
rands = [
{ sides = 6, value = 2 },
{ sides = 6, value = 3 },
]

[[ test ]]
game_system = "SwordWorld2.5"
input = "dru[0,3,6]+10+4-5"
output = "(Dru[0,3,6]+9) > 2D[3,3]=6 > 0+9 > 9"
rands = [
{ sides = 6, value = 3 },
{ sides = 6, value = 3 },
]

[[ test ]]
game_system = "SwordWorld2.5"
input = "dru[0,3,6]+10+4-5"
output = "(Dru[0,3,6]+9) > 2D[4,3]=7 > 3+9 > 12"
rands = [
{ sides = 6, value = 4 },
{ sides = 6, value = 3 },
]

[[ test ]]
game_system = "SwordWorld2.5"
input = "Dru[13,16,19]+12+8-10"
output = "(Dru[13,16,19]+10) > 2D[4,4]=8 > 16+10 > 26"
rands = [
{ sides = 6, value = 4 },
{ sides = 6, value = 4 },
]

[[ test ]]
game_system = "SwordWorld2.5"
input = "Dru[13,16,19]+12+8-10"
output = "(Dru[13,16,19]+10) > 2D[4,5]=9 > 16+10 > 26"
rands = [
{ sides = 6, value = 4 },
{ sides = 6, value = 5 },
]