Skip to content

Commit 9e53076

Browse files
authored
Merge pull request #838 from bcdice/refactor/Alsetto
[Alsetto] リファクタリング
2 parents 58077cf + bcc5f37 commit 9e53076

File tree

2 files changed

+61
-53
lines changed

2 files changed

+61
-53
lines changed

.rubocop_todo.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,6 @@ Naming/MethodName:
9191
Exclude:
9292
- 'lib/bcdice/base.rb'
9393
- 'lib/bcdice/deprecated/*.rb'
94-
- 'lib/bcdice/game_system/Alsetto.rb'
9594
- 'lib/bcdice/game_system/AlterRaise.rb'
9695
- 'lib/bcdice/game_system/Avandner.rb'
9796
- 'lib/bcdice/game_system/BadLife.rb'
@@ -171,7 +170,6 @@ Naming/MethodParameterName:
171170
MinNameLength: 1
172171
Exclude:
173172
- 'lib/bcdice/base.rb'
174-
- 'lib/bcdice/game_system/Alsetto.rb'
175173
- 'lib/bcdice/game_system/Avandner.rb'
176174
- 'lib/bcdice/game_system/BadLife.rb'
177175
- 'lib/bcdice/game_system/BarnaKronika.rb'
@@ -212,7 +210,6 @@ Naming/MethodParameterName:
212210
Naming/VariableName:
213211
Exclude:
214212
- 'lib/bcdice/base.rb'
215-
- 'lib/bcdice/game_system/Alsetto.rb'
216213
- 'lib/bcdice/game_system/AlterRaise.rb'
217214
- 'lib/bcdice/game_system/Avandner.rb'
218215
- 'lib/bcdice/game_system/BadLife.rb'

lib/bcdice/game_system/Alsetto.rb

Lines changed: 61 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -45,76 +45,87 @@ def initialize(command)
4545
end
4646

4747
def eval_game_system_specific_command(command)
48-
# ALCコマンド:命中判定
49-
# ALCコマンド:成功判定
50-
if command =~ /(\d+)AL(C|G)?(\d+)?((x|\*)(\d+))?$/i
51-
rapid = Regexp.last_match(1).to_i
52-
isCritical = Regexp.last_match(2).nil?
53-
if isCritical
54-
criticalNumber = 1
55-
else
56-
if Regexp.last_match(2) == "G"
57-
isCritical = true
58-
criticalNumber = 2
59-
else
60-
criticalNumber = 0
61-
end
62-
end
63-
target = (Regexp.last_match(3) || 3).to_i
64-
damage = (Regexp.last_match(6) || 0).to_i
65-
return checkRoll(rapid, target, damage, isCritical, criticalNumber)
48+
check_roll(command)
49+
end
50+
51+
private
52+
53+
def parce_check_roll(command)
54+
m = /(\d+)AL(C|G)?(\d+)?((x|\*)(\d+))?$/i.match(command)
55+
unless m
56+
return nil
6657
end
6758

68-
return nil
59+
rapid = m[1].to_i
60+
enable_critical = m[2].nil? || m[2] == "G"
61+
critical_number =
62+
case m[2]
63+
when "G"
64+
2
65+
when "C"
66+
0
67+
else
68+
1
69+
end
70+
target = m[3]&.to_i || 3
71+
damage = m[6].to_i
72+
73+
return {
74+
rapid: rapid,
75+
enable_critical: enable_critical,
76+
critical_number: critical_number,
77+
target: target,
78+
damage: damage,
79+
}
6980
end
7081

71-
def checkRoll(rapid, target, damage, isCritical, criticalNumber)
72-
totalSuccessCount = 0
73-
totalCriticalCount = 0
74-
text = ""
75-
76-
rollCount = rapid
82+
def check_roll(command)
83+
parsed = parce_check_roll(command)
84+
unless parsed
85+
return nil
86+
end
7787

78-
while rollCount > 0
79-
diceArray = @randomizer.roll_barabara(rollCount, 6).sort
80-
diceText = diceArray.join(",")
88+
rapid = parsed[:rapid]
89+
enable_critical = parsed[:enable_critical]
90+
critical_number = parsed[:critical_number]
91+
target = parsed[:target]
92+
damage = parsed[:damage]
8193

82-
successCount = 0
83-
criticalCount = 0
94+
total_success_count = 0
95+
total_critical_count = 0
96+
text = ""
8497

85-
diceArray.each do |i|
86-
if i <= target
87-
successCount += 1
88-
end
98+
roll_count = rapid
8999

90-
if i <= criticalNumber
91-
criticalCount += 1
92-
end
93-
end
100+
while roll_count > 0
101+
dice_array = @randomizer.roll_barabara(roll_count, 6).sort
102+
dice_text = dice_array.join(",")
94103

95-
totalSuccessCount += successCount
96-
totalCriticalCount += 1 unless criticalCount == 0
104+
success_count = dice_array.count { |v| v <= target }
105+
critical_count = dice_array.count { |v| v <= critical_number }
106+
total_success_count += success_count
107+
total_critical_count += 1 if critical_count > 0
97108

98109
text += "+" unless text.empty?
99-
text += "#{successCount}[#{diceText}]"
110+
text += "#{success_count}[#{dice_text}]"
100111

101-
break unless isCritical
112+
break unless enable_critical
102113

103-
rollCount = criticalCount
114+
roll_count = critical_count
104115
end
105116

106-
isDamage = (damage != 0)
117+
is_damage = (damage != 0)
107118

108-
if isDamage
109-
totalDamage = totalSuccessCount * damage
119+
if is_damage
120+
total_damage = total_success_count * damage
110121

111-
result = "(#{rapid}D6\<\=#{target}) > #{text} > Hits:#{totalSuccessCount}*#{damage}#{totalDamage}ダメージ"
122+
result = "(#{rapid}D6\<\=#{target}) > #{text} > Hits:#{total_success_count}*#{damage}#{total_damage}ダメージ"
112123
else
113-
result = "(#{rapid}D6\<\=#{target}) > #{text} > 成功数:#{totalSuccessCount}"
124+
result = "(#{rapid}D6\<\=#{target}) > #{text} > 成功数:#{total_success_count}"
114125
end
115126

116-
if isCritical
117-
result += " / #{totalCriticalCount}トライアンフ"
127+
if enable_critical
128+
result += " / #{total_critical_count}トライアンフ"
118129
end
119130

120131
return result

0 commit comments

Comments
 (0)