class BCDice::GameSystem::Utakaze
Constants
- DRAGON_DICE_NAME
- HELP_MESSAGE
ダイスボットの使い方
- ID
ゲームシステムの識別子
- NAME
ゲームシステム名
- SORT_KEY
ゲームシステム名の読みがな
Public Instance Methods
eval_game_system_specific_command(command)
click to toggle source
# File lib/bcdice/game_system/Utakaze.rb, line 33 def eval_game_system_specific_command(command) debug('eval_game_system_specific_command command', command) check_roll(command) end
Private Instance Methods
check_roll(command)
click to toggle source
# File lib/bcdice/game_system/Utakaze.rb, line 50 def check_roll(command) m = /^(\d+)?UK(@?(\d))?(>=(\d+))?$/i.match(command) return nil unless m base = (m[1] || 2).to_i crit = m[3].to_i diff = m[5].to_i base = getValue(base) crit = getValue(crit) return nil if base < 1 crit = 6 if crit > 6 dice_list = @randomizer.roll_barabara(base, 6).sort result = get_roll_result(dice_list, crit, diff) sequence = [ command, "(#{base}D6)", "[#{dice_list.join(',')}]", result.text ] result.text = sequence.join(" > ") return result end
getDiceCountHash(dice_list, critical)
click to toggle source
各ダイスの個数を数えてHashにする
# File lib/bcdice/game_system/Utakaze.rb, line 136 def getDiceCountHash(dice_list, critical) dice_list .select { |dice| isNomalDice(critical) || dice == critical } .group_by(&:itself) .transform_values(&:size) end
getSuccessInfo(diceList, crit)
click to toggle source
# File lib/bcdice/game_system/Utakaze.rb, line 106 def getSuccessInfo(diceList, crit) debug("checkSuccess diceList, crit", diceList, crit) diceCountHash = getDiceCountHash(diceList, crit) debug("diceCountHash", diceCountHash) maxnum = 0 successDiceList = [] countThreshold = (isDragonDice(crit) ? 1 : 2) diceCountHash.each do |dice, count| maxnum = count if count > maxnum successDiceList << dice if count >= countThreshold end debug("successDiceList", successDiceList) if successDiceList.size <= 0 # 失敗:ゾロ目無し(全部違う) return false, 0, 0 end # 竜のダイスの場合 maxnum *= 2 if isDragonDice(crit) # 成功:ゾロ目あり return true, maxnum, successDiceList.size end
getValue(number)
click to toggle source
# File lib/bcdice/game_system/Utakaze.rb, line 151 def getValue(number) return 0 if number > 100 return number end
get_roll_result(diceList, crit, diff)
click to toggle source
# File lib/bcdice/game_system/Utakaze.rb, line 79 def get_roll_result(diceList, crit, diff) success, maxnum, setCount = getSuccessInfo(diceList, crit) sequence = [] if isDragonDice(crit) sequence.push("龍のダイス「#{DRAGON_DICE_NAME[crit]}」(#{crit})を使用") end if success sequence.push("成功レベル:#{maxnum} (#{setCount}セット)") else sequence.push("失敗") return Result.failure(sequence.join(" > ")) end if diff == 0 return Result.success(sequence.join(" > ")) # 難易度なしでも成功として扱う elsif maxnum >= diff sequence.push("成功") return Result.success(sequence.join(" > ")) else sequence.push("失敗") return Result.failure(sequence.join(" > ")) end end
isDragonDice(crit)
click to toggle source
# File lib/bcdice/game_system/Utakaze.rb, line 147 def isDragonDice(crit) (crit != 0) end
isNomalDice(crit)
click to toggle source
# File lib/bcdice/game_system/Utakaze.rb, line 143 def isNomalDice(crit) !isDragonDice(crit) end