BCDice/内部処理/AddDiceクラス

提供: TRPGツール開発・運用Wiki
ナビゲーションに移動 検索に移動
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

加算ロールの演算処理を担うクラス。

getSlashedDice

https://github.com/torgtaitai/BCDice/blob/86b8dd03ae00f8ea6a8787f9f514a5d83b2e3d41/src/dice/AddDice.rb#L290-L311

ダイスロール結果の除算を行う。接尾辞 UR によって丸め処理の方法を指定することができる。

例:

  • 4D10 の結果が 30 のとき
    • 切り捨て:4D10/7 → 4.2… → 4
    • 四捨五入:4D10/7R → 4.2… → 4
    • 切り上げ:4D10/7U → 4.2… → 5
  • 4D10 の結果が 32 のとき
    • 切り捨て:4D10/7 → 4.5… → 4
    • 四捨五入:4D10/7R → 4.5… → 5
    • 切り上げ:4D10/7U → 4.5… → 5
def getSlashedDice(slashMark, dice)

  return dice unless( /^\/(\d+)(.)?$/i === slashMark )

  rate = $1.to_i
  mark = $2

  return dice if( rate == 0 )

  value = (1.0 * dice / rate)

  case mark
  when "U"
    dice = value.ceil
  when "R"
    dice = value.round
  else
    dice = value.floor
  end

  return dice
end