Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ブラドリウムに対応 #599

Merged
merged 1 commit into from
Feb 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 = []