Skip to content

Commit

Permalink
Merge 222a846 into de79755
Browse files Browse the repository at this point in the history
  • Loading branch information
koi-chan committed Sep 24, 2019
2 parents de79755 + 222a846 commit 34814c3
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
3 changes: 3 additions & 0 deletions config/dice_roll.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@
DiceRoll:
# 日本語ダイス機能を有効化するか
JaDice: false
# 多すぎるダイスロールをした時、机ではなく荷台からダイスが落ちる確率
# 1 - 1000 で指定してください。初期値は 100 、0 を指定すると無効化します
FallOffTrack: 100
3 changes: 3 additions & 0 deletions doc/plugins/dice_roll.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,9 @@ DiceRoll:
# 日本語ダイス機能を有効化するか
# false (無効)以外の文字を入力すると true (有効)として扱う
JaDice: false
# 多すぎるダイスロールをした時、机ではなく荷台からダイスが落ちる確率
# 1 - 1000 で指定してください。初期値は 100 、0 を指定すると無効化します
FallOffTrack: 100
```

ToDo
Expand Down
18 changes: 16 additions & 2 deletions lib/rgrb/plugin/dice_roll/generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class Generator
# ダイス数が多すぎた場合のメッセージ
# @return [String]
EXCESS_DICE_MESSAGE = "ダイスが机から落ちてしまいましたの☆"
EXCESS_TRACK_DICE_MESSAGE = "ダイスが荷台から落ちてしまいましたの☆"

# ジェネレータを初期化する
def initialize
Expand All @@ -38,6 +39,8 @@ def configure(config_data)
prepare_db_dir

@db_secret_dice = "#{@db_dir}/secret_dice"

@fall_off_track = config_data['FallOffTrack'].to_i || 100
end

# 基本的なダイスロールの結果を返す
Expand All @@ -46,7 +49,7 @@ def configure(config_data)
# @return [String]
def basic_dice(rolls, sides)
if rolls > 100
"#{rolls}d#{sides}: #{EXCESS_DICE_MESSAGE}"
"#{rolls}d#{sides}: #{excess_message}"
else
dice_roll(rolls, sides).dice_roll_format
end
Expand All @@ -62,7 +65,7 @@ def basic_dice_ja(rolls_ja, sides_ja)
# @return [String]
def dxx_dice(rolls)
if rolls.size > 20
"d#{rolls}: #{EXCESS_DICE_MESSAGE}"
"d#{rolls}: #{excess_message}"
else
values = dxx_roll(rolls)
"d#{rolls} = [#{values.join(',')}] = #{values.join('')}"
Expand All @@ -88,6 +91,7 @@ def save_secret_roll(target, message)
end
end

# シークレットダイスの結果をまとめて公開し、削除する
# @param [String] target
# @return [Array, nil]
def open_dice(target)
Expand Down Expand Up @@ -141,6 +145,16 @@ def prepare_db_dir
end
end
end

# 振るダイスの量が多すぎるときのエラーメッセージを返す
# @return [String]
def excess_message
if (1..1000) === @fall_off_track && @random.rand(0..1000) % @fall_off_track == 0
EXCESS_TRACK_DICE_MESSAGE
else
EXCESS_DICE_MESSAGE
end
end
end
end
end
Expand Down

0 comments on commit 34814c3

Please sign in to comment.