bcdice/BCDice

View on GitHub
lib/bcdice/game_system/Gundog.rb

Summary

Maintainability
A
3 hrs
Test Coverage
A
96%
# frozen_string_literal: true

module BCDice
  module GameSystem
    class Gundog < Base
      # ゲームシステムの識別子
      ID = 'Gundog'

      # ゲームシステム名
      NAME = 'ガンドッグ'

      # ゲームシステム名の読みがな
      SORT_KEY = 'かんとつく'

      # ダイスボットの使い方
      HELP_MESSAGE = <<~INFO_MESSAGE_TEXT
        失敗、成功、クリティカル、ファンブルとロールの達成値の自動判定を行います。
        nD9ロールも対応。
      INFO_MESSAGE_TEXT

      def initialize(command)
        super(command)
        @enabled_d9 = true
      end

      # ゲーム別成功度判定(1d100)
      def result_1d100(total, _dice_total, cmp_op, target)
        return nil unless cmp_op == :<=

        if total >= 100
          Result.fumble("ファンブル")
        elsif total <= 1
          Result.critical("絶対成功(達成値1+SL)")
        elsif target == "?"
          Result.nothing
        elsif total <= target
          dig10 = total / 10
          dig1 = total - dig10 * 10
          dig10 = 0 if dig10 >= 10
          dig1 = 0 if dig1 >= 10 # 条件的にはあり得ない(笑

          if dig1 <= 0
            Result.critical("クリティカル(達成値20+SL)")
          else
            Result.success("成功(達成値#{dig10 + dig1}+SL)")
          end
        else
          Result.failure("失敗")
        end
      end
    end
  end
end