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

サンサーラ・バラッドのダイスボット追加 #203

Merged
merged 14 commits into from
May 25, 2020
Merged
Show file tree
Hide file tree
Changes from 8 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 src/configBcDice.rb
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@
Ryutama
SMTKakuseihen
SRS
SamsaraBallad
Satasupe
SevenFortressMobius
ScreamHighSchool
Expand Down
1 change: 1 addition & 0 deletions src/diceBot/DiceBotLoaderList.rb
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ def self.find(gameTitle)
DiceBotLoader.new('DarkSouls'),
DiceBotLoader.new('SterileLife'),
DiceBotLoader.new('Paradiso'),
DiceBotLoader.new('SamsaraBallad'),
DiceBotLoader.new('None', :filenames => [], :class => :DiceBot)
]
end
127 changes: 127 additions & 0 deletions src/diceBot/SamsaraBallad.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
# -*- coding: utf-8 -*-
# frozen_string_literal: true

class SamsaraBallad < DiceBot
# ゲームシステムの識別子
ID = 'SamsaraBallad'

# ゲームシステム名
NAME = 'サンサーラ・バラッド'

# ゲームシステム名の読みがな
#
# 「ゲームシステム名の読みがなの設定方法」(docs/dicebot_sort_key.md)を参考にして
# 設定してください
SORT_KEY = 'さんさあらはらつと'

# ダイスボットの使い方
HELP_MESSAGE = <<MESSAGETEXT
SB 通常の1d100ロールを行う
SBS スワップロールで1d100ロールを行う
SB#x@y F値をx、C値をyとして通常の1d100ロールを行う
SBS#x@y F値をx、C値をyとしてスワップロールで1d100ロールを行う

例:
SB<=85 通常の技能で成功率85%の判定
SBS<=70 習熟を得た技能で成功率70%の判定
SBS#3@7<=80 習熟を得た技能で、F値3、C値7で成功率80%の判定
MESSAGETEXT

# ダイスボットで使用するコマンドを配列で列挙する
setPrefixes(['SBS?(#\d@\d)?.*'])

def initialize
@swap = false
@f_value = -1
@c_value = 10
super
end

def rollDiceCommand(command)
debug("rollDiceCommand Begin")

case command
when /SBS#(\d)@(\d)/i
debug("Swap roll with F and C")
@swap = true
@f_value = Regexp.last_match(1).to_i
@c_value = Regexp.last_match(2).to_i
ochaochaocha3 marked this conversation as resolved.
Show resolved Hide resolved
return getCheckResult(command)
when /SB#(\d)@(\d)/i
debug("Normal roll with F and C")
@swap = false
@f_value = Regexp.last_match(1).to_i
@c_value = Regexp.last_match(2).to_i
return getCheckResult(command)
when /SBS/i
debug("Swap roll")
@swap = true
@f_value = -1
@c_value = 10
return getCheckResult(command)
when /SB/i
debug("Normal roll")
@swap = false
@f_value = -1
@c_value = 10
return getCheckResult(command)
end
return nil
end

def getCheckResult(command)
diff = 0

