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

『デモンスパイク』を追加 #636

Merged
merged 1 commit into from
Aug 6, 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 @@ -56,6 +56,7 @@
require "bcdice/game_system/DarkSouls"
require "bcdice/game_system/DeadlineHeroes"
require "bcdice/game_system/DemonParasite"
require "bcdice/game_system/DemonSpike"
require "bcdice/game_system/DesperateRun"
require "bcdice/game_system/DetatokoSaga"
require "bcdice/game_system/DetatokoSaga_Korean"
Expand Down
89 changes: 89 additions & 0 deletions lib/bcdice/game_system/DemonSpike.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
# frozen_string_literal: true

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

# ゲームシステム名
NAME = 'デモンスパイク'

# ゲームシステム名の読みがな
SORT_KEY = 'てもんすはいく'

# ダイスボットの使い方
HELP_MESSAGE = <<~INFO_MESSAGE_TEXT
・行為判定 xDS+y
 行為判定を行い、達成値、成否、成功度を出力する。
 x: ダイス数(省略:2)
 y: 能力値やスパイク能力による達成値の修正(省略可)
INFO_MESSAGE_TEXT

register_prefix('\d*DS')

def eval_game_system_specific_command(command)
roll_action(command)
end

private

def roll_action(command)
parser = Command::Parser.new("DS", round_type: @round_type)
.enable_prefix_number
.restrict_cmp_op_to(nil)
parsed = parser.parse(command)
unless parsed
return nil
end

parsed.prefix_number ||= 2
if parsed.prefix_number < 2
return nil
end

step = roll_step(parsed.prefix_number)
step_list = [step]
while step[:dice_sum] == 10
step = roll_step(parsed.prefix_number)
step_list.push(step)
end

is_fumble = step_list[0][:dice_sum] == 2
total = is_fumble ? 0 : step_list.sum { |s| s[:dice_sum] } + parsed.modify_number
success_level = total / 10
is_success = total >= 10

res =
if is_success
"成功, 成功度#{success_level}"
elsif is_fumble
"自動的失敗"
else
"失敗"
end

sequence = [
"(#{parsed})",
step_list.map { |s| "#{s[:dice_sum]}[#{s[:dice_list].join(',')}]" },
total,
res,
].flatten

return Result.new.tap do |r|
r.condition = is_success
r.critical = step_list.length > 1
r.fumble = is_fumble
r.text = sequence.join(" > ")
end
end

def roll_step(times)
dice_list = @randomizer.roll_barabara(times, 6).sort.reverse
dice_sum = (dice_list[0] + dice_list[1]).clamp(2, 10)

return {dice_list: dice_list, dice_sum: dice_sum}
end
end
end
end
141 changes: 141 additions & 0 deletions test/data/DemonSpike.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
[[ test ]]
game_system = "DemonSpike"
input = "DS+7"
output = "(2DS+7) > 9[5,4] > 16 > 成功, 成功度1"
success = true
rands = [
{ sides = 6, value = 4 },
{ sides = 6, value = 5 },
]

[[ test ]]
game_system = "DemonSpike"
input = "DS+7"
output = "(2DS+7) > 10[6,5] > 10[6,6] > 2[1,1] > 29 > 成功, 成功度2"
success = true
critical = true
rands = [
{ sides = 6, value = 6 },
{ sides = 6, value = 5 },
{ sides = 6, value = 6 },
{ sides = 6, value = 6 },
{ sides = 6, value = 1 },
{ sides = 6, value = 1 },
]

[[ test ]]
game_system = "DemonSpike"
input = "DS+8"
output = "(2DS+8) > 10[6,5] > 10[6,6] > 2[1,1] > 30 > 成功, 成功度3"
success = true
critical = true
rands = [
{ sides = 6, value = 6 },
{ sides = 6, value = 5 },
{ sides = 6, value = 6 },
{ sides = 6, value = 6 },
{ sides = 6, value = 1 },
{ sides = 6, value = 1 },
]

[[ test ]]
game_system = "DemonSpike"
input = "DS+6"
output = "(2DS+6) > 3[2,1] > 9 > 失敗"
failure = true
rands = [
{ sides = 6, value = 2 },
{ sides = 6, value = 1 },
]

[[ test ]]
game_system = "DemonSpike"
input = "DS+7"
output = "(2DS+7) > 2[1,1] > 0 > 自動的失敗"
failure = true
fumble = true
rands = [
{ sides = 6, value = 1 },
{ sides = 6, value = 1 },
]

[[ test ]]
game_system = "DemonSpike"
input = "DS"
output = "(2DS) > 10[5,5] > 7[5,2] > 17 > 成功, 成功度1"
success = true
critical = true
rands = [
{ sides = 6, value = 5 },
{ sides = 6, value = 5 },
{ sides = 6, value = 5 },
{ sides = 6, value = 2 },
]

[[ test ]]
game_system = "DemonSpike"
input = "DS"
output = "(2DS) > 9[5,4] > 9 > 失敗"
failure = true
rands = [
{ sides = 6, value = 4 },
{ sides = 6, value = 5 },
]

[[ test ]]
game_system = "DemonSpike"
input = "3DS+7"
output = "(3DS+7) > 9[5,4,3] > 16 > 成功, 成功度1"
success = true
rands = [
{ sides = 6, value = 4 },
{ sides = 6, value = 5 },
{ sides = 6, value = 3 },
]

[[ test ]]
game_system = "DemonSpike"
input = "3DS+7"
output = "(3DS+7) > 3[2,1,1] > 10 > 成功, 成功度1"
success = true
rands = [
{ sides = 6, value = 1 },
{ sides = 6, value = 1 },
{ sides = 6, value = 2 },
]

[[ test ]]
game_system = "DemonSpike"
input = "3DS+7"
output = "(3DS+7) > 2[1,1,1] > 0 > 自動的失敗"
failure = true
fumble = true
rands = [
{ sides = 6, value = 1 },
{ sides = 6, value = 1 },
{ sides = 6, value = 1 },
]

[[ test ]]
game_system = "DemonSpike"
input = "3DS+7"
output = "(3DS+7) > 10[6,5,1] > 10[6,6,1] > 2[1,1,1] > 29 > 成功, 成功度2"
success = true
critical = true
rands = [
{ sides = 6, value = 6 },
{ sides = 6, value = 5 },
{ sides = 6, value = 1 },
{ sides = 6, value = 6 },
{ sides = 6, value = 6 },
{ sides = 6, value = 1 },
{ sides = 6, value = 1 },
{ sides = 6, value = 1 },
{ sides = 6, value = 1 },
]

[[ test ]]
game_system = "DemonSpike"
input = "1DS"
output = ""
rands = []