diff --git a/lib/bcdice/game_system.rb b/lib/bcdice/game_system.rb index a028fa5ee..5b888d651 100644 --- a/lib/bcdice/game_system.rb +++ b/lib/bcdice/game_system.rb @@ -56,6 +56,7 @@ require "bcdice/game_system/DarkSouls" require "bcdice/game_system/DeadlineHeroes" require "bcdice/game_system/DemonParasite" +require "bcdice/game_system/DemonSpike" require "bcdice/game_system/DesperateRun" require "bcdice/game_system/DetatokoSaga" require "bcdice/game_system/DetatokoSaga_Korean" diff --git a/lib/bcdice/game_system/DemonSpike.rb b/lib/bcdice/game_system/DemonSpike.rb new file mode 100644 index 000000000..3c4758e1d --- /dev/null +++ b/lib/bcdice/game_system/DemonSpike.rb @@ -0,0 +1,89 @@ +# frozen_string_literal: true + +module BCDice + module GameSystem + class DemonSpike < Base + # ゲームシステムの識別子 + ID = 'DemonSpike' + + # ゲームシステム名 + NAME = 'デモンスパイク' + + # ゲームシステム名の読みがな + SORT_KEY = 'てもんすはいく' + + # ダイスボットの使い方 + HELP_MESSAGE = <<~INFO_MESSAGE_TEXT + ・行為判定 xDS+y +  行為判定を行い、達成値、成否、成功度を出力する。 +  x: ダイス数(省略:2) +  y: 能力値やスパイク能力による達成値の修正(省略可) + INFO_MESSAGE_TEXT + + register_prefix('\d*DS') + + def eval_game_system_specific_command(command) + roll_action(command) + end + + private + + def roll_action(command) + parser = Command::Parser.new("DS", round_type: @round_type) + .enable_prefix_number + .restrict_cmp_op_to(nil) + parsed = parser.parse(command) + unless parsed + return nil + end + + parsed.prefix_number ||= 2 + if parsed.prefix_number < 2 + return nil + end + + step = roll_step(parsed.prefix_number) + step_list = [step] + while step[:dice_sum] == 10 + step = roll_step(parsed.prefix_number) + step_list.push(step) + end + + is_fumble = step_list[0][:dice_sum] == 2 + total = is_fumble ? 0 : step_list.sum { |s| s[:dice_sum] } + parsed.modify_number + success_level = total / 10 + is_success = total >= 10 + + res = + if is_success + "成功, 成功度#{success_level}" + elsif is_fumble + "自動的失敗" + else + "失敗" + end + + sequence = [ + "(#{parsed})", + step_list.map { |s| "#{s[:dice_sum]}[#{s[:dice_list].join(',')}]" }, + total, + res, + ].flatten + + return Result.new.tap do |r| + r.condition = is_success + r.critical = step_list.length > 1 + r.fumble = is_fumble + r.text = sequence.join(" > ") + end + end + + def roll_step(times) + dice_list = @randomizer.roll_barabara(times, 6).sort.reverse + dice_sum = (dice_list[0] + dice_list[1]).clamp(2, 10) + + return {dice_list: dice_list, dice_sum: dice_sum} + end + end + end +end diff --git a/test/data/DemonSpike.toml b/test/data/DemonSpike.toml new file mode 100644 index 000000000..31b25c8cf --- /dev/null +++ b/test/data/DemonSpike.toml @@ -0,0 +1,141 @@ +[[ test ]] +game_system = "DemonSpike" +input = "DS+7" +output = "(2DS+7) > 9[5,4] > 16 > 成功, 成功度1" +success = true +rands = [ + { sides = 6, value = 4 }, + { sides = 6, value = 5 }, +] + +[[ test ]] +game_system = "DemonSpike" +input = "DS+7" +output = "(2DS+7) > 10[6,5] > 10[6,6] > 2[1,1] > 29 > 成功, 成功度2" +success = true +critical = true +rands = [ + { sides = 6, value = 6 }, + { sides = 6, value = 5 }, + { sides = 6, value = 6 }, + { sides = 6, value = 6 }, + { sides = 6, value = 1 }, + { sides = 6, value = 1 }, +] + +[[ test ]] +game_system = "DemonSpike" +input = "DS+8" +output = "(2DS+8) > 10[6,5] > 10[6,6] > 2[1,1] > 30 > 成功, 成功度3" +success = true +critical = true +rands = [ + { sides = 6, value = 6 }, + { sides = 6, value = 5 }, + { sides = 6, value = 6 }, + { sides = 6, value = 6 }, + { sides = 6, value = 1 }, + { sides = 6, value = 1 }, +] + +[[ test ]] +game_system = "DemonSpike" +input = "DS+6" +output = "(2DS+6) > 3[2,1] > 9 > 失敗" +failure = true +rands = [ + { sides = 6, value = 2 }, + { sides = 6, value = 1 }, +] + +[[ test ]] +game_system = "DemonSpike" +input = "DS+7" +output = "(2DS+7) > 2[1,1] > 0 > 自動的失敗" +failure = true +fumble = true +rands = [ + { sides = 6, value = 1 }, + { sides = 6, value = 1 }, +] + +[[ test ]] +game_system = "DemonSpike" +input = "DS" +output = "(2DS) > 10[5,5] > 7[5,2] > 17 > 成功, 成功度1" +success = true +critical = true +rands = [ + { sides = 6, value = 5 }, + { sides = 6, value = 5 }, + { sides = 6, value = 5 }, + { sides = 6, value = 2 }, +] + +[[ test ]] +game_system = "DemonSpike" +input = "DS" +output = "(2DS) > 9[5,4] > 9 > 失敗" +failure = true +rands = [ + { sides = 6, value = 4 }, + { sides = 6, value = 5 }, +] + +[[ test ]] +game_system = "DemonSpike" +input = "3DS+7" +output = "(3DS+7) > 9[5,4,3] > 16 > 成功, 成功度1" +success = true +rands = [ + { sides = 6, value = 4 }, + { sides = 6, value = 5 }, + { sides = 6, value = 3 }, +] + +[[ test ]] +game_system = "DemonSpike" +input = "3DS+7" +output = "(3DS+7) > 3[2,1,1] > 10 > 成功, 成功度1" +success = true +rands = [ + { sides = 6, value = 1 }, + { sides = 6, value = 1 }, + { sides = 6, value = 2 }, +] + +[[ test ]] +game_system = "DemonSpike" +input = "3DS+7" +output = "(3DS+7) > 2[1,1,1] > 0 > 自動的失敗" +failure = true +fumble = true +rands = [ + { sides = 6, value = 1 }, + { sides = 6, value = 1 }, + { sides = 6, value = 1 }, +] + +[[ test ]] +game_system = "DemonSpike" +input = "3DS+7" +output = "(3DS+7) > 10[6,5,1] > 10[6,6,1] > 2[1,1,1] > 29 > 成功, 成功度2" +success = true +critical = true +rands = [ + { sides = 6, value = 6 }, + { sides = 6, value = 5 }, + { sides = 6, value = 1 }, + { sides = 6, value = 6 }, + { sides = 6, value = 6 }, + { sides = 6, value = 1 }, + { sides = 6, value = 1 }, + { sides = 6, value = 1 }, + { sides = 6, value = 1 }, +] + +[[ test ]] +game_system = "DemonSpike" +input = "1DS" +output = "" +rands = []