Skip to content

Commit

Permalink
[CastleInGray] 『灰色城綺譚』 CASTLE IN GRAY The Haunted Palace (#495)
Browse files Browse the repository at this point in the history
* implementation

* add tests for tables

* remove some tests

* リファクタリング

Co-authored-by: reismannnr2 <[email protected]>
Co-authored-by: SAKATA Sinji <[email protected]>
  • Loading branch information
3 people authored Aug 23, 2021
1 parent bc77d98 commit 7edfc0b
Show file tree
Hide file tree
Showing 3 changed files with 364 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/bcdice/game_system.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
133 changes: 133 additions & 0 deletions lib/bcdice/game_system/CastleInGray.rb
Original file line number Diff line number Diff line change
@@ -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
230 changes: 230 additions & 0 deletions test/data/CastleInGray.toml
Original file line number Diff line number Diff line change
@@ -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 },
]

0 comments on commit 7edfc0b

Please sign in to comment.