|
#--*-coding:utf-8-*-- |
|
|
|
class RecordofSteam < DiceBot |
|
|
|
def gameType |
|
"RecordofSteam" |
|
end |
|
|
|
|
|
def getHelpMessage |
|
return <<MESSAGETEXT |
|
2S2@1 |
|
RecordofSteam: (2S2@1) > 1,2,3,4 > 1回転 > 成功数2 |
|
|
|
4S3@2 |
|
RecordofSteam: (4S3@2) > 2,1,2,4,4,4,2,3,4,5,6 > 4回転 > 成功数5 |
|
MESSAGETEXT |
|
end |
|
|
|
# rubyの定数の定め方をよく知らないのだけれども、何か方法があるならそちらで代替のこと。 |
|
def getErrorMessage |
|
"(多分)無限個なので振れません! ヤメテクダサイ、(プロセスが)死んでしまいますっ" |
|
end |
|
|
|
# サンプルのダイスコマンドは「nSt@c」で n=ダイス個数, t=目標値, c=クリティカル値。@cのみ省略可 |
|
def rollDiceCommandResult(string) |
|
|
|
# 分解 |
|
unless( /(\d+)[sS](\d+)(@(\d+))?/i =~ string ) |
|
return "1" |
|
end |
|
|
|
# 記述のエラー検出 |
|
return getErrorMessage if($1.to_i>=150) |
|
return getErrorMessage if($4.to_i>=3) |
|
|
|
# 値を取得 |
|
diceCount = $1.to_i # d6を振る個数 |
|
targetNumber = $2.to_i # それぞれのd6で目指す目標値(targetNumber"以下") |
|
criticalValue = $4.to_i # それぞれのd6で目指すクリティカル値(criticalValue"以下") |
|
specialValue = [ diceCount, 0 ].max |
|
|
|
rollResult, successCount, roundCount, specialCount = getDiceRollResult(diceCount, targetNumber, criticalValue, specialValue) |
|
|
|
output = "(#{string}) > #{rollResult}" |
|
|
|
if(output.length > $SEND_STR_MAX) |
|
output = "(#{string}) > ..." |
|
end |
|
|
|
roundCountText = getRoundCountText(roundCount) |
|
successText = getSuccessText(successCount) |
|
specialText = getSpecialText(specialCount) |
|
|
|
result = "#{output}#{roundCountText}#{specialText}#{successText}" |
|
|
|
return result |
|
end |
|
|
|
|
|
def getDiceRollResult(diceCount, targetNumber, criticalValue, specialValue) |
|
successCount = 0 |
|
roundCount = 0 |
|
rollResult = "" |
|
specialCount = 0 |
|
|
|
while(diceCount > 0) |
|
totalValue, diceListText, = roll(diceCount, 6) |
|
debug("diceListText", diceListText) |
|
|
|
rollResult += "," if(rollResult != "") |
|
rollResult += diceListText |
|
|
|
diceList = getDiceListFromDiceText(diceListText) |
|
debug("diceList", diceList) |
|
|
|
diceCount = 0 |
|
if(totalValue == specialValue && roundCount == 0 ) |
|
specialCount = 1 |
|
successCount = specialValue * 3 |
|
return rollResult, successCount ,roundCount, specialCount |
|
end |
|
|
|
diceList.each do |diceValue| |
|
debug("diceValue", diceValue) |
|
debug("criticalValue", criticalValue) |
|
debug("specialValue", specialValue) |
|
|
|
if(diceValue <= criticalValue) |
|
diceCount += 2 |
|
roundCount += 1 |
|
end |
|
if(diceValue <= targetNumber) |
|
successCount += 1 |
|
end |
|
|
|
end |
|
end |
|
|
|
return rollResult, successCount ,roundCount, specialCount |
|
end |
|
|
|
|
|
def getRoundCountText(roundCount) |
|
if( roundCount <= 0 ) |
|
return "" |
|
end |
|
|
|
return " > #{roundCount}回転" |
|
end |
|
|
|
def getSuccessText(successCount) |
|
if(successCount > 0) |
|
return " > 成功数#{successCount}" |
|
end |
|
|
|
return " > 失敗" |
|
end |
|
|
|
def getSpecialText(specialCount) |
|
if(specialCount == 1) |
|
return " > スペシャル" |
|
end |
|
end |
|
end |