Class: BCDice::GameSystem::DungeonsAndDragons5

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

Constant Summary collapse

ID =

ゲームシステムの識別子

'DungeonsAndDragons5'
NAME =

ゲームシステム名

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

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

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

ダイスボットの使い方

<<~INFO_MESSAGE_TEXT
  ・攻撃ロール AT[x][@c][>=t][y]
   x:+-修正。省略可。
   c:クリティカル値。省略可。
   t:敵のアーマークラス。>=を含めて省略可。
   y:有利(A), 不利(D)。省略可。
   ファンブル/失敗/成功/クリティカル を自動判定。
   例)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
  ・能力値判定 AR[x][>=t][y]
   攻撃ロールと同様。失敗/成功を自動判定。
   例)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
  ・両手持ちのダメージ 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.



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

def initialize(command)
  super(command)

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

Instance Method Details

#ability_roll(command) ⇒ Object

能力値ロール



141
142
143
144
145
146
147
148
149
150
151
152
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
197
198
199
200
201
202
203
204
205
206
207
# File 'lib/bcdice/game_system/DungeonsAndDragons5.rb', line 141

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

  modify = m[1].to_i
  difficulty = m[3].to_i
  advantage = m[4]

  usedie = 0
  roll_die = ""

  dice_command = "AR#{number_with_sign_from_int(modify)}"
  if difficulty > 0
    dice_command += ">=#{difficulty}"
  end
  unless advantage.empty?
    dice_command += advantage.to_s
  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
  end

  if modify != 0
    output.push("#{roll_die}#{number_with_sign_from_int(modify)}")
    output.push((usedie + modify).to_s)
  else
    unless advantage.empty?
      output.push(roll_die)
    end
    output.push(usedie.to_s)
  end

  result = Result.new
  if difficulty > 0
    if usedie + modify >= difficulty
      result.success = true
      output.push("成功")
    else
      output.push("失敗")
    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

攻撃ロール



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
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
# File 'lib/bcdice/game_system/DungeonsAndDragons5.rb', line 59

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

  modify = m[1].to_i
  critical_no = m[3].to_i
  difficulty = m[5].to_i
  advantage = m[6]

  usedie = 0
  roll_die = ""

  dice_command = "AT#{number_with_sign_from_int(modify)}"
  if critical_no > 0
    dice_command += "@#{critical_no}"
  else
    critical_no = 20
  end
  if difficulty > 0
    dice_command += ">=#{difficulty}"
  end
  unless advantage.empty?
    dice_command += advantage.to_s
  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
  end

  if modify != 0
    output.push("#{roll_die}#{number_with_sign_from_int(modify)}")
    output.push((usedie + modify).to_s)
  else
    unless advantage.empty?
      output.push(roll_die)
    end
    output.push(usedie.to_s)
  end

  result = Result.new
  if usedie >= critical_no
    result.critical = true
    result.success = true
    output.push("クリティカル")
  elsif usedie == 1
    result.fumble = true
    output.push("ファンブル")
  elsif difficulty > 0
    if usedie + modify >= difficulty
      result.success = true
      output.push("成功")
    else
      output.push("失敗")
    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



44
45
46
# File 'lib/bcdice/game_system/DungeonsAndDragons5.rb', line 44

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

#number_with_sign_from_int(number) ⇒ Object



48
49
50
51
52
53
54
55
56
# File 'lib/bcdice/game_system/DungeonsAndDragons5.rb', line 48

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

武器の両手持ちダメージ



210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
# File 'lib/bcdice/game_system/DungeonsAndDragons5.rb', line 210

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 = m[3].to_i
  mod_str = number_with_sign_from_int(modify)
  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