From 7edfc0bcdeeee23c093ddab984a6f3a70b56085f Mon Sep 17 00:00:00 2001 From: reismannnr2 <52961769+reismannnr2@users.noreply.github.com> Date: Mon, 23 Aug 2021 22:47:39 +0900 Subject: [PATCH] =?UTF-8?q?[CastleInGray]=20=E3=80=8E=E7=81=B0=E8=89=B2?= =?UTF-8?q?=E5=9F=8E=E7=B6=BA=E8=AD=9A=E3=80=8F=20CASTLE=20IN=20GRAY=20The?= =?UTF-8?q?=20Haunted=20Palace=20(#495)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * implementation * add tests for tables * remove some tests * リファクタリング Co-authored-by: reismannnr2 Co-authored-by: SAKATA Sinji --- lib/bcdice/game_system.rb | 1 + lib/bcdice/game_system/CastleInGray.rb | 133 ++++++++++++++ test/data/CastleInGray.toml | 230 +++++++++++++++++++++++++ 3 files changed, 364 insertions(+) create mode 100644 lib/bcdice/game_system/CastleInGray.rb create mode 100644 test/data/CastleInGray.toml diff --git a/lib/bcdice/game_system.rb b/lib/bcdice/game_system.rb index 41de38484..7c822bd20 100644 --- a/lib/bcdice/game_system.rb +++ b/lib/bcdice/game_system.rb @@ -27,6 +27,7 @@ require "bcdice/game_system/BloodCrusade" require "bcdice/game_system/BloodMoon" require "bcdice/game_system/CardRanker" +require "bcdice/game_system/CastleInGray" require "bcdice/game_system/ChaosFlare" require "bcdice/game_system/Chill" require "bcdice/game_system/Chill3" diff --git a/lib/bcdice/game_system/CastleInGray.rb b/lib/bcdice/game_system/CastleInGray.rb new file mode 100644 index 000000000..33fcebe4b --- /dev/null +++ b/lib/bcdice/game_system/CastleInGray.rb @@ -0,0 +1,133 @@ +module BCDice + module GameSystem + class CastleInGray < Base + # ゲームシステムの識別子 + ID = "CastleInGray".freeze + + # ゲームシステム名 + NAME = "灰色城綺譚".freeze + + # ゲームシステム名の読みがな + SORT_KEY = "はいいろしようきたん".freeze + + HELP_MESSAGE = <<~TEXT.freeze + ■ 色占い (BnWm) + n: 黒 + m: 白 + n, m は1~12の異なる整数 + + 例) B12W7 + 例) B5W12 + + ■ 悪意の渦による占い (MALn) + n: 悪意の渦 + n は1~12の整数 + + ■ その他 + ・感情表 ET + ・暗示表(黒) BIT + ・暗示表(白) WIT + TEXT + + TABLES = { + "ET" => DiceTable::Table.new( + "感情表", + "1D12", + [ + "友情(白)/敵視(黒)", + "恋慕(白)/嫌悪(黒)", + "信頼(白)/不信(黒)", + "同情(白)/憐憫(黒)", + "憧憬(白)/劣等感(黒)", + "尊敬(白)/蔑視(黒)", + "忠誠(白)/執着(黒)", + "有用(白)/邪魔(黒)", + "許容(白)/罪悪感(黒)", + "羨望(白)/嫉妬(黒)", + "共感(白)/拒絶(黒)", + "愛情(白)/狂信(黒)" + ] + ), + "BIT" => DiceTable::Table.new( + "暗示表(黒)", + "1D12", + [ + "終わりなき夜に生まれつく者もあり", + "悪意もて真実を語らば", + "笑えども笑みはなし", + "影より抜け出ることあたわじ", + "心の赴くままに手をとれ", + "時ならぬ嵐の過ぎ去るを待つ", + "赦されぬと知るがゆえに", + "見張りは持ち場を離れる", + "誰もが盲いたる彷徨い人なり", + "落ちる日を眺めるがごとく", + "冷たく雨ぞ降りしきる", + "今日は笑む花も明日には枯れゆく" + ] + ), + "WIT" => DiceTable::Table.new( + "暗示表(白)", + "1D12", + [ + "無垢なる者のみが真実を得る", + "げに慈悲深きは沈黙なり", + "懐かしき日々は去りぬ", + "束の間に光さす", + "迷える者に手を差し伸べよ", + "嵐の前には静けさがある", + "どうか責めないで", + "灯した明かりを絶やさぬように", + "目を開けて見よ", + "淑やかに訪れる", + "今こそ泣け、さもなくば二度と泣くな", + "時が許す間に薔薇を摘め" + ] + ), + }.freeze + + register_prefix('B', 'MAL', TABLES.keys) + + def eval_game_system_specific_command(command) + return roll_color(command) || roll_mal(command) || roll_tables(command, TABLES) + end + + def roll_color(command) + m = /^B(\d{1,2})W(\d{1,2})$/.match(command) + return nil unless m + + black = m[1].to_i + white = m[2].to_i + return nil unless black.between?(1, 12) && white.between?(1, 12) + + value = @randomizer.roll_once(12) + + if black == white + return color_text(black, white, value, '白と黒は重ねられません') + end + + if white > black + return color_text(black, white, value, black <= value && value < white ? '黒' : '白') + else + return color_text(black, white, value, white <= value && value < black ? '白' : '黒') + end + end + + def color_text(black, white, value, result) + return "色占い(黒#{black}白#{white}) > [#{value}] > #{result}" + end + + def roll_mal(command) + m = /^MAL(\d{1,2})$/i.match(command) + return nil unless m + + mal = m[1].to_i + return nil unless mal.between?(1, 12) + + value = @randomizer.roll_once(12) + result = value <= mal ? '黒' : '白' + return "悪意の渦(#{mal}) > [#{value}] > #{result}" + end + end + end +end diff --git a/test/data/CastleInGray.toml b/test/data/CastleInGray.toml new file mode 100644 index 000000000..1d8c933e8 --- /dev/null +++ b/test/data/CastleInGray.toml @@ -0,0 +1,230 @@ +[[ test ]] +game_system = "CastleInGray" +input = "B10W10" +output = "色占い(黒10白10) > [10] > 白と黒は重ねられません" +rands = [ + { sides = 12, value = 10 }, +] + +[[ test ]] +game_system = "CastleInGray" +input = "B10W5" +output = "色占い(黒10白5) > [11] > 黒" +rands = [ + { sides = 12, value = 11 }, +] + +[[ test ]] +game_system = "CastleInGray" +input = "B10W5" +output = "色占い(黒10白5) > [7] > 白" +rands = [ + { sides = 12, value = 7 }, +] + +[[ test ]] +game_system = "CastleInGray" +input = "B10W5" +output = "色占い(黒10白5) > [5] > 白" +rands = [ + { sides = 12, value = 5 }, +] + +[[ test ]] +game_system = "CastleInGray" +input = "B10W5" +output = "色占い(黒10白5) > [10] > 黒" +rands = [ + { sides = 12, value = 10 }, +] + +[[ test ]] +game_system = "CastleInGray" +input = "B9W12" +output = "色占い(黒9白12) > [11] > 黒" +rands = [ + { sides = 12, value = 11 }, +] + +[[ test ]] +game_system = "CastleInGray" +input = "B9W12" +output = "色占い(黒9白12) > [4] > 白" +rands = [ + { sides = 12, value = 4 }, +] + +[[ test ]] +game_system = "CastleInGray" +input = "B8W0" +output = "" +rands = [] + +[[ test ]] +game_system = "CastleInGray" +input = "B9W13" +output = "" +rands = [] + +[[ test ]] +game_system = "CastleInGray" +input = "B0W4" +output = "" +rands = [] + +[[ test ]] +game_system = "CastleInGray" +input = "B13W2" +output = "" +rands = [] + +[[ test ]] +game_system = "CastleInGray" +input = "MAL1" +output = "悪意の渦(1) > [1] > 黒" +rands = [ + { sides = 12, value = 1 }, +] + +[[ test ]] +game_system = "CastleInGray" +input = "MAL1" +output = "悪意の渦(1) > [2] > 白" +rands = [ + { sides = 12, value = 2 }, +] + +[[ test ]] +game_system = "CastleInGray" +input = "MAL5" +output = "悪意の渦(5) > [11] > 白" +rands = [ + { sides = 12, value = 11 }, +] + +[[ test ]] +game_system = "CastleInGray" +input = "MAL5" +output = "悪意の渦(5) > [3] > 黒" +rands = [ + { sides = 12, value = 3 }, +] + +[[ test ]] +game_system = "CastleInGray" +input = "MAL5" +output = "悪意の渦(5) > [5] > 黒" +rands = [ + { sides = 12, value = 5 }, +] + +[[ test ]] +game_system = "CastleInGray" +input = "MAL5" +output = "悪意の渦(5) > [6] > 白" +rands = [ + { sides = 12, value = 6 }, +] + +[[ test ]] +game_system = "CastleInGray" +input = "MAL12" +output = "悪意の渦(12) > [12] > 黒" +rands = [ + { sides = 12, value = 12 }, +] + +[[ test ]] +game_system = "CastleInGray" +input = "MAL12" +output = "悪意の渦(12) > [3] > 黒" +rands = [ + { sides = 12, value = 3 }, +] + +[[ test ]] +game_system = "CastleInGray" +input = "MAL0" +output = "" +rands = [] + +[[ test ]] +game_system = "CastleInGray" +input = "MAL13" +output = "" +rands = [] + +[[test]] +game_system = "CastleInGray" +input = "ET" +output = "感情表(1) > 友情(白)/敵視(黒)" +rands = [ + { sides = 12, value = 1 }, +] + +[[test]] +game_system = "CastleInGray" +input = "ET" +output = "感情表(4) > 同情(白)/憐憫(黒)" +rands = [ + { sides = 12, value = 4 }, +] + +[[test]] +game_system = "CastleInGray" +input = "ET" +output = "感情表(12) > 愛情(白)/狂信(黒)" +rands = [ + { sides = 12, value = 12 }, +] + +[[test]] +game_system = "CastleInGray" +input = "BIT" +output = "暗示表(黒)(1) > 終わりなき夜に生まれつく者もあり" +rands = [ + { sides = 12, value = 1 }, +] + + +[[test]] +game_system = "CastleInGray" +input = "BIT" +output = "暗示表(黒)(10) > 落ちる日を眺めるがごとく" +rands = [ + { sides = 12, value = 10 }, +] + + +[[test]] +game_system = "CastleInGray" +input = "BIT" +output = "暗示表(黒)(12) > 今日は笑む花も明日には枯れゆく" +rands = [ + { sides = 12, value = 12 }, +] + + +[[test]] +game_system = "CastleInGray" +input = "WIT" +output = "暗示表(白)(1) > 無垢なる者のみが真実を得る" +rands = [ + { sides = 12, value = 1 }, +] + +[[test]] +game_system = "CastleInGray" +input = "WIT" +output = "暗示表(白)(6) > 嵐の前には静けさがある" +rands = [ + { sides = 12, value = 6 }, +] + +[[test]] +game_system = "CastleInGray" +input = "WIT" +output = "暗示表(白)(12) > 時が許す間に薔薇を摘め" +rands = [ + { sides = 12, value = 12 }, +]