From 6bdb593774d6ff9c0b31160ec6bb50c8c5c4d1f4 Mon Sep 17 00:00:00 2001 From: SAKATA Sinji Date: Mon, 30 Mar 2020 12:47:15 +0900 Subject: [PATCH 1/5] Refactor BCDice#check_suc MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - DiceBot#check_suc に移動 - パラメータを厳格化 - DiceBot#getDiceList, @diceText, @diffText を廃止 --- src/bcdiceCore.rb | 75 -------------------------- src/dice/AddDice.rb | 18 +++++-- src/diceBot/DiceBot.rb | 116 +++++++++++++++++++++++----------------- src/utils/normalizer.rb | 36 +++++++++++++ 4 files changed, 116 insertions(+), 129 deletions(-) create mode 100644 src/utils/normalizer.rb diff --git a/src/bcdiceCore.rb b/src/bcdiceCore.rb index 3582f851e..5c96368f2 100755 --- a/src/bcdiceCore.rb +++ b/src/bcdiceCore.rb @@ -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 - ########################################################################### # ** 出力関連 ########################################################################### diff --git a/src/dice/AddDice.rb b/src/dice/AddDice.rb index b9503123c..4ed7138e4 100644 --- a/src/dice/AddDice.rb +++ b/src/dice/AddDice.rb @@ -1,10 +1,14 @@ # -*- coding: utf-8 -*- +require "utils/normalizer" + class AddDice def initialize(bcdice, diceBot) @bcdice = bcdice @diceBot = diceBot @nick_e = @bcdice.nick_e + + @dice_list = [] end #################### 加算ダイス ######################## @@ -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) @@ -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 = Normalizer.cmp_op(signOfInequality) + target = Normalizer.target_number(diffText) + successText = @diceBot.check_suc(total_n, dice_n, @dice_list, dice_max, cmp_op, target) debug("check_suc successText", successText) output += successText end @@ -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) @@ -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 diff --git a/src/diceBot/DiceBot.rb b/src/diceBot/DiceBot.rb index d30ef587a..9e52f29f9 100644 --- a/src/diceBot/DiceBot.rb +++ b/src/diceBot/DiceBot.rb @@ -188,10 +188,6 @@ def rand(max) @@bcdice.rand(max) end - def check_suc(*params) - @@bcdice.check_suc(*params) - end - def roll(*args) @@bcdice.roll(*args) end @@ -288,39 +284,84 @@ def rollDiceCommand(_command) nil end - def setDiceText(diceText) - debug("setDiceText diceText", diceText) - @diceText = diceText - end - - def setDiffText(diffText) - @diffText = diffText - end - def dice_command_xRn(_string, _nick_e) '' end - def check_2D6(_total_n, _dice_n, _signOfInequality, _diff, _dice_cnt, _dice_max, _n1, _n_max) # ゲーム別成功度判定(2D6) - '' - end + # @param total [Integer] コマンド合計値 + # @param dice_total [Integer] ダイス目の合計値 + # @param dice_list [Array] ダイスの一覧 + # @param sides [Integer] 振ったダイスの面数 + # @param cmp_op [Symbol] 比較演算子 + # @param target [Integer, String] 目標値の整数か'?' + # @return [String] + def check_suc(total, dice_total, dice_list, sides, cmp_op, target) + ret = + case [dice_list.size, sides] + when [1, 100] + check_1D100(total, dice_total, cmp_op, target) + when [1, 20] + check_1D20(total, dice_total, cmp_op, target) + when [2, 6] + check_2D6(total, dice_total, dice_list, cmp_op, target) + end - def check_nD6(_total_n, _dice_n, _signOfInequality, _diff, _dice_cnt, _dice_max, _n1, _n_max) # ゲーム別成功度判定(nD6) - '' - end + return ret unless ret.nil? || ret.empty? - def check_nD10(_total_n, _dice_n, _signOfInequality, _diff, _dice_cnt, _dice_max, _n1, _n_max) # ゲーム別成功度判定(nD10) - '' - end + ret = + case sides + when 10 + check_nD10(total, dice_total, dice_list, cmp_op, target) + when 6 + check_nD6(total, dice_total, dice_list, cmp_op, target) + end - def check_1D100(_total_n, _dice_n, _signOfInequality, _diff, _dice_cnt, _dice_max, _n1, _n_max) # ゲーム別成功度判定(1d100) - '' + return ret unless ret.nil? || ret.empty? + + check_nDx(total, cmp_op, target) end - def check_1D20(_total_n, _dice_n, _signOfInequality, _diff, _dice_cnt, _dice_max, _n1, _n_max) # ゲーム別成功度判定(1d20) - '' + # 成功か失敗かを文字列で返す + # + # @param (see #check_suc) + # @return [String] + def check_nDx(total, cmp_op, target) + return " > 失敗" if target.is_a?(String) + + # Due to Ruby 1.8 + success = cmp_op == :"!=" ? total != target : total.send(cmp_op, target) + if success + " > 成功" + else + " > 失敗" + end end + # @abstruct + # @param (see #check_suc) + # @return [nil] + def check_1D100(total, dice_total, cmp_op, target); end + + # @abstruct + # @param (see #check_suc) + # @return [nil] + def check_1D20(total, dice_total, cmp_op, target); end + + # @abstruct + # @param (see #check_suc) + # @return [nil] + def check_nD10(total, dice_total, dice_list, cmp_op, target); end + + # @abstruct + # @param (see #check_suc) + # @return [nil] + def check_2D6(total, dice_total, dice_list, cmp_op, target); end + + # @abstruct + # @param (see #check_suc) + # @return [nil] + def check_nD6(total, dice_total, dice_list, cmp_op, target); end + def get_table_by_2d6(table) get_table_by_nD6(table, 2) end @@ -431,29 +472,6 @@ def should_reroll?(loop_count) loop_count < @rerollLimitCount || @rerollLimitCount == 0 end - def getDiceList - getDiceListFromDiceText(@diceText) - end - - def getDiceListFromDiceText(diceText) - debug("getDiceList diceText", diceText) - - diceList = [] - - if /\[([\d,]+)\]/ =~ diceText - diceText = Regexp.last_match(1) - end - - return diceList unless /([\d,]+)/ =~ diceText - - diceString = Regexp.last_match(1) - diceList = diceString.split(/,/).collect { |i| i.to_i } - - debug("diceList", diceList) - - return diceList - end - # ** 汎用表サブルーチン def get_table_by_number(index, table, default = '1') table.each do |item| diff --git a/src/utils/normalizer.rb b/src/utils/normalizer.rb new file mode 100644 index 000000000..ef59e62c7 --- /dev/null +++ b/src/utils/normalizer.rb @@ -0,0 +1,36 @@ +module Normalizer + module_function + + # 比較演算子をシンボルに正規化する + # + # @param op [String] + # @return [Symbol, nil] + def cmp_op(op) + case op + when /<=|==|=>/ + :>= + when /<>|!=|=!/ + :'!=' + when // + :> + when /\=/ + :== + end + end + + # 目標値を正規化する + # + # @param val [String] + # @return [Integer, String] 整数か'?' + def target_number(val) + if val == '?' + val + else + val.to_i + end + end +end From 01807724048991938ce86d3914839a32d870efc5 Mon Sep 17 00:00:00 2001 From: SAKATA Sinji Date: Mon, 30 Mar 2020 12:50:07 +0900 Subject: [PATCH 2/5] =?UTF-8?q?DiceBot#check=5Fsuc=E9=96=A2=E9=80=A3?= =?UTF-8?q?=E3=81=AE=E3=83=80=E3=82=A4=E3=82=B9=E3=83=9C=E3=83=83=E3=83=88?= =?UTF-8?q?=E5=81=B4=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - GranCrest: 目標値?の挙動修正 - RuneQuest: 成功度の範囲を確認するテストを追加 --- src/diceBot/Arianrhod.rb | 39 ++++------ src/diceBot/BeastBindTrinity.rb | 16 +--- src/diceBot/BeginningIdol.rb | 25 +++--- src/diceBot/BeginningIdol_Korean.rb | 25 +++--- src/diceBot/BloodCrusade.rb | 20 ++--- src/diceBot/BloodMoon.rb | 10 +-- src/diceBot/CardRanker.rb | 10 +-- src/diceBot/ChaosFlare.rb | 21 ++--- src/diceBot/Chill.rb | 27 ++++--- src/diceBot/Chill3.rb | 39 ++++------ src/diceBot/CthulhuTech.rb | 30 +++---- src/diceBot/DarkBlaze.rb | 24 +++--- src/diceBot/DarkDaysDrive.rb | 27 +++---- src/diceBot/DemonParasite.rb | 29 +++---- src/diceBot/DoubleCross.rb | 14 ++-- src/diceBot/EclipsePhase.rb | 27 ++++--- src/diceBot/Elric.rb | 14 ++-- src/diceBot/EmbryoMachine.rb | 21 +++-- src/diceBot/Gorilla.rb | 26 ++----- src/diceBot/GranCrest.rb | 25 +++--- src/diceBot/Gundog.rb | 34 ++++---- src/diceBot/GundogRevised.rb | 34 ++++---- src/diceBot/Gurps.rb | 29 ++++--- src/diceBot/GurpsFW.rb | 63 +++++++-------- src/diceBot/HarnMaster.rb | 6 +- src/diceBot/Hieizan.rb | 45 +++++------ src/diceBot/HouraiGakuen.rb | 7 +- src/diceBot/HuntersMoon.rb | 20 ++--- src/diceBot/InfiniteFantasia.rb | 43 +++++----- src/diceBot/Insane.rb | 29 +++---- src/diceBot/Insane_Korean.rb | 29 +++---- src/diceBot/IthaWenUa.rb | 27 ++----- src/diceBot/JamesBond.rb | 43 +++++----- src/diceBot/KanColle.rb | 20 ++--- src/diceBot/KillDeathBusiness.rb | 29 +++---- src/diceBot/KillDeathBusiness_Korean.rb | 29 +++---- src/diceBot/MagicaLogia.rb | 27 ++----- src/diceBot/MeikyuDays.rb | 25 +++--- src/diceBot/MeikyuKingdom.rb | 95 ++++++++++------------- src/diceBot/MetalHead.rb | 28 +++---- src/diceBot/Nechronica.rb | 59 ++++---------- src/diceBot/Nechronica_Korean.rb | 42 ++++------ src/diceBot/NightWizard.rb | 11 --- src/diceBot/NightmareHunterDeep.rb | 21 +++-- src/diceBot/NjslyrBattle.rb | 39 ++++------ src/diceBot/OneWayHeroics.rb | 2 +- src/diceBot/Peekaboo.rb | 10 +-- src/diceBot/Pendragon.rb | 24 +++--- src/diceBot/PhantasmAdventure.rb | 10 +-- src/diceBot/RuneQuest.rb | 38 +++++---- src/diceBot/SharedFantasia.rb | 27 +++---- src/diceBot/ShinMegamiTenseiKakuseihen.rb | 25 +++--- src/diceBot/ShinobiGami.rb | 18 ++--- src/diceBot/StratoShout.rb | 10 +-- src/diceBot/SwordWorld.rb | 27 +++---- src/diceBot/SwordWorld2_0.rb | 11 ++- src/diceBot/TokumeiTenkousei.rb | 10 +-- src/diceBot/TrinitySeven.rb | 9 ++- src/diceBot/TunnelsAndTrolls.rb | 26 +++---- src/diceBot/WARPS.rb | 29 +++---- src/diceBot/WaresBlade.rb | 28 +++---- src/diceBot/Warhammer.rb | 14 ++-- src/diceBot/YankeeYogSothoth.rb | 25 +++--- src/diceBot/_InsaneScp.rb | 29 +++---- src/diceBot/_Template.rb | 2 - src/test/data/GranCrest.txt | 4 +- src/test/data/RuneQuest.txt | 60 ++++++++++++++ 67 files changed, 785 insertions(+), 956 deletions(-) diff --git a/src/diceBot/Arianrhod.rb b/src/diceBot/Arianrhod.rb index c2e761c22..5ebfe6b55 100644 --- a/src/diceBot/Arianrhod.rb +++ b/src/diceBot/Arianrhod.rb @@ -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 diff --git a/src/diceBot/BeastBindTrinity.rb b/src/diceBot/BeastBindTrinity.rb index e8272b53d..3b5f3fcc7 100644 --- a/src/diceBot/BeastBindTrinity.rb +++ b/src/diceBot/BeastBindTrinity.rb @@ -24,7 +24,7 @@ class BeastBindTrinity < DiceBot HELP_MESSAGE = <=" - - if total_n >= diff - return " > 成功" - else - return " > 失敗" - end - end - #################### ビーストバインド トリニティ ######################## def bbt_check(string) @@ -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 = Normalizer.cmp_op(signOfInequality) + dice_list = dice_num + output += check_suc(total_n, dice_now, dice_list, 6, cmp_op, diff) end return output diff --git a/src/diceBot/BeginningIdol.rb b/src/diceBot/BeginningIdol.rb index 7a61504d3..b8f1721b9 100644 --- a/src/diceBot/BeginningIdol.rb +++ b/src/diceBot/BeginningIdol.rb @@ -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+)?$/ diff --git a/src/diceBot/BeginningIdol_Korean.rb b/src/diceBot/BeginningIdol_Korean.rb index 7b446ca4b..717a2a247 100644 --- a/src/diceBot/BeginningIdol_Korean.rb +++ b/src/diceBot/BeginningIdol_Korean.rb @@ -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+)?$/ diff --git a/src/diceBot/BloodCrusade.rb b/src/diceBot/BloodCrusade.rb index 82c713d0e..2330d834e 100644 --- a/src/diceBot/BloodCrusade.rb +++ b/src/diceBot/BloodCrusade.rb @@ -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 diff --git a/src/diceBot/BloodMoon.rb b/src/diceBot/BloodMoon.rb index 382e57dbc..7b2229dd4 100644 --- a/src/diceBot/BloodMoon.rb +++ b/src/diceBot/BloodMoon.rb @@ -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 " > 失敗" diff --git a/src/diceBot/CardRanker.rb b/src/diceBot/CardRanker.rb index a48ed4eff..7a56d5dad 100644 --- a/src/diceBot/CardRanker.rb +++ b/src/diceBot/CardRanker.rb @@ -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 " > 失敗" diff --git a/src/diceBot/ChaosFlare.rb b/src/diceBot/ChaosFlare.rb index 18e4e281c..fce2f1423 100644 --- a/src/diceBot/ChaosFlare.rb +++ b/src/diceBot/ChaosFlare.rb @@ -29,24 +29,25 @@ def postSet end # ゲーム別成功度判定(2D6) - def check_2D6(total_n, dice_n, signOfInequality, diff, _dice_cnt, _dice_max, _n1, _n_max) + def check_2D6(total, dice_total, _dice_list, cmp_op, target) output = '' - if dice_n <= 2 - total_n -= 20 - output += " > ファンブル(-20)" + if dice_total <= 2 + total -= 20 + output = " > ファンブル(-20)" end - return output unless signOfInequality == ">=" + unless cmp_op == :>= + return output + end - if total_n >= diff + if total >= target output += " > 成功" - if total_n > diff - output += " > 差分値#{total_n - diff}" + if total > target + output += " > 差分値#{total - target}" end else - output += " > 失敗" - output += " > 差分値#{total_n - diff}" + output += " > 失敗 > 差分値#{total - target}" end return output diff --git a/src/diceBot/Chill.rb b/src/diceBot/Chill.rb index 1b77fbfe2..7e00abb50 100644 --- a/src/diceBot/Chill.rb +++ b/src/diceBot/Chill.rb @@ -23,17 +23,22 @@ class Chill < DiceBot setPrefixes(['SR\d+.*']) - def check_1D100(total_n, _dice_n, signOfInequality, diff, _dice_cnt, _dice_max, _n1, _n_max) # ゲーム別成功度判定(1D10) - return '' if signOfInequality != "<=" - - return " > ファンブル" if total_n >= 100 - return " > 失敗" if total_n > diff - - return " > L成功" if total_n >= (diff * 0.9) - return " > M成功" if total_n >= (diff / 2) - return " > H成功" if total_n >= (diff / 10) - - return " > C成功" + def check_1D100(total, _dice_total, cmp_op, target) + return '' if cmp_op != :<= + + if total >= 100 + " > ファンブル" + elsif total > target + " > 失敗" + elsif total >= (target * 0.9) + " > L成功" + elsif total >= (target / 2) + " > M成功" + elsif total >= (target / 10) + " > H成功" + else + " > C成功" + end end def rollDiceCommand(command) diff --git a/src/diceBot/Chill3.rb b/src/diceBot/Chill3.rb index 6e116b11d..273d65b67 100644 --- a/src/diceBot/Chill3.rb +++ b/src/diceBot/Chill3.rb @@ -18,36 +18,31 @@ class Chill3 < DiceBot    Chill3 : (1D100<=50) > 55 > Botch INFO_MESSAGE_TEXT - def check_1D100(total_n, dice_n, signOfInequality, diff, _dice_cnt, _dice_max, _n1, _n_max) # ゲーム別成功度判定(1D100) - return '' unless signOfInequality == "<=" + def check_1D100(total, dice_total, cmp_op, target) + return '' unless cmp_op == :<= # ゾロ目ならC-ResultかBotch - s10 = dice_n.div(10) # 10'sダイスの出目 - s1 = dice_n % 10 # 1'sダイスの出目 + tens = (dice_total / 10) % 10 + ones = dice_total % 10 - if s10 == 10 - s10 = 0 # 10'sと1'sの表記をそろえる - end - - if s10 == s1 - if (total_n > diff) || (dice_n == 100) # 00は必ず失敗 - if diff > 100 # 目標値が100を超えている場合は、00を振ってもBotchにならない + if tens == ones + if (total > target) || (dice_total == 100) # 00は必ず失敗 + if target > 100 # 目標値が100を超えている場合は、00を振ってもBotchにならない return " > 失敗" + else + return " > Botch" end - - return " > Botch" + else + return " > C成功" end - return " > C成功" - end - - if (total_n <= diff) || (dice_n == 1) # 01は必ず成功 - if total_n <= (diff / 2) + elsif (total <= target) || (dice_total == 1) # 01は必ず成功 + if total <= (target / 2) return " > H成功" + else + return " > L成功" end - - return " > L成功" + else + return " > 失敗" end - - return " > 失敗" end end diff --git a/src/diceBot/CthulhuTech.rb b/src/diceBot/CthulhuTech.rb index fb4b06d88..e77c5da39 100644 --- a/src/diceBot/CthulhuTech.rb +++ b/src/diceBot/CthulhuTech.rb @@ -24,47 +24,47 @@ def initialize @sortType = 1 end - def check_nD10(total_n, dice_n, signOfInequality, diff, dice_cnt, dice_max, n1, n_max) # ゲーム別成功度判定(nD10) - if signOfInequality == ">=" # 通常のテスト + def check_nD10(total, dice_total, dice_list, cmp_op, target) + if cmp_op == :>= + # 通常のテスト @isCombatTest = false - return check_nD10_nomalTest(total_n, dice_n, signOfInequality, diff, dice_cnt, dice_max, n1, n_max) - end - - if signOfInequality == ">" # コンバットテスト + return check_nD10_nomalTest(total, dice_total, dice_list, cmp_op, target) + elsif cmp_op == :> + # コンバットテスト @isCombatTest = true - return check_nD10_combatTest(total_n, dice_n, signOfInequality, diff, dice_cnt, dice_max, n1, n_max) + return check_nD10_combatTest(total, dice_total, dice_list, cmp_op, target) end end - def check_nD10_nomalTest(total_n, _dice_n, _signOfInequality, diff, dice_cnt, _dice_max, n1, _n_max) - if n1 >= (dice_cnt / 2 + 0.9).to_i + def check_nD10_nomalTest(total, _dice_total, dice_list, _cmp_op, target) + if dice_list.count(1) >= (dice_list.size + 1) / 2 return " > ファンブル" end isSuccess = false if @isCombatTest - isSuccess = (total_n > diff) + isSuccess = (total > target) else - isSuccess = (total_n >= diff) + isSuccess = (total >= target) end unless isSuccess return " > 失敗" end - if total_n >= diff + 10 + if total >= target + 10 return " > クリティカル" end return " > 成功" end - def check_nD10_combatTest(total_n, dice_n, signOfInequality, diff, dice_cnt, dice_max, n1, n_max) - result = check_nD10_nomalTest(total_n, dice_n, signOfInequality, diff, dice_cnt, dice_max, n1, n_max) + def check_nD10_combatTest(total, dice_total, dice_list, cmp_op, target) + result = check_nD10_nomalTest(total, dice_total, dice_list, cmp_op, target) case result when " > クリティカル", " > 成功" - result += getDamageDice(total_n, diff) + result += getDamageDice(total, target) end return result diff --git a/src/diceBot/DarkBlaze.rb b/src/diceBot/DarkBlaze.rb index c11a1b3c6..2809863fa 100644 --- a/src/diceBot/DarkBlaze.rb +++ b/src/diceBot/DarkBlaze.rb @@ -49,16 +49,14 @@ def dice_command_xRn(string, nick_e) end # ゲーム別成功度判定(nD6) - def check_nD6(total_n, _dice_n, signOfInequality, diff, _dice_cnt, _dice_max, _n1, _n_max) - return '' unless signOfInequality == ">=" - - return '' if diff == "?" - - if total_n >= diff - return " > 成功" + def check_nD6(total, _dice_total, _dice_list, cmp_op, target) + if cmp_op != :>= || target == "?" + '' + elsif total >= target + " > 成功" + else + " > 失敗" end - - return " > 失敗" end def check_roll(string, nick_e) @@ -85,11 +83,13 @@ def check_roll(string, nick_e) diff = m[9].to_i end - total, out_str = get_dice(mod, abl, skl) + total, out_str, dice_list = get_dice(mod, abl, skl) output = "#{nick_e}: (#{string}) > #{out_str}" if signOfInequality != "" # 成功度判定処理 - output += check_suc(total, 0, signOfInequality, diff, 3, 6, 0, 0) + dice_total = dice_list.inject(&:+) + cmp_op = Normalizer.cmp_op(signOfInequality) + output += check_suc(total, dice_total, dice_list, 6, cmp_op, diff) end return output @@ -135,7 +135,7 @@ def get_dice(mod, abl, skl) output = "#{total}[#{dice_str}]#{resultText}" - return total, output + return total, output, dice_arr end def rollDiceCommand(command) diff --git a/src/diceBot/DarkDaysDrive.rb b/src/diceBot/DarkDaysDrive.rb index 1452b1286..2e25a7b1a 100644 --- a/src/diceBot/DarkDaysDrive.rb +++ b/src/diceBot/DarkDaysDrive.rb @@ -49,21 +49,18 @@ def initialize end # ゲーム別成功度判定(2D6) - def check_2D6(total_n, dice_n, signOfInequality, diff, _dice_cnt, _dice_max, _n1, _n_max) - return '' unless signOfInequality == ">=" - - output = - if dice_n <= 2 - " > ファンブル(判定失敗。失敗表(FT)を追加で1回振る)" - elsif dice_n >= 12 - " > スペシャル(判定成功。大成功表(GJT)を1回使用可能)" - elsif total_n >= diff - " > 成功" - else - " > 失敗" - end - - return output + def check_2D6(total, dice_total, _dice_list, cmp_op, target) + return '' unless cmp_op == :>= + + if dice_total <= 2 + " > ファンブル(判定失敗。失敗表(FT)を追加で1回振る)" + elsif dice_total >= 12 + " > スペシャル(判定成功。大成功表(GJT)を1回使用可能)" + elsif total >= target + " > 成功" + else + " > 失敗" + end end def rollDiceCommand(command) diff --git a/src/diceBot/DemonParasite.rb b/src/diceBot/DemonParasite.rb index 003946c80..8a76af978 100644 --- a/src/diceBot/DemonParasite.rb +++ b/src/diceBot/DemonParasite.rb @@ -37,30 +37,21 @@ def initialize end # ゲーム別成功度判定(nD6) - def check_nD6(total_n, _dice_n, signOfInequality, diff, _dice_cnt, _dice_max, n1, n_max) - if n1 >= 2 # 1の目が2個以上ならファンブル + def check_nD6(total, _dice_total, dice_list, cmp_op, target) + if dice_list.count(1) >= 2 # 1の目が2個以上ならファンブル return " > 致命的失敗" - end - - if n_max >= 2 # 6の目が2個以上あったらクリティカル + elsif dice_list.count(6) >= 2 # 6の目が2個以上あったらクリティカル return " > 効果的成功" + elsif target == "?" + return '' end - return '' if diff == "?" - - case signOfInequality - when ">=" - if total_n >= diff - return " > 成功" + if [:>=, :>].include?(cmp_op) + if total.send(cmp_op, target) + " > 成功" + else + " > 失敗" end - - return " > 失敗" - when ">" - if total_n > diff - return " > 成功" - end - - return " > 失敗" end end diff --git a/src/diceBot/DoubleCross.rb b/src/diceBot/DoubleCross.rb index 552e929c0..29d2196a3 100644 --- a/src/diceBot/DoubleCross.rb +++ b/src/diceBot/DoubleCross.rb @@ -224,15 +224,15 @@ def compare_result end end - def check_nD10(total_n, _dice_n, signOfInequality, diff, dice_cnt, _dice_max, n1, _n_max) # ゲーム別成功度判定(nD10) - return '' unless signOfInequality == ">=" + def check_nD10(total, _dice_total, dice_list, cmp_op, target) + return '' unless cmp_op == :>= - if n1 >= dice_cnt - return " > ファンブル" - elsif total_n >= diff - return " > 成功" + if dice_list.count(1) == dice_list.size + " > ファンブル" + elsif total >= target + " > 成功" else - return " > 失敗" + " > 失敗" end end diff --git a/src/diceBot/EclipsePhase.rb b/src/diceBot/EclipsePhase.rb index 5ac84305a..f70b2c947 100644 --- a/src/diceBot/EclipsePhase.rb +++ b/src/diceBot/EclipsePhase.rb @@ -15,34 +15,33 @@ class EclipsePhase < DiceBot HELP_MESSAGE = '1D100<=m 方式の判定で成否、クリティカル・ファンブルを自動判定' - def check_1D100(total_n, _dice_n, signOfInequality, diff, _dice_cnt, _dice_max, _n1, _n_max)\ - return '' unless signOfInequality == '<=' + def check_1D100(total, _dice_total, cmp_op, target) + return '' unless cmp_op == :<= - diceValue = total_n % 100 # 出目00は100ではなく00とする + diceValue = total % 100 # 出目00は100ではなく00とする dice_ten_place = diceValue / 10 dice_one_place = diceValue % 10 - debug("total_n", total_n) - debug("dice_ten_place, dice_one_place", dice_ten_place, dice_one_place) - if dice_ten_place == dice_one_place return ' > 決定的失敗' if diceValue == 99 return ' > 00 > 決定的成功' if diceValue == 0 - return ' > 決定的成功' if total_n <= diff + return ' > 決定的成功' if total <= target return ' > 決定的失敗' end diff_threshold = 30 - if total_n <= diff - return ' > エクセレント' if total_n >= diff_threshold - - return ' > 成功' + if total <= target + if total >= diff_threshold + ' > エクセレント' + else + ' > 成功' + end + elsif (total - target) >= diff_threshold + ' > シビア' else - return ' > シビア' if (total_n - diff) >= diff_threshold - - return ' > 失敗' + ' > 失敗' end end end diff --git a/src/diceBot/Elric.rb b/src/diceBot/Elric.rb index acc72c581..d1bfb3393 100644 --- a/src/diceBot/Elric.rb +++ b/src/diceBot/Elric.rb @@ -15,17 +15,17 @@ class Elric < DiceBot HELP_MESSAGE = "貫通、クリティカル、ファンブルの自動判定を行います。\n" # ゲーム別成功度判定(1d100) - def check_1D100(total_n, _dice_n, signOfInequality, diff, _dice_cnt, _dice_max, _n1, _n_max) - return '' unless signOfInequality == "<=" + def check_1D100(total, _dice_total, cmp_op, target) + return '' unless cmp_op == :<= # 1は常に貫通 - return " > 貫通" if total_n <= 1 + return " > 貫通" if total <= 1 # 100は常に致命的失敗 - return " > 致命的失敗" if total_n >= 100 + return " > 致命的失敗" if total >= 100 - return " > 決定的成功" if total_n <= (diff / 5 + 0.9) - return " > 成功" if total_n <= diff - return " > 致命的失敗" if (total_n >= 99) && (diff < 100) + return " > 決定的成功" if total <= (target / 5 + 0.9) + return " > 成功" if total <= target + return " > 致命的失敗" if (total >= 99) && (target < 100) return " > 失敗" end diff --git a/src/diceBot/EmbryoMachine.rb b/src/diceBot/EmbryoMachine.rb index 48e1fe9b7..dafc29043 100644 --- a/src/diceBot/EmbryoMachine.rb +++ b/src/diceBot/EmbryoMachine.rb @@ -47,18 +47,17 @@ def dice_command_xRn(string, nick_e) end # ゲーム別成功度判定(nD10) - def check_nD10(total_n, dice_n, signOfInequality, diff, _dice_cnt, _dice_max, _n1, _n_max) - debug("EmbryoMachine check_nD10 begin") - return '' unless signOfInequality == ">=" - - if dice_n <= 2 - return " > ファンブル" - elsif dice_n >= 20 - return " > クリティカル" - elsif total_n >= diff - return " > 成功" + def check_nD10(total, dice_total, _dice_list, cmp_op, target) + return '' unless cmp_op == :>= + + if dice_total <= 2 + " > ファンブル" + elsif dice_total >= 20 + " > クリティカル" + elsif total >= target + " > 成功" else - return " > 失敗" + " > 失敗" end end diff --git a/src/diceBot/Gorilla.rb b/src/diceBot/Gorilla.rb index 23fc2db7f..8cd867a5f 100644 --- a/src/diceBot/Gorilla.rb +++ b/src/diceBot/Gorilla.rb @@ -27,25 +27,13 @@ def changeText(string) return string end - def check_2D6(totalValue, dice_n, signOfInequality, diff, _dice_cnt, _dice_max, _n1, _n_max) # ゲーム別成功度判定(2D6) - if dice_n == 10 - diceList = getDiceList() - if diceList[0] == 5 - # 2d6の合計が10で片方5ならもう片方も5であろうという手抜き判定 - return " > ゴリティカル(自動的成功)" - end + def check_2D6(total, _dice_total, dice_list, cmp_op, target) + if dice_list == [5, 5] + " > ゴリティカル(自動的成功)" + elsif total.send(cmp_op, target) + " > 成功" + else + " > 失敗" end - # 2014.02.24 余り無いと思うが'>'に対応できてなかったので追記 - if signOfInequality == '>=' - if totalValue >= diff - return " > 成功" - end - end - if signOfInequality == '>' - if totalValue > diff - return " > 成功" - end - end - return " > 失敗" end end diff --git a/src/diceBot/GranCrest.rb b/src/diceBot/GranCrest.rb index 785dd8101..53b51dad3 100644 --- a/src/diceBot/GranCrest.rb +++ b/src/diceBot/GranCrest.rb @@ -44,27 +44,20 @@ def initialize @fractionType = "omit" end - # ゲーム別成功度判定(2D6) - 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 - # ゲーム別成功度判定(nD6) - def check_nD6(total_n, _dice_n, signOfInequality, diff, _dice_cnt, _dice_max, _n1, n_max) - debug("check_nD6 begin") - + def check_nD6(total, _dice_total, dice_list, cmp_op, target) result = '' - if n_max >= 2 - total_n += 10 - result += "(クリティカル)" - result += " > #{total_n}" + if dice_list.count(6) >= 2 + total += 10 + result = "(クリティカル) > #{total}" end - return result unless signOfInequality == ">=" - return result if diff == "?" + if cmp_op != :>= || target == '?' + return result + end - if total_n >= diff + if total >= target result += " > 成功" else result += " > 失敗" @@ -73,6 +66,8 @@ def check_nD6(total_n, _dice_n, signOfInequality, diff, _dice_cnt, _dice_max, _n return result end + alias check_2D6 check_nD6 + def rollDiceCommand(command) debug("rollDiceCommand command", command) diff --git a/src/diceBot/Gundog.rb b/src/diceBot/Gundog.rb index 6b13f4619..cb3aa49c2 100644 --- a/src/diceBot/Gundog.rb +++ b/src/diceBot/Gundog.rb @@ -18,31 +18,27 @@ class Gundog < DiceBot INFO_MESSAGE_TEXT # ゲーム別成功度判定(1d100) - def check_1D100(total_n, _dice_n, signOfInequality, diff, _dice_cnt, _dice_max, _n1, _n_max) - return '' unless signOfInequality == "<=" - - if total_n >= 100 - return " > ファンブル" - end - - if total_n <= 1 - return " > 絶対成功(達成値1+SL)" - end - - if total_n <= diff - dig10 = (total_n / 10).to_i - dig1 = total_n - dig10 * 10 + def check_1D100(total, _dice_total, cmp_op, target) + return '' unless cmp_op == :<= + + if total >= 100 + " > ファンブル" + elsif total <= 1 + " > 絶対成功(達成値1+SL)" + elsif total <= target + dig10 = total / 10 + dig1 = total - dig10 * 10 dig10 = 0 if dig10 >= 10 dig1 = 0 if dig1 >= 10 # 条件的にはあり得ない(笑 if dig1 <= 0 - return " > クリティカル(達成値20+SL)" + " > クリティカル(達成値20+SL)" + else + " > 成功(達成値#{(dig10 + dig1)}+SL)" end - - return " > 成功(達成値#{(dig10 + dig1)}+SL)" + else + " > 失敗" end - - return " > 失敗" end def isD9 diff --git a/src/diceBot/GundogRevised.rb b/src/diceBot/GundogRevised.rb index 46eef09ee..24be4c797 100644 --- a/src/diceBot/GundogRevised.rb +++ b/src/diceBot/GundogRevised.rb @@ -29,31 +29,27 @@ class GundogRevised < DiceBot # ---- 以降、Gundog.rbよりほぼコピペ(絶対成功→ベアリーに用語変更対応の為、継承だと不都合) # ゲーム別成功度判定(1d100) - def check_1D100(total_n, _dice_n, signOfInequality, diff, _dice_cnt, _dice_max, _n1, _n_max) - return '' unless signOfInequality == "<=" - - if total_n >= 100 - return " > ファンブル" - end - - if total_n <= 1 - return " > ベアリー(達成値1+SL)" - end - - if total_n <= diff - dig10 = (total_n / 10).to_i - dig1 = total_n - dig10 * 10 + def check_1D100(total, _dice_total, cmp_op, target) + return '' unless cmp_op == :<= + + if total >= 100 + " > ファンブル" + elsif total <= 1 + " > ベアリー(達成値1+SL)" + elsif total <= target + dig10 = total / 10 + dig1 = total - dig10 * 10 dig10 = 0 if dig10 >= 10 dig1 = 0 if dig1 >= 10 # 条件的にはあり得ない(笑 if dig1 <= 0 - return " > クリティカル(達成値20+SL)" + " > クリティカル(達成値20+SL)" + else + " > 成功(達成値#{(dig10 + dig1)}+SL)" end - - return " > 成功(達成値#{(dig10 + dig1)}+SL)" + else + " > 失敗" end - - return " > 失敗" end def isD9 diff --git a/src/diceBot/Gurps.rb b/src/diceBot/Gurps.rb index 253df9227..0b88ab86a 100644 --- a/src/diceBot/Gurps.rb +++ b/src/diceBot/Gurps.rb @@ -40,35 +40,35 @@ def initialize end # ゲーム別成功度判定(nD6) - def check_nD6(total_n, dice_n, signOfInequality, diff, dice_cnt, _dice_max, _n1, _n_max) - return '' unless dice_cnt == 3 && signOfInequality == "<=" + def check_nD6(total, dice_total, dice_list, cmp_op, target) + return '' unless dice_list.size == 3 && cmp_op == :<= - success = diff - total_n # 成功度 + success = target - total # 成功度 crt_string = " > クリティカル(成功度:#{success})" fmb_string = " > ファンブル(失敗度:#{success})" fail_string = " > 自動失敗(失敗度:#{success})" # クリティカル - if (dice_n <= 6) && (diff >= 16) + if (dice_total <= 6) && (target >= 16) return crt_string - elsif (dice_n <= 5) && (diff >= 15) + elsif (dice_total <= 5) && (target >= 15) return crt_string - elsif dice_n <= 4 + elsif dice_total <= 4 return crt_string end # ファンブル - if (diff - dice_n) <= -10 + if (target - dice_total) <= -10 return fmb_string - elsif (dice_n >= 17) && (diff <= 15) + elsif (dice_total >= 17) && (target <= 15) return fmb_string - elsif dice_n >= 18 + elsif dice_total >= 18 return fmb_string - elsif dice_n >= 17 + elsif dice_total >= 17 return fail_string end - if total_n <= diff + if total <= target return " > 成功(成功度:#{success})" else return " > 失敗(失敗度:#{success})" @@ -107,14 +107,11 @@ def getRollDiceResult(command) dice_cnt = 3 dice_max = 6 dice_n, dice_str = roll(dice_cnt, dice_max) - diceList = dice_str.split(/,/).collect { |i| i.to_i }.sort - n1 = diceList.select { |i| i == 1 }.size - n_max = diceList.select { |i| i == dice_max }.size + diceList = dice_str.split(',').map(&:to_i).sort diff = getValue(diffStr, 0) total_n = dice_n + getValue(modStr, 0) - signOfInequality = "<=" - result = "(3D6#{modStr}<=#{diff}) > #{dice_n}[#{dice_str}]#{modStr} > #{total_n}#{check_nD6(total_n, dice_n, signOfInequality, diff, dice_cnt, dice_max, n1, n_max)}" + result = "(3D6#{modStr}<=#{diff}) > #{dice_n}[#{dice_str}]#{modStr} > #{total_n}#{check_nD6(total_n, dice_n, diceList, :<=, diff)}" return result end diff --git a/src/diceBot/GurpsFW.rb b/src/diceBot/GurpsFW.rb index b348cb5b4..431b60877 100644 --- a/src/diceBot/GurpsFW.rb +++ b/src/diceBot/GurpsFW.rb @@ -94,42 +94,39 @@ def dice_command(string, name) return output_msg, secret_flg end - def check_nD6(total_n, dice_n, signOfInequality, diff, dice_cnt, _dice_max, _n1, _n_max) # ゲーム別成功度判定(nD6) - if (dice_cnt == 3) && (signOfInequality == "<=") - - success = diff - total_n; # 成功度 - crt_string = " > クリティカル(成功度:#{success})" - fmb_string = " > ファンブル(失敗度:#{success})" - fail_string = " > 自動失敗(失敗度:#{success})" - - # クリティカル - if (dice_n <= 6) && (diff >= 16) - return crt_string - elsif (dice_n <= 5) && (diff >= 15) - return crt_string - elsif dice_n <= 4 - return crt_string - end - # ファンブル - if diff - dice_n <= -10 - return fmb_string - elsif (dice_n >= 17) && (diff <= 15) - return fmb_string - elsif dice_n >= 18 - return fmb_string - elsif dice_n >= 17 - return fail_string - end - - if total_n <= diff - return " > 成功(成功度:#{success})" - else - return " > 失敗(失敗度:#{success})" - end + def check_nD6(total, dice_total, dice_list, cmp_op, target) + return "" unless dice_list.size == 3 && cmp_op == :<= + + success = target - total # 成功度 + crt_string = " > クリティカル(成功度:#{success})" + fmb_string = " > ファンブル(失敗度:#{success})" + fail_string = " > 自動失敗(失敗度:#{success})" + + # クリティカル + if (dice_total <= 6) && (target >= 16) + return crt_string + elsif (dice_total <= 5) && (target >= 15) + return crt_string + elsif dice_total <= 4 + return crt_string + end + # ファンブル + if (target - dice_total) <= -10 + return fmb_string + elsif (dice_total >= 17) && (target <= 15) + return fmb_string + elsif dice_total >= 18 + return fmb_string + elsif dice_total >= 17 + return fail_string end - return '' + if total <= target + return " > 成功(成功度:#{success})" + else + return " > 失敗(失敗度:#{success})" + end end def getCommandResult(string, nick_e) diff --git a/src/diceBot/HarnMaster.rb b/src/diceBot/HarnMaster.rb index fc0ad96bd..24167e8a5 100644 --- a/src/diceBot/HarnMaster.rb +++ b/src/diceBot/HarnMaster.rb @@ -22,10 +22,10 @@ class HarnMaster < DiceBot setPrefixes(['SHK\d+.*', 'SLH', 'SLHU', 'SLHD']) - def check_1D100(total_n, _dice_n, signOfInequality, diff, _dice_cnt, _dice_max, _n1, _n_max) - return '' unless signOfInequality == "<=" + def check_1D100(total, _dice_total, cmp_op, target) + return '' unless cmp_op == :<= - result = getCheckResult(total_n, diff) + result = getCheckResult(total, target) return "> #{result}" end diff --git a/src/diceBot/Hieizan.rb b/src/diceBot/Hieizan.rb index 00c229f9e..911a40087 100644 --- a/src/diceBot/Hieizan.rb +++ b/src/diceBot/Hieizan.rb @@ -15,32 +15,29 @@ class Hieizan < DiceBot HELP_MESSAGE = "大成功、自動成功、失敗、自動失敗、大失敗の自動判定を行います。\n" # ゲーム別成功度判定(1d100) - def check_1D100(total_n, _dice_n, _signOfInequality, diff, _dice_cnt, _dice_max, _n1, _n_max) - if total_n <= 1 # 1は自動成功 - if total_n <= (diff / 5) - return " > 大成功" # 大成功 > 自動成功 + def check_1D100(total, _dice_total, _cmp_op, target) + if total <= 1 + # 1は自動成功 + if total <= (target / 5) + " > 大成功" + else + " > 自動成功" end - - return " > 自動成功" - end - - if total_n >= 100 - return " > 大失敗" # 00は大失敗(大失敗は自動失敗でもある) - end - - if total_n >= 96 - return " > 自動失敗" # 96-00は自動失敗 - end - - if total_n <= diff - - if total_n <= (diff / 5) - return " > 大成功" # 目標値の1/5以下は大成功 + elsif total >= 100 + # 00は大失敗(大失敗は自動失敗でもある) + " > 大失敗" + elsif total >= 96 + # 96-00は自動失敗 + " > 自動失敗" + elsif total <= target + if total <= (target / 5) + # 目標値の1/5以下は大成功 + " > 大成功" + else + " > 成功" end - - return " > 成功" + else + " > 失敗" end - - return " > 失敗" end end diff --git a/src/diceBot/HouraiGakuen.rb b/src/diceBot/HouraiGakuen.rb index cdd3a89dc..c6cda6092 100644 --- a/src/diceBot/HouraiGakuen.rb +++ b/src/diceBot/HouraiGakuen.rb @@ -76,7 +76,7 @@ def getRollResult(command) end def getCheckResult(diceText, total, target) - diceList = getDiceListFromText(diceText) + diceList = diceText.split(',').map(&:to_i).sort if isFamble(diceList) return @@famble @@ -93,11 +93,6 @@ def getCheckResult(diceText, total, target) return @@failure end - def getDiceListFromText(diceText) - diceList = diceText.split(/,/).collect { |i| i.to_i }.sort - return diceList - end - def isFamble(diceList) return diceList === [6, 6, 6] end diff --git a/src/diceBot/HuntersMoon.rb b/src/diceBot/HuntersMoon.rb index f3dcd8d92..29a1f7b10 100644 --- a/src/diceBot/HuntersMoon.rb +++ b/src/diceBot/HuntersMoon.rb @@ -50,17 +50,17 @@ def initialize end # ゲーム別成功度判定(2D6) - def check_2D6(total_n, dice_n, signOfInequality, diff, _dice_cnt, _dice_max, _n1, _n_max) - return '' unless signOfInequality == ">=" - - if dice_n <= 2 - return " > ファンブル(モノビースト追加行動+1)" - elsif dice_n >= 12 - return " > スペシャル(変調1つ回復orダメージ+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 + " > ファンブル(モノビースト追加行動+1)" + elsif dice_total >= 12 + " > スペシャル(変調1つ回復orダメージ+1D6)" + elsif total >= target + " > 成功" else - return " > 失敗" + " > 失敗" end end diff --git a/src/diceBot/InfiniteFantasia.rb b/src/diceBot/InfiniteFantasia.rb index 9e3e8b684..9a377e791 100644 --- a/src/diceBot/InfiniteFantasia.rb +++ b/src/diceBot/InfiniteFantasia.rb @@ -15,29 +15,32 @@ class InfiniteFantasia < DiceBot HELP_MESSAGE = "失敗、成功レベルの自動判定を行います。\n" # ゲーム別成功度判定(1d20) - def check_1D20(total_n, _dice_n, signOfInequality, diff, _dice_cnt, _dice_max, _n1, _n_max) - return '' unless signOfInequality == "<=" - - return " > 失敗" unless total_n <= diff - - critical = "" - - if total_n <= 1 - critical = "/クリティカル" + def check_1D20(total, _dice_total, cmp_op, target) + if cmp_op != :<= + return '' + elsif total > target + return " > 失敗" end - if total_n <= (diff / 32) - return " > 32レベル成功(32Lv+)#{critical}" - elsif total_n <= (diff / 16) - return " > 16レベル成功(16LV+)#{critical}" - elsif total_n <= (diff / 8) - return " > 8レベル成功#{critical}" - elsif total_n <= (diff / 4) - return " > 4レベル成功#{critical}" - elsif total_n <= (diff / 2) - return " > 2レベル成功#{critical}" + output = + if total <= (target / 32) + " > 32レベル成功(32Lv+)" + elsif total <= (target / 16) + " > 16レベル成功(16LV+)" + elsif total <= (target / 8) + " > 8レベル成功" + elsif total <= (target / 4) + " > 4レベル成功" + elsif total <= (target / 2) + " > 2レベル成功" + else + " > 1レベル成功" + end + + if total <= 1 + output += "/クリティカル" end - return " > 1レベル成功#{critical}" + output end end diff --git a/src/diceBot/Insane.rb b/src/diceBot/Insane.rb index e78704983..0217b3f78 100644 --- a/src/diceBot/Insane.rb +++ b/src/diceBot/Insane.rb @@ -56,23 +56,18 @@ def initialize end # ゲーム別成功度判定(2D6) - def check_2D6(total_n, dice_n, signOfInequality, diff, dice_cnt, dice_max, n1, n_max) - debug("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 signOfInequality == ">=" - - output = - if dice_n <= 2 - " > ファンブル(判定失敗。山札から【狂気】を1枚獲得)" - elsif dice_n >= 12 - " > スペシャル(判定成功。【生命力】1点か【正気度】1点回復)" - elsif total_n >= diff - " > 成功" - else - " > 失敗" - end - - return output + def check_2D6(total, dice_total, _dice_list, cmp_op, target) + return '' unless cmp_op == :>= + + if dice_total <= 2 + " > ファンブル(判定失敗。山札から【狂気】を1枚獲得)" + elsif dice_total >= 12 + " > スペシャル(判定成功。【生命力】1点か【正気度】1点回復)" + elsif total >= target + " > 成功" + else + " > 失敗" + end end def rollDiceCommand(command) diff --git a/src/diceBot/Insane_Korean.rb b/src/diceBot/Insane_Korean.rb index 7732fe94c..d73879944 100644 --- a/src/diceBot/Insane_Korean.rb +++ b/src/diceBot/Insane_Korean.rb @@ -56,23 +56,18 @@ def initialize end # 게임 별 성공 여부 판정(2D6) - def check_2D6(total_n, dice_n, signOfInequality, diff, dice_cnt, dice_max, n1, n_max) - debug("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 signOfInequality == ">=" - - output = - if dice_n <= 2 - " > 펌블(판정실패。 덱에서 【광기】를 1장 획득)" - elsif dice_n >= 12 - " > 스페셜(판정성공。 【생명력】 1점이나 【정신력】 1점 회복)" - elsif total_n >= diff - " > 성공" - else - " > 실패" - end - - return output + def check_2D6(total, dice_total, _dice_list, cmp_op, target) + return '' unless cmp_op == :>= + + if dice_total <= 2 + " > 펌블(판정실패。 덱에서 【광기】를 1장 획득)" + elsif dice_total >= 12 + " > 스페셜(판정성공。 【생명력】 1점이나 【정신력】 1점 회복)" + elsif total >= target + " > 성공" + else + " > 실패" + end end def rollDiceCommand(command) diff --git a/src/diceBot/IthaWenUa.rb b/src/diceBot/IthaWenUa.rb index d1279de07..77317659b 100644 --- a/src/diceBot/IthaWenUa.rb +++ b/src/diceBot/IthaWenUa.rb @@ -14,32 +14,21 @@ class IthaWenUa < DiceBot # ダイスボットの使い方 HELP_MESSAGE = "1D100<=m 方式の判定で成否、クリティカル(01)・ファンブル(00)を自動判定します。\n" - def check_1D100(total_n, _dice_n, signOfInequality, diff, _dice_cnt, _dice_max, _n1, _n_max) # ゲーム別成功度判定(1d100) - return '' unless signOfInequality == '<=' + def check_1D100(total, _dice_total, cmp_op, target) + return '' unless cmp_op == :<= - diceValue = total_n % 100 + diceValue = total % 100 dice0 = diceValue / 10 # 10の位を代入 dice1 = diceValue % 10 # 1の位を代入 - debug("total_n", total_n) - debug("dice0, dice1", dice0, dice1) - if (dice0 == 0) && (dice1 == 1) - - return ' > 01 > クリティカル' - + ' > 01 > クリティカル' elsif (dice0 == 0) && (dice1 == 0) - - return ' > 00 > ファンブル' - + ' > 00 > ファンブル' + elsif total <= target + ' > 成功' else - - if total_n <= diff - return ' > 成功' - else - return ' > 失敗' - end - + ' > 失敗' end end end diff --git a/src/diceBot/JamesBond.rb b/src/diceBot/JamesBond.rb index 639f352cb..5e0fd2634 100644 --- a/src/diceBot/JamesBond.rb +++ b/src/diceBot/JamesBond.rb @@ -18,31 +18,24 @@ class JamesBond < DiceBot    JamesBond : (1D100<=50) → 20 → 効果3(良) INFO_MESSAGE_TEXT - def check_1D100(total_n, _dice_n, signOfInequality, diff, _dice_cnt, _dice_max, _n1, _n_max) # ゲーム別成功度判定(1d100) - return '' unless signOfInequality == "<=" - - if total_n >= 100 # 100は常に失敗 - return " > 失敗" - end - - base = ((diff + 9) / 10).floor - - if total_n <= base - return " > 効果1(完璧)" - end - - if total_n <= base * 2 - return " > 効果2(かなり良い)" + def check_1D100(total, _dice_total, cmp_op, target) # ゲーム別成功度判定(1d100) + return '' unless cmp_op == :<= + + base = ((target + 9) / 10).floor + + if total >= 100 + # 100は常に失敗 + " > 失敗" + elsif total <= base + " > 効果1(完璧)" + elsif total <= base * 2 + " > 効果2(かなり良い)" + elsif total <= base * 5 + " > 効果3(良)" + elsif total <= target + " > 効果4(まあまあ)" + else + " > 失敗" end - - if total_n <= base * 5 - return " > 効果3(良)" - end - - if total_n <= diff - return " > 効果4(まあまあ)" - end - - return " > 失敗" end end diff --git a/src/diceBot/KanColle.rb b/src/diceBot/KanColle.rb index 4882d534c..37f4f2114 100644 --- a/src/diceBot/KanColle.rb +++ b/src/diceBot/KanColle.rb @@ -48,17 +48,17 @@ def initialize @d66Type = 2 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 " > ファンブル(判定失敗。アクシデント表を自分のPCに適用)" - elsif dice_n >= 12 - return " > スペシャル(判定成功。【行動力】が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 + " > ファンブル(判定失敗。アクシデント表を自分のPCに適用)" + elsif dice_total >= 12 + " > スペシャル(判定成功。【行動力】が1D6点回復)" + elsif total >= target + " > 成功" else - return " > 失敗" + " > 失敗" end end diff --git a/src/diceBot/KillDeathBusiness.rb b/src/diceBot/KillDeathBusiness.rb index 615218cbc..5b96709a8 100644 --- a/src/diceBot/KillDeathBusiness.rb +++ b/src/diceBot/KillDeathBusiness.rb @@ -48,23 +48,18 @@ def initialize end # ゲーム別成功度判定(2D6) - def check_2D6(total_n, dice_n, signOfInequality, diff, dice_cnt, dice_max, n1, n_max) - debug("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 signOfInequality == ">=" - - output = - if dice_n <= 2 - " > ファンブル(判定失敗。【視聴率】が20%減少)" - elsif dice_n >= 12 - " > スペシャル(判定成功。【視聴率】が10%増加)" - elsif total_n >= diff - " > 成功" - else - " > 失敗" - end - - return output + def check_2D6(total, dice_total, _dice_list, cmp_op, target) + return '' unless cmp_op == :>= + + if dice_total <= 2 + " > ファンブル(判定失敗。【視聴率】が20%減少)" + elsif dice_total >= 12 + " > スペシャル(判定成功。【視聴率】が10%増加)" + elsif total >= target + " > 成功" + else + " > 失敗" + end end def rollDiceCommand(command) diff --git a/src/diceBot/KillDeathBusiness_Korean.rb b/src/diceBot/KillDeathBusiness_Korean.rb index 81bd6e9d8..065fb8a0f 100644 --- a/src/diceBot/KillDeathBusiness_Korean.rb +++ b/src/diceBot/KillDeathBusiness_Korean.rb @@ -91,23 +91,18 @@ def initialize end # 게임별 성공도 판정(2D6) - def check_2D6(total_n, dice_n, signOfInequality, diff, dice_cnt, dice_max, n1, n_max) - debug("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 signOfInequality == ">=" - - output = - if dice_n <= 2 - " > 펌블(판정 실패.【시청률】이 20%감소)" - elsif dice_n >= 12 - " > 스페셜(판정 성공.【시청률】이 10%증가)" - elsif total_n >= diff - " > 성공" - else - " > 실패" - end - - return output + def check_2D6(total, dice_total, _dice_list, cmp_op, target) + return '' unless cmp_op == :>= + + if dice_total <= 2 + " > 펌블(판정 실패.【시청률】이 20%감소)" + elsif dice_total >= 12 + " > 스페셜(판정 성공.【시청률】이 10%증가)" + elsif total >= target + " > 성공" + else + " > 실패" + end end def rollDiceCommand(command) diff --git a/src/diceBot/MagicaLogia.rb b/src/diceBot/MagicaLogia.rb index 34e70512c..67b925d13 100644 --- a/src/diceBot/MagicaLogia.rb +++ b/src/diceBot/MagicaLogia.rb @@ -53,23 +53,21 @@ def initialize end # ゲーム別成功度判定(2D6) - def check_2D6(total_n, dice_n, signOfInequality, diff, dice_cnt, dice_max, n1, n_max) - debug("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 signOfInequality == ">=" + def check_2D6(total, dice_total, dice_list, cmp_op, target) + return '' unless cmp_op == :>= output = - if dice_n <= 2 + if dice_total <= 2 " > ファンブル" - elsif dice_n >= 12 + elsif dice_total >= 12 " > スペシャル(魔力1D6点か変調1つ回復)" - elsif total_n >= diff + elsif total >= target " > 成功" else " > 失敗" end - output += getGainMagicElementText() + output += gainMagicElement(dice_list[0], dice_list[1]) return output end @@ -326,19 +324,6 @@ def magicalogia_accident_table end # 魔素獲得チェック - def getGainMagicElementText() - diceList = getDiceList - debug("getGainMagicElementText diceList", diceList) - - return '' if diceList.empty? - - dice1 = diceList[0] - dice2 = diceList[1] - - # マギカロギア用魔素取得判定 - return gainMagicElement(dice1, dice2) - end - def gainMagicElement(dice1, dice2) return "" unless dice1 == dice2 diff --git a/src/diceBot/MeikyuDays.rb b/src/diceBot/MeikyuDays.rb index e981e0539..bdc7a5d12 100644 --- a/src/diceBot/MeikyuDays.rb +++ b/src/diceBot/MeikyuDays.rb @@ -50,17 +50,17 @@ def dice_command_xRn(string, nick_e) return checkRoll(string) 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 " > 絶対失敗" - elsif dice_n >= 12 - return " > 絶対成功" - elsif total_n >= diff - return " > 成功" + def check_2D6(total, dice_total, _dice_list, cmp_op, target) + return '' unless cmp_op == :>= + + if dice_total <= 2 + " > 絶対失敗" + elsif dice_total >= 12 + " > 絶対成功" + elsif total >= target + " > 成功" else - return " > 失敗" + " > 失敗" end end @@ -89,7 +89,7 @@ def checkRoll(string) total_n = 0 _, dice_str, = roll(dice_c, 6, (sortType & 1)) - dice_num = dice_str.split(/,/).collect { |i| i.to_i } + dice_num = dice_str.split(',').map(&:to_i) dice_now = dice_num[dice_c - 2] + dice_num[dice_c - 1] total_n = dice_now + bonus @@ -115,7 +115,8 @@ def checkRoll(string) end if signOfInequality != "" # 成功度判定処理 - output += check_suc(total_n, dice_now, signOfInequality, diff, 2, 6, 0, 0) + cmp_op = Normalizer.cmp_op(signOfInequality) + output += check_2D6(total_n, dice_now, dice_num, cmp_op, diff) end return output diff --git a/src/diceBot/MeikyuKingdom.rb b/src/diceBot/MeikyuKingdom.rb index dcb983e1a..7fb581efc 100644 --- a/src/diceBot/MeikyuKingdom.rb +++ b/src/diceBot/MeikyuKingdom.rb @@ -80,56 +80,48 @@ def dice_command_xRn(string, nick_e) return mayokin_check(string, nick_e) end - def check_2D6(total_n, dice_n, signOfInequality, diff, _dice_cnt, _dice_max, _n1, _n_max) # ゲーム別成功度判定(2D6) - result = get2D6Result(total_n, dice_n, signOfInequality, diff) - result += getKiryokuResult(total_n, dice_n, signOfInequality, diff) + def check_nD6(total, dice_total, dice_list, cmp_op, target) + result = get2D6Result(total, dice_total, cmp_op, target) + result += getKiryokuResult(total, dice_list, target) return result end + alias check_2D6 check_nD6 + def get2D6Result(total_n, dice_n, signOfInequality, diff) - return '' unless signOfInequality == ">=" + return '' unless signOfInequality == :>= if dice_n <= 2 - return " > 絶対失敗" + " > 絶対失敗" elsif dice_n >= 12 - return " > 絶対成功" + " > 絶対成功" + else + get2D6ResultOnlySuccess(total_n, diff) end - - return get2D6ResultOnlySuccess(total_n, diff) end def get2D6ResultOnlySuccess(total_n, diff) if total_n >= diff - return " > 成功" + " > 成功" + else + " > 失敗" end - - return " > 失敗" end - def getKiryokuResult(total_n, _dice_n, _signOfInequality, diff) - output_msg = "" - - diceList = getDiceList - debug("getKiryokuResult diceList", diceList) + def getKiryokuResult(total_n, dice_list, diff) + num_6 = dice_list.count(6) - dice6List = diceList.find_all { |i| i == 6 } - debug("dice6List", dice6List) - - if dice6List.empty? - return output_msg - end - - if dice6List.length >= 2 - return " & 《気力》#{dice6List.length}点獲得" + if num_6 == 0 + return "" + elsif num_6 >= 2 + return " & 《気力》#{num_6}点獲得" end - diceNone6List = diceList.find_all { |i| i != 6 } - diceNone6List.sort! - debug("diceNone6List", diceNone6List) + none6_list = dice_list.reject { |i| i == 6 }.sort - maxDice1 = diceNone6List.pop.to_i - maxDice2 = diceNone6List.pop.to_i + maxDice1 = none6_list.pop.to_i + maxDice2 = none6_list.pop.to_i debug("maxDice1", maxDice1) debug("maxDice2", maxDice2) @@ -142,7 +134,7 @@ def getKiryokuResult(total_n, _dice_n, _signOfInequality, diff) debug("diff", diff) none6DiceReuslt = get2D6ResultOnlySuccess(none6Total_n, diff) - return " (もしくは) #{none6Total_n}#{none6DiceReuslt} & 《気力》#{dice6List.length}点獲得" + return " (もしくは) #{none6Total_n}#{none6DiceReuslt} & 《気力》1点獲得" end #################### 迷宮キングダム ######################## @@ -151,45 +143,35 @@ def mayokin_check(string, nick_e) output = "1" - return output unless /(^|\s)S?((\d+)[rR]6([\+\-\d]*)(([>=]+)(\d+))?)(\s|$)/i =~ string + # return output unless /(^|\s)S?((\d+)[rR]6([\+\-\d]*)(([>=]+)(\d+))?)(\s|$)/i =~ string - string = Regexp.last_match(2) - diceCount = Regexp.last_match(3).to_i - modifyText = Regexp.last_match(4) - signOfInequality = Regexp.last_match(6) - signOfInequality ||= "" - - diff = Regexp.last_match(7).to_i - diff ||= 0 + m = /^S?((\d+)R6([\+\-\d]*)(([>=]+)(\d+))?)/i.match(string) + unless m + return "1" + end - debug("string", string) - debug("diceCount", diceCount) - debug("modifyText", modifyText) + string = m[1] + diceCount = m[2].to_i + modifyText = m[3] + signOfInequality = m[5] || "" + diff = m[6].to_i - bonus = 0 - if modifyText - bonus = parren_killer("(0#{modifyText})").to_i - end - debug("bonus", bonus) + bonus = modifyText ? ArithmeticEvaluator.new.eval(modifyText) : 0 dice_now = 0 dice_str = "" total_n = 0 _, dice_str, = roll(diceCount, 6, (sortType & 1)) - dice_num = dice_str.split(/,/).collect { |i| i.to_i } - debug("diceCount, dice_num", diceCount, dice_num) + dice_list = dice_str.split(',').map(&:to_i) - dice1 = 0 - dice2 = 0 - dice1 = dice_num[diceCount - 2] if diceCount >= 2 - dice2 = dice_num[diceCount - 1] if diceCount >= 1 + dice1 = diceCount >= 2 ? dice_list[diceCount - 2] : 0 + dice2 = diceCount >= 1 ? dice_list[diceCount - 1] : 0 dice_now = dice1 + dice2 debug("dice1, dice2, dice_now", dice1, dice2, dice_now) total_n = dice_now + bonus dice_str = "[#{dice_str}]" - setDiceText(dice_str) output = "#{dice_now}#{dice_str}" if bonus > 0 @@ -209,7 +191,8 @@ def mayokin_check(string, nick_e) end if signOfInequality != "" # 成功度判定処理 - output += check_suc(total_n, dice_now, signOfInequality, diff, 2, 6, 0, 0) + cmp_op = Normalizer.cmp_op(signOfInequality) + output += check_suc(total_n, dice_now, dice_list, 6, cmp_op, diff) end return output diff --git a/src/diceBot/MetalHead.rb b/src/diceBot/MetalHead.rb index 6c2432fe8..ea28d8045 100644 --- a/src/diceBot/MetalHead.rb +++ b/src/diceBot/MetalHead.rb @@ -61,16 +61,18 @@ def changeText(string) return string end - def check_2D6(totalValue, dice_n, signOfInequality, diff, _dice_cnt, _dice_max, _n1, _n_max) - return '' if signOfInequality != ">=" - return '' if diff == "?" - - return " > 絶対成功" if dice_n >= 12 - return " > 絶対失敗" if dice_n <= 2 - - return " > 成功" if totalValue >= diff - - return " > 失敗" + def check_2D6(total, dice_total, _dice_list, cmp_op, target) + return '' if cmp_op != :>= || target == "?" + + if dice_total >= 12 + " > 絶対成功" + elsif dice_total <= 2 + " > 絶対失敗" + elsif total >= target + " > 成功" + else + " > 失敗" + end end def rollHit(target) @@ -82,10 +84,10 @@ def rollHit(target) return text end - def check_1D100(total_n, dice_n, signOfInequality, diff, _dice_cnt, _dice_max, _n1, _n_max) - return '' unless signOfInequality == '<=' + def check_1D100(total, dice_total, cmp_op, target) + return '' unless cmp_op == :<= - return getResult(total_n, dice_n, diff) + return getResult(total, dice_total, target) end def getHitResult(total_n, _dice_n, diff) diff --git a/src/diceBot/Nechronica.rb b/src/diceBot/Nechronica.rb index 055b1766e..021e9e0a0 100644 --- a/src/diceBot/Nechronica.rb +++ b/src/diceBot/Nechronica.rb @@ -44,29 +44,20 @@ def dice_command_xRn(string, nick_e) return nechronica_check(string) end - def check_nD10(total_n, _dice_n, signOfInequality, diff, dice_cnt, _dice_max, n1, _n_max) # ゲーム別成功度判定(nD10) - return '' unless signOfInequality == ">=" - - if total_n >= 11 - return " > 大成功" - end - - if total_n >= diff - return " > 成功" + def check_nD10(total, _dice_total, dice_list, cmp_op, target) # ゲーム別成功度判定(nD10) + return '' unless cmp_op == :>= + + if total >= 11 + " > 大成功" + elsif total >= target + " > 成功" + elsif dice_list.count { |i| i <= 1 } == 0 + " > 失敗" + elsif dice_list.size > 1 + " > 大失敗 > 使用パーツ全損" + else + " > 大失敗" end - - # 失敗パターン - - if n1 <= 0 - return " > 失敗" - end - - result = " > 大失敗" - if dice_cnt > 1 - result += " > 使用パーツ全損" - end - - return result end def nechronica_check(string) @@ -80,7 +71,6 @@ def nechronica_check(string) end string = Regexp.last_match(2) - signOfInequality = ">=" dice_n = 1 dice_n = Regexp.last_match(3).to_i if Regexp.last_match(3) @@ -98,7 +88,7 @@ def nechronica_check(string) diff = 6 total_n = 0 - _, dice_str, n1, cnt_max, n_max = roll(dice_n, 10, 1) + _, dice_str, _n1, _cnt_max, n_max = roll(dice_n, 10, 1) total_n = n_max + mod @@ -109,28 +99,13 @@ def nechronica_check(string) output += "+#{mod}" end - n1 = 0 - cnt_max = 0 - - dice = dice_str.split(/,/).collect { |i| i.to_i } - dice.length.times do |i| - dice[i] += mod - n1 += 1 if dice[i] <= 1 - cnt_max += 1 if dice[i] >= 10 - end + dice = dice_str.split(',').map(&:to_i) + dice.map! { |i| i + mod } dice_str = dice.join(",") output += " > #{total_n}[#{dice_str}]" - diceMax = 10 - output += check_suc(total_n, n_max, signOfInequality, diff, dice_n, diceMax, n1, n_max) - - debug("dice_n, n1, total_n diff", dice_n, n1, total_n, diff) - - # β版の実装 - # if( (dice_n > 1) and (n1 >= 1) and (total_n <= diff) ) - # output += " > 損傷#{n1}" - # end + output += check_nD10(total_n, dice_n, dice, :>=, diff) if isBattleMode hit_loc = getHitLocation(total_n) diff --git a/src/diceBot/Nechronica_Korean.rb b/src/diceBot/Nechronica_Korean.rb index 44d47fcc5..4dc2cb2fa 100644 --- a/src/diceBot/Nechronica_Korean.rb +++ b/src/diceBot/Nechronica_Korean.rb @@ -44,29 +44,20 @@ def dice_command_xRn(string, nick_e) return nechronica_check(string) end - def check_nD10(total_n, _dice_n, signOfInequality, diff, dice_cnt, _dice_max, n1, _n_max) # ゲーム別成功度判定(nD10) - return '' unless signOfInequality == ">=" - - if total_n >= 11 - return " > 대성공" - end - - if total_n >= diff - return " > 성공" + def check_nD10(total, _dice_total, dice_list, cmp_op, target) + return '' unless cmp_op == :>= + + if total >= 11 + " > 대성공" + elsif total >= target + " > 성공" + elsif dice_list.count { |i| i <= 1 } == 0 + " > 실패" + elsif dice_list.size > 1 + " > 대실패 > 사용파츠 전부 손실" + else + " > 대실패" end - - # 失敗パターン - - if n1 <= 0 - return " > 실패" - end - - result = " > 대실패" - if dice_cnt > 1 - result += " > 사용파츠 전부 손실" - end - - return result end def nechronica_check(string) @@ -80,7 +71,6 @@ def nechronica_check(string) end string = Regexp.last_match(2) - signOfInequality = ">=" dice_n = 1 dice_n = Regexp.last_match(3).to_i if Regexp.last_match(3) @@ -112,7 +102,7 @@ def nechronica_check(string) n1 = 0 cnt_max = 0 - dice = dice_str.split(/,/).collect { |i| i.to_i } + dice = dice_str.split(',').map(&:to_i) dice.length.times do |i| dice[i] += mod n1 += 1 if dice[i] <= 1 @@ -122,8 +112,8 @@ def nechronica_check(string) dice_str = dice.join(",") output += " > #{total_n}[#{dice_str}]" - diceMax = 10 - output += check_suc(total_n, n_max, signOfInequality, diff, dice_n, diceMax, n1, n_max) + dice_total = dice.inject(&:+) + output += check_nD10(total_n, dice_total, dice, :>=, diff) debug("dice_n, n1, total_n diff", dice_n, n1, total_n, diff) diff --git a/src/diceBot/NightWizard.rb b/src/diceBot/NightWizard.rb index 3189adea7..42ffe900d 100644 --- a/src/diceBot/NightWizard.rb +++ b/src/diceBot/NightWizard.rb @@ -43,17 +43,6 @@ def dice_command_xRn(string, nick_e) return checkRoll(string, nick_e) end - # ゲーム別成功度判定(2D6) - def check_2D6(total_n, _dice_n, signOfInequality, diff, _dice_cnt, _dice_max, _n1, _n_max) - return '' unless signOfInequality == ">=" - - if total_n >= diff - return " > 成功" - end - - return " > 失敗" - end - def checkRoll(string, nick_e) debug('checkRoll string', string) diff --git a/src/diceBot/NightmareHunterDeep.rb b/src/diceBot/NightmareHunterDeep.rb index 78da40ba8..1189bcaef 100644 --- a/src/diceBot/NightmareHunterDeep.rb +++ b/src/diceBot/NightmareHunterDeep.rb @@ -32,26 +32,25 @@ def changeText(string) return string end - def check_nD6(total_n, _dice_n, signOfInequality, diff, _dice_cnt, _dice_max, _n1, _n_max) # ゲーム別成功度判定(nD6) - return '' unless signOfInequality == ">=" + def check_nD6(total, _dice_total, _dice_list, cmp_op, target) + return '' unless cmp_op == :>= - if diff != "?" - if total_n >= diff + if target != "?" + if total >= target return " > 成功" + else + return " > 失敗" end - - return " > 失敗" end - # diff == "?" sucLv = 1 sucNL = 0 - while total_n >= sucLv * 5 - 1 + while total >= sucLv * 5 - 1 sucLv += 1 end - while total_n >= (sucNL * 5 + 5) + while total >= (sucNL * 5 + 5) sucNL += 1 end @@ -59,9 +58,9 @@ def check_nD6(total_n, _dice_n, signOfInequality, diff, _dice_cnt, _dice_max, _n sucNL -= 1 if sucLv <= 0 - return " > 失敗" + " > 失敗" else - return " > Lv#{sucLv}/NL#{sucNL}成功" + " > Lv#{sucLv}/NL#{sucNL}成功" end end diff --git a/src/diceBot/NjslyrBattle.rb b/src/diceBot/NjslyrBattle.rb index ab3bce9bd..5c01a5c1d 100644 --- a/src/diceBot/NjslyrBattle.rb +++ b/src/diceBot/NjslyrBattle.rb @@ -20,42 +20,31 @@ class NjslyrBattle < DiceBot INFO_MESSAGE_TEXT # ゲーム別成功度判定(2D6) - def check_2D6(total_n, _dice_n, signOfInequality, diff, _dice_cnt, _dice_max, _n1, _n_max) - return '' if signOfInequality != "<=" + def check_2D6(total, _dice_total, dice_list, cmp_op, target) + return '' if cmp_op != :<= - success = checkSuccess(total_n, diff) - juuten = getJuuten - - return success + juuten + return success_text(total, target) + juuten(dice_list) end - def checkSuccess(total_n, diff) - if total_n <= diff - return " > 成功" + def success_text(total, target) + if total <= target + " > 成功" + else + " > 失敗" end - - return " > 失敗" end - def getJuuten - diceList = getDiceList - return '' if diceList.length != 2 - - juuten = 0 + def juuten(dice_list) + juuten = dice_list.count(1) + dice_list.count(6) - diceList.each do |i| - juuten += 1 if i == 1 - juuten += 1 if i == 6 - end - - if diceList[0] == diceList[1] + if dice_list[0] == dice_list[1] juuten += 1 end if juuten > 0 - return " 重点 #{juuten} 溜まる" + " 重点 #{juuten} 溜まる" + else + "" end - - return '' end end diff --git a/src/diceBot/OneWayHeroics.rb b/src/diceBot/OneWayHeroics.rb index 45b93df0d..80630b67f 100644 --- a/src/diceBot/OneWayHeroics.rb +++ b/src/diceBot/OneWayHeroics.rb @@ -117,7 +117,7 @@ def rollJudgeDice(diceCount) return dice, diceText end - diceList = getDiceListFromDiceText(diceText) + diceList = diceText.split(",").map(&:to_i) diceList.sort! diceList.reverse! diff --git a/src/diceBot/Peekaboo.rb b/src/diceBot/Peekaboo.rb index 0b1c83bee..7648a0329 100644 --- a/src/diceBot/Peekaboo.rb +++ b/src/diceBot/Peekaboo.rb @@ -43,14 +43,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 " > ファンブル(【眠気】が1d6点上昇)" - elsif dice_n >= 12 + elsif dice_total >= 12 return " > スペシャル(【魔力】あるいは【眠気】が1d6点回復)" - elsif total_n >= diff + elsif total >= target return " > 成功" else return " > 失敗" diff --git a/src/diceBot/Pendragon.rb b/src/diceBot/Pendragon.rb index 333504282..90e0f143f 100644 --- a/src/diceBot/Pendragon.rb +++ b/src/diceBot/Pendragon.rb @@ -17,21 +17,19 @@ class Pendragon < DiceBot INFO_MESSAGE_TEXT # ゲーム別成功度判定(1d20) - def check_1D20(total_n, _dice_n, signOfInequality, diff, _dice_cnt, _dice_max, _n1, _n_max) - return '' unless signOfInequality == "<=" - - if total_n <= diff - if (total_n >= (40 - diff)) || (total_n == diff) - return " > クリティカル" + def check_1D20(total, _dice_total, cmp_op, target) + return '' unless cmp_op == :<= + + if total <= target + if (total >= (40 - target)) || (total == target) + " > クリティカル" + else + " > 成功" end - - return " > 成功" + elsif total == 20 + " > ファンブル" else - if total_n == 20 - return " > ファンブル" - end - - return " > 失敗" + " > 失敗" end end end diff --git a/src/diceBot/PhantasmAdventure.rb b/src/diceBot/PhantasmAdventure.rb index 057699471..030fc5563 100644 --- a/src/diceBot/PhantasmAdventure.rb +++ b/src/diceBot/PhantasmAdventure.rb @@ -22,8 +22,8 @@ def initialize end # ゲーム別成功度判定(1d20) - def check_1D20(total_n, _dice_n, signOfInequality, diff, _dice_cnt, _dice_max, _n1, _n_max) - return '' unless signOfInequality == "<=" + def check_1D20(total, _dice_total, cmp_op, diff) + return '' unless cmp_op == :<= # 技能値の修正を計算する skill_mod = 0 @@ -38,7 +38,7 @@ def check_1D20(total_n, _dice_n, signOfInequality, diff, _dice_cnt, _dice_max, _ critical = 1 + skill_mod dice_now, = roll(1, 20) - if (total_n >= fumble) || (total_n >= 20) + if (total >= fumble) || (total >= 20) fum_num = dice_now - skill_mod fum_num = 20 if fum_num > 20 fum_num = 1 if fum_num < 1 @@ -55,7 +55,7 @@ def check_1D20(total_n, _dice_n, signOfInequality, diff, _dice_cnt, _dice_max, _ end return " > 致命的失敗(#{fum_str})" - elsif (total_n <= critical) || (total_n <= 1) + elsif (total <= critical) || (total <= 1) crit_num = dice_now + skill_mod crit_num = 20 if crit_num > 20 crit_num = 1 if crit_num < 1 @@ -70,7 +70,7 @@ def check_1D20(total_n, _dice_n, signOfInequality, diff, _dice_cnt, _dice_max, _ return " > 決定的成功(#{crit_num})" - elsif total_n <= diff + elsif total <= diff return " > 成功" else return " > 失敗" diff --git a/src/diceBot/RuneQuest.rb b/src/diceBot/RuneQuest.rb index 711317bae..785758f5b 100644 --- a/src/diceBot/RuneQuest.rb +++ b/src/diceBot/RuneQuest.rb @@ -17,21 +17,27 @@ class RuneQuest < DiceBot INFO_MESSAGE_TEXT # ゲーム別成功度判定(1d100) - def check_1D100(total_n, _dice_n, signOfInequality, diff, _dice_cnt, _dice_max, _n1, _n_max) - return "" unless signOfInequality == "<=" - - cliticalValue = ((1.0 * diff / 20) + 0.5) - - # 1は常に決定的成功 - return " > 決定的成功" if (total_n <= 1) || (total_n <= cliticalValue) - - # 100は常に致命的失敗 - return " > 致命的失敗" if total_n >= 100 - - return " > 効果的成功" if total_n <= (diff / 5 + 0.5) - return " > 成功" if total_n <= diff - return " > 致命的失敗" if total_n >= (95 + (diff / 20 + 0.5)) - - return " > 失敗" + def check_1D100(total, _dice_total, cmp_op, target) + return nil unless cmp_op == :<= + + # RuneQuest QUICK-START RULESを元に修正 + # https://www.chaosium.com/content/FreePDFs/RuneQuest/CHA4027%20-%20RuneQuest%20Quickstart.pdf + critical_value = (target.to_f / 20).round + + if (total <= 1) || (total <= critical_value) + # 1は常に決定的成功 + " > 決定的成功" + elsif total >= 100 + # 100は常に致命的失敗 + " > 致命的失敗" + elsif total <= (target.to_f / 5).round + " > 効果的成功" + elsif total <= target + " > 成功" + elsif total >= 95 + critical_value + " > 致命的失敗" + else + " > 失敗" + end end end diff --git a/src/diceBot/SharedFantasia.rb b/src/diceBot/SharedFantasia.rb index 19c25ad5f..b33b1f701 100644 --- a/src/diceBot/SharedFantasia.rb +++ b/src/diceBot/SharedFantasia.rb @@ -33,42 +33,39 @@ def changeText(string) return string end - def check_2D6(totalValue, dice_n, signOfInequality, diff, _dice_cnt, _dice_max, _n1, _n_max) # ゲーム別成功度判定(2D6) - resultString = '' + def check_2D6(total, dice_total, _dice_list, cmp_op, target) critical = false fumble = false - if dice_n == 12 + if dice_total == 12 critical = true - elsif dice_n == 2 + elsif dice_total == 2 fumble = true end totalValueBonus = 0 - if signOfInequality == '>=' + if cmp_op == :>= totalValueBonus = 1 end - if signOfInequality =~ />/ - if (totalValue + totalValueBonus) > diff + if [:>=, :>].include?(cmp_op) + if (total + totalValueBonus) > target if critical - resultString += " > 自動成功(劇的成功)" + return " > 自動成功(劇的成功)" elsif fumble - resultString += " > 自動失敗" + return " > 自動失敗" else - resultString += " > 成功" + return " > 成功" end else if critical - resultString += " > 自動成功" + return " > 自動成功" elsif fumble - resultString += " > 自動失敗(致命的失敗)" + return " > 自動失敗(致命的失敗)" else - resultString += " > 失敗" + return " > 失敗" end end end - - return resultString end end diff --git a/src/diceBot/ShinMegamiTenseiKakuseihen.rb b/src/diceBot/ShinMegamiTenseiKakuseihen.rb index af810c261..fb0fa9c3c 100644 --- a/src/diceBot/ShinMegamiTenseiKakuseihen.rb +++ b/src/diceBot/ShinMegamiTenseiKakuseihen.rb @@ -19,12 +19,10 @@ class ShinMegamiTenseiKakuseihen < DiceBot INFO_MESSAGE_TEXT # ゲーム別成功度判定(1d100) - def check_1D100(total_n, _dice_n, signOfInequality, diff, _dice_cnt, _dice_max, _n1, _n_max) - return '' unless signOfInequality == "<=" + def check_1D100(total, dice_total, cmp_op, target) + return '' unless cmp_op == :<= - total_n = total_n % 100 - - dice1, dice2 = getTwoDice + dice1, dice2 = split_tens(dice_total) total1 = dice1 * 10 + dice2 total2 = dice2 * 10 + dice1 @@ -33,25 +31,22 @@ def check_1D100(total_n, _dice_n, signOfInequality, diff, _dice_cnt, _dice_max, isRepdigit = (dice1 == dice2) result = " > スワップ" - result += getCheckResultText(diff, [total1, total2].min, isRepdigit) + result += getCheckResultText(target, [total1, total2].min, isRepdigit) result += "/通常" - result += getCheckResultText(diff, total_n, isRepdigit) + result += getCheckResultText(target, total % 100, isRepdigit) result += "/逆スワップ" - result += getCheckResultText(diff, [total1, total2].max, isRepdigit) + result += getCheckResultText(target, [total1, total2].max, isRepdigit) return result end - def getTwoDice - value = getDiceList.first - value ||= 0 - + def split_tens(value) value %= 100 - dice1 = value / 10 - dice2 = value % 10 + ones = value / 10 + tens = value % 10 - return [dice1, dice2] + return [ones, tens] end def getCheckResultText(diff, total, isRepdigit) diff --git a/src/diceBot/ShinobiGami.rb b/src/diceBot/ShinobiGami.rb index d9d4cfd7a..f8568923e 100644 --- a/src/diceBot/ShinobiGami.rb +++ b/src/diceBot/ShinobiGami.rb @@ -40,17 +40,17 @@ def initialize @d66Type = 2 end - def check_2D6(total_n, dice_n, signOfInequality, diff, _dice_cnt, _dice_max, _n1, _n_max) # ゲーム別成功度判定(2D6) - return '' unless signOfInequality == ">=" + def check_2D6(total, dice_total, _dice_list, cmp_op, target) + return '' unless cmp_op == :>= - if dice_n <= 2 - return " > ファンブル" - elsif dice_n >= 12 - return " > スペシャル(生命点1点か変調1つ回復)" - elsif total_n >= diff - return " > 成功" + if dice_total <= 2 + " > ファンブル" + elsif dice_total >= 12 + " > スペシャル(生命点1点か変調1つ回復)" + elsif total >= target + " > 成功" else - return " > 失敗" + " > 失敗" end end diff --git a/src/diceBot/StratoShout.rb b/src/diceBot/StratoShout.rb index fc9da1a75..c20de4a81 100644 --- a/src/diceBot/StratoShout.rb +++ b/src/diceBot/StratoShout.rb @@ -45,14 +45,14 @@ def initialize @d66Type = 2 end - 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 " > ファンブル! (ドラマフェイズ: 【ディスコード】+2 / ライブフェイズ: 【コンディション】-2)" - elsif dice_n >= 12 + elsif dice_total >= 12 " > スペシャル! (【コンディション】+2)" - elsif total_n >= diff + elsif total >= target " > 成功" else " > 失敗" diff --git a/src/diceBot/SwordWorld.rb b/src/diceBot/SwordWorld.rb index 6a97a2175..40f9f9de4 100644 --- a/src/diceBot/SwordWorld.rb +++ b/src/diceBot/SwordWorld.rb @@ -39,23 +39,18 @@ def getRatingCommandStrings "cmCM" end - def check_2D6(totalValue, dice_n, signOfInequality, diff, _dice_cnt, _dice_max, _n1, _n_max) # ゲーム別成功度判定(2D6) - if dice_n >= 12 - return " > 自動的成功" - end - - if dice_n <= 2 - return " > 自動的失敗" - end - - return '' if signOfInequality != ">=" - return '' if diff == "?" - - if totalValue >= diff - return " > 成功" + def check_2D6(total, dice_total, _dice_list, cmp_op, target) + if dice_total >= 12 + " > 自動的成功" + elsif dice_total <= 2 + " > 自動的失敗" + elsif cmp_op != :>= || target == "?" + '' + elsif total >= target + " > 成功" + else + " > 失敗" end - - return " > 失敗" end def rollDiceCommand(command) diff --git a/src/diceBot/SwordWorld2_0.rb b/src/diceBot/SwordWorld2_0.rb index d6f4b0d81..7cf1d5632 100644 --- a/src/diceBot/SwordWorld2_0.rb +++ b/src/diceBot/SwordWorld2_0.rb @@ -150,11 +150,10 @@ def check2dCritical(critical, dice_new, dice_arry, loop_count) end end - def check_nD6(total_n, dice_n, signOfInequality, diff, dice_cnt, dice_max, n1, n_max) # ゲーム別成功度判定(nD6) - debug("check_nD6") - result = super(total_n, dice_n, signOfInequality, diff, dice_cnt, dice_max, n1, n_max) + def check_nD6(total, dice_total, dice_list, cmp_op, target) + result = super(total, dice_total, dice_list, cmp_op, target) - return result unless result == "" + return result unless result.nil? string = bcdice.getOriginalMessage @@ -162,8 +161,8 @@ def check_nD6(total_n, dice_n, signOfInequality, diff, dice_cnt, dice_max, n1, n if /@(\d+)/ === string critical = Regexp.last_match(1).to_i - if dice_n >= critical - if total_n >= superSuccessValue + if dice_total >= critical + if total >= superSuccessValue return " > 超成功" end end diff --git a/src/diceBot/TokumeiTenkousei.rb b/src/diceBot/TokumeiTenkousei.rb index 8fd9341d2..5bbe8845e 100644 --- a/src/diceBot/TokumeiTenkousei.rb +++ b/src/diceBot/TokumeiTenkousei.rb @@ -22,12 +22,12 @@ def initialize @sameDiceRerollType = 2 # ゾロ目で振り足しのロール種別(0=判定のみ, 1=ダメージのみ, 2=両方) end - def check_nD6(total_n, _dice_n, signOfInequality, diff, _dice_cnt, _dice_max, _n1, _n_max) # ゲーム別成功度判定(nD6) - return '' unless signOfInequality == ">=" - - return '' if diff == "?" + def check_nD6(total, _dice_total, _dice_list, cmp_op, target) + if cmp_op != :>= && target == "?" + return '' + end - if total_n >= diff + if total >= target return " > 成功" else return " > 失敗" diff --git a/src/diceBot/TrinitySeven.rb b/src/diceBot/TrinitySeven.rb index eb05efc0e..8d12389c5 100644 --- a/src/diceBot/TrinitySeven.rb +++ b/src/diceBot/TrinitySeven.rb @@ -132,9 +132,12 @@ def getRollDamageCritialText(diceCount, critical, total, diceText, modify) return total, diceList end - def check_1D100(_total_n, dice_n, _signOfInequality, _diff, _dice_cnt, _dice_max, _n1, _n_max) - return " > ファンブル" if dice_n >= 96 - return " > クリティカル" if dice_n <= 7 + def check_1D100(_total, dice_total, _cmp_op, _target) + if dice_total >= 96 + " > ファンブル" + elsif dice_total <= 7 + " > クリティカル" + end end # 名前表 diff --git a/src/diceBot/TunnelsAndTrolls.rb b/src/diceBot/TunnelsAndTrolls.rb index 68d8680dc..d2cf36ec3 100644 --- a/src/diceBot/TunnelsAndTrolls.rb +++ b/src/diceBot/TunnelsAndTrolls.rb @@ -60,27 +60,19 @@ def dice_command_xRn(string, nick_e) return tandt_berserk(string, nick_e) end - def check_2D6(total_n, dice_n, signOfInequality, diff, _dice_cnt, _dice_max, _n1, _n_max) # ゲーム別成功度判定(2D6) - debug('Tunnels & Trolls check_2D6 begin') + def check_2D6(total, dice_total, _dice_list, cmp_op, target) + return '' unless cmp_op == :>= - return '' unless signOfInequality == ">=" - - debug('Tunnels & Trolls check_2D6 pass1') - - if dice_n == 3 + if dice_total == 3 return " > 自動失敗" - end - - if @diffText == "?" - return getMaxSuccessLevel(total_n, dice_n) - end - - if total_n >= diff - experiencePoint = getExperiencePoint(diff, dice_n) + elsif target == "?" + return getMaxSuccessLevel(total, dice_total) + elsif total >= target + experiencePoint = getExperiencePoint(target, dice_total) return " > 成功 > 経験値#{experiencePoint}" + else + return " > 失敗" end - - return " > 失敗" end def getMaxSuccessLevel(total_n, dice_n) diff --git a/src/diceBot/WARPS.rb b/src/diceBot/WARPS.rb index 3d6673059..6188f05ef 100644 --- a/src/diceBot/WARPS.rb +++ b/src/diceBot/WARPS.rb @@ -14,26 +14,17 @@ class WARPS < DiceBot # ダイスボットの使い方 HELP_MESSAGE = "失敗、成功度の自動判定を行います。\n" - def check_2D6(total_n, dice_n, signOfInequality, diff, _dice_cnt, _dice_max, _n1, _n_max) # ゲーム別成功度判定(2D6) - debug('WARPS check_2D6 betgin') - debug('diff', diff) - debug('total_n', total_n) - - if dice_n <= 2 - return " > クリティカル" - elsif dice_n >= 12 - return " > ファンブル" - elsif signOfInequality == "<=" - if diff != "?" - if total_n <= diff - success = diff - total_n - return " > #{success}成功" - else - return " > 失敗" - end + def check_2D6(total, dice_total, _dice_list, cmp_op, target) + if dice_total <= 2 + " > クリティカル" + elsif dice_total >= 12 + " > ファンブル" + elsif cmp_op == :<= && target != "?" + if total <= target + " > #{target - total}成功" + else + " > 失敗" end end - - return output end end diff --git a/src/diceBot/WaresBlade.rb b/src/diceBot/WaresBlade.rb index 91aacdcb2..0de61bfac 100644 --- a/src/diceBot/WaresBlade.rb +++ b/src/diceBot/WaresBlade.rb @@ -14,25 +14,17 @@ class WaresBlade < DiceBot # ダイスボットの使い方 HELP_MESSAGE = "nD10>=m 方式の判定で成否、完全成功、完全失敗を自動判定します。\n" - def check_nD10(total_n, dice_n, signOfInequality, diff, dice_cnt, _dice_max, _n1, _n_max) # ゲーム別成功度判定(nD10) - return '' unless signOfInequality == '>=' - - if dice_n == 10 * dice_cnt - - return ' > 完全成功' - - elsif dice_n == 1 * dice_cnt - - return ' > 絶対失敗' - + def check_nD10(total, _dice_total, dice_list, cmp_op, target) + return '' unless cmp_op == :>= + + if dice_list.count(10) == dice_list.size + ' > 完全成功' + elsif dice_list.count(1) == dice_list.size + ' > 絶対失敗' + elsif total >= target + ' > 成功' else - - if total_n >= diff - return ' > 成功' - else - return ' > 失敗' - end - + ' > 失敗' end end end diff --git a/src/diceBot/Warhammer.rb b/src/diceBot/Warhammer.rb index f391a5e5a..5c39bc9a3 100644 --- a/src/diceBot/Warhammer.rb +++ b/src/diceBot/Warhammer.rb @@ -50,14 +50,14 @@ def rollDiceCommand(command) return output_msg end - def check_1D100(total_n, _dice_n, signOfInequality, diff, _dice_cnt, _dice_max, _n1, _n_max) # ゲーム別成功度判定(1d100) - return '' unless signOfInequality == "<=" + def check_1D100(total, _dice_total, cmp_op, target) + return '' unless cmp_op == :<= - if total_n <= diff - return " > 成功(成功度#{((diff - total_n) / 10)})" + if total <= target + " > 成功(成功度#{(target - total) / 10})" + else + " > 失敗(失敗度#{(total - target) / 10})" end - - return " > 失敗(失敗度#{((total_n - diff) / 10)})" end #################### WHFRP関連 ######################## @@ -322,7 +322,7 @@ def getAttackResult(string) total_n, = roll(1, 100) output = "(#{string}) > #{total_n}" - output += check_suc(total_n, 0, "<=", diff, 1, 100, 0, total_n) + output += check_1D100(total_n, total_n, :<=, diff) pos_num = (total_n % 10) * 10 + (total_n / 10).to_i pos_num = 100 if total_n >= 100 diff --git a/src/diceBot/YankeeYogSothoth.rb b/src/diceBot/YankeeYogSothoth.rb index 94c488509..2f06f22b2 100644 --- a/src/diceBot/YankeeYogSothoth.rb +++ b/src/diceBot/YankeeYogSothoth.rb @@ -47,21 +47,18 @@ 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 == :>= - output = - if dice_n <= 2 - " > ファンブル(判定失敗。ファンブル表(FT)を振ること)" - elsif dice_n >= 12 - " > スペシャル(判定成功。【テンション】が1段階上昇)" - elsif total_n >= diff - " > 成功" - else - " > 失敗" - end - - return output + if dice_total <= 2 + " > ファンブル(判定失敗。ファンブル表(FT)を振ること)" + elsif dice_total >= 12 + " > スペシャル(判定成功。【テンション】が1段階上昇)" + elsif total >= target + " > 成功" + else + " > 失敗" + end end def rollDiceCommand(command) diff --git a/src/diceBot/_InsaneScp.rb b/src/diceBot/_InsaneScp.rb index e168b9d70..a9189e9c2 100644 --- a/src/diceBot/_InsaneScp.rb +++ b/src/diceBot/_InsaneScp.rb @@ -65,23 +65,18 @@ def dice_command_xRn(_string, _nick_e) end # ゲーム別成功度判定(2D6) - def check_2D6(total_n, dice_n, signOfInequality, diff, dice_cnt, dice_max, n1, n_max) - debug("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 signOfInequality == ">=" - - output = - if dice_n <= 2 - " > ファンブル(判定失敗。山札から【狂気】を1枚獲得)" - elsif dice_n >= 12 - " > スペシャル(判定成功。【生命力】1点か【正気度】1点回復)" - elsif total_n >= diff - " > 成功" - else - " > 失敗" - end - - return output + def check_2D6(total, dice_total, _dice_list, _cmp_op, target) + return '' unless signOfInequality == :>= + + if dice_total <= 2 + " > ファンブル(判定失敗。山札から【狂気】を1枚獲得)" + elsif dice_total >= 12 + " > スペシャル(判定成功。【生命力】1点か【正気度】1点回復)" + elsif total >= target + " > 成功" + else + " > 失敗" + end end def rollDiceCommand(command) diff --git a/src/diceBot/_Template.rb b/src/diceBot/_Template.rb index 5dea48f9c..1984ee7c1 100644 --- a/src/diceBot/_Template.rb +++ b/src/diceBot/_Template.rb @@ -81,6 +81,4 @@ def check_1D20(_total_n, _dice_n, _signOfInequality, _diff, _dice_cnt, _dice_max # get_table_by_1d3(table) # get_table_by_number(index, table) # get_table_by_d66(table) - - # getDiceList を呼び出すとロース結果のダイス目の配列が手に入ります。 end diff --git a/src/test/data/GranCrest.txt b/src/test/data/GranCrest.txt index 09ddef6b7..661737c7b 100644 --- a/src/test/data/GranCrest.txt +++ b/src/test/data/GranCrest.txt @@ -31,13 +31,13 @@ rand:6/6,6/6,6/6 input: 3d6>=? output: -GranCrest : (3D6>=?) > 14[2,6,6] > 14(クリティカル) > 24 > 成功 +GranCrest : (3D6>=?) > 14[2,6,6] > 14(クリティカル) > 24 rand:2/6,6/6,6/6 ============================ input: 3d6+7>=? output: -GranCrest : (3D6+7>=?) > 13[1,6,6]+7 > 20(クリティカル) > 30 > 成功 +GranCrest : (3D6+7>=?) > 13[1,6,6]+7 > 20(クリティカル) > 30 rand:1/6,6/6,6/6 ============================ input: diff --git a/src/test/data/RuneQuest.txt b/src/test/data/RuneQuest.txt index f61555b81..df3bfed7d 100644 --- a/src/test/data/RuneQuest.txt +++ b/src/test/data/RuneQuest.txt @@ -189,3 +189,63 @@ output: RuneQuest : (1D100>=80) > 11 > 失敗 rand:11/100 ============================ +input: +1D100<=50 +output: +RuneQuest : (1D100<=50) > 1 > 決定的成功 +rand:1/100 +============================ +input: +1D100<=50 +output: +RuneQuest : (1D100<=50) > 3 > 決定的成功 +rand:3/100 +============================ +input: +1D100<=50 +output: +RuneQuest : (1D100<=50) > 4 > 効果的成功 +rand:4/100 +============================ +input: +1D100<=50 +output: +RuneQuest : (1D100<=50) > 10 > 効果的成功 +rand:10/100 +============================ +input: +1D100<=50 +output: +RuneQuest : (1D100<=50) > 11 > 成功 +rand:11/100 +============================ +input: +1D100<=50 +output: +RuneQuest : (1D100<=50) > 50 > 成功 +rand:50/100 +============================ +input: +1D100<=50 +output: +RuneQuest : (1D100<=50) > 51 > 失敗 +rand:51/100 +============================ +input: +1D100<=50 +output: +RuneQuest : (1D100<=50) > 97 > 失敗 +rand:97/100 +============================ +input: +1D100<=50 +output: +RuneQuest : (1D100<=50) > 98 > 致命的失敗 +rand:98/100 +============================ +input: +1D100<=50 +output: +RuneQuest : (1D100<=50) > 100 > 致命的失敗 +rand:100/100 +============================ From bdd9b90f2d1704bcae1c9fce2292994e19502428 Mon Sep 17 00:00:00 2001 From: SAKATA Sinji Date: Wed, 1 Apr 2020 16:04:58 +0900 Subject: [PATCH 3/5] Rename method to DiceBot#check_result --- src/dice/AddDice.rb | 2 +- src/diceBot/ArsMagica.rb | 2 +- src/diceBot/BeastBindTrinity.rb | 2 +- src/diceBot/DarkBlaze.rb | 2 +- src/diceBot/DiceBot.rb | 14 +++++++------- src/diceBot/MeikyuKingdom.rb | 2 +- src/diceBot/NightWizard.rb | 2 +- 7 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/dice/AddDice.rb b/src/dice/AddDice.rb index 4ed7138e4..e51d46768 100644 --- a/src/dice/AddDice.rb +++ b/src/dice/AddDice.rb @@ -93,7 +93,7 @@ def rollDice(string) if signOfInequality != "" # 成功度判定処理 cmp_op = Normalizer.cmp_op(signOfInequality) target = Normalizer.target_number(diffText) - successText = @diceBot.check_suc(total_n, dice_n, @dice_list, dice_max, cmp_op, target) + successText = @diceBot.check_result(total_n, dice_n, @dice_list, dice_max, cmp_op, target) debug("check_suc successText", successText) output += successText end diff --git a/src/diceBot/ArsMagica.rb b/src/diceBot/ArsMagica.rb index e8a3382cf..ac44e38e9 100644 --- a/src/diceBot/ArsMagica.rb +++ b/src/diceBot/ArsMagica.rb @@ -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 diff --git a/src/diceBot/BeastBindTrinity.rb b/src/diceBot/BeastBindTrinity.rb index 3b5f3fcc7..dc24655be 100644 --- a/src/diceBot/BeastBindTrinity.rb +++ b/src/diceBot/BeastBindTrinity.rb @@ -274,7 +274,7 @@ def bbt_check(string) if signOfInequality != "" # 成功度判定処理 cmp_op = Normalizer.cmp_op(signOfInequality) dice_list = dice_num - output += check_suc(total_n, dice_now, dice_list, 6, cmp_op, diff) + output += check_result(total_n, dice_now, dice_list, 6, cmp_op, diff) end return output diff --git a/src/diceBot/DarkBlaze.rb b/src/diceBot/DarkBlaze.rb index 2809863fa..dd3c7ee37 100644 --- a/src/diceBot/DarkBlaze.rb +++ b/src/diceBot/DarkBlaze.rb @@ -89,7 +89,7 @@ def check_roll(string, nick_e) if signOfInequality != "" # 成功度判定処理 dice_total = dice_list.inject(&:+) cmp_op = Normalizer.cmp_op(signOfInequality) - output += check_suc(total, dice_total, dice_list, 6, cmp_op, diff) + output += check_result(total, dice_total, dice_list, 6, cmp_op, diff) end return output diff --git a/src/diceBot/DiceBot.rb b/src/diceBot/DiceBot.rb index 9e52f29f9..fabbba23e 100644 --- a/src/diceBot/DiceBot.rb +++ b/src/diceBot/DiceBot.rb @@ -295,7 +295,7 @@ def dice_command_xRn(_string, _nick_e) # @param cmp_op [Symbol] 比較演算子 # @param target [Integer, String] 目標値の整数か'?' # @return [String] - def check_suc(total, dice_total, dice_list, sides, cmp_op, target) + def check_result(total, dice_total, dice_list, sides, cmp_op, target) ret = case [dice_list.size, sides] when [1, 100] @@ -323,7 +323,7 @@ def check_suc(total, dice_total, dice_list, sides, cmp_op, target) # 成功か失敗かを文字列で返す # - # @param (see #check_suc) + # @param (see #check_result) # @return [String] def check_nDx(total, cmp_op, target) return " > 失敗" if target.is_a?(String) @@ -338,27 +338,27 @@ def check_nDx(total, cmp_op, target) end # @abstruct - # @param (see #check_suc) + # @param (see #check_result) # @return [nil] def check_1D100(total, dice_total, cmp_op, target); end # @abstruct - # @param (see #check_suc) + # @param (see #check_result) # @return [nil] def check_1D20(total, dice_total, cmp_op, target); end # @abstruct - # @param (see #check_suc) + # @param (see #check_result) # @return [nil] def check_nD10(total, dice_total, dice_list, cmp_op, target); end # @abstruct - # @param (see #check_suc) + # @param (see #check_result) # @return [nil] def check_2D6(total, dice_total, dice_list, cmp_op, target); end # @abstruct - # @param (see #check_suc) + # @param (see #check_result) # @return [nil] def check_nD6(total, dice_total, dice_list, cmp_op, target); end diff --git a/src/diceBot/MeikyuKingdom.rb b/src/diceBot/MeikyuKingdom.rb index 7fb581efc..b05dea0d4 100644 --- a/src/diceBot/MeikyuKingdom.rb +++ b/src/diceBot/MeikyuKingdom.rb @@ -192,7 +192,7 @@ def mayokin_check(string, nick_e) if signOfInequality != "" # 成功度判定処理 cmp_op = Normalizer.cmp_op(signOfInequality) - output += check_suc(total_n, dice_now, dice_list, 6, cmp_op, diff) + output += check_result(total_n, dice_now, dice_list, 6, cmp_op, diff) end return output diff --git a/src/diceBot/NightWizard.rb b/src/diceBot/NightWizard.rb index 42ffe900d..cfcce2838 100644 --- a/src/diceBot/NightWizard.rb +++ b/src/diceBot/NightWizard.rb @@ -90,7 +90,7 @@ def checkRoll(string, nick_e) output = "#{nick_e}: (#{string}) > #{out_str}" if signOfInequality != "" # 成功度判定処理 - output += check_suc(total, 0, signOfInequality, diff, 3, 6, 0, 0) + output += check_result(total, 0, signOfInequality, diff, 3, 6, 0, 0) end return output From 6456840c820943991946539600a23bfa8a3fd84a Mon Sep 17 00:00:00 2001 From: SAKATA Sinji Date: Wed, 1 Apr 2020 17:04:46 +0900 Subject: [PATCH 4/5] Normalizer#comparison_op --- src/dice/AddDice.rb | 2 +- src/diceBot/BeastBindTrinity.rb | 2 +- src/diceBot/DarkBlaze.rb | 2 +- src/diceBot/MeikyuDays.rb | 2 +- src/diceBot/MeikyuKingdom.rb | 2 +- src/utils/normalizer.rb | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/dice/AddDice.rb b/src/dice/AddDice.rb index e51d46768..6624712b4 100644 --- a/src/dice/AddDice.rb +++ b/src/dice/AddDice.rb @@ -91,7 +91,7 @@ def rollDice(string) total_n += revision if signOfInequality != "" # 成功度判定処理 - cmp_op = Normalizer.cmp_op(signOfInequality) + cmp_op = Normalizer.comparison_op(signOfInequality) target = Normalizer.target_number(diffText) successText = @diceBot.check_result(total_n, dice_n, @dice_list, dice_max, cmp_op, target) debug("check_suc successText", successText) diff --git a/src/diceBot/BeastBindTrinity.rb b/src/diceBot/BeastBindTrinity.rb index dc24655be..2aa0f5bb4 100644 --- a/src/diceBot/BeastBindTrinity.rb +++ b/src/diceBot/BeastBindTrinity.rb @@ -272,7 +272,7 @@ def bbt_check(string) end if signOfInequality != "" # 成功度判定処理 - cmp_op = Normalizer.cmp_op(signOfInequality) + cmp_op = Normalizer.comparison_op(signOfInequality) dice_list = dice_num output += check_result(total_n, dice_now, dice_list, 6, cmp_op, diff) end diff --git a/src/diceBot/DarkBlaze.rb b/src/diceBot/DarkBlaze.rb index dd3c7ee37..80bb7c2bd 100644 --- a/src/diceBot/DarkBlaze.rb +++ b/src/diceBot/DarkBlaze.rb @@ -88,7 +88,7 @@ def check_roll(string, nick_e) if signOfInequality != "" # 成功度判定処理 dice_total = dice_list.inject(&:+) - cmp_op = Normalizer.cmp_op(signOfInequality) + cmp_op = Normalizer.comparison_op(signOfInequality) output += check_result(total, dice_total, dice_list, 6, cmp_op, diff) end diff --git a/src/diceBot/MeikyuDays.rb b/src/diceBot/MeikyuDays.rb index bdc7a5d12..a14cd40e2 100644 --- a/src/diceBot/MeikyuDays.rb +++ b/src/diceBot/MeikyuDays.rb @@ -115,7 +115,7 @@ def checkRoll(string) end if signOfInequality != "" # 成功度判定処理 - cmp_op = Normalizer.cmp_op(signOfInequality) + cmp_op = Normalizer.comparison_op(signOfInequality) output += check_2D6(total_n, dice_now, dice_num, cmp_op, diff) end diff --git a/src/diceBot/MeikyuKingdom.rb b/src/diceBot/MeikyuKingdom.rb index b05dea0d4..45fc69b51 100644 --- a/src/diceBot/MeikyuKingdom.rb +++ b/src/diceBot/MeikyuKingdom.rb @@ -191,7 +191,7 @@ def mayokin_check(string, nick_e) end if signOfInequality != "" # 成功度判定処理 - cmp_op = Normalizer.cmp_op(signOfInequality) + cmp_op = Normalizer.comparison_op(signOfInequality) output += check_result(total_n, dice_now, dice_list, 6, cmp_op, diff) end diff --git a/src/utils/normalizer.rb b/src/utils/normalizer.rb index ef59e62c7..6536a9062 100644 --- a/src/utils/normalizer.rb +++ b/src/utils/normalizer.rb @@ -5,7 +5,7 @@ module Normalizer # # @param op [String] # @return [Symbol, nil] - def cmp_op(op) + def comparison_op(op) case op when /<=|= Date: Wed, 1 Apr 2020 23:02:31 +0900 Subject: [PATCH 5/5] Rename to Normalize.comparison_operator --- src/dice/AddDice.rb | 6 +++--- src/diceBot/BeastBindTrinity.rb | 2 +- src/diceBot/DarkBlaze.rb | 2 +- src/diceBot/MeikyuDays.rb | 2 +- src/diceBot/MeikyuKingdom.rb | 2 +- src/utils/{normalizer.rb => normalize.rb} | 4 ++-- 6 files changed, 9 insertions(+), 9 deletions(-) rename src/utils/{normalizer.rb => normalize.rb} (91%) diff --git a/src/dice/AddDice.rb b/src/dice/AddDice.rb index 6624712b4..a89fa4287 100644 --- a/src/dice/AddDice.rb +++ b/src/dice/AddDice.rb @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- -require "utils/normalizer" +require "utils/normalize" class AddDice def initialize(bcdice, diceBot) @@ -91,8 +91,8 @@ def rollDice(string) total_n += revision if signOfInequality != "" # 成功度判定処理 - cmp_op = Normalizer.comparison_op(signOfInequality) - target = Normalizer.target_number(diffText) + 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 diff --git a/src/diceBot/BeastBindTrinity.rb b/src/diceBot/BeastBindTrinity.rb index 2aa0f5bb4..b8fc6dcba 100644 --- a/src/diceBot/BeastBindTrinity.rb +++ b/src/diceBot/BeastBindTrinity.rb @@ -272,7 +272,7 @@ def bbt_check(string) end if signOfInequality != "" # 成功度判定処理 - cmp_op = Normalizer.comparison_op(signOfInequality) + cmp_op = Normalize.comparison_operator(signOfInequality) dice_list = dice_num output += check_result(total_n, dice_now, dice_list, 6, cmp_op, diff) end diff --git a/src/diceBot/DarkBlaze.rb b/src/diceBot/DarkBlaze.rb index 80bb7c2bd..1aea1caf8 100644 --- a/src/diceBot/DarkBlaze.rb +++ b/src/diceBot/DarkBlaze.rb @@ -88,7 +88,7 @@ def check_roll(string, nick_e) if signOfInequality != "" # 成功度判定処理 dice_total = dice_list.inject(&:+) - cmp_op = Normalizer.comparison_op(signOfInequality) + cmp_op = Normalize.comparison_operator(signOfInequality) output += check_result(total, dice_total, dice_list, 6, cmp_op, diff) end diff --git a/src/diceBot/MeikyuDays.rb b/src/diceBot/MeikyuDays.rb index a14cd40e2..6db80418f 100644 --- a/src/diceBot/MeikyuDays.rb +++ b/src/diceBot/MeikyuDays.rb @@ -115,7 +115,7 @@ def checkRoll(string) end if signOfInequality != "" # 成功度判定処理 - cmp_op = Normalizer.comparison_op(signOfInequality) + cmp_op = Normalize.comparison_operator(signOfInequality) output += check_2D6(total_n, dice_now, dice_num, cmp_op, diff) end diff --git a/src/diceBot/MeikyuKingdom.rb b/src/diceBot/MeikyuKingdom.rb index 45fc69b51..4f82a41d5 100644 --- a/src/diceBot/MeikyuKingdom.rb +++ b/src/diceBot/MeikyuKingdom.rb @@ -191,7 +191,7 @@ def mayokin_check(string, nick_e) end if signOfInequality != "" # 成功度判定処理 - cmp_op = Normalizer.comparison_op(signOfInequality) + cmp_op = Normalize.comparison_operator(signOfInequality) output += check_result(total_n, dice_now, dice_list, 6, cmp_op, diff) end diff --git a/src/utils/normalizer.rb b/src/utils/normalize.rb similarity index 91% rename from src/utils/normalizer.rb rename to src/utils/normalize.rb index 6536a9062..ed6de5d44 100644 --- a/src/utils/normalizer.rb +++ b/src/utils/normalize.rb @@ -1,11 +1,11 @@ -module Normalizer +module Normalize module_function # 比較演算子をシンボルに正規化する # # @param op [String] # @return [Symbol, nil] - def comparison_op(op) + def comparison_operator(op) case op when /<=|=