Class: BCDice::GameSystem::EarthDawn3

Inherits:
EarthDawn show all
Defined in:
lib/bcdice/game_system/EarthDawn3.rb

Constant Summary collapse

ID =

ゲームシステムの識別子

'EarthDawn3'
NAME =

ゲームシステム名

'アースドーン3版'
SORT_KEY =

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

'ああすとおん3'
HELP_MESSAGE =

ダイスボットの使い方

<<~INFO_MESSAGE_TEXT
  ステップダイス (xEn+k)
  ステップx、目標値n(省略可能)、カルマダイスk(D2~D20)でステップダイスをロールします。
  振り足しも自動。
  例)ステップ10:10E
    ステップ10、目標値8:10E8
    ステップ12、目標値8、カルマダイスD12:10E8+1D6
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 EarthDawn

#getStepTable

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) ⇒ EarthDawn3

Returns a new instance of EarthDawn3.



29
30
31
32
33
# File 'lib/bcdice/game_system/EarthDawn3.rb', line 29

def initialize(command)
  super(command)

  @sort_add_dice = true
end

Instance Method Details

#addStepToResult(result, step) ⇒ Object



164
165
166
167
168
169
170
# File 'lib/bcdice/game_system/EarthDawn3.rb', line 164

def addStepToResult(result, step)
  result.size.times do |i|
    result[i] += step[i]
  end

  return result
end

#ed_step(str) ⇒ Object

アースドーンステップ表



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

def ed_step(str)
  output = getStepResult(str)

  return output
end

#eval_game_system_specific_command(command) ⇒ Object



35
36
37
# File 'lib/bcdice/game_system/EarthDawn3.rb', line 35

def eval_game_system_specific_command(command)
  return ed_step(command)
end

#getBaseStepTableObject



107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# File 'lib/bcdice/game_system/EarthDawn3.rb', line 107

def getBaseStepTable
  stepTable =
    [
      #      dice
      #      D20  D12  D10  D8  D6  D4  mod
      [1, [0, 0, 0, 0, 1, 0, -3]],
      [2,  [0,   0,   0,  0,  1,  0,  -2]],
      [3,  [0,   0,   0,  0,  1,  0,  -1]],
      [4,  [0,   0,   0,  0,  1,  0,   0]],
      [5,  [0,   0,   0,  1,  0,  0,   0]],
      [6,  [0,   0,   1,  0,  0,  0,   0]],
      [7,  [0,   1,   0,  0,  0,  0,   0]],
    ]

  return stepTable
end

#getModifyText(modify) ⇒ Object



98
99
100
101
102
103
104
105
# File 'lib/bcdice/game_system/EarthDawn3.rb', line 98

def getModifyText(modify)
  @string = ""
  return @string if  modify == 0

  @string += "+" if  modify > 0
  @string += modify.to_s
  return @string
end

#getStepInfo(step) ⇒ Object



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
151
152
153
154
155
156
157
158
159
160
161
162
# File 'lib/bcdice/game_system/EarthDawn3.rb', line 124

def getStepInfo(step)
  baseStepTable = getBaseStepTable
  baseMaxStep = baseStepTable.last.first

  if step <= baseMaxStep
    return get_table_by_number(step, baseStepTable)
  end

  baseStepInfo = [0, 1, 0, 0, 0, 0, 0]
  overStep = step - baseMaxStep - 1

  stepRythm =
    [
      # dice
      # D20  D12  D10  D8  D6  D4  mod
      [0, 0, 0, 0, 2, 0, 0],
      [0,   0,   0,  1,  1,  0,   0],
      [0,   0,   0,  2,  0,  0,   0],
      [0,   0,   1,  1,  0,  0,   0],
      [0,   0,   2,  0,  0,  0,   0],
      [0,   1,   1,  0,  0,  0,   0],
      [0,   2,   0,  0,  0,  0,   0],
    ]

  result = [0, 0, 0, 0, 0, 0, 0]

  loopCount = (overStep / stepRythm.size)

  loopCount.times do
    addStepToResult(result, baseStepInfo)
  end

  index = (overStep % stepRythm.size)
  restStepInfo = stepRythm[index]

  addStepToResult(result, restStepInfo)

  return result
end

#getStepResult(str) ⇒ 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
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/bcdice/game_system/EarthDawn3.rb', line 46

def getStepResult(str)
  return nil unless /^(\d+)E(\d+)?(\+(\d*)D(\d+))?(\+\d)?/i =~ str

  stepTotal = 0
  @isFailed = true

  step = Regexp.last_match(1).to_i # ステップ
  targetNumber = [Regexp.last_match(2).to_i, 20].min # 目標値
  hasKarmaDice = !Regexp.last_match(3).nil? # カルマダイスの有無
  karmaDiceCount = [1, Regexp.last_match(4).to_i].max # カルマダイスの個数
  karmaDiceType = Regexp.last_match(5).to_i # カルマダイスの種類
  diceModify = Regexp.last_match(6).to_i

  karmaDiceInfo = Hash.new(0)
  if hasKarmaDice
    karmaDiceInfo[karmaDiceType] = karmaDiceCount
  end

  return nil if targetNumber < 0

  stepInfo = getStepInfo(step)
  debug('stepInfo', stepInfo)

  @string = ""

  diceTypes = [20, 12, 10, 8, 6, 4]
  diceTypes.each do |type|
    stepTotal += rollStep(type, stepInfo.shift)
  end
  modify = stepInfo.shift

  karmaDiceInfo.each do |diceType, diceCount|
    stepTotal += rollStep(diceType, diceCount)
  end

  @string += (getModifyText(modify) + getModifyText(diceModify))
  stepTotal += (modify + diceModify)

  # ステップ判定終了
  @string += "#{stepTotal}"

  output = "ステップ#{step}#{@string}"
  return output if targetNumber == 0

  # 結果判定
  @string += '' + getSuccess(targetNumber, stepTotal)

  output = "ステップ#{step}>=#{targetNumber}#{@string}"

  return output
