Skip to content

Commit

Permalink
Merge pull request #599 from bcdice/bloodorium
Browse files Browse the repository at this point in the history
ブラドリウムに対応
  • Loading branch information
ysakasin authored Feb 17, 2023
2 parents 17f2815 + c8df4cb commit 60130e8
Show file tree
Hide file tree
Showing 3 changed files with 161 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 @@ -31,6 +31,7 @@
require "bcdice/game_system/BlindMythos"
require "bcdice/game_system/BloodCrusade"
require "bcdice/game_system/BloodMoon"
require "bcdice/game_system/Bloodorium"
require "bcdice/game_system/CardRanker"
require "bcdice/game_system/CastleInGray"
require "bcdice/game_system/ChaosFlare"
Expand Down
68 changes: 68 additions & 0 deletions lib/bcdice/game_system/Bloodorium.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# frozen_string_literal: true

module BCDice
module GameSystem
class Bloodorium < Base
# ゲームシステムの識別子
ID = 'Bloodorium'

# ゲームシステム名
NAME = 'ブラドリウム'

# ゲームシステム名の読みがな
SORT_KEY = 'ふらとりうむ'

# ダイスボットの使い方
HELP_MESSAGE = <<~INFO_MESSAGE_TEXT
・ダイスチェック xDC+y
 【ダイスチェック】を行う。《トライアンフ》を結果に自動反映する。
 x: ダイス数
 y: 結果への修正値 (省略可)
INFO_MESSAGE_TEXT

register_prefix('\dDC')

def eval_game_system_specific_command(command)
dicecheck(command)
end

private

def dicecheck(command)
parser = Command::Parser.new("DC", round_type: @round_type).has_prefix_number.restrict_cmp_op_to(nil)
parsed = parser.parse(command)
unless parsed
return nil
end

dice_list = @randomizer.roll_barabara(parsed.prefix_number, 6).sort
dice_value = dice_list.max
values_count = dice_list
.group_by(&:itself)
.transform_values(&:length)
triumph = values_count.values.max

total = dice_value * triumph + parsed.modify_number

sequence = [
"(#{parsed})",
"[#{dice_list.join(',')}]#{Format.modifier(parsed.modify_number)}",
("《トライアンフ》(*#{triumph})" if triumph > 1),
(total_expr(dice_value, triumph, parsed.modify_number) if total != dice_value),
total,
].compact

return Result.new.tap do |r|
r.critical = triumph > 1
r.text = sequence.join(" > ")
end
end

def total_expr(dice_value, triumph, modify_number)
formated_triumph = triumph > 1 ? "*#{triumph}" : nil

return "#{dice_value}#{formated_triumph}#{Format.modifier(modify_number)}"
end
end
end
end
92 changes: 92 additions & 0 deletions test/data/Bloodorium.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
[[ test ]]
game_system = "Bloodorium"
input = "4DC"
output = "(4DC) > [1,2,3,4] > 4"
rands = [
{ sides = 6, value = 1 },
{ sides = 6, value = 2 },
{ sides = 6, value = 3 },
{ sides = 6, value = 4 },
]

[[ test ]]
game_system = "Bloodorium"
input = "3DC"
output = "(3DC) > [3,4,5] > 5"
rands = [
{ sides = 6, value = 3 },
{ sides = 6, value = 4 },
{ sides = 6, value = 5 },
]

[[ test ]]
game_system = "Bloodorium"
input = "4DC"
output = "(4DC) > [1,2,2,4] > 《トライアンフ》(*2) > 4*2 > 8"
critical = true
rands = [
{ sides = 6, value = 1 },
{ sides = 6, value = 2 },
{ sides = 6, value = 2 },
{ sides = 6, value = 4 },
]

[[ test ]]
game_system = "Bloodorium"
input = "5DC"
output = "(5DC) > [2,2,5,5,5] > 《トライアンフ》(*3) > 5*3 > 15"
critical = true
rands = [
{ sides = 6, value = 2 },
{ sides = 6, value = 2 },
{ sides = 6, value = 5 },
{ sides = 6, value = 5 },
{ sides = 6, value = 5 },
]

[[ test ]]
game_system = "Bloodorium"
input = "4DC+1"
output = "(4DC+1) > [1,2,3,4]+1 > 4+1 > 5"
rands = [
{ sides = 6, value = 1 },
{ sides = 6, value = 2 },
{ sides = 6, value = 3 },
{ sides = 6, value = 4 },
]

[[ test ]]
game_system = "Bloodorium"
input = "4DC+1+2"
output = "(4DC+3) > [1,2,3,4]+3 > 4+3 > 7"
rands = [
{ sides = 6, value = 1 },
{ sides = 6, value = 2 },
{ sides = 6, value = 3 },
{ sides = 6, value = 4 },
]

[[ test ]]
game_system = "Bloodorium"
input = "5DC+1"
output = "(5DC+1) > [2,2,5,5,5]+1 > 《トライアンフ》(*3) > 5*3+1 > 16"
critical = true
rands = [
{ sides = 6, value = 2 },
{ sides = 6, value = 5 },
{ sides = 6, value = 2 },
{ sides = 6, value = 5 },
{ sides = 6, value = 5 },
]

[[ test ]]
game_system = "Bloodorium"
input = "DC"
output = ""
rands = []

[[ test ]]
game_system = "Bloodorium"
input = "DC+1"
output = ""
rands = []

0 comments on commit 60130e8

Please sign in to comment.