Skip to content

Commit

Permalink
WorldOfDarkness: fix. add STA for 20th Ed. (#137)
Browse files Browse the repository at this point in the history
* WorldOfDarkness: fix. add STA for 20th Ed.

* WorldOfDarkness: allow diff=2

* WorldOfDarkness: refactor

* WorldOfDarkness: refactor

* WorldOfDarkness: fix

* Remove unused block variable

Co-authored-by: SAKATA Sinji <[email protected]>
  • Loading branch information
opparco and ysakasin authored Mar 17, 2020
1 parent 9851ab3 commit 01170eb
Show file tree
Hide file tree
Showing 2 changed files with 215 additions and 89 deletions.
160 changes: 86 additions & 74 deletions src/diceBot/WorldOfDarkness.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,7 @@
# -*- coding: utf-8 -*-

class WorldOfDarkness < DiceBot
setPrefixes(['\d+st.*'])

def initialize
super
@successDice = 0
@botchDice = 0
@rerollDice = 0
end
setPrefixes(['\d+ST.*'])

def gameName
'ワールドオブダークネス'
Expand All @@ -20,95 +13,114 @@ def gameType

def getHelpMessage
return <<INFO_MESSAGE_TEXT
・判定コマンド(xSTn+y or xSTSn+y)
・判定コマンド(xSTn+y or xSTSn+y or xSTAn+y)
 (ダイス個数)ST(難易度)+(自動成功)
 (ダイス個数)STS(難易度)+(自動成功) ※出目10で振り足し
 (ダイス個数)STS(難易度)+(自動成功) ※出目10で振り足し
 (ダイス個数)STA(難易度)+(自動成功) ※出目10は2成功 [20thルール]
 難易度=省略時6
 自動成功=省略時0
 例)3ST7 5ST+1 4ST5+2
INFO_MESSAGE_TEXT
end

def rollDiceCommand(command)
result = rollWorldOfDarkness(command)
return result unless result.empty?
end

def rollWorldOfDarkness(string)
diceCount = 1
difficulty = 6
automaticSuccess = 0
dice_pool = 1
diff = 6
auto_success = 0

output = ''
rerollNumber = 11
enable_reroll = false
enable_20th = false

m = string.match(/(\d+)(STS?)(\d*)([^\d\s][\+\-\d]+)?/i)
diceCount = m[1].to_i
rerollNumber = 10 if m[2] == 'STS'
difficulty = m[3].to_i
automaticSuccess = m[4].to_i if m[4]
md = command.match(/\A(\d+)(ST[SA]?)(\d+)?([+-]\d+)?/)

difficulty = 6 if difficulty < 2

output = 'DicePool=' + diceCount.to_s + ', Difficulty=' + difficulty.to_s + ', AutomaticSuccess=' + automaticSuccess.to_s

@successDice = 0
@botchDice = 0
@rerollDice = 0

output += rollDiceWorldOfDarknessSpecial(diceCount, difficulty, rerollNumber)
while @rerollDice > 0
diceCount = @rerollDice
@rerollDice = 0
output += rollDiceWorldOfDarknessSpecial(diceCount, difficulty, rerollNumber)
dice_pool = md[1].to_i
case md[2]
when 'STS'
enable_reroll = true
when 'STA'
enable_20th = true
end
diff = md[3].to_i if md[3]
auto_success = md[4].to_i if md[4]

diff = 6 if diff < 2

sequence = []
sequence.push "DicePool=#{dice_pool}, Difficulty=#{diff}, AutomaticSuccess=#{auto_success}"

# 出力では Difficulty=11..12 もあり得る
diff = 10 if diff > 10

total_success = auto_success
total_botch = 0

dice, success, botch, auto_success = roll_wod(dice_pool, diff, true, enable_20th ? 2 : 1)
sequence.push dice.join(',')
total_success += success
total_botch += botch

if enable_reroll
# 振り足し
while auto_success > 0
dice_pool = auto_success
# 振り足しの出目1は大失敗ではない
dice, success, botch, auto_success = roll_wod(dice_pool, diff, false)
sequence.push dice.join(',')
total_success += success
total_botch += botch
end
end

@successDice += automaticSuccess
if @successDice > 0
output += " > 成功数" + @successDice.to_s
if total_success > 0
sequence.push "成功数#{total_success}"
elsif total_botch > 0
sequence.push "大失敗"
else
if @botchDice > 0
output += " > 大失敗"
else
output += " > 失敗"
end
sequence.push "失敗"
end

return output
output = sequence.join(' > ')
secret = false
return output, secret
end

def rollDiceWorldOfDarknessSpecial(diceCount, difficulty, rerollNumber)
diceType = 10
diceResults = Array.new(diceCount)

diceCount.times do |i|
dice_now, = roll(1, diceType)

