[Aionia]慈悲なきアイオニアのダイスボット改善#835
Conversation
ysakasin
left a comment
There was a problem hiding this comment.
寄稿ありがとうございます。気になるところが何点かあったので、修正をおねがいします。
| INFO_MESSAGE_TEXT | ||
|
|
||
| register_prefix('ABT?\d+([\+\-]\d+)?>=\d+(\/\d+)*') | ||
| register_prefix('ABT?\d+.*', 'DMG.*') |
There was a problem hiding this comment.
| register_prefix('ABT?\d+.*', 'DMG.*') | |
| register_prefix('ABT?', 'DMG') |
先頭一致のみ指定すれば良いので、 .*は不要です。
| if command.start_with?('DMG') | ||
| return roll_damage_check(command) | ||
| end | ||
|
|
||
| return roll_skills(command) |
There was a problem hiding this comment.
| if command.start_with?('DMG') | |
| return roll_damage_check(command) | |
| end | |
| return roll_skills(command) | |
| return roll_skills(command) || roll_damage_check(command) |
| targets = m[4].split('/').map(&:to_i) | ||
|
|
||
| # 値の計算 | ||
| bonus = Arithmetic.eval(m[3] == '' ? '0' : m[3], RoundType::FLOOR) |
There was a problem hiding this comment.
| bonus = Arithmetic.eval(m[3] == '' ? '0' : m[3], RoundType::FLOOR) | |
| bonus = m[3] != '' ? Arithmetic.eval(m[3], RoundType::FLOOR) : 0 |
文字列 '0' をパースしてもあまりうれしくないので、パース後の値をそのまま指定するようにした方がよさそうです。
| return nil unless bonus | ||
|
|
||
| base_targets = m[4].split('/').map(&:to_i) | ||
| target_bonus = Arithmetic.eval(m[5] == '' ? '0' : m[5], RoundType::FLOOR) |
There was a problem hiding this comment.
| target_bonus = Arithmetic.eval(m[5] == '' ? '0' : m[5], RoundType::FLOOR) | |
| target_bonus = m[5] != '' ? Arithmetic.eval(m[5], RoundType::FLOOR) : 0 |
| end | ||
|
|
||
| def roll_damage_check(command) | ||
| m = /^DMG>=(.+)$/.match(command) |
There was a problem hiding this comment.
このようなシンプルなコマンドであれば、 Command::Parser を使ってパースする方良さそうです。その方がよくある処理を書かずにすみます。
| end | ||
|
|
||
| def roll_damage_check(command) | ||
| parser = Command::Parser.new("DMG", round_type: BCDice::RoundType::FLOOR) |
There was a problem hiding this comment.
このままだと、比較の記号が指定されていないため、>= 意外の記号でもパースが通過されてしまいます。BCDice::Command::Parser#restrict_cmp_op_to を使って >= のみ受け付けるようにしてください。
例:
BCDice/lib/bcdice/game_system/Agnostos.rb
Line 45 in bbba2b5
There was a problem hiding this comment.
失礼いたしました。
以下のコミットで修正いたしました。合わせてテストも追加しております。
99e10c7
|
ありがとうございます。マージしました。 |
慈悲なきアイオニアのダイスボットを改善しました。
変更内容
備考
以下のコマンドのpassを確認しています。
bundle exec rubocop -a
bundle exec rake test