bcdice/BCDice

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

Summary

Maintainability
A
1 hr
Test Coverage
A
98%
# frozen_string_literal: true

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

      # ゲームシステム名
      NAME = 'ゲイシャ・ガール・ウィズ・カタナ'

      # ゲームシステム名の読みがな
      SORT_KEY = 'けいしやかあるういすかたな'

      # ダイスボットの使い方
      HELP_MESSAGE = <<~MESSAGETEXT
        ・判定 (GK#n)
          役やチョムバを含めて1回分のダイスロールを判定します。
         役は (通常判定)/(戦闘時) の順で両方出力されます。
          GK のみの場合5%の確率でチョムバます。
          GK#3 の様に #n をつけることによってチョムバの確率をn%にすることができます。
         例)GK GK#10
        ・隠しコマンド (GL)
          必ずチョムバします。GMが空気を読んでチョムバさせたいときや、
          GKコマンドを打ち間違えてチョムバするを想定してます。
         例)GL
      MESSAGETEXT

      register_prefix('GK', 'GL')

      def eval_game_system_specific_command(command)
        output = nil

        if /^GL$/i =~ command
          return getChombaResultText()
        end

        unless /^GK(#(\d+))?$/i =~ command
          return output
        end

        chomba_counter = Regexp.last_match(2)

        if isChomba(chomba_counter)
          return getChombaResultText()
        end

        diceList = @randomizer.roll_barabara(3, 6).sort

        yakuResult = getYaku(diceList)
        unless yakuResult.nil?
          return getResultTextByDice(diceList, "【役】#{yakuResult}")
        end

        deme, zorome = getDemeZorome(diceList)
        if deme == 0
          return getResultTextByDice(diceList, "失敗")
        end

        yp = (zorome == 1 ? " YPが1増加" : "")
        output = getResultTextByDice(diceList, "達成値#{deme}#{yp}")
        debug("getGGwKResult(command) result", output)

        return output
      end

      def isChomba(chomba_counter)
        chomba_counter ||= 5
        chomba_counter = chomba_counter.to_i

        chomba = @randomizer.roll_once(100)

        return (chomba <= chomba_counter)
      end

      def getChombaResultText()
        getResultText("チョムバ!!")
      end

      def getYaku(diceList)
        rule = {
          [1, 2, 3] => "自動失敗/自分の装甲効果無しでダメージを受けてしまう",
          [4, 5, 6] => "自動成功/敵の装甲を無視してダメージを与える",
          [1, 1, 1] => "10倍成功 YPが10増加/10倍ダメージ YPが10増加",
          [2, 2, 2] => "2倍成功/2倍ダメージ",
          [3, 3, 3] => "3倍成功/3倍ダメージ",
          [4, 4, 4] => "4倍成功/4倍ダメージ",
          [5, 5, 5] => "5倍成功/5倍ダメージ",
          [6, 6, 6] => "6倍成功/6倍ダメージ",
        }

        yaku = rule[diceList]
        return yaku
      end

      def getDemeZorome(diceList)
        deme = 0
        zorome = 0

        if diceList[0] == diceList[1]
          deme = diceList[2]
          zorome = diceList[0]
        elsif diceList[1] == diceList[2]
          deme = diceList[0]
          zorome = diceList[1]
        end

        return deme, zorome
      end

      def getResultTextByDice(diceList, result)
        getResultText("#{diceList.join(',')} > #{result}")
      end

      def getResultText(result)
        "(3B6) > #{result}"
      end
    end
  end
end