Class: BCDice::GameSystem::BarnaKronika

Inherits:
Base
  • Object
show all
Defined in:
lib/bcdice/game_system/BarnaKronika.rb

Constant Summary collapse

ID =

ゲームシステムの識別子

'BarnaKronika'
NAME =

ゲームシステム名

'バルナ・クロニカ'
SORT_KEY =

ゲームシステム名の読みがな

'はるなくろにか'
HELP_MESSAGE =

ダイスボットの使い方

<<~INFO_MESSAGE_TEXT
  ・通常判定 nBK
   ダイス数nで判定ロールを行います。
   セット数が1以上の時はセット数も表示します。
  ・攻撃判定 nBA
   ダイス数nで判定ロールを行い、攻撃値と命中部位も表示します。
  ・クリティカルコール nBKCt nBACt
   判定コマンドの後ろに「Ct」を付けるとクリティカルコールです。
   ダイス数n,コール数tで判定ロールを行います。
   ダイス数nで判定ロールを行います。
   セット数が1以上の時はセット数も表示し、攻撃判定の場合は命中部位も表示します。
INFO_MESSAGE_TEXT

Instance Attribute Summary

Attributes inherited from Base

#d66_sort_type, #default_cmp_op, #default_target_number, #randomizer, #reroll_dice_reroll_threshold, #round_type, #sides_implicit_d, #upper_dice_reroll_threshold

Instance Method Summary collapse

Methods inherited from Base

#change_text, #check_result, command_pattern, #enable_debug, #enabled_d9?, #eval, eval, #grich_text, prefixes_pattern, register_prefix, register_prefix_from_super_class, #sort_add_dice?, #sort_barabara_dice?

Methods included from Translate

#translate

Constructor Details

#initialize(command) ⇒ BarnaKronika

Returns a new instance of BarnaKronika.



31
32
33
34
35
36
# File 'lib/bcdice/game_system/BarnaKronika.rb', line 31

def initialize(command)
  super(command)

  @sort_add_dice = true
  @sort_barabara_dice = true
end

Instance Method Details

#eval_game_system_specific_command(string) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/bcdice/game_system/BarnaKronika.rb', line 46

def eval_game_system_specific_command(string)
  string = replace_text(string)

  return nil unless /(^|\s)S?((\d+)[rR]6(\[([,\d]+)\])?)(\s|$)/i =~ string

  string = Regexp.last_match(2)
  option = Regexp.last_match(5)
  dice_n = Regexp.last_match(3)
  dice_n ||= 1

  @isBattleMode = false # 0=判定モード, 1=戦闘モード
  criticalCallDice = 0 # 0=通常, 1〜6=クリティカルコール

  if option
    battleModeText, criticalCallDice = option.split(",").map(&:to_i)
    @isBattleMode = (battleModeText == 1)
  end

  debug("@isBattleMode", @isBattleMode)

  dice_str, suc, set, at_str = roll_barna_kronika(dice_n, criticalCallDice)

  output = "(#{string}) > [#{dice_str}] > "

  if @isBattleMode
    output += at_str
  else
    debug("suc", suc)
    if suc > 1
      output += "成功数#{suc}"
    else
      output += "失敗"
    end

    debug("set", set)
    output += ",セット#{set}" if set > 0
  end

  return output
end

#getAttackHitLocation(num) ⇒ Object

命中部位表



174
175
176
177
178
179
180
181
182
183
184
185
# File 'lib/bcdice/game_system/BarnaKronika.rb', line 174

def getAttackHitLocation(num)
  table = [
    [1, '頭部'],
    [2, '右腕'],
    [3, '左腕'],
    [4, '右脚'],
    [5, '左脚'],
    [6, '胴体'],
  ]

  return get_table_by_number(num, table)
end

#getAttackStringWhenCriticalCall(index, diceCount) ⇒ Object



159
160
161
162
163
164
# File 'lib/bcdice/game_system/BarnaKronika.rb', line 159

def getAttackStringWhenCriticalCall(index, diceCount)
  hitLocation = getAttackHitLocation(index + 1)
  attackValue = (diceCount * 2)
  result = hitLocation + ":攻撃値#{attackValue},"
  return result
end

#getAttackStringWhenNomal(index, diceCount) ⇒ Object



166
167
168
169
170
171
# File 'lib/bcdice/game_system/BarnaKronika.rb', line 166

def getAttackStringWhenNomal(index, diceCount)
  hitLocation = getAttackHitLocation(index + 1)
  attackValue = diceCount
  result = hitLocation + ":攻撃値#{attackValue},"
  return result
end

#isCriticalCall(index, criticalCallDice) ⇒ Object



145
146
147
148
149
150
# File 'lib/bcdice/game_system/BarnaKronika.rb', line 145

def isCriticalCall(index, criticalCallDice)
  return false unless @isBattleMode
  return false if criticalCallDice == 0

  return (criticalCallDice == (index + 1))
end

#isNomalAttack(criticalCallDice, diceCount) ⇒ Object



152
153
154
155
156
157
# File 'lib/bcdice/game_system/BarnaKronika.rb', line 152

def isNomalAttack(criticalCallDice, diceCount)
  return false unless @isBattleMode
  return false if criticalCallDice != 0

  return (diceCount > 1)
end

#replace_text(string) ⇒ Object



38
39
40
41
42
43
44
# File 'lib/bcdice/game_system/BarnaKronika.rb', line 38

def replace_text(string)
  string = string.gsub(/(\d+)BKC(\d)/) { "#{Regexp.last_match(1)}R6[0,#{Regexp.last_match(2)}]" }
  string = string.gsub(/(\d+)BAC(\d)/) { "#{Regexp.last_match(1)}R6[1,#{Regexp.last_match(2)}]" }
  string = string.gsub(/(\d+)BK/) { "#{Regexp.last_match(1)}R6[0,0]" }
  string = string.gsub(/(\d+)BA/) { "#{Regexp.last_match(1)}R6[1,0]" }
  return string
end

#roll_barna_kronika(dice_n, criticalCallDice) ⇒ Object



87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
# File 'lib/bcdice/game_system/BarnaKronika.rb', line 87

def roll_barna_kronika(dice_n, criticalCallDice)
  dice_n = dice_n.to_i

  output = ''
  suc = 0
  set = 0
  at_str = ''
  diceCountList = [0, 0, 0, 0, 0, 0]

  dice_n.times do |_i|
    index = @randomizer.roll_index(6)
    diceCountList[index] += 1
    if diceCountList[index] > suc
      suc = diceCountList[index]
    end
  end

  6.times do |i|
    diceCount = diceCountList[i]

    next if diceCount == 0

    diceCount.times do |_j|
      output += "#{i + 1},"
    end

    if isCriticalCall(i, criticalCallDice)
      debug("isCriticalCall")
      at_str += getAttackStringWhenCriticalCall(i, diceCount)
    elsif isNomalAttack(criticalCallDice, diceCount)
      debug("isNomalAttack")
      at_str += getAttackStringWhenNomal(i, diceCount)
    end

    set += 1 if diceCount > 1
  end

  if criticalCallDice != 0
    c_cnt = diceCountList[criticalCallDice - 1]
    suc = c_cnt * 2

    if  c_cnt != 0
      set = 1
    else
      set = 0
    end
  end

  if @isBattleMode && (suc < 2)
    at_str = "失敗"
  end

  output = output.sub(/,$/, '')
  at_str = at_str.sub(/,$/, '')

  return output, suc, set, at_str
end