case dice_now
when rerollNumber..12 then
@successDice += 1
@rerollDice += 1
when difficulty..11 then
@successDice += 1
when 1 then
@successDice -= 1
@botchDice += 1
end

diceResults[i] = dice_now
# Revised Edition
# 出目10は1自動成功 振り足し
# 出目1は大失敗: 成功を1つ相殺
def roll_wod(dice_pool, diff, enable_botch = true, auto_success_value = 1)
# FIXME: まとめて振る
dice = Array.new(dice_pool) do
dice_now, = roll(1, 10)
dice_now
end

diceResults.sort!
dice.sort!

result = " > "
diceResults.each do |diceResult|
result += diceResult.to_s + ','
success = 0
botch = 0
auto_success = 0

dice.each do |d|
case d
when 10
auto_success += auto_success_value
when diff..10
success += 1
when 1
botch += 1 if enable_botch
end
end

result = result.chop
# 自動成功を成功に加算する
success += auto_success

if enable_botch
# 成功と大失敗を相殺する
c = [ success, botch ].min
success -= c
botch -= c
end

return result
return dice, success, botch, auto_success
end
end
144 changes: 129 additions & 15 deletions src/test/data/WorldOfDarkness.txt
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ WorldOfDarkness : DicePool=1, Difficulty=7, AutomaticSuccess=0 > 7 > 成功
rand:7/10
============================
input:
10ST11
output:
WorldOfDarkness : DicePool=10, Difficulty=11, AutomaticSuccess=0 > 2,2,3,4,5,6,7,8,9,10 > 成功数1
rand:10/10,9/10,8/10,7/10,6/10,5/10,4/10,3/10,2/10,2/10
============================
input:
1ST7+1
output:
WorldOfDarkness : DicePool=1, Difficulty=7, AutomaticSuccess=1 > 6 > 成功数1
Expand All @@ -67,7 +73,13 @@ rand:1/10,5/10,6/10,7/10,10/10
input:
5ST
output:
WorldOfDarkness : DicePool=5, Difficulty=6, AutomaticSuccess=0 > 1,1,5,6,10 > 大失敗
WorldOfDarkness : DicePool=5, Difficulty=6, AutomaticSuccess=0 > 1,2,5,5,5 > 大失敗
rand:1/10,5/10,5/10,2/10,5/10
============================
input:
5ST
output:
WorldOfDarkness : DicePool=5, Difficulty=6, AutomaticSuccess=0 > 1,1,5,6,10 > 失敗
rand:1/10,5/10,6/10,1/10,10/10
============================
input:
Expand Down Expand Up @@ -137,6 +149,12 @@ WorldOfDarkness : DicePool=1, Difficulty=7, AutomaticSuccess=0 > 7 > 成功
rand:7/10
============================
input:
10STS11
output:
WorldOfDarkness : DicePool=10, Difficulty=11, AutomaticSuccess=0 > 2,2,3,4,5,6,7,8,9,10 > 2 > 成功数1
rand:10/10,9/10,8/10,7/10,6/10,5/10,4/10,3/10,2/10,2/10,2/10
============================
input:
1STS7+1
output:
WorldOfDarkness : DicePool=1, Difficulty=7, AutomaticSuccess=1 > 6 > 成功数1
Expand All @@ -163,7 +181,13 @@ rand:1/10,5/10,6/10,7/10,10/10,10/10,6/10
input:
5STS
output:
WorldOfDarkness : DicePool=5, Difficulty=6, AutomaticSuccess=0 > 1,1,5,6,10 > 10 > 1 > 大失敗
WorldOfDarkness : DicePool=5, Difficulty=6, AutomaticSuccess=0 > 1,5,6,7,10 > 10 > 1 > 成功数3
rand:1/10,5/10,6/10,7/10,10/10,10/10,1/10
============================
input:
5STS
output:
WorldOfDarkness : DicePool=5, Difficulty=6, AutomaticSuccess=0 > 1,1,5,6,10 > 10 > 1 > 成功数1
rand:1/10,5/10,6/10,1/10,10/10,10/10,1/10
============================
input:
Expand All @@ -181,7 +205,7 @@ rand:1/10,5/10,6/10,10/10,10/10,5/10,4/10
input:
5STS7+1
output:
WorldOfDarkness : DicePool=5, Difficulty=7, AutomaticSuccess=1 > 1,5,6,10,10 > 7,10 > 1 > 成功数3
WorldOfDarkness : DicePool=5, Difficulty=7, AutomaticSuccess=1 > 1,5,6,10,10 > 7,10 > 1 > 成功数4
rand:1/10,5/10,6/10,10/10,10/10,10/10,7/10,1/10
============================
input:
Expand All @@ -191,25 +215,115 @@ WorldOfDarkness : DicePool=5, Difficulty=6, AutomaticSuccess=1 > 2,5,6,7,9 >
rand:2/10,5/10,6/10,7/10,9/10
============================
input:
1D10+5
1STA テキスト
output:
WorldOfDarkness : DicePool=1, Difficulty=6, AutomaticSuccess=0 > 1 > 大失敗
rand:1/10
============================
input:
1STA
output:
WorldOfDarkness : DicePool=1, Difficulty=6, AutomaticSuccess=0 > 5 > 失敗
rand:5/10
============================
input:
1STA
output:
WorldOfDarkness : DicePool=1, Difficulty=6, AutomaticSuccess=0 > 6 > 成功数1
rand:6/10
============================
input:
1STA
output:
WorldOfDarkness : DicePool=1, Difficulty=6, AutomaticSuccess=0 > 10 > 成功数2
rand:10/10
============================
input:
1STA1
output:
WorldOfDarkness : DicePool=1, Difficulty=6, AutomaticSuccess=0 > 6 > 成功数1
rand:6/10
============================
input:
1STA7
output:
WorldOfDarkness : DicePool=1, Difficulty=7, AutomaticSuccess=0 > 6 > 失敗
rand:6/10
============================
input:
1STA7
output:
WorldOfDarkness : DicePool=1, Difficulty=7, AutomaticSuccess=0 > 7 > 成功数1
rand:7/10
============================
input:
10STA11
output:
WorldOfDarkness : DicePool=10, Difficulty=11, AutomaticSuccess=0 > 2,2,3,4,5,6,7,8,9,10 > 成功数2
rand:10/10,9/10,8/10,7/10,6/10,5/10,4/10,3/10,2/10,2/10
============================
input:
1STA7+1
output:
WorldOfDarkness : DicePool=1, Difficulty=7, AutomaticSuccess=1 > 6 > 成功数1
rand:6/10
============================
input:
1STA7+1
output:
WorldOfDarkness : DicePool=1, Difficulty=7, AutomaticSuccess=1 > 7 > 成功数2
rand:7/10
============================
input:
1STA+1
output:
WorldOfDarkness : DicePool=1, Difficulty=6, AutomaticSuccess=1 > 6 > 成功数2
rand:6/10
============================
input:
5STA
output:
WorldOfDarkness : (1D10+5) > 2[2]+57
rand:2/10
WorldOfDarkness : DicePool=5, Difficulty=6, AutomaticSuccess=0 > 1,5,6,7,10成功数3
rand:1/10,5/10,6/10,7/10,10/10
============================
input:
1D10-5 あああ
5STA
output:
WorldOfDarkness : (1D10-5) > 4[4]-5 > -1
rand:4/10
WorldOfDarkness : DicePool=5, Difficulty=6, AutomaticSuccess=0 > 1,1,5,6,10 > 成功数1
rand:1/10,5/10,6/10,1/10,10/10
============================
input:
5STA
output:
WorldOfDarkness : DicePool=5, Difficulty=6, AutomaticSuccess=0 > 2,3,4,5,5 > 失敗
rand:3/10,2/10,5/10,4/10,5/10
============================
input:
5STA7
output:
WorldOfDarkness : DicePool=5, Difficulty=7, AutomaticSuccess=0 > 1,5,6,10,10 > 成功数3
rand:1/10,5/10,6/10,10/10,10/10
============================
input:
5STA7+1
output:
WorldOfDarkness : DicePool=5, Difficulty=7, AutomaticSuccess=1 > 1,5,6,10,10 > 成功数4
rand:1/10,5/10,6/10,10/10,10/10
============================
input:
5STA+1
output:
WorldOfDarkness : DicePool=5, Difficulty=6, AutomaticSuccess=1 > 2,5,6,7,9 > 成功数4
rand:2/10,5/10,6/10,7/10,9/10
============================
input:
10D10
5STA
output:
WorldOfDarkness : (10D10) > 55[1,2,3,4,5,6,7,8,9,10]55
rand:1/10,2/10,3/10,4/10,5/10,6/10,7/10,8/10,9/10,10/10
WorldOfDarkness : DicePool=5, Difficulty=6, AutomaticSuccess=0 > 1,1,5,6,10成功数1
rand:1/10,5/10,6/10,10/10,1/10
============================
input:
10B10
5STA7
output:
WorldOfDarkness : (10B10) > 10,9,8,7,6,5,4,3,2,1
rand:10/10,9/10,8/10,7/10,6/10,5/10,4/10,3/10,2/10,1/10
WorldOfDarkness : DicePool=5, Difficulty=7, AutomaticSuccess=0 > 1,1,5,6,10 > 失敗
rand:1/10,5/10,6/10,10/10,1/10

0 comments on commit 01170eb

Please sign in to comment.