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

アサルトエンジンダイスボットを新規実装 #506

Merged
merged 1 commit into from
Oct 16, 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 @@ -14,6 +14,7 @@
require "bcdice/game_system/AnimaAnimus"
require "bcdice/game_system/Arianrhod"
require "bcdice/game_system/ArsMagica"
require "bcdice/game_system/AssaultEngine"
require "bcdice/game_system/Avandner"
require "bcdice/game_system/BBN"
require "bcdice/game_system/BadLife"
Expand Down
91 changes: 91 additions & 0 deletions lib/bcdice/game_system/AssaultEngine.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
# frozen_string_literal: true

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

# ゲームシステム名
NAME = 'アサルトエンジン'

# ゲームシステム名の読みがな
SORT_KEY = 'あさるとえんしん'

# ダイスボットの使い方
HELP_MESSAGE = <<~MESSAGETEXT
・判定 AEt (t目標値)
例: AE45 (目標値45)
・リロール nAEt (nロール前の値、t目標値)
例: 76AE45 (目標値45で、76を振り直す)

・スワップ(t目標値) エネミーブックP11
例: AES45 (目標値45、スワップ表示あり)
MESSAGETEXT

register_prefix('\d*AE')

def initialize(command)
super(command)
@round_type = RoundType::FLOOR # 端数切り捨て
end

def eval_game_system_specific_command(command)
cmd = Command::Parser.new(/AES?/, round_type: round_type).enable_prefix_number
.has_suffix_number.parse(command)
return nil unless cmd

target = cmd.suffix_number
target = 99 if target >= 100

if cmd.command.include?("AES") # SWAP初回
total = @randomizer.roll_once(100) % 100 # 0-99
swap = (total % 10) * 10 + (total / 10)
r1 = judge(target, total)
r2 = judge(target, swap)
text = "(AES#{format00(target)}) > #{r1.text} / スワップ#{r2.text}"
check_result(r1, r2, text)
elsif cmd.prefix_number.nil? # 初回ロール
total = @randomizer.roll_once(100) % 100 # 0-99
judge(target, total).tap do |r|
r.text = "(AE#{format00(target)}) > #{r.text}"
end
else # リロール
now = cmd.prefix_number
die = @randomizer.roll_once(10) % 10 # 0-9
new1 = judge(target, (now / 10 * 10) + die) # 1の位を振り直す
new2 = judge(target, now % 10 + die * 10) # 10の位を振り直す

text = "(#{format00(now)}AE#{format00(target)}) > #{die} > #{new1.text} / #{new2.text}"
check_result(new1, new2, text)
end
end

def format00(dice)
format("%02d", dice)
end

def check_result(result1, result2, text)
if result1.critical? || result2.critical?
Result.critical(text)
elsif result1.success? || result2.success?
Result.success(text)
elsif result1.fumble? && result2.fumble?
Result.fumble(text)
else
Result.failure(text)
end
end

def judge(target, total)
double = (total / 10) == (total % 10)
total_text = format00(total)
if total <= target
double ? Result.critical("(#{total_text})クリティカル") : Result.success("(#{total_text})成功")
else
double ? Result.fumble("(#{total_text})ファンブル") : Result.failure("(#{total_text})失敗")
end
end
end
end
end
120 changes: 120 additions & 0 deletions test/data/AssaultEngine.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
[[ test ]]
game_system = "AssaultEngine"
input = "AE44"
output = "(AE44) > (05)成功"
success = true
rands = [ { sides = 100, value = 5 } ]

[[ test ]]
game_system = "AssaultEngine"
input = "AE44"
output = "(AE44) > (33)クリティカル"
success = true
critical = true
rands = [ { sides = 100, value = 33 } ]

[[ test ]]
game_system = "AssaultEngine"
input = "AE44"
output = "(AE44) > (44)クリティカル"
success = true
critical = true
rands = [ { sides = 100, value = 44 } ]

[[ test ]]
game_system = "AssaultEngine"
input = "AE44"
output = "(AE44) > (45)失敗"
failure = true
rands = [ { sides = 100, value = 45 } ]

[[ test ]]
game_system = "AssaultEngine"
input = "AE44"
output = "(AE44) > (55)ファンブル"
failure = true
fumble = true
rands = [ { sides = 100, value = 55 } ]

[[ test ]]
game_system = "AssaultEngine"
input = "AE0 100=00は常にクリティカル"
output = "(AE00) > (00)クリティカル"
success = true
critical = true
rands = [ { sides = 100, value = 100 } ]

[[ test ]]
game_system = "AssaultEngine"
input = "AE09"
output = "(AE09) > (00)クリティカル"
success = true
critical = true
rands = [ { sides = 100, value = 100 } ]

[[ test ]]
game_system = "AssaultEngine"
input = "AE123"
output = "(AE99) > (99)クリティカル"
success = true
critical = true
rands = [ { sides = 100, value = 99 } ]

[[ test ]]
game_system = "AssaultEngine"
input = "AES44"
output = "(AES44) > (00)クリティカル / スワップ(00)クリティカル"
success = true
critical = true
rands = [ { sides = 100, value = 100 } ]

[[ test ]]
game_system = "AssaultEngine"
input = "AES44"
output = "(AES44) > (53)失敗 / スワップ(35)成功"
success = true
rands = [ { sides = 100, value = 53 } ]

[[ test ]]
game_system = "AssaultEngine"
input = "AES44"
output = "(AES44) > (00)クリティカル / スワップ(00)クリティカル"
success = true
critical = true
rands = [ { sides = 100, value = 100 } ]

[[ test ]]
game_system = "AssaultEngine"
input = "12AES44 AESではprefix無視"
output = "(AES44) > (43)成功 / スワップ(34)成功"
success = true
rands = [ { sides = 100, value = 43 } ]

[[ test ]]
game_system = "AssaultEngine"
input = "56AE44"
output = "(56AE44) > 1 > (51)失敗 / (16)成功"
success = true
rands = [ { sides = 10, value = 1 } ]

[[ test ]]
game_system = "AssaultEngine"
input = "56AE44"
output = "(56AE44) > 8 > (58)失敗 / (86)失敗"
failure = true
rands = [ { sides = 10, value = 8 } ]

[[ test ]]
game_system = "AssaultEngine"
input = "66AE44 本来ファンブルは振り直せないが、警告等はださない"
output = "(66AE44) > 7 > (67)失敗 / (76)失敗"
failure = true
rands = [ { sides = 10, value = 7 } ]

[[ test ]]
game_system = "AssaultEngine"
input = "90AE44"
output = "(90AE44) > 0 > (90)失敗 / (00)クリティカル"
success = true
critical = true
rands = [ { sides = 10, value = 10 } ]