Skip to content

Commit

Permalink
Merge pull request #424 from h-mikisato/feature/sword_world_result
Browse files Browse the repository at this point in the history
[SwordWorld/SwordWorld2.0/SwordWorld2.5] Result対応
  • Loading branch information
ysakasin authored Apr 21, 2021
2 parents 2df3312 + 92b14f0 commit 738b1b3
Show file tree
Hide file tree
Showing 5 changed files with 200 additions and 13 deletions.
19 changes: 14 additions & 5 deletions lib/bcdice/game_system/SwordWorld.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# frozen_string_literal: true

require "bcdice/base"
require "bcdice/game_system/sword_world/rating_parser"

module BCDice
Expand Down Expand Up @@ -125,10 +126,17 @@ def rating(string) # レーティング表
break unless dice >= command.critical
end

output += getResultText(totalValue, command, diceResults, diceResultTotals,
rateResults, diceOnlyTotal, round)
result_text, critical, fumble = getResultText(
totalValue, command, diceResults, diceResultTotals,
rateResults, diceOnlyTotal, round
)
output += result_text

return output
return Result.new.tap do |r|
r.text = output
r.critical = critical
r.fumble = fumble
end
end

def getSW2_0_RatingTable
Expand Down Expand Up @@ -301,6 +309,7 @@ def rollDice(_command)
# @param rateResults [Array<String>]
# @param dice_total [Integer]
# @param round [Integer]
# @return [Array(String, Boolean, Boolean)] output, critical, fumble
def getResultText(rating_total, command, diceResults, diceResultTotals,
rateResults, dice_total, round)
sequence = []
Expand All @@ -310,7 +319,7 @@ def getResultText(rating_total, command, diceResults, diceResultTotals,
if dice_total <= 2
sequence.push(rateResults.join(','))
sequence.push("自動的失敗")
return sequence.join(" > ")
return sequence.join(" > "), false, true
end

# rate回数が1回で、修正値がない時には途中式と最終結果が一致するので、途中式を省略する
Expand Down Expand Up @@ -347,7 +356,7 @@ def getResultText(rating_total, command, diceResults, diceResultTotals,
total_text = total.to_s
sequence.push(total_text)

return sequence.join(" > ")
return sequence.join(" > "), round > 1, false
end
end
end
Expand Down
34 changes: 26 additions & 8 deletions lib/bcdice/game_system/sword_world/transcendent_test.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
require "bcdice/result"

module BCDice
module GameSystem
class SwordWorld2_0 < SwordWorld
# 超越判定のノード
class TranscendentTest
RESULT_STR = {
success: "成功",
failure: "失敗",
super_success: "超成功",
critical: "自動的成功",
fumble: "自動的失敗",
}.freeze

# @param [Integer] critical_value クリティカル値
# @param [Integer] modifier 修正値
# @param [String, nil] cmp_op 比較演算子(> または >=)
Expand Down Expand Up @@ -40,14 +50,21 @@ def execute(randomizer)
sum = sum_of_dice(value_groups)
total_sum = sum + @modifier

result = result_status(total_sum, value_groups.length, fumble, critical)
parts = [
"(#{@expression})",
"#{dice_str(value_groups, sum)}#{@modifier_str}",
total_sum,
@target && result_str(total_sum, value_groups.length, fumble, critical)
RESULT_STR[result],
].compact

return parts.join(" > ")
return Result.new.tap do |r|
r.text = parts.join(" > ")
r.fumble = result == :fumble
r.critical = result == :critical
r.success = [:success, :super_success, :critical].include?(result)
r.failure = [:failure, :fumble].include?(result)
end
end

private
Expand Down Expand Up @@ -86,16 +103,17 @@ def dice_str(value_groups, sum)
# @param [Integer] n_value_groups 出目のグループの数
# @param [Boolean] fumble ファンブルかどうか
# @param [Boolean] critical クリティカルかどうか
# @return [String]
def result_str(total_sum, n_value_groups, fumble, critical)
return "自動的失敗" if fumble
return "自動的成功" if critical
# @return [Symbol]
def result_status(total_sum, n_value_groups, fumble, critical)
return :no_target unless @target
return :fumble if fumble
return :critical if critical

if total_sum.send(@cmp_op, @target)
# 振り足しが行われ、合計値が41以上ならば「超成功」
n_value_groups >= 2 && total_sum >= 41 ? "超成功" : "成功"
n_value_groups >= 2 && total_sum >= 41 ? :super_success : :success
else
"失敗"
:failure
end
end
end
Expand Down
Loading

0 comments on commit 738b1b3

Please sign in to comment.