Skip to content

Commit

Permalink
[SwordWorld2.5] レーティング表の結果を1.5倍にするオプション
Browse files Browse the repository at this point in the history
  • Loading branch information
ysakasin committed Nov 28, 2023
1 parent 6ca3489 commit 3c3b8c1
Show file tree
Hide file tree
Showing 6 changed files with 153 additions and 3 deletions.
16 changes: 16 additions & 0 deletions lib/bcdice/game_system/SwordWorld.rb
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,11 @@ def getResultText(rating_total, command, diceResults, diceResultTotals,
if command.modifier_after_half != 0
text += Format.modifier(command.modifier_after_half)
end
elsif command.one_and_a_half
text = "(#{text})*1.5"
if command.modifier_after_one_and_a_half != 0
text += Format.modifier(command.modifier_after_one_and_a_half)
end
end
sequence.push(text)
elsif command.half
Expand All @@ -342,6 +347,12 @@ def getResultText(rating_total, command, diceResults, diceResultTotals,
text += Format.modifier(command.modifier_after_half)
end
sequence.push(text)
elsif command.one_and_a_half
text = "#{rateResults.first}*1.5"
if command.modifier_after_one_and_a_half != 0
text += Format.modifier(command.modifier_after_one_and_a_half)
end
sequence.push(text)
end

if round > 1
Expand All @@ -355,6 +366,11 @@ def getResultText(rating_total, command, diceResults, diceResultTotals,
if command.modifier_after_half != 0
total += command.modifier_after_half
end
elsif command.one_and_a_half
total = (total * 1.5).ceil
if command.modifier_after_one_and_a_half != 0
total += command.modifier_after_one_and_a_half
end
end

total_text = total.to_s
Expand Down
9 changes: 8 additions & 1 deletion lib/bcdice/game_system/SwordWorld2_5.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@ class SwordWorld2_5 < SwordWorld2_0
 クリティカル値を指定しない場合、クリティカルなしと扱われます。
 例)HK20  K20h  HK10-5@9  K10-5@9H  K20gfH  K20+8H+2  K20+8H+(1+1)
・レーティング表の1.5倍 (OHKx, KxOH+N)
 レーティング表の先頭または末尾に"OH"をつけると、レーティング表を振って最終結果を1.5倍します。
 末尾につけた場合、直後に修正ををつけることで、1.5倍後の加減算を行うことができます。
 この際、複数の項による修正にはカッコで囲うことが必要です(カッコがないとパースに失敗します)
 クリティカル値を指定しない場合、クリティカルなしと扱われます。
 例)OHK20  K20oh  OHK10-5@9  K20+8OH+2  K20+8OH+(1+1)
・ダイス目の修正(運命変転やクリティカルレイ用)
 末尾に「$修正値」でダイス目に修正がかかります。
 $+1と修正表記ならダイス目に+修正、$9のように固定値ならダイス目をその出目に差し替え。
Expand Down Expand Up @@ -82,7 +89,7 @@ class SwordWorld2_5 < SwordWorld2_0
 アビスカース表を出すことができます。
INFO_MESSAGE_TEXT

register_prefix('H?K', 'Gr', '2D6?@\d+', 'FT', 'TT', 'Dru', 'ABT')
register_prefix('H?K', 'OHK', 'Gr', '2D6?@\d+', 'FT', 'TT', 'Dru', 'ABT')

def eval_game_system_specific_command(command)
case command
Expand Down
3 changes: 3 additions & 0 deletions lib/bcdice/game_system/sword_world/rating_options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ class RatingOptions
# @return [Integer, nil]
attr_accessor :modifier_after_half

# @return [Integer, nil]
attr_accessor :modifier_after_one_and_a_half

def settable_first_roll_adjust_option?
return first_modify.nil? && first_to.nil?
end
Expand Down
9 changes: 9 additions & 0 deletions lib/bcdice/game_system/sword_world/rating_parsed.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ class RatingParsed
# @return [Integer, nil]
attr_accessor :modifier_after_half

# @return [Integer, nil]
attr_accessor :modifier_after_one_and_a_half

def initialize(rate, modifier)
@rate = rate
@modifier = modifier
Expand All @@ -49,13 +52,19 @@ def initialize(rate, modifier)
@semi_fixed_val = 0
@tmp_fixed_val = 0
@modifier_after_half = nil
@modifier_after_one_and_a_half = nil
end

# @return [Boolean]
def half
return !@modifier_after_half.nil?
end

# @return [Boolean]
def one_and_a_half
return !@modifier_after_one_and_a_half.nil?
end

# @return [Integer]
def min_critical
if @semi_fixed_val <= 1
Expand Down
30 changes: 28 additions & 2 deletions lib/bcdice/game_system/sword_world/rating_parser.y
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class RatingParser
token NUMBER K R H G F S T PLUS MINUS ASTERISK SLASH PARENL PARENR BRACKETL BRACKETR AT SHARP DOLLAR
token NUMBER K R H O G F S T PLUS MINUS ASTERISK SLASH PARENL PARENR BRACKETL BRACKETR AT SHARP DOLLAR

expect 4

Expand All @@ -13,10 +13,19 @@ class RatingParser
| H rate option
{
_, rate, option = val
raise ParseError if option.modifier_after_one_and_a_half
option.modifier_after_half ||= Arithmetic::Node::Number.new(0)
modifier = option.modifier || Arithmetic::Node::Number.new(0)
result = parsed(rate, modifier.eval(@round_type), option)
}
| O H rate option
{
_, _, rate, option = val
raise ParseError if option.modifier_after_half
option.modifier_after_one_and_a_half ||= Arithmetic::Node::Number.new(0)
modifier = option.modifier || Arithmetic::Node::Number.new(0)
result = parsed(rate, modifier.eval(@round_type), option)
}


rate: K NUMBER
Expand Down Expand Up @@ -90,6 +99,22 @@ class RatingParser
option.modifier_after_half = term
result = option
}
| option O H
{
option, _ = val
raise ParseError if option.modifier_after_one_and_a_half

option.modifier_after_one_and_a_half = Arithmetic::Node::Number.new(0)
result = option
}
| option O H unary
{
option, _, term = val
raise ParseError if option.modifier_after_one_and_a_half

option.modifier_after_one_and_a_half = term
result = option
}
| option R unary
{
option, _, term = val
Expand Down Expand Up @@ -214,7 +239,8 @@ def parsed(rate, modifier, option)
p.semi_fixed_val = option.semi_fixed_val&.clamp(1, 6) || 0
p.tmp_fixed_val = option.tmp_fixed_val&.clamp(1, 6) || 0
p.modifier_after_half = option.modifier_after_half&.eval(@round_type)
p.critical = option.critical&.eval(@round_type)&.clamp(0, 13) || (p.half ? 13 : 10)
p.modifier_after_one_and_a_half = option.modifier_after_one_and_a_half&.eval(@round_type)
p.critical = option.critical&.eval(@round_type)&.clamp(0, 13) || (p.half || p.one_and_a_half ? 13 : 10)
end
end

Expand Down
89 changes: 89 additions & 0 deletions test/data/SwordWorld2_5.toml
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,95 @@ rands = [
{ sides = 6, value = 1 },
]

[[ test ]]
game_system = "SwordWorld2.5"
input = "OHk10 OHKのクリティカル値は13"
output = "KeyNo.10 > 2D:[6,6]=12 > 7*1.5 > 11"
rands = [
{ sides = 6, value = 6 },
{ sides = 6, value = 6 },
]

[[ test ]]
game_system = "SwordWorld2.5"
input = "k10oh"
output = "KeyNo.10 > 2D:[6,6]=12 > 7*1.5 > 11"
rands = [
{ sides = 6, value = 6 },
{ sides = 6, value = 6 },
]

[[ test ]]
game_system = "SwordWorld2.5"
input = "ohk10oh"
output = "KeyNo.10 > 2D:[6,6]=12 > 7*1.5 > 11"
rands = [
{ sides = 6, value = 6 },
{ sides = 6, value = 6 },
]

[[ test ]]
game_system = "SwordWorld2.5"
input = "ohk10[9]+10"
output = "KeyNo.10c[9]+10 > 2D:[5,3]=8 > (4+10)*1.5 > 21"
rands = [
{ sides = 6, value = 5 },
{ sides = 6, value = 3 },
]

[[ test ]]
game_system = "SwordWorld2.5"
input = "ohk10[9]+10 切り上げ"
output = "KeyNo.10c[9]+10 > 2D:[2,4]=6 > (3+10)*1.5 > 20"
rands = [
{ sides = 6, value = 2 },
{ sides = 6, value = 4 },
]

[[ test ]]
game_system = "SwordWorld2.5"
input = "OHK20+6@4"
output = "KeyNo.20c[4]+6 > 2D:[4,3 2,5 2,6 1,1]=7,7,8,2 > (5,5,6,**+6)*1.5 > 3回転 > 33"
critical = true
rands = [
{ sides = 6, value = 4 },
{ sides = 6, value = 3 },
{ sides = 6, value = 2 },
{ sides = 6, value = 5 },
{ sides = 6, value = 2 },
{ sides = 6, value = 6 },
{ sides = 6, value = 1 },
{ sides = 6, value = 1 },
]

[[ test ]]
game_system = "SwordWorld2.5"
input = "K20+6@4oh"
output = "KeyNo.20c[4]+6 > 2D:[4,3 2,5 2,6 1,1]=7,7,8,2 > (5,5,6,**+6)*1.5 > 3回転 > 33"
critical = true
rands = [
{ sides = 6, value = 4 },
{ sides = 6, value = 3 },
{ sides = 6, value = 2 },
{ sides = 6, value = 5 },
{ sides = 6, value = 2 },
{ sides = 6, value = 6 },
{ sides = 6, value = 1 },
{ sides = 6, value = 1 },
]

[[ test ]]
game_system = "SwordWorld2.5"
input = "hk10oh"
output = ""
rands = []

[[ test ]]
game_system = "SwordWorld2.5"
input = "ohk10h"
output = ""
rands = []

[[ test ]]
game_system = "SwordWorld2.5"
input = "k20sf4 sf通常時"
Expand Down

0 comments on commit 3c3b8c1

Please sign in to comment.