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

[Aoharubaan] 『はちゃめちゃ!JK・TRPG あおはるばーんっ』のダイスボットを追加 #511

Merged
merged 1 commit into from
Nov 10, 2021
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 @@ -12,6 +12,7 @@
require "bcdice/game_system/Amadeus_Korean"
require "bcdice/game_system/AngelGear"
require "bcdice/game_system/AnimaAnimus"
require "bcdice/game_system/Aoharubaan"
require "bcdice/game_system/Arianrhod"
require "bcdice/game_system/ArsMagica"
require "bcdice/game_system/AssaultEngine"
Expand Down
91 changes: 91 additions & 0 deletions lib/bcdice/game_system/Aoharubaan.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
# frozen_string_literal: true

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

# ゲームシステム名
NAME = 'あおはるばーんっ'

# ゲームシステム名の読みがな
SORT_KEY = 'あおはるはあんつ'

# ダイスボットの使い方
HELP_MESSAGE = <<~HELP
カレカノ反応表( KR, KReaction )
HELP

JUDGE_ROLL_REG = /^(1d6?|d6)(\+\d+)?(>=|=>)(\d+)$/i.freeze
register_prefix('(1d6?|d6)(\+\d+)?(>=|=>)(\d+)')

def eval_game_system_specific_command(command)
command = ALIAS[command] || command

if (m = JUDGE_ROLL_REG.match(command))
roll_judge(m[2], m[4])
else
roll_tables(command, TABLES)
end
end

private

def roll_judge(modifier_expression, border_expression)
modifier = modifier_expression ? Arithmetic.eval(modifier_expression, RoundType::FLOOR) : nil
border = border_expression.to_i

command_text = make_command_text(modifier, border)

dice = @randomizer.roll_once(6)
score = dice + modifier.to_i

is_success = score >= border # 「成功」か?
is_right = is_success && score == border # 「ピタリ賞」か?
is_excellent = is_success && score >= 7 # 「限界突破」か?

result_elements = []
result_elements << (is_success ? '成功' : '失敗')
result_elements << "ピタリ賞" if is_right
result_elements << "限界突破" if is_excellent

message_elements = []
message_elements << command_text
message_elements << "#{dice}+#{modifier}" if modifier
message_elements << score
message_elements << result_elements.join(" & ")

Result.new(message_elements.join(' > ')).tap do |r|
r.condition = is_success
r.critical = is_right || is_excellent
end
end

def make_command_text(modifier, border)
command = "1D6"
command = "#{command}+#{modifier}" if modifier
command = "#{command}>=#{border}"
"(#{command})"
end

ALIAS = {
"KR" => "KReaction",
}.transform_keys(&:upcase).transform_values(&:upcase).freeze

TABLES = {
"KReaction" => DiceTable::RangeTable.new(
"カレカノ反応表",
"1D6",
[
[1..2, "何となく素っ気ない気がする。"],
[3..4, "いつもと変わらない安心感。"],
[5..6, "何故だかすごくデレてきた! 嬉しくて〈テンション〉1回復。"],
]
),
}.transform_keys(&:upcase).freeze

register_prefix(ALIAS.keys, TABLES.keys)
end
end
end
115 changes: 115 additions & 0 deletions test/data/Aoharubaan.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
[[ test ]]
game_system = "Aoharubaan"
input = "1d6>=4"
output = "(1D6>=4) > 5 > 成功"
rands = [
{ sides = 6, value = 5 },
]
success = true

[[ test ]]
game_system = "Aoharubaan"
input = "1d>=4"
output = "(1D6>=4) > 5 > 成功"
rands = [
{ sides = 6, value = 5 },
]
success = true

[[ test ]]
game_system = "Aoharubaan"
input = "d6>=4"
output = "(1D6>=4) > 5 > 成功"
rands = [
{ sides = 6, value = 5 },
]
success = true

[[ test ]]
game_system = "Aoharubaan"
input = "d6>=4"
output = "(1D6>=4) > 3 > 失敗"
rands = [
{ sides = 6, value = 3 },
]
failure = true

[[ test ]]
game_system = "Aoharubaan"
input = "d6>=4"
output = "(1D6>=4) > 4 > 成功 & ピタリ賞"
rands = [
{ sides = 6, value = 4 },
]
success = true
critical = true

[[ test ]]
game_system = "Aoharubaan"
input = "d6+1>=5"
output = "(1D6+1>=5) > 3+1 > 4 > 失敗"
rands = [
{ sides = 6, value = 3 },
]
failure = true

[[ test ]]
game_system = "Aoharubaan"
input = "d6+1>=5"
output = "(1D6+1>=5) > 5+1 > 6 > 成功"
rands = [
{ sides = 6, value = 5 },
]
success = true

[[ test ]]
game_system = "Aoharubaan"
input = "d6+2>=5"
output = "(1D6+2>=5) > 5+2 > 7 > 成功 & 限界突破"
rands = [
{ sides = 6, value = 5 },
]
success = true
critical = true

[[ test ]]
game_system = "Aoharubaan"
input = "d6+2>=7"
output = "(1D6+2>=7) > 5+2 > 7 > 成功 & ピタリ賞 & 限界突破"
rands = [
{ sides = 6, value = 5 },
]
success = true
critical = true

[[ test ]]
game_system = "Aoharubaan"
input = "kreaction"
output = "カレカノ反応表(1) > 何となく素っ気ない気がする。"
rands = [
{ sides = 6, value = 1 },
]

[[ test ]]
game_system = "Aoharubaan"
input = "KReaction"
output = "カレカノ反応表(2) > 何となく素っ気ない気がする。"
rands = [
{ sides = 6, value = 2 },
]

[[ test ]]
game_system = "Aoharubaan"
input = "kr"
output = "カレカノ反応表(3) > いつもと変わらない安心感。"
rands = [
{ sides = 6, value = 3 },
]

[[ test ]]
game_system = "Aoharubaan"
input = "KR"
output = "カレカノ反応表(5) > 何故だかすごくデレてきた! 嬉しくて〈テンション〉1回復。"
rands = [
{ sides = 6, value = 5 },
]