From 91b06e5192438e5c91135db1decb2e8e69b1625e Mon Sep 17 00:00:00 2001 From: SAKATA Sinji Date: Sun, 12 Sep 2021 19:58:59 +0900 Subject: [PATCH 1/2] FateCoreSystem --- lib/bcdice/game_system.rb | 1 + lib/bcdice/game_system/FateCoreSystem.rb | 115 ++++++++++++ test/data/FateCoreSystem.toml | 219 +++++++++++++++++++++++ 3 files changed, 335 insertions(+) create mode 100644 lib/bcdice/game_system/FateCoreSystem.rb create mode 100644 test/data/FateCoreSystem.toml diff --git a/lib/bcdice/game_system.rb b/lib/bcdice/game_system.rb index 7c822bd20..e0798e9c1 100644 --- a/lib/bcdice/game_system.rb +++ b/lib/bcdice/game_system.rb @@ -68,6 +68,7 @@ require "bcdice/game_system/Emoklore" require "bcdice/game_system/EndBreaker" require "bcdice/game_system/EtrianOdysseySRS" +require "bcdice/game_system/FateCoreSystem" require "bcdice/game_system/Fiasco" require "bcdice/game_system/Fiasco_Korean" require "bcdice/game_system/FilledWith" diff --git a/lib/bcdice/game_system/FateCoreSystem.rb b/lib/bcdice/game_system/FateCoreSystem.rb new file mode 100644 index 000000000..f82d3f351 --- /dev/null +++ b/lib/bcdice/game_system/FateCoreSystem.rb @@ -0,0 +1,115 @@ +# frozen_string_literal: true + +module BCDice + module GameSystem + class FateCoreSystem < Base + # ゲームシステムの識別子 + ID = 'FateCoreSystem' + + # ゲームシステム名 + NAME = 'Fate Core System' + + # ゲームシステム名の読みがな + SORT_KEY = 'ふえいとこあしすてむ' + + # ダイスボットの使い方 + HELP_MESSAGE = <<~MESSAGETEXT + ・判定 (nEB) + n個のD6を振る判定。ダブルトリガー発動で自動振り足し。 + ・各種表 + ・生死不明表 (LDUT) + MESSAGETEXT + + register_prefix('\d+DF') + + def eval_game_system_specific_command(command) + roll_df(command) + end + + private + + def roll_df(command) + parser = Command::Parser.new("DF", round_type: @round_type) + .enable_prefix_number() + .restrict_cmp_op_to(:>=, nil) + + parsed = parser.parse(command) + unless parsed + return nil + end + + dice_list = roll_fate_dice(parsed.prefix_number) + total = dice_list.sum() + parsed.modify_number + + fate_dice_list = dice_list.map do |i| + if i.zero? + "[ ]" + elsif i.positive? + "[+]" + else + "[-]" + end + end + + result = outcome(total, parsed.target_number) + sequence = [ + "(#{parsed})", + "#{fate_dice_list.join()}#{Format.modifier(parsed.modify_number)}", + result_ladder(total), + result.text, + ] + + result.text = sequence.compact.join(" > ") + return result + end + + def roll_fate_dice(times) + @randomizer.roll_barabara(times, 3).map { |i| i - 2 } + end + + def result_ladder(total) + ladder = + case total.clamp(-2, 8) + when 8 + "Legendary" + when 7 + "Epic" + when 6 + "Fantastic" + when 5 + "Superb" + when 4 + "Great" + when 3 + "Good" + when 2 + "Fair" + when 1 + "Average" + when 0 + "Mediocre" + when -1 + "Poor" + else + "Terrible" + end + + return "#{ladder}(#{format('%+d', total)})" + end + + def outcome(total, target) + if target.nil? + Result.new + elsif total == target + Result.success("Tie") + elsif total >= target + 3 + Result.critical("Succeed with Style") + elsif total >= target + Result.success("Succeed") + else + Result.failure("Fail") + end + end + end + end +end diff --git a/test/data/FateCoreSystem.toml b/test/data/FateCoreSystem.toml new file mode 100644 index 000000000..1eb0866bf --- /dev/null +++ b/test/data/FateCoreSystem.toml @@ -0,0 +1,219 @@ +[[ test ]] +game_system = "FateCoreSystem" +input = "4DF" +output = "(4DF) > [-][ ][-][-] > Terrible(-3)" +rands = [ + { sides = 3, value = 1 }, + { sides = 3, value = 2 }, + { sides = 3, value = 1 }, + { sides = 3, value = 1 }, +] + +[[ test ]] +game_system = "FateCoreSystem" +input = "4DF" +output = "(4DF) > [-][ ][-][ ] > Terrible(-2)" +rands = [ + { sides = 3, value = 1 }, + { sides = 3, value = 2 }, + { sides = 3, value = 1 }, + { sides = 3, value = 2 }, +] + +[[ test ]] +game_system = "FateCoreSystem" +input = "4DF" +output = "(4DF) > [ ][ ][-][ ] > Poor(-1)" +rands = [ + { sides = 3, value = 2 }, + { sides = 3, value = 2 }, + { sides = 3, value = 1 }, + { sides = 3, value = 2 }, +] + +[[ test ]] +game_system = "FateCoreSystem" +input = "4DF" +output = "(4DF) > [ ][ ][ ][ ] > Mediocre(+0)" +rands = [ + { sides = 3, value = 2 }, + { sides = 3, value = 2 }, + { sides = 3, value = 2 }, + { sides = 3, value = 2 }, +] + +[[ test ]] +game_system = "FateCoreSystem" +input = "4DF" +output = "(4DF) > [+][ ][ ][ ] > Average(+1)" +rands = [ + { sides = 3, value = 3 }, + { sides = 3, value = 2 }, + { sides = 3, value = 2 }, + { sides = 3, value = 2 }, +] + +[[ test ]] +game_system = "FateCoreSystem" +input = "4DF" +output = "(4DF) > [+][+][ ][ ] > Fair(+2)" +rands = [ + { sides = 3, value = 3 }, + { sides = 3, value = 3 }, + { sides = 3, value = 2 }, + { sides = 3, value = 2 }, +] + +[[ test ]] +game_system = "FateCoreSystem" +input = "4DF" +output = "(4DF) > [+][+][+][ ] > Good(+3)" +rands = [ + { sides = 3, value = 3 }, + { sides = 3, value = 3 }, + { sides = 3, value = 3 }, + { sides = 3, value = 2 }, +] + +[[ test ]] +game_system = "FateCoreSystem" +input = "4DF" +output = "(4DF) > [+][+][+][+] > Great(+4)" +rands = [ + { sides = 3, value = 3 }, + { sides = 3, value = 3 }, + { sides = 3, value = 3 }, + { sides = 3, value = 3 }, +] + +[[ test ]] +game_system = "FateCoreSystem" +input = "5DF" +output = "(5DF) > [+][+][+][+][+] > Superb(+5)" +rands = [ + { sides = 3, value = 3 }, + { sides = 3, value = 3 }, + { sides = 3, value = 3 }, + { sides = 3, value = 3 }, + { sides = 3, value = 3 }, +] + +[[ test ]] +game_system = "FateCoreSystem" +input = "5DF+1" +output = "(5DF+1) > [+][+][+][+][+]+1 > Fantastic(+6)" +rands = [ + { sides = 3, value = 3 }, + { sides = 3, value = 3 }, + { sides = 3, value = 3 }, + { sides = 3, value = 3 }, + { sides = 3, value = 3 }, +] + +[[ test ]] +game_system = "FateCoreSystem" +input = "5DF+2" +output = "(5DF+2) > [+][+][+][+][+]+2 > Epic(+7)" +rands = [ + { sides = 3, value = 3 }, + { sides = 3, value = 3 }, + { sides = 3, value = 3 }, + { sides = 3, value = 3 }, + { sides = 3, value = 3 }, +] + +[[ test ]] +game_system = "FateCoreSystem" +input = "5DF+3" +output = "(5DF+3) > [+][+][+][+][+]+3 > Legendary(+8)" +rands = [ + { sides = 3, value = 3 }, + { sides = 3, value = 3 }, + { sides = 3, value = 3 }, + { sides = 3, value = 3 }, + { sides = 3, value = 3 }, +] + +[[ test ]] +game_system = "FateCoreSystem" +input = "5DF+4" +output = "(5DF+4) > [+][+][+][+][+]+4 > Legendary(+9)" +rands = [ + { sides = 3, value = 3 }, + { sides = 3, value = 3 }, + { sides = 3, value = 3 }, + { sides = 3, value = 3 }, + { sides = 3, value = 3 }, +] + +[[ test ]] +game_system = "FateCoreSystem" +input = "4DF" +output = "(4DF) > [ ][-][ ][+] > Mediocre(+0)" +rands = [ + { sides = 3, value = 2 }, + { sides = 3, value = 1 }, + { sides = 3, value = 2 }, + { sides = 3, value = 3 }, +] + +[[ test ]] +game_system = "FateCoreSystem" +input = "4DF>=3" +output = "(4DF>=3) > [+][+][+][+] > Great(+4) > Succeed" +success = true +rands = [ + { sides = 3, value = 3 }, + { sides = 3, value = 3 }, + { sides = 3, value = 3 }, + { sides = 3, value = 3 }, +] + +[[ test ]] +game_system = "FateCoreSystem" +input = "4DF+1>=3" +output = "(4DF+1>=3) > [+][+][+][+]+1 > Superb(+5) > Succeed" +success = true +rands = [ + { sides = 3, value = 3 }, + { sides = 3, value = 3 }, + { sides = 3, value = 3 }, + { sides = 3, value = 3 }, +] + +[[ test ]] +game_system = "FateCoreSystem" +input = "4DF+2>=3" +output = "(4DF+2>=3) > [+][+][+][+]+2 > Fantastic(+6) > Succeed with Style" +success = true +critical = true +rands = [ + { sides = 3, value = 3 }, + { sides = 3, value = 3 }, + { sides = 3, value = 3 }, + { sides = 3, value = 3 }, +] + +[[ test ]] +game_system = "FateCoreSystem" +input = "4DF+1>=3" +output = "(4DF+1>=3) > [+][+][+][-]+1 > Good(+3) > Tie" +success = true +rands = [ + { sides = 3, value = 3 }, + { sides = 3, value = 3 }, + { sides = 3, value = 3 }, + { sides = 3, value = 1 }, +] + +[[ test ]] +game_system = "FateCoreSystem" +input = "4DF+1>=3" +output = "(4DF+1>=3) > [+][ ][+][-]+1 > Fair(+2) > Fail" +failure = true +rands = [ + { sides = 3, value = 3 }, + { sides = 3, value = 2 }, + { sides = 3, value = 3 }, + { sides = 3, value = 1 }, +] From f16d161de912ecee2ee3c074acd85086efdc95a3 Mon Sep 17 00:00:00 2001 From: SAKATA Sinji Date: Sat, 16 Oct 2021 16:02:33 +0900 Subject: [PATCH 2/2] =?UTF-8?q?[FateCoreSystem]=20=E3=83=98=E3=83=AB?= =?UTF-8?q?=E3=83=97=E3=83=A1=E3=83=83=E3=82=BB=E3=83=BC=E3=82=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/bcdice/game_system/FateCoreSystem.rb | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/bcdice/game_system/FateCoreSystem.rb b/lib/bcdice/game_system/FateCoreSystem.rb index f82d3f351..e28d50206 100644 --- a/lib/bcdice/game_system/FateCoreSystem.rb +++ b/lib/bcdice/game_system/FateCoreSystem.rb @@ -14,10 +14,12 @@ class FateCoreSystem < Base # ダイスボットの使い方 HELP_MESSAGE = <<~MESSAGETEXT - ・判定 (nEB) - n個のD6を振る判定。ダブルトリガー発動で自動振り足し。 - ・各種表 - ・生死不明表 (LDUT) + ■ ファッジダイスによる判定 (xDF+y>=t) + ファッジダイスをx個ダイスロールし、結果を判定します。 + x: ダイス数 + y: 修正値(省略可) + t: 目標値値(省略可) + 例)4DF, 4DF>=3, 4DF+1>=3 MESSAGETEXT register_prefix('\d+DF')