Skip to content

Commit

Permalink
Merge pull request #196 from bcdice/sw20-fix-hk
Browse files Browse the repository at this point in the history
ソード・ワールド2.0/2.5: 威力表の半減(HK)を実行できるようにする
  • Loading branch information
ysakasin authored May 17, 2020
2 parents 9f1cb99 + 8cdfec1 commit 9980254
Show file tree
Hide file tree
Showing 5 changed files with 111 additions and 28 deletions.
27 changes: 17 additions & 10 deletions src/diceBot/SwordWorld.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

class SwordWorld < DiceBot
include ModifierFormatter

# ゲームシステムの識別子
ID = 'SwordWorld'

Expand All @@ -25,17 +26,23 @@ def initialize
@rating_table = rating_table
end

def changeText(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)}]" }
string = string.gsub(/\@(\d+)/i) { "c[#{Regexp.last_match(1)}]" }
string = string.gsub(/\$([\+\-]?[\d]+)/i) { "m[#{Regexp.last_match(1)}]" }
string = string.gsub(/r([\+\-]?[\d]+)/i) { "r[#{Regexp.last_match(1)}]" }
debug('parren_killer_add after string', string)
# changeTextで使うレーティング表コマンドの正規表現
#
# SW 2.5のダイスボットでも必要なため、共通化のために定数として定義する
RATING_TABLE_RE_FOR_CHANGE_TEXT = /\AS?H?K\d+/i.freeze

return string
# コマンド実行前にメッセージを置換する
# @param [String] string 受信したメッセージ
# @return [String]
def changeText(string)
# TODO: Ruby 2.4以降では Regexp#match? を使うこと
return string unless RATING_TABLE_RE_FOR_CHANGE_TEXT.match(string)

string.
gsub(/\[(\d+)\]/) { "c[#{Regexp.last_match(1)}]" }.
gsub(/@(\d+)/) { "c[#{Regexp.last_match(1)}]" }.
gsub(/\$([-+]?\d+)/) { "m[#{Regexp.last_match(1)}]" }.
gsub(/r([-+]?\d+)/i) { "r[#{Regexp.last_match(1)}]" }
end

def getRatingCommandStrings
Expand Down
2 changes: 1 addition & 1 deletion src/diceBot/SwordWorld2_0.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class SwordWorld2_0 < SwordWorld
 絡み効果表を出すことができます。
INFO_MESSAGE_TEXT

setPrefixes(['K\d+.*', 'Gr(\d+)?', 'FT', 'TT'])
setPrefixes(['H?K\d+.*', 'Gr(\d+)?', 'FT', 'TT'])

def initialize
rating_table = 2
Expand Down
26 changes: 9 additions & 17 deletions src/diceBot/SwordWorld2_5.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,27 +67,19 @@ class SwordWorld2_5 < SwordWorld2_0
 絡み効果表を出すことができます。
INFO_MESSAGE_TEXT

setPrefixes(['K\d+.*', 'Gr(\d+)?', 'FT', 'TT'])
setPrefixes(['H?K\d+.*', 'Gr(\d+)?', 'FT', 'TT'])

# コマンド実行前にメッセージを置換する
# @param [String] string 受信したメッセージ
# @return [String]
def changeText(string)
return string unless /(^|\s)[sS]?(K[\d]+)/i =~ string
# TODO: Ruby 2.4以降では Regexp#match? を使うこと
return string unless RATING_TABLE_RE_FOR_CHANGE_TEXT.match(string)

string = super(string)

debug('parren_killer_add before string', string)

string = string.gsub(/#([\+\-]?[\d]+)/i) do
value = Regexp.last_match(1).to_i
if value >= 0
"a[+#{value}]"
else
"a[#{value}]"
end
super(string).gsub(/#([-+]?\d+)/) do
modifier = Regexp.last_match(1).to_i
"a[#{format_modifier(modifier)}]"
end

debug('parren_killer_add after string', string)

return string
end

def getRatingCommandStrings
Expand Down
42 changes: 42 additions & 0 deletions src/test/data/SwordWorld2_0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,48 @@ SwordWorld2.0 : KeyNo.20c[10]+5 > 2D:[5,2]=7 > 5+5 > 10###secret dice###
rand:5/6,2/6
============================
input:
hk10 HKのクリティカル値は13
output:
SwordWorld2.0 : KeyNo.10 > 2D:[6,6]=12 > 7/2 > 4
rand:6/6,6/6
============================
input:
k10h
output:
SwordWorld2.0 : KeyNo.10 > 2D:[6,6]=12 > 7/2 > 4
rand:6/6,6/6
============================
input:
hk10h
output:
SwordWorld2.0 : KeyNo.10 > 2D:[6,6]=12 > 7/2 > 4
rand:6/6,6/6
============================
input:
hk10[9]+10
output:
SwordWorld2.0 : KeyNo.10c[9]+10 > 2D:[5,3]=8 > (4+10)/2 > 7
rand:5/6,3/6
============================
input:
hk10[9]+10 切り上げ
output:
SwordWorld2.0 : KeyNo.10c[9]+10 > 2D:[2,4]=6 > (3+10)/2 > 7
rand:2/6,4/6
============================
input:
HK20+6@4
output:
SwordWorld2.0 : 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:
SwordWorld2.0 : 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:
2D6@10+15>=30
output:
SwordWorld2.0 : (2D6@10+15>=30) > 9[6,3]+15 > 24 > 失敗
Expand Down
42 changes: 42 additions & 0 deletions src/test/data/SwordWorld2_5.txt
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,48 @@ SwordWorld2.5 : KeyNo.10c[9]a[+2]-5 > 2D:[5,4 2,2]=11,6 > 6,3-5 > 1回転
rand:5/6,4/6,2/6,2/6
============================
input:
hk10 HKのクリティカル値は13
output:
SwordWorld2.5 : KeyNo.10 > 2D:[6,6]=12 > 7/2 > 4
rand:6/6,6/6
============================
input:
k10h
output:
SwordWorld2.5 : KeyNo.10 > 2D:[6,6]=12 > 7/2 > 4
rand:6/6,6/6
============================
input:
hk10h
output:
SwordWorld2.5 : KeyNo.10 > 2D:[6,6]=12 > 7/2 > 4
rand:6/6,6/6
============================
input:
hk10[9]+10
output:
SwordWorld2.5 : KeyNo.10c[9]+10 > 2D:[5,3]=8 > (4+10)/2 > 7
rand:5/6,3/6
============================
input:
hk10[9]+10 切り上げ
output:
SwordWorld2.5 : KeyNo.10c[9]+10 > 2D:[2,4]=6 > (3+10)/2 > 7
rand:2/6,4/6
============================
input:
HK20+6@4
output:
SwordWorld2.5 : 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:
SwordWorld2.5 : 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:
2D6@10+15>=30
output:
SwordWorld2.5 : (2D6@10+15>=30) > 9[6,3]+15 > 24 > 失敗
Expand Down

0 comments on commit 9980254

Please sign in to comment.