Skip to content

Commit

Permalink
Merge pull request #145 from bcdice/refactor_check_suc
Browse files Browse the repository at this point in the history
Refactor BCDice#check_suc
  • Loading branch information
ysakasin authored Apr 2, 2020
2 parents 4875ce6 + 414bf48 commit 8e70b47
Show file tree
Hide file tree
Showing 72 changed files with 903 additions and 1,087 deletions.
75 changes: 0 additions & 75 deletions src/bcdiceCore.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1444,81 +1444,6 @@ def check_hit(dice_now, signOfInequality, diff) # 成功数判定用
return suc
end

#################### ゲーム別成功度判定 ########################
def check_suc(*check_param)
total_n, dice_n, signOfInequality, diff, dice_cnt, dice_max, n1, n_max = *check_param

debug('check params : total_n, dice_n, signOfInequality, diff, dice_cnt, dice_max, n1, n_max',
total_n, dice_n, signOfInequality, diff, dice_cnt, dice_max, n1, n_max)

return "" unless /((\+|\-)?[\d]+)[)]?$/ =~ total_n.to_s

total_n = Regexp.last_match(1).to_i
diff = diff.to_i

check_paramNew = [total_n, dice_n, signOfInequality, diff, dice_cnt, dice_max, n1, n_max]

text = getSuccessText(*check_paramNew)
text ||= ""

if text.empty?
if signOfInequality != ""
debug('どれでもないけど判定するとき')
return check_nDx(*check_param)
end
end

return text
end

def getSuccessText(*check_param)
debug('getSuccessText begin')

_total_n, _dice_n, _signOfInequality, _diff, dice_cnt, dice_max, = *check_param

debug("dice_max, dice_cnt", dice_max, dice_cnt)

if (dice_max == 100) && (dice_cnt == 1)
debug('1D100判定')
return @diceBot.check_1D100(*check_param)
end

if (dice_max == 20) && (dice_cnt == 1)
debug('1d20判定')
return @diceBot.check_1D20(*check_param)
end

if dice_max == 10
debug('d10ベース判定')
return @diceBot.check_nD10(*check_param)
end

if dice_max == 6
if dice_cnt == 2
debug('2d6判定')
result = @diceBot.check_2D6(*check_param)
return result unless result.empty?
end

debug('xD6判定')
return @diceBot.check_nD6(*check_param)
end

return ""
end

def check_nDx(total_n, _dice_n, signOfInequality, diff, _dice_cnt, _dice_max, _n1, _n_max) # ゲーム別成功度判定(ダイスごちゃ混ぜ系)
debug('check_nDx begin diff', diff)
success = check_hit(total_n, signOfInequality, diff)
debug('check_nDx success', success)

if success >= 1
return " > 成功"
end

return " > 失敗"
end

###########################################################################
# ** 出力関連
###########################################################################
Expand Down
18 changes: 13 additions & 5 deletions src/dice/AddDice.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
# -*- coding: utf-8 -*-

require "utils/normalize"

class AddDice
def initialize(bcdice, diceBot)
@bcdice = bcdice
@diceBot = diceBot
@nick_e = @bcdice.nick_e

@dice_list = []
end

#################### 加算ダイス ########################
Expand Down Expand Up @@ -69,9 +73,6 @@ def rollDice(string)
string += "#{signOfInequality}#{diffText}"
end

@diceBot.setDiceText(output)
@diceBot.setDiffText(diffText)

# ダイス目による補正処理(現状ナイトメアハンターディープ専用)
addText, revision = @diceBot.getDiceRevision(n_max, dice_max, total_n)
debug('addText, revision', addText, revision)
Expand All @@ -90,7 +91,9 @@ def rollDice(string)
total_n += revision

if signOfInequality != "" # 成功度判定処理
successText = @bcdice.check_suc(total_n, dice_n, signOfInequality, diffText, dice_cnt, dice_max, n1, n_max)
cmp_op = Normalize.comparison_operator(signOfInequality)
target = Normalize.target_number(diffText)
successText = @diceBot.check_result(total_n, dice_n, @dice_list, dice_max, cmp_op, target)
debug("check_suc successText", successText)
output += successText
end
Expand Down Expand Up @@ -295,7 +298,10 @@ def rollLocal(dice_wk, dice_max, sortType)
return rollD66(dice_wk)
end

return @bcdice.roll(dice_wk, dice_max, sortType)
ret = @bcdice.roll(dice_wk, dice_max, sortType)
@dice_list.concat(ret[1].split(",").map(&:to_i))

return ret
end

def rollD66(count)
Expand All @@ -310,6 +316,8 @@ def rollD66(count)
n1Count = d66List.count(1)
nMaxCount = d66List.count(66)

@dice_list.concat(d66List)

