From 28ac2bf5ae083d04e4d039521d633ae898773c0b Mon Sep 17 00:00:00 2001 From: GenKuzumochi Date: Fri, 8 Oct 2021 19:34:51 +0900 Subject: [PATCH] =?UTF-8?q?=E3=82=A2=E3=82=B5=E3=83=AB=E3=83=88=E3=82=A8?= =?UTF-8?q?=E3=83=B3=E3=82=B8=E3=83=B3=E5=AE=9F=E8=A3=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/bcdice/game_system.rb | 1 + lib/bcdice/game_system/AssaultEngine.rb | 91 ++++++++++++++++++ test/data/AssaultEngine.toml | 120 ++++++++++++++++++++++++ 3 files changed, 212 insertions(+) create mode 100644 lib/bcdice/game_system/AssaultEngine.rb create mode 100644 test/data/AssaultEngine.toml diff --git a/lib/bcdice/game_system.rb b/lib/bcdice/game_system.rb index 7c822bd20..992a91fc7 100644 --- a/lib/bcdice/game_system.rb +++ b/lib/bcdice/game_system.rb @@ -14,6 +14,7 @@ require "bcdice/game_system/AnimaAnimus" require "bcdice/game_system/Arianrhod" require "bcdice/game_system/ArsMagica" +require "bcdice/game_system/AssaultEngine" require "bcdice/game_system/Avandner" require "bcdice/game_system/BBN" require "bcdice/game_system/BadLife" diff --git a/lib/bcdice/game_system/AssaultEngine.rb b/lib/bcdice/game_system/AssaultEngine.rb new file mode 100644 index 000000000..3d9b0495e --- /dev/null +++ b/lib/bcdice/game_system/AssaultEngine.rb @@ -0,0 +1,91 @@ +# frozen_string_literal: true + +module BCDice + module GameSystem + class AssaultEngine < Base + # ゲームシステムの識別子 + ID = 'AssaultEngine' + + # ゲームシステム名 + NAME = 'アサルトエンジン' + + # ゲームシステム名の読みがな + SORT_KEY = 'あさるとえんしん' + + # ダイスボットの使い方 + HELP_MESSAGE = <<~MESSAGETEXT + ・判定 AEt (t目標値) + 例: AE45 (目標値45) + ・リロール nAEt (nロール前の値、t目標値) + 例: 76AE45 (目標値45で、76を振り直す) + + ・スワップ(t目標値) エネミーブックP11 + 例: AES45 (目標値45、スワップ表示あり) + MESSAGETEXT + + register_prefix('\d*AE') + + def initialize(command) + super(command) + @round_type = RoundType::FLOOR # 端数切り捨て + end + + def eval_game_system_specific_command(command) + cmd = Command::Parser.new(/AES?/, round_type: round_type).enable_prefix_number + .has_suffix_number.parse(command) + return nil unless cmd + + target = cmd.suffix_number + target = 99 if target >= 100 + + if cmd.command.include?("AES") # SWAP初回 + total = @randomizer.roll_once(100) % 100 # 0-99 + swap = (total % 10) * 10 + (total / 10) + r1 = judge(target, total) + r2 = judge(target, swap) + text = "(AES#{format00(target)}) > #{r1.text} / スワップ#{r2.text}" + check_result(r1, r2, text) + elsif cmd.prefix_number.nil? # 初回ロール + total = @randomizer.roll_once(100) % 100 # 0-99 + judge(target, total).tap do |r| + r.text = "(AE#{format00(target)}) > #{r.text}" + end + else # リロール + now = cmd.prefix_number + die = @randomizer.roll_once(10) % 10 # 0-9 + new1 = judge(target, (now / 10 * 10) + die) # 1の位を振り直す + new2 = judge(target, now % 10 + die * 10) # 10の位を振り直す + + text = "(#{format00(now)}AE#{format00(target)}) > #{die} > #{new1.text} / #{new2.text}" + check_result(new1, new2, text) + end + end + + def format00(dice) + format("%02d", dice) + end + + def check_result(result1, result2, text) + if result1.critical? || result2.critical? + Result.critical(text) + elsif result1.success? || result2.success? + Result.success(text) + elsif result1.fumble? && result2.fumble? + Result.fumble(text) + else + Result.failure(text) + end + end + + def judge(target, total) + double = (total / 10) == (total % 10) + total_text = format00(total) + if total <= target + double ? Result.critical("(#{total_text})クリティカル") : Result.success("(#{total_text})成功") + else + double ? Result.fumble("(#{total_text})ファンブル") : Result.failure("(#{total_text})失敗") + end + end + end + end +end diff --git a/test/data/AssaultEngine.toml b/test/data/AssaultEngine.toml new file mode 100644 index 000000000..8592a2338 --- /dev/null +++ b/test/data/AssaultEngine.toml @@ -0,0 +1,120 @@ +[[ test ]] +game_system = "AssaultEngine" +input = "AE44" +output = "(AE44) > (05)成功" +success = true +rands = [ { sides = 100, value = 5 } ] + +[[ test ]] +game_system = "AssaultEngine" +input = "AE44" +output = "(AE44) > (33)クリティカル" +success = true +critical = true +rands = [ { sides = 100, value = 33 } ] + +[[ test ]] +game_system = "AssaultEngine" +input = "AE44" +output = "(AE44) > (44)クリティカル" +success = true +critical = true +rands = [ { sides = 100, value = 44 } ] + +[[ test ]] +game_system = "AssaultEngine" +input = "AE44" +output = "(AE44) > (45)失敗" +failure = true +rands = [ { sides = 100, value = 45 } ] + +[[ test ]] +game_system = "AssaultEngine" +input = "AE44" +output = "(AE44) > (55)ファンブル" +failure = true +fumble = true +rands = [ { sides = 100, value = 55 } ] + +[[ test ]] +game_system = "AssaultEngine" +input = "AE0 100=00は常にクリティカル" +output = "(AE00) > (00)クリティカル" +success = true +critical = true +rands = [ { sides = 100, value = 100 } ] + +[[ test ]] +game_system = "AssaultEngine" +input = "AE09" +output = "(AE09) > (00)クリティカル" +success = true +critical = true +rands = [ { sides = 100, value = 100 } ] + +[[ test ]] +game_system = "AssaultEngine" +input = "AE123" +output = "(AE99) > (99)クリティカル" +success = true +critical = true +rands = [ { sides = 100, value = 99 } ] + +[[ test ]] +game_system = "AssaultEngine" +input = "AES44" +output = "(AES44) > (00)クリティカル / スワップ(00)クリティカル" +success = true +critical = true +rands = [ { sides = 100, value = 100 } ] + +[[ test ]] +game_system = "AssaultEngine" +input = "AES44" +output = "(AES44) > (53)失敗 / スワップ(35)成功" +success = true +rands = [ { sides = 100, value = 53 } ] + +[[ test ]] +game_system = "AssaultEngine" +input = "AES44" +output = "(AES44) > (00)クリティカル / スワップ(00)クリティカル" +success = true +critical = true +rands = [ { sides = 100, value = 100 } ] + +[[ test ]] +game_system = "AssaultEngine" +input = "12AES44 AESではprefix無視" +output = "(AES44) > (43)成功 / スワップ(34)成功" +success = true +rands = [ { sides = 100, value = 43 } ] + +[[ test ]] +game_system = "AssaultEngine" +input = "56AE44" +output = "(56AE44) > 1 > (51)失敗 / (16)成功" +success = true +rands = [ { sides = 10, value = 1 } ] + +[[ test ]] +game_system = "AssaultEngine" +input = "56AE44" +output = "(56AE44) > 8 > (58)失敗 / (86)失敗" +failure = true +rands = [ { sides = 10, value = 8 } ] + +[[ test ]] +game_system = "AssaultEngine" +input = "66AE44 本来ファンブルは振り直せないが、警告等はださない" +output = "(66AE44) > 7 > (67)失敗 / (76)失敗" +failure = true +rands = [ { sides = 10, value = 7 } ] + +[[ test ]] +game_system = "AssaultEngine" +input = "90AE44" +output = "(90AE44) > 0 > (90)失敗 / (00)クリティカル" +success = true +critical = true +rands = [ { sides = 10, value = 10 } ]