end

#getSuccess(targetNumber, stepTotal) ⇒ Object



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

def getSuccess(targetNumber, stepTotal)
  return '自動失敗' if @isFailed

  successTable = getSuccessTable
  successInfo = get_table_by_number(targetNumber, successTable)

  pathetic, poor, average, good, excelent, extraordinary = successInfo

  return 'Extraordinary(極上)' if stepTotal >= extraordinary
  return 'Excelent(最高)' if stepTotal >= excelent
  return 'Good(上出来)' if stepTotal >= good
  return 'Average(そこそこ)' if stepTotal >= average
  return 'Poor(お粗末)' if stepTotal >= poor
  return 'Pathetic(惨め)' if stepTotal >= pathetic
end

#getSuccessTableObject



188
189
190
191
192
193
194
195
196
197
198
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
231
232
233
234
# File 'lib/bcdice/game_system/EarthDawn3.rb', line 188

def getSuccessTable
  successTable =
    [
      #       Pathetic Poor Average Good Excellent Extraordinary
      [2, [0, 1, 2, 5, 7, 9]],
      [3,  [0,     1,     3,     6, 8, 10]],
      [4,  [0,     1,     4,     7,    10,    12]],
      [5,  [1,     2,     5,     8,    11,    14]],
      [6,  [1,     2,     6,     9,    13,    17]],
      [7,  [1,     3,     7,    11,    15,    19]],
      [8,  [1,     4,     8,    13,    16,    20]],
      [9,  [1,     5,     9,    15,    18,    22]],
      [10,  [1,     6,    10,    16,    20,    24]],
      [11,  [1,     6,    11,    17,    21,    25]],
      [12,  [1,     7,    12,    18,    23,    27]],
      [13,  [1,     7,    13,    20,    25,    29]],
      [14,  [1,     8,    14,    21,    26,    31]],
      [15,  [1,     9,    15,    23,    27,    31]],
      [16,  [1,    10,    16,    24,    28,    33]],
      [17,  [1,    11,    17,    25,    30,    34]],
      [18,  [1,    12,    18,    26,    31,    36]],
      [19,  [1,    12,    19,    28,    33,    37]],
      [20,  [1,    13,    20,    29,    34,    39]],
      [21,  [1,    14,    21,    30,    36,    41]],
      [22,  [1,    15,    22,    31,    37,    42]],
      [23,  [1,    16,    23,    33,    38,    43]],
      [24,  [1,    16,    24,    34,    39,    44]],
      [25,  [1,    17,    25,    35,    41,    46]],
      [26,  [1,    18,    26,    36,    42,    47]],
      [27,  [1,    19,    27,    37,    43,    49]],
      [28,  [1,    19,    28,    39,    45,    50]],
      [29,  [1,    21,    29,    40,    46,    51]],
      [30,  [1,    21,    30,    41,    47,    53]],
      [31,  [1,    22,    31,    42,    48,    54]],
      [32,  [1,    23,    32,    43,    49,    55]],
      [33,  [1,    24,    33,    45,    51,    57]],
      [34,  [1,    24,    34,    46,    52,    58]],
      [35,  [1,    25,    35,    47,    53,    60]],
      [36,  [1,    26,    36,    48,    54,    60]],
      [37,  [1,    27,    37,    49,    56,    62]],
      [38,  [1,    28,    38,    51,    57,    63]],
      [39,  [1,    29,    39,    52,    58,    64]],
      [40,  [1,    30,    40,    53,    59,    66]],
    ]

  return successTable
end

#rollStep(diceType, diceCount) ⇒ Object



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

def rollStep(diceType, diceCount)
  debug('rollStep diceType, diceCount, @string', diceType, diceCount, @string)

  stepTotal = 0
  return stepTotal unless diceCount > 0

  # diceぶんのステップ判定

  @string += "+" unless @string.empty?
  @string += "#{diceCount}d#{diceType}["
  debug('rollStep @string', @string)

  diceCount.times do |i|
    dice_now = @randomizer.roll_once(diceType)

    if dice_now != 1
      @isFailed = false
    end

    dice_in = dice_now

    while dice_now == diceType
      dice_now = @randomizer.roll_once(diceType)

      dice_in += dice_now
    end

    stepTotal += dice_in

    @string += ',' if i != 0
    @string += dice_in.to_s
  end

  @string += "]"

  return stepTotal
end