Class: BCDice::GameSystem::DungeonsAndDragons5

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

Direct Known Subclasses

DungeonsAndDragons5_Korean

Constant Summary collapse

ID =

ゲームシステムの識別子

'DungeonsAndDragons5'
NAME =

ゲームシステム名

'ダンジョンズ&ドラゴンズ第5版'
SORT_KEY =

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

'たんしよんすあんととらこんす5'
HELP_MESSAGE =

ダイスボットの使い方

<<~INFO_MESSAGE_TEXT
  ・攻撃ロール AT[x][@c][>=t][y][B]
   x:+-修正。省略可。
   c:クリティカル値。省略可。
   t:敵のアーマークラス。>=を含めて省略可。
   y:有利(A), 不利(D)。省略可。
   B:ブレスやガイダンス等によるボーナス。省略可。
    Bだけを書くと+1d4、B[1D4+1D8]などと書くと[]内のロールをボーナスとしてロールします。
   ファンブル/失敗/成功/クリティカル を自動判定。
   例)AT AT>=10 AT+5>=18 AT-3>=16 ATA AT>=10A AT+3>=18A AT-3>=16 ATD AT>=10D AT+5>=18D AT-5>=16D
       AT@19 AT+5@18 AT-2@19>=15 AT+3>=18AB AT+3>=18DB[1D6]
  ・能力値判定 AR[x][>=t][y][b]
   攻撃ロールと同様。失敗/成功を自動判定。
   例)AR AR>=10 AR+5>=18 AR-3>=16 ARA AR>=10A AR+3>=18A AR-3>=16 ARD AR>=10D AR+5>=18D AR-5>=16D
        AR+3>=18AB AR+3>=18DB[1D6]
  ・両手持ちのダメージ 2HnDx[m]
   n:ダイスの個数
   x:ダイスの面数
   m:+-修正。省略可。
   パラディンとファイターの武器の両手持ちによるダメージダイスの1,2の出目の振り直しを行います。
   例)2H3D6 2H1D10+3 2H2D8-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) ⇒ DungeonsAndDragons5

Returns a new instance of DungeonsAndDragons5.



41
42
43
44
45
# File 'lib/bcdice/game_system/DungeonsAndDragons5.rb', line 41

def initialize(command)
  super(command)

  @sort_barabara_dice = false # バラバラロール(Bコマンド)でソート無
end

Instance Method Details

#ability_roll(command) ⇒ Object

能力値ロール



199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
# File 'lib/bcdice/game_system/DungeonsAndDragons5.rb', line 199

def ability_roll(command)
  m = /^AR([-+\d]+)?(>=(\d+))?([AD]?)6?(B(\[(\d+D\d+([-+]\d+D\d+)*)\])?)?/.match(command)
  unless m
    return nil
  end

  usedie, dice_result, difficulty, output = exec_roll(command)
  if usedie.nil?
    return nil
  end

  result = Result.new
  if difficulty > 0
    if dice_result >= difficulty
      result.success = true
      output.push(translate('success'))
    else
      output.push(translate('failure'))
    end
  end

  Result.new.tap do |r|
    r.text = output.join("")
    if result
      if difficulty > 0
        r.condition = result.success?
      end
      r.critical = result.critical?
      r.fumble = result.fumble?
    end
  end
end

#attack_roll(command) ⇒ Object

攻撃ロール



153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
# File 'lib/bcdice/game_system/DungeonsAndDragons5.rb', line 153

def attack_roll(command)
  m = /^AT([-+\d]+)?(@(\d+))?(>=(\d+))?([AD]?)6?(B(\[(\d+D\d+([-+]\d+D\d+)*)\])?)?/.match(command)
  unless m
    return nil
  end

  critical_no = 20
  unless m[3].nil?
    critical_no = m[3].to_i
  end

  usedie, dice_result, difficulty, output = exec_roll(command)
  if usedie.nil?
    return nil
  end

  result = Result.new
  if usedie >= critical_no
    result.critical = true
    result.success = true
    output.push(translate('critical'))
  elsif usedie == 1
    result.fumble = true
    output.push(translate('fumble'))
  elsif difficulty > 0
    if dice_result >= difficulty
      result.success = true
      output.push(translate('success'))
    else
      output.push(translate('failure'))
    end
  end

  Result.new.tap do |r|
    r.text = output.join("")
    if result
      if difficulty > 0 || result.critical? || result.fumble?
        r.condition = result.success?
      end
      r.critical = result.critical?
      r.fumble = result.fumble?
    end
  end
end

#eval_game_system_specific_command(command) ⇒ Object



47
48
49
# File 'lib/bcdice/game_system/DungeonsAndDragons5.rb', line 47

def eval_game_system_specific_command(command)
  attack_roll(command) || ability_roll(command) || twohands_damage_roll(command)
end

#exec_roll(command) ⇒ Object