return [total, text, n1Count, nMaxCount, 0, 0, 0]
end

Expand Down
39 changes: 17 additions & 22 deletions src/diceBot/Arianrhod.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,28 +24,23 @@ def initialize
@d66Type = 1
end

def check_2D6(total_n, dice_n, signOfInequality, diff, dice_cnt, dice_max, n1, n_max) # ゲーム別成功度判定(2D6)
check_nD6(total_n, dice_n, signOfInequality, diff, dice_cnt, dice_max, n1, n_max)
end

def check_nD6(total_n, _dice_n, signOfInequality, diff, dice_cnt, _dice_max, n1, n_max) # ゲーム別成功度判定(nD6)
debug("check_nD6 begin")

# 全部1の目ならファンブル
return " > ファンブル" if n1 >= dice_cnt

# 2個以上6の目があったらクリティカル
return " > クリティカル(+#{n_max}D6)" if n_max >= 2

result = ''

return result unless signOfInequality == ">="
return result if diff == "?"

if total_n >= diff
return " > 成功"
def check_nD6(total, _dice_total, dice_list, cmp_op, target)
n_max = dice_list.count(6)

if dice_list.count(1) == dice_list.size
# 全部1の目ならファンブル
" > ファンブル"
elsif n_max >= 2
# 2個以上6の目があったらクリティカル
" > クリティカル(+#{n_max}D6)" if n_max >= 2
elsif cmp_op != :>= || target == '?'
''
elsif total >= target
" > 成功"
else
" > 失敗"
end

return " > 失敗"
end

alias check_2D6 check_nD6
end
2 changes: 1 addition & 1 deletion src/diceBot/ArsMagica.rb
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ def arsmagica_stress(string, _nick_e)
end
end
if signOfInequality != "" # 成功度判定処理
output += check_suc(total, 0, signOfInequality, diff, 1, 10, 0, 0)
output += check_result(total, 0, signOfInequality, diff, 1, 10, 0, 0)
end

