Skip to content

Commit

Permalink
Merge branch 'master' into add_dice-dice_roll_with_filter
Browse files Browse the repository at this point in the history
  • Loading branch information
ochaochaocha3 committed May 5, 2020
2 parents c6d3a57 + 57a0cef commit 6686478
Show file tree
Hide file tree
Showing 9 changed files with 80 additions and 20 deletions.
5 changes: 5 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ indent_style = space
indent_size = 2
trim_trailing_whitespace = true

[Rakefile]
indent_style = space
indent_size = 2
trim_trailing_whitespace = true

[*.yml]
indent_style = space
indent_size = 2
Expand Down
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
# ChangeLog

### Unreleased
### Ver2.05.00 2020/05/04
- ダンジョンズ&ドラゴンズのIDを修正 (#143)
- モノトーンミュージアムのIDを修正、くりちかりちさんありがとうっ! (#144)
- 「新クトゥルフ」のフルオート射撃判定のバグを修正。404 not friendさん報告、ニャル提督さん修正ありがとうっ! (#148)
- 「コード:レイヤード」で達成値修正とクリティカル値変更に対応。くずもちさんありがとうっ! (#149)
- 「SwordWorld/2.0/2.5」 レーティング表で半減ができるように。銀色のかぼちゃさん提案ありがとうっ! (#151)
- ダイスボットに「迷宮キングダム 基本ルールブック」を追加。TakaYamsさんありがとうっ! (#152)
- ダイスボットに「イヤーゼロエンジン」を追加。フレッド緑野さんありがとうっ! (#161)
- ダイスボットに「TORG Eternity」を追加。ほえほえさんありがとうっ! (#164)
- ダイスボットに「BBNTRPG」を追加。neuzさん、エレリーナさんありがとうっ! (#166)
- 「クトゥルフテック」の対抗判定成功時の表記を修正 (#165)
- 「アルスマギカ」の表示形式の問題を修正 (#160)
Expand Down
40 changes: 40 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,46 @@ task :clean_coverage do
end
end

desc 'Release BCDice'
task :release, ['version'] do |_, args|
version = args.version
version_with_prefix = "Ver#{version}"
version_tag = "v#{version}"
date = Time.now.strftime("%Y/%m/%d")

header = "#{version_with_prefix} #{date}"
md_header = "### #{header}"

def replace(file, src, dst)
txt = File.read(file).sub(src, dst)
File.write(file, txt)
end

# Replace versions
replace('CHANGELOG.md', '### Unreleased', md_header)
replace('src/bcdiceCore.rb', /VERSION = ".+"/, "VERSION = \"#{version}\"")
replace('src/configBcDice.rb', /\$bcDiceVersion = ".+"/, "$bcDiceVersion = \"#{version}\"")
sh "git --no-pager diff"

# Test and lint
Rake::Task[:test].invoke

# Commit release
sh "git commit -a -v -e --message='Release #{version_with_prefix}'"

# Create tag
sections = File.read('CHANGELOG.md').split(/\n{2,}/)
section = sections.find { |s| s.start_with?(md_header) }
section_body = section.sub(md_header, '').strip
sh "git tag -a -e #{version_tag} -m '#{header}' -m '#{section_body}'"

puts "Do followings:"
puts " $ git checkout release; git merge master"
puts " $ git push origin release"
puts " $ git push origin master"
puts " $ git push origin #{version_tag}"
end

namespace :test do
Rake::TestTask.new(:dicebots) do |t|
t.description = 'ダイスボット'
Expand Down
2 changes: 1 addition & 1 deletion src/bcdiceCore.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ class BCDice
# 設定コマンドのパターン
SET_COMMAND_PATTERN = /\Aset\s+(.+)/i.freeze

VERSION = "2.04.00".freeze
VERSION = "2.05.00".freeze

attr_reader :cardTrader
attr_reader :rand_results, :detailed_rand_results
Expand Down
2 changes: 1 addition & 1 deletion src/configBcDice.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

$isDebug = false

$bcDiceVersion = "2.03.05"
$bcDiceVersion = "2.05.00"

$SEND_STR_MAX = 405; # 最大送信文字数(本来は500byte上限)
$isRollVoidDiceAtAnyRecive = true; # 発言の度に空ダイスを振るか?
Expand Down
12 changes: 10 additions & 2 deletions src/dice/add_dice/node.rb
Original file line number Diff line number Diff line change
Expand Up @@ -299,9 +299,17 @@ def initialize(times, sides, critical)
# @param [Randomizer] randomizer ランダマイザ
# @return [Integer] 評価結果(出目の合計値)
def eval(randomizer)
total, @text = randomizer.roll(@times, @sides, @critical)
dice_groups = randomizer.roll(@times, @sides, @critical)

total
# TODO: Ruby 2.4以降では Array#sum が使える
total = dice_groups.flatten.reduce(0, &:+)

dice_str = dice_groups.
map { |dice_list| "[#{dice_list.join(',')}]" }.
join
@text = "#{total}#{dice_str}"

return total
end

# 文字列に変換する
Expand Down
10 changes: 7 additions & 3 deletions src/dice/add_dice/parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ def initialize(expr)
@idx = 0
# 構文解析エラーが発生したかどうか
@error = false
# 式にダイスロールが含まれるか
@contain_dice_roll = false
end

# 構文解析を実行する
Expand All @@ -32,7 +34,7 @@ def parse()
@tokens = tokenize(lhs)
lhs = expr()

if @idx != @tokens.size
if @idx != @tokens.size || !@contain_dice_roll
@error = true
end

Expand Down Expand Up @@ -150,18 +152,20 @@ def unary
def term
num = expect_number()
if consume("D")
times = num
sides = expect_number()

filter = dice_roll_filter()
if filter
# ダイスロール後のフィルタリングあり
n_filtering = expect_number()
return Node::DiceRollWithFilter.new(num, sides, n_filtering, filter)
return Node::DiceRollWithFilter.new(times, sides, n_filtering, filter)
end

# 通常のダイスロール
critical = consume("@") ? expect_number() : nil
return Node::DiceRoll.new(num, sides, critical)
@contain_dice_roll = true
return Node::DiceRoll.new(times, sides, critical)
end

return num
Expand Down
16 changes: 4 additions & 12 deletions src/dice/add_dice/randomizer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,10 @@ def initialize(bcdice, dicebot, cmp_op)
# @param [Integer] times ダイス数
# @param [Integer] sides 面数
# @param [Integer] critical クリティカルヒットの閾値
# @return [(Integer, String)] 合計、および出目の文字列
# @return [Array<Array<Integer>>] 出目のグループの配列
def roll(times, sides, critical)
# 振り足し分も含めた出目の総計
total_sum = 0
# 振り足し分も含めた出目グループの配列
results_list = []
dice_groups = []

loop_count = 0
queue = [times]
Expand All @@ -35,20 +33,14 @@ def roll(times, sides, critical)
# TODO: Ruby 2.4以降では dice_list.sum とできる
sum = dice_list.reduce(0, &:+)

total_sum += sum
results_list.push(dice_list)
dice_groups.push(dice_list)

enqueue_reroll(dice_list, queue, times)
@dicebot.check2dCritical(critical, sum, queue, loop_count)
loop_count += 1
end

text = total_sum.to_s
results_list.each do |list|
text += '[' + list.join(',') + ']'
end

[total_sum, text]
return dice_groups
end

# ダイスを振る(振り足しなしの1回分)
Expand Down
10 changes: 10 additions & 0 deletions src/test/data/None.txt
Original file line number Diff line number Diff line change
Expand Up @@ -838,6 +838,16 @@ DiceBot : (1U6[3]) > 5[3,2] > 5/5(最大/合計)###secret dice###
rand:3/6,2/6
============================
input:
134 数値だけには反応しない
output:
rand:
============================
input:
1+2*3/4 数式だけには反応しない
output:
rand:
============================
input:
C(1+2)
output:
DiceBot : 計算結果 > 3
Expand Down

0 comments on commit 6686478

Please sign in to comment.