ロール処理



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
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
144
145
146
147
148
149
150
# File 'lib/bcdice/game_system/DungeonsAndDragons5.rb', line 62

def exec_roll(command)
  m = /^(AT|AR)([-+\d]+)?(@(\d+))?(>=(\d+))?([AD]?)6?(B(\[(\d+D\d+([-+]\d+D\d+)*)\])?)?/.match(command)
  unless m
    return nil
  end

  modify = 0
  mod_str = ""
  unless m[2].nil?
    if Arithmetic.eval(m[2], @round_type).nil?
      return nil
    else
      modify = Arithmetic.eval(m[2], @round_type)
      mod_str = number_with_sign_from_int(modify).to_s
    end
  end
  critical_no = m[4].to_i
  difficulty = m[6].to_i
  advantage = m[7].to_s
  bonus = m[8].to_s
  bonus_dice = m[10].to_s

  usedie = 0
  bonus_mod = 0
  bonus_str = ""
  bonus_mod_arr = []
  roll_die = ""

  dice_command = "#{m[1]}#{number_with_sign_from_int(modify)}"
  unless critical_no < 1
    dice_command += "@#{critical_no}"
  end
  if difficulty > 0
    dice_command += ">=#{difficulty}"
  end
  unless advantage.empty?
    dice_command += advantage
  end
  unless bonus.empty?
    dice_command += bonus
  end

  output = ["(#{dice_command})"]

  if advantage.empty?
    usedie = @randomizer.roll_once(20)
    roll_die = usedie
  else
    dice = @randomizer.roll_barabara(2, 20)
    roll_die = "[" + dice.join(",") + "]"
    if advantage == "A"
      usedie = dice.max
    else
      usedie = dice.min
    end
    roll_die = "#{usedie}#{roll_die}"
  end

  unless bonus.empty?
    if bonus == "B"
      bonus_mod = @randomizer.roll_once(4).to_i
      bonus_str = number_with_sign_from_int(bonus_mod).to_s
    else
      unless bonus_dice.empty?
        bonus_dice_arr = bonus_dice.gsub(/([+-])/, ",\\1").split(',')
        bonus_dice_arr.each do |i|
          now_bonus_dice = i.split("D")
          now_dice_count = now_bonus_dice[0].to_i
          now_dice_number = now_bonus_dice[1].to_i
          dice = @randomizer.roll_barabara(now_dice_count.abs, now_dice_number)
          if now_dice_count.positive?
            bonus_mod_arr.push(dice.sum())
          else
            bonus_mod_arr.push(-dice.sum())
          end
        end
        bonus_mod = bonus_mod_arr.sum()
        bonus_str = "#{number_with_sign_from_int(bonus_mod)}[#{bonus_mod_arr.join(',')}]"
      end
    end
  end

  output.push("#{roll_die}#{mod_str}#{bonus_str}")
  unless mod_str.empty? && advantage.empty? && bonus.empty?
    output.push((usedie + modify + bonus_mod).to_s)
  end

  return usedie, (usedie + modify + bonus_mod), difficulty, output
end

#number_with_sign_from_int(number) ⇒ Object



51
52
53
54
55
56
57
58
59
# File 'lib/bcdice/game_system/DungeonsAndDragons5.rb', line 51

def number_with_sign_from_int(number)
  if number == 0
    return ""
  elsif number > 0
    return "+#{number}"
  else
    return number.to_s
  end
end

#twohands_damage_roll(command) ⇒ Object

武器の両手持ちダメージ



233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
# File 'lib/bcdice/game_system/DungeonsAndDragons5.rb', line 233

def twohands_damage_roll(command)
  m = /^2H(\d+)D(\d+)([-+\d]+)?/.match(command)
  unless m
    return nil
  end

  dice_count = m[1].to_i
  dice_number = m[2].to_i

  modify = 0
  mod_str = ""
  unless m[3].nil?
    if Arithmetic.eval(m[3], @round_type).nil?
      return nil
    else
      modify = Arithmetic.eval(m[3], @round_type)
      mod_str = number_with_sign_from_int(modify).to_s
    end
  end

  output = ["(2H#{dice_count}D#{dice_number}#{mod_str})"]

  dice = @randomizer.roll_barabara(dice_count, dice_number)
  roll_dice = "[" + dice.join(",") + "]"
  output.push("#{roll_dice}#{mod_str}")

  ex_dice = []
  new_dice = []
  sum_dice = 0
  dice.each do |num|
    if num.to_i > 2
      sum_dice += num.to_i
      ex_dice.push(num)
    else
      one_die = @randomizer.roll_once(dice_number)
      sum_dice += one_die.to_i
      new_dice.push(one_die)
    end
  end
  unless new_dice.empty?
    output.push("[" + ex_dice.join(",") + "][" + new_dice.join(",") + "]#{mod_str}")
  end
  output.push((sum_dice + modify).to_s)

  Result.new.tap do |r|
    r.text = output.join("")
  end
end