return output
Expand Down
16 changes: 4 additions & 12 deletions src/diceBot/BeastBindTrinity.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class BeastBindTrinity < DiceBot
HELP_MESSAGE = <<INFO_MESSAGE_TEXT
・判定 (nBB+m%w@x#y$z&v)
 n個のD6を振り、出目の大きい2個から達成値を算出。修正mも可能。
 
 %w、@x、#y、$z、&vはすべて省略可能。
>%w:現在の人間性が w であるとして、クリティカル値(C値)を計算。
・省略した場合、C値=12として達成値を算出する。
Expand Down Expand Up @@ -79,16 +79,6 @@ def dice_command_xRn(string, nick_e)
return bbt_check(string)
end

def check_2D6(total_n, _dice_n, signOfInequality, diff, _dice_cnt, _dice_max, _n1, _n_max) # ゲーム別成功度判定(2D6)
return '' unless signOfInequality == ">="

if total_n >= diff
return " > 成功"
else
return " > 失敗"
end
end

#################### ビーストバインド トリニティ ########################

def bbt_check(string)
Expand Down Expand Up @@ -282,7 +272,9 @@ def bbt_check(string)
end

if signOfInequality != "" # 成功度判定処理
output += check_suc(total_n, dice_now, signOfInequality, diff, 2, 6, 0, 0)
cmp_op = Normalize.comparison_operator(signOfInequality)
dice_list = dice_num
output += check_result(total_n, dice_now, dice_list, 6, cmp_op, diff)
end

return output
Expand Down
25 changes: 12 additions & 13 deletions src/diceBot/BeginningIdol.rb
Original file line number Diff line number Diff line change
Expand Up @@ -150,23 +150,22 @@ def initialize
@d66Type = 2
end

def check_2D6(total_n, dice_n, signOfInequality, diff, dice_cnt, dice_max, n1, n_max)
check_nD6(total_n, dice_n, signOfInequality, diff, dice_cnt, dice_max, n1, n_max)
end

def check_nD6(total_n, dice_n, signOfInequality, diff, _dice_cnt, _dice_max, _n1, _n_max)
return '' unless signOfInequality == ">="
if dice_n <= 2
return " > ファンブル(変調がランダムに1つ発生し、PCは【思い出】を1つ獲得する)"
elsif dice_n >= 12
return " > スペシャル!(PCは【思い出】を1つ獲得する)"
elsif total_n >= diff
return " > 成功"
def check_nD6(total, dice_total, _dice_list, cmp_op, target)
return '' unless cmp_op == :>=

if dice_total <= 2
" > ファンブル(変調がランダムに1つ発生し、PCは【思い出】を1つ獲得する)"
elsif dice_total >= 12
" > スペシャル!(PCは【思い出】を1つ獲得する)"
elsif total >= target
" > 成功"
else
return " > 失敗"
" > 失敗"
end
end

alias check_2D6 check_nD6

def rollDiceCommand(command)
case command.upcase
when /^([1-7]*)PD(\d+)([\+\-]\d+)?$/
Expand Down
25 changes: 12 additions & 13 deletions src/diceBot/BeginningIdol_Korean.rb
Original file line number Diff line number Diff line change
Expand Up @@ -145,23 +145,22 @@ def initialize
@d66Type = 2
end

def check_2D6(total_n, dice_n, signOfInequality, diff, dice_cnt, dice_max, n1, n_max)
check_nD6(total_n, dice_n, signOfInequality, diff, dice_cnt, dice_max, n1, n_max)
end

def check_nD6(total_n, dice_n, signOfInequality, diff, _dice_cnt, _dice_max, _n1, _n_max)
return '' unless signOfInequality == ">="
if dice_n <= 2
return " > ファンブル(変調がランダムに1つ発生し、PCは【思い出】を1つ獲得する)"
elsif dice_n >= 12
return " > 스페셜!(PC는 【추억】 1개 획득)"
elsif total_n >= diff
return " > 성공"
def check_nD6(total, dice_total, _dice_list, cmp_op, target)
return '' unless cmp_op == :>=

if dice_total <= 2
" > ファンブル(変調がランダムに1つ発生し、PCは【思い出】を1つ獲得する)"
elsif dice_total >= 12
" > 스페셜!(PC는 【추억】 1개 획득)"
elsif total >= target
" > 성공"
else
return " > 실패"
" > 실패"
end
end

alias check_2D6 check_nD6

def rollDiceCommand(command)
case command.upcase
when /^([1-7]*)PD(\d+)([\+\-]\d+)?$/
Expand Down
20 changes: 10 additions & 10 deletions src/diceBot/BloodCrusade.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,17 @@ def initialize
@fractionType = "roundUp" # 端数切り上げに設定
end

def check_2D6(total_n, dice_n, signOfInequality, diff, _dice_cnt, _dice_max, _n1, _n_max) # ゲーム別成功度判定(2D6)
return '' unless signOfInequality == ">="

if dice_n <= 2
return " > ファンブル(【モラル】-3。追跡フェイズなら吸血シーンを追加。戦闘フェイズなら吸血鬼は追加行動を一回得る)"
elsif dice_n >= 12
return " > スペシャル(【モラル】+3。追跡フェイズならあなたに関係を持つPCの【モラル】+2。攻撃判定ならダメージ+1D6)"
elsif total_n >= diff
return " > 成功"
def check_2D6(total, dice_total, _dice_list, cmp_op, target)
return '' unless cmp_op == :>=

if dice_total <= 2
" > ファンブル(【モラル】-3。追跡フェイズなら吸血シーンを追加。戦闘フェイズなら吸血鬼は追加行動を一回得る)"
elsif dice_total >= 12
" > スペシャル(【モラル】+3。追跡フェイズならあなたに関係を持つPCの【モラル】+2。攻撃判定ならダメージ+1D6)"
elsif total >= target
" > 成功"
else
return " > 失敗"
" > 失敗"
end
end

Expand Down
10 changes: 5 additions & 5 deletions src/diceBot/BloodMoon.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,14 @@ def initialize
end

# ゲーム別成功度判定(2D6)
def check_2D6(total_n, dice_n, signOfInequality, diff, _dice_cnt, _dice_max, _n1, _n_max)
return '' unless signOfInequality == ">="
def check_2D6(total, dice_total, _dice_list, cmp_op, target)
return '' unless cmp_op == :>=

if dice_n <= 2
if dice_total <= 2
return " > ファンブル(【余裕】が 0 に)"
elsif dice_n >= 12
elsif dice_total >= 12
return " > スペシャル(【余裕】+3)"
elsif total_n >= diff
elsif total >= target
return " > 成功"
else
return " > 失敗"
Expand Down
10 changes: 5 additions & 5 deletions src/diceBot/CardRanker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,14 @@ def initialize
end

# ゲーム別成功度判定(2D6)
def check_2D6(total_n, dice_n, signOfInequality, diff, _dice_cnt, _dice_max, _n1, _n_max)
return '' unless signOfInequality == ">="
def check_2D6(total, dice_total, _dice_list, cmp_op, target)
return '' unless cmp_op == :>=

if dice_n <= 2
if dice_total <= 2
return " > ファンブル"
elsif dice_n >= 12
elsif dice_total >= 12
return " > スペシャル > " + getRandumMonster()
elsif total_n >= diff
elsif total >= target
return " > 成功"
else
return " > 失敗"
Expand Down
Loading

0 comments on commit 8e70b47

Please sign in to comment.