if (m = %r{SBS?(#\d@\d)?<=([+-/*\d]+)}i.match(command))
diff = ArithmeticEvaluator.new.eval(m[2])
end
ochaochaocha3 marked this conversation as resolved.
Show resolved Hide resolved

if @swap
d100_n1, = roll(1, 10)
d100_n2, = roll(1, 10)
d100_dice = [d100_n1, d100_n2]
min_n = d100_dice.min
max_n = d100_dice.max
debug(min_n, max_n)
if min_n == 10
total_n = 100
elsif max_n == 10
total_n = min_n
else
total_n = 10 * min_n + max_n
end
dice_label = "#{d100_n1},#{d100_n2} > #{total_n}"
else
total_n, = roll(1, 100)
dice_label = total_n.to_s
end

is_fumble = @f_value >= 0 && total_n % 10 <= @f_value
is_critical = !is_fumble && @c_value < 10 && total_n % 10 >= @c_value

if diff > 0
output = "(D100<=#{diff})"
output += " > #{dice_label}"
if (total_n <= diff) && (total_n < 100)
if is_fumble
output += " > ファンブル"
elsif is_critical
output += " > クリティカル"
else
output += " > 成功"
end
else
output += " > 失敗"
end
else
output = "D100 > #{dice_label}"
if is_fumble
output += " > ファンブル"
elsif is_critical
output += " > クリティカル"
end
end

return output
end
end
203 changes: 203 additions & 0 deletions src/test/data/SamsaraBallad.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,203 @@
input:
1D100<=90 roll 90
output:
SamsaraBallad : (1D100<=90) > 99 > 失敗
rand:99/100
============================
input:
SB roll
output:
SamsaraBallad : D100 > 75
rand:75/100
============================
input:
SB#2@8 roll
output:
SamsaraBallad : D100 > 80 > ファンブル
rand:80/100
============================
input:
SB#2@8 roll
output:
SamsaraBallad : D100 > 83
rand:83/100
============================
input:
SB#2@8 roll
output:
SamsaraBallad : D100 > 89 > クリティカル
rand:89/100
============================
input:
SBS roll
output:
SamsaraBallad : D100 > 7,5 > 57
rand:7/10,5/10
============================
input:
SBS roll
output:
SamsaraBallad : D100 > 7,10 > 7
rand:7/10,10/10
============================
input:
SBS roll
output:
SamsaraBallad : D100 > 10,10 > 100
rand:10/10,10/10
============================
input:
SB<=90 roll 90
output:
SamsaraBallad : (D100<=90) > 75 > 成功
rand:75/100
============================
input:
SB<=80 roll 80
output:
SamsaraBallad : (D100<=80) > 80 > 成功
rand:80/100
============================
input:
SB<=80 roll 79
output:
SamsaraBallad : (D100<=80) > 79 > 成功
rand:79/100
============================
input:
SB<=80 roll 80
output:
SamsaraBallad : (D100<=80) > 81 > 失敗
rand:81/100
============================
input:
SB<=90 roll 90
output:
SamsaraBallad : (D100<=90) > 100 > 失敗
rand:100/100
============================
input:
SBS<=80 roll 80 swap
output:
SamsaraBallad : (D100<=80) > 8,9 > 89 > 失敗
rand:8/10,9/10
============================
input:
SBS<=80 roll 80 swap
output:
SamsaraBallad : (D100<=80) > 8,1 > 18 > 成功
rand:8/10,1/10
============================
input:
SBS<=80 roll 80 swap
output:
SamsaraBallad : (D100<=80) > 7,9 > 79 > 成功
rand:7/10,9/10
============================
input:
SBS<=90 roll 90 swap
output:
SamsaraBallad : (D100<=90) > 10,10 > 100 > 失敗
rand:10/10,10/10
============================
input:
SB#2@8<=90 roll 90
output:
SamsaraBallad : (D100<=90) > 54 > 成功
rand:54/100
============================
input:
SB#2@8<=90 roll 90
output:
SamsaraBallad : (D100<=90) > 58 > クリティカル
rand:58/100
============================
input:
SB#2@8<=90 roll 90
output:
SamsaraBallad : (D100<=90) > 59 > クリティカル
rand:59/100
============================
input:
SB#2@8<=90 roll 90
output:
SamsaraBallad : (D100<=90) > 57 > 成功
rand:57/100
============================
input:
SB#0@9<=80 roll 80
output:
SamsaraBallad : (D100<=80) > 81 > 失敗
rand:81/100
============================
input:
SB#2@8<=90 roll 90
output:
SamsaraBallad : (D100<=90) > 52 > ファンブル
rand:52/100
============================
input:
SB#0@8<=90 roll 90
output:
SamsaraBallad : (D100<=90) > 80 > ファンブル
rand:80/100
============================
input:
SB#2@8<=90 roll 90
output:
SamsaraBallad : (D100<=90) > 51 > ファンブル
rand:51/100
============================
input:
SBS#2@8<=80 roll 80
output:
SamsaraBallad : (D100<=80) > 8,1 > 18 > クリティカル
rand:8/10,1/10
============================
input:
SBS#2@8<=80 roll 80
output:
SamsaraBallad : (D100<=80) > 9,7 > 79 > クリティカル
rand:9/10,7/10
============================
input:
SBS#2@8<=80 roll 80
output:
SamsaraBallad : (D100<=80) > 7,5 > 57 > 成功
rand:7/10,5/10
============================
input:
SBS#2@8<=80 roll 80
output:
SamsaraBallad : (D100<=80) > 5,7 > 57 > 成功
rand:5/10,7/10
============================
input:
SBS#2@8<=80 roll 80
output:
SamsaraBallad : (D100<=80) > 8,9 > 89 > 失敗
rand:8/10,9/10
============================
input:
SBS#2@8<=80 roll 80
output:
SamsaraBallad : (D100<=80) > 2,1 > 12 > ファンブル
rand:2/10,1/10
============================
input:
SBS#2@8<=90 roll 90
output:
SamsaraBallad : (D100<=90) > 1,3 > 13 > 成功
rand:1/10,3/10
============================
input:
SBS#2@8<=90 roll 90
output:
SamsaraBallad : (D100<=90) > 1,1 > 11 > ファンブル
rand:1/10,1/10
============================
input:
SB#5@3<=90 roll 90
output:
SamsaraBallad : (D100<=90) > 24 > ファンブル
rand:24/100