Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SwordWorld] レーティング表の半減 #151

Merged
merged 5 commits into from
Apr 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
103 changes: 59 additions & 44 deletions src/diceBot/SwordWorld.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
# -*- coding: utf-8 -*-
# frozen_string_literal: true

require "utils/modifier_formatter"

class SwordWorld < DiceBot
include ModifierFormatter
# ゲームシステムの識別子
ID = 'SwordWorld'

Expand All @@ -14,7 +17,7 @@ class SwordWorld < DiceBot
# ダイスボットの使い方
HELP_MESSAGE = "・SW レーティング表 (Kx[c]+m$f) (x:キー, c:クリティカル値, m:ボーナス, f:出目修正)\n"

setPrefixes(['K\d+.*'])
setPrefixes(['H?K\d+.*'])

def initialize
rating_table = 0
Expand All @@ -23,7 +26,7 @@ def initialize
end

def changeText(string)
return string unless /(^|\s)[sS]?(K[\d]+)/i =~ string
return string unless /^S?(H?K[\d]+)/i =~ string

debug('parren_killer_add before string', string)
string = string.gsub(/\[(\d+)\]/i) { "c[#{Regexp.last_match(1)}]" }
Expand Down Expand Up @@ -57,21 +60,25 @@ def rollDiceCommand(command)
rating(command)
end

private

#################### SWレーティング表 ########################
def rating(string) # レーティング表
debug("rating string", string)

commands = getRatingCommandStrings

unless /(^|\s)[sS]?(((k|K)[\d\+\-]+)([#{commands}]\[([\d\+\-]+)\])*([\d\+\-]*)([cmrCMR]\[([\d\+\-]+)\]|gf|GF)*)($|\s)/ =~ string
m = /^S?(H?K[\d\+\-]+([#{commands}]\[([\d\+\-]+)\])*([\d\+\-]*)([CMR]\[([\d\+\-]+)\]|GF|H)*)/i.match(string)
unless m
debug("not matched")
return '1'
end

string = Regexp.last_match(2)
string = m[1]
half = string.include?("H")

rateUp, string = getRateUpFromString(string)
crit, string = getCriticalFromString(string)
crit, string = getCriticalFromString(string, half)
firstDiceChanteTo, firstDiceChangeModify, string = getDiceChangesFromString(string)

key, addValue = getKeyAndAddValueFromString(string)
Expand Down Expand Up @@ -163,7 +170,7 @@ def rating(string) # レーティング表

limitLength = $SEND_STR_MAX - output.length
output += getResultText(totalValue, addValue, diceResults, diceResultTotals,
rateResults, diceOnlyTotal, round, crit, limitLength)
rateResults, diceOnlyTotal, round, limitLength, half)

return output
end
Expand All @@ -177,8 +184,8 @@ def getAdditionalDiceValue(_dice, _values)
0
end

def getCriticalFromString(string)
crit = 10
def getCriticalFromString(string, half)
crit = half ? 13 : 10

regexp = /c\[(\d+)\]/i

Expand Down Expand Up @@ -393,52 +400,60 @@ def rollDice(_values)
return dice, diceText
end

def getResultText(totalValue, addValue, diceResults, diceResultTotals,
rateResults, diceOnlyTotal, round, _crit, limitLength)
output = ""

totalText = (totalValue + addValue).to_s

if sendMode > 1 # 表示モード2以上
output += "2D:[#{diceResults.join(' ')}]=#{diceResultTotals.join(',')}"
rateResultsText = rateResults.join(',')
output += " > #{rateResultsText}" unless rateResultsText == totalText
elsif sendMode > 0 # 表示モード1以上
output += "2D:#{diceResultTotals.join(',')}"
else # 表示モード0
output += totalValue.to_s
# @param rating_total [Integer]
# @param modifier [Integer]
# @param diceResults [Array<String>]
# @param diceResultTotals [Array<String>]
# @param rateResults [Array<String>]
# @param dice_total [Integer]
# @param round [Integer]
# @param limitLength [Integer]
# @param half [Boolean]
def getResultText(rating_total, modifier, diceResults, diceResultTotals,
rateResults, dice_total, round, limitLength, half)
sequence = []
short = ["..."]

sequence.push("2D:[#{diceResults.join(' ')}]=#{diceResultTotals.join(',')}")

if dice_total <= 2
sequence.push(rateResults.join(','))
sequence.push("自動的失敗")
return sequence.join(" > ")
end

if diceOnlyTotal <= 2
return "#{output} > 自動的失敗"
# rate回数が1回で、修正値がない時には途中式と最終結果が一致するので、途中式を省略する
if rateResults.size > 1 || modifier != 0
text = rateResults.join(',') + format_modifier(modifier)
if half
text = "(#{text})/2"
end
sequence.push(text)
elsif half
sequence.push("#{rateResults.first}/2")
end

addText = getAddText(addValue)
output += "#{addText} > "

roundText = ""
if round > 1
roundText += "#{round - 1}回転 > "
round_text = "#{round - 1}回転"
sequence.push(round_text)
short.push(round_text)
end

output += "#{roundText}#{totalText}"

if output.length > limitLength # 回りすぎて文字列オーバーしたときの救済
output = "... > #{roundText}#{totalText}"
total = rating_total + modifier
if half
total = (total / 2.0).ceil
end

return output
end

def getAddText(addValue)
addText = ""

return addText if addValue == 0
total_text = total.to_s
sequence.push(total_text)
short.push(total_text)

operator = (addValue > 0 ? "+" : "")
addText += "#{operator}#{addValue}"

return addText
ret = sequence.join(" > ")
if ret.length > limitLength
short.join(" > ")
else
ret
end
end

def setRatingTable(tnick)
Expand Down
5 changes: 5 additions & 0 deletions src/diceBot/SwordWorld2_0.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ class SwordWorld2_0 < SwordWorld
 またタイプの軽減化のために末尾に「@クリティカル値」でも処理するようにしました。
 例)K20[10]   K10+5[9]   k30[10]   k10[9]+10   k10-5@9

・レーティング表の半減 (HKx)
 レーティング表の先頭または末尾に"H"をつけると、レーティング表を振って最終結果を半減させます。
 クリティカル値を指定しない場合、クリティカルなしと扱われます。
 例)HK20  K20h  HK10-5@9  K10-5@9H  K20gfH

・ダイス目の修正(運命変転やクリティカルレイ用)
 末尾に「$修正値」でダイス目に修正がかかります。
 $+1と修正表記ならダイス目に+修正、$9のように固定値ならダイス目をその出目に差し替え。
Expand Down
5 changes: 5 additions & 0 deletions src/diceBot/SwordWorld2_5.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ class SwordWorld2_5 < SwordWorld2_0
 またタイプの軽減化のために末尾に「@クリティカル値」でも処理するようにしました。
 例)K20[10]   K10+5[9]   k30[10]   k10[9]+10   k10-5@9

・レーティング表の半減 (HKx)
 レーティング表の先頭または末尾に"H"をつけると、レーティング表を振って最終結果を半減させます。
 クリティカル値を指定しない場合、クリティカルなしと扱われます。
 例)HK20  K20h  HK10-5@9  K10-5@9H  K20gfH

・ダイス目の修正(運命変転やクリティカルレイ用)
 末尾に「$修正値」でダイス目に修正がかかります。
 $+1と修正表記ならダイス目に+修正、$9のように固定値ならダイス目をその出目に差し替え。
Expand Down
42 changes: 42 additions & 0 deletions src/test/data/SwordWorld.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1437,3 +1437,45 @@ K9@3-1$12
output:
SwordWorld : KeyNo.9c[3]m[12]-1 > 2D:[5,1 6,6 5,6 3,3 3,6 6,1 5,1 5,2 5,6 3,4 2,5 1,2 6,5 1,1]=12,12,11,6,9,7,6,7,11,7,7,3,11,2 > 7,7,6,3,4,3,3,3,6,3,3,0,6,**-1 > 13回転 > 53
rand:5/6,1/6,6/6,6/6,5/6,6/6,3/6,3/6,3/6,6/6,6/6,1/6,5/6,1/6,5/6,2/6,5/6,6/6,3/6,4/6,2/6,5/6,1/6,2/6,6/6,5/6,1/6,1/6
============================
input:
hk10 HKのクリティカル値は13
output:
SwordWorld : KeyNo.10 > 2D:[6,6]=12 > 7/2 > 4
rand:6/6,6/6
============================
input:
k10h
output:
SwordWorld : KeyNo.10 > 2D:[6,6]=12 > 7/2 > 4
rand:6/6,6/6
============================
input:
hk10h
output:
SwordWorld : KeyNo.10 > 2D:[6,6]=12 > 7/2 > 4
rand:6/6,6/6
============================
input:
hk10[9]+10
output:
SwordWorld : KeyNo.10c[9]+10 > 2D:[5,3]=8 > (4+10)/2 > 7
rand:5/6,3/6
============================
input:
hk10[9]+10 切り上げ
output:
SwordWorld : KeyNo.10c[9]+10 > 2D:[2,4]=6 > (3+10)/2 > 7
rand:2/6,4/6
============================
input:
HK20+6@4
output:
SwordWorld : KeyNo.20c[4]+6 > 2D:[4,3 2,5 2,6 1,1]=7,7,8,2 > (5,5,6,**+6)/2 > 3回転 > 11
rand:4/6,3/6,2/6,5/6,2/6,6/6,1/6,1/6
============================
input:
K20+6@4h
output:
SwordWorld : KeyNo.20c[4]+6 > 2D:[4,3 2,5 2,6 1,1]=7,7,8,2 > (5,5,6,**+6)/2 > 3回転 > 11
rand:4/6,3/6,2/6,5/6,2/6,6/6,1/6,1/6
12 changes: 12 additions & 0 deletions src/test/data/SwordWorld2_0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,18 @@ SwordWorld2.0 : KeyNo.10c[10]gf > 2D:[5,5 2,2]=10,4 > 5,1 > 1回転 > 6
rand:5/6,2/6
============================
input:
K10gfh
output:
SwordWorld2.0 : KeyNo.10gf > 2D:[5,5]=10 > 5/2 > 3
rand:5/6
============================
input:
K10hgf
output:
SwordWorld2.0 : KeyNo.10gf > 2D:[5,5]=10 > 5/2 > 3
rand:5/6
============================
input:
K40+24@8$12r10gf
output:
SwordWorld2.0 : KeyNo.40c[8]m[12]r[10]gf+24 > 2D:[4,4 4,4 4,4 4,4 4,4 4,4 3,3]=12,8,8,8,8,8,6 > 13,12,13,16,18,19,18+24 > 6回転 > 133
Expand Down