Class: BCDice::GameSystem::YearZeroEngine

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

Constant Summary collapse

ID =

ゲームシステムの識別子

'YearZeroEngine'
NAME =

ゲームシステム名

'YearZeroEngine'
SORT_KEY =

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

'いやあせろえんしん'
HELP_MESSAGE =

ダイスボットの使い方

<<~INFO_MESSAGE_TEXT
  ・ダイスプール判定コマンド(nYZEx+x+x+m)
    (難易度)YZE(能力ダイス数)+(技能ダイス数)+(アイテムダイス数)+(修正値)  # (6のみを数える)
    (難易度)YZE(能力ダイス数)+(技能ダイス数)+(アイテムダイス数)-(修正値)  # (6のみを数える)

  ・ダイスプール判定コマンド(nMYZx+x+x)
    (難易度)MYZ(能力ダイス数)+(技能ダイス数)+(アイテムダイス数)  # (1と6を数え、プッシュ可能数を表示)
    (難易度)MYZ(能力ダイス数)-(技能ダイス数)+(アイテムダイス数)  # (1と6を数え、プッシュ可能数を表示、技能のマイナス指定)

    ※ 難易度と技能、アイテムダイス数は省略可能

  ・ステップダイス判定コマンド(nYZSx+x+m+f)
    (難易度)YZS(能力ダイス面数)+(技能ダイス面数)+(修正値)   # (1,6を数え、プッシュ可能数を表示)
    (難易度)YZS(能力ダイス面数)+(技能ダイス面数)-(修正値)   # (1,6を数え、プッシュ可能数を表示)
    (難易度)YZS(能力ダイス面数)+(技能ダイス面数)+(修正値)A  # (1,6を数え、プッシュ可能数を表示、有利)
    (難易度)YZS(能力ダイス面数)+(技能ダイス面数)-(修正値)A  # (1,6を数え、プッシュ可能数を表示、有利)
    (難易度)YZS(能力ダイス面数)+(技能ダイス面数)+(修正値)D  # (1,6を数え、プッシュ可能数を表示、不利)
    (難易度)YZS(能力ダイス面数)+(技能ダイス面数)-(修正値)D  # (1,6を数え、プッシュ可能数を表示、不利)
INFO_MESSAGE_TEXT
DIFFICULTY_INDEX =

難易度のインデックス

1
COMMAND_TYPE_INDEX =

コマンドタイプのインデックス

2
ABILITY_INDEX =

能力値ダイスのインデックス

3
SKILL_SIGNED_INDEX =

技能値ダイス符号のインデックス

5
SKILL_INDEX =

技能値ダイスのインデックス

6
GEAR_INDEX =

アイテムダイスのインデックス

8
MODIFIER_SIGNED_INDEX =

修正値の符号のインデックス

10
MODIFIER_INDEX =

修正値のインデックス

11

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, #initialize, prefixes_pattern, register_prefix, register_prefix_from_super_class, #sort_add_dice?, #sort_barabara_dice?

Methods included from Translate

#translate

Constructor Details

This class inherits a constructor from BCDice::Base

Instance Method Details

#dice_info_initObject



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

def dice_info_init()
  @total_success_dice = 0
  @total_botch_dice = 0
  @base_botch_dice = 0
  @skill_botch_dice = 0
  @gear_botch_dice = 0
  @push_dice = 0
  @difficulty = 0
end

#eval_game_system_specific_command(command) ⇒ Object



57
58
59
60
61
# File 'lib/bcdice/game_system/YearZeroEngine.rb', line 57

def eval_game_system_specific_command(command)
  resolute_action(command) ||
    resolute_push_action(command) ||
    resolute_step_action(command)
end

#get_rolling_dice(dice_type1, dice_type2, dice_upgrade) ⇒ Object



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

def get_rolling_dice(dice_type1, dice_type2, dice_upgrade)
  dice_type1 = 4 if dice_type1 < 4
  dice_type2 = 4 if dice_type2 < 4

  while dice_upgrade > 0
    if dice_type1 >= dice_type2
      dice_type2 += 2 if dice_type2 < 12
    else
      dice_type1 += 2 if dice_type1 < 12
    end
    dice_upgrade -= 1
  end

  while dice_upgrade < 0
    if dice_type1 <= dice_type2
      dice_type2 -= 2 if dice_type2 > 4
    else
      dice_type1 -= 2 if dice_type1 > 4
    end
    dice_upgrade += 1
  end

  if dice_type1 == 4 && dice_type2 == 4
    dice_type1 = 6
  end

  return dice_type1, dice_type2
end

#make_dice_a_roll(count, type) ⇒ Object



233
234
235
236
237
238
239
240
241
242
243
244
# File 'lib/bcdice/game_system/YearZeroEngine.rb', line 233

def make_dice_a_roll(count, type)
  dice_list = @randomizer.roll_barabara(count, type)
  botch_dice = dice_list.count(1)
  success_dice = dice_list.count { |val| val >= 6 }
  success_level = success_dice + dice_list.count { |val| val >= 10 }

  @total_success_dice += success_level
  @total_botch_dice += botch_dice
  @push_dice += (count - (success_dice + botch_dice))

  return "[#{dice_list.join(',')}]", botch_dice
end

#make_dice_roll(dice_pool) ⇒ Object



225
226
227
228
229
230
231
# File 'lib/bcdice/game_system/YearZeroEngine.rb', line 225

def make_dice_roll(dice_pool)
  dice_list = @randomizer.roll_barabara(dice_pool, 6)
  success_dice = dice_list.count(6)
  botch_dice = dice_list.count(1)

  return "[#{dice_list.join(',')}]", success_dice, botch_dice
end

#make_result_with_myz(dice_count_text, dice_text) ⇒ Object



210
211
212
213
214
215
216
217
218
219
220
221
222
223
# File 'lib/bcdice/game_system/YearZeroEngine.rb', line 210

def make_result_with_myz(dice_count_text, dice_text)
  result_text = "#{dice_count_text}#{dice_text} 成功数:#{@total_success_dice}"
  atter_text = "\n出目1:[能力:#{@base_botch_dice},技能:#{@skill_botch_dice},アイテム:#{@gear_botch_dice}) プッシュ可能=#{@push_dice}ダイス"

  if @difficulty > 0
    if @total_success_dice >= @difficulty
      return Result.success("#{result_text} 難易度=#{@difficulty}:判定成功!#{atter_text}")
    else
      return Result.failure("#{result_text} 難易度=#{@difficulty}:判定失敗!#{atter_text}")
    end
  end

  return "#{result_text}#{atter_text}"
end

#make_result_with_yze(dice_count_text, dice_text) ⇒ Object



198
199
200
201
202
203
204
205
206
207
208
# File 'lib/bcdice/game_system/YearZeroEngine.rb', line 198

def make_result_with_yze(dice_count_text, dice_text)
  result_text = "#{dice_count_text}#{dice_text} 成功数:#{@total_success_dice}"
  if @difficulty > 0
    if @total_success_dice >= @difficulty
      return Result.success("#{result_text} 難易度=#{@difficulty}:判定成功!")
    else
      return Result.failure("#{result_text} 難易度=#{@difficulty}:判定失敗!")
    end
  end
  return result_text
end

#resolute_action(command) ⇒ Object



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/YearZeroEngine.rb', line 63

def resolute_action(command)
  m = /\A(\d+)?(YZE)(\d+)((\+)(\d+))?(\+(\d+))?((\+|-)(\d+))?/.match(command)
  unless m
    return nil
  end

  dice_info_init

  @difficulty = m[DIFFICULTY_INDEX].to_i
  attribute = m[ABILITY_INDEX].to_i
  skill = m[SKILL_INDEX].to_i
  gear = m[GEAR_INDEX].to_i
  modifier = m[MODIFIER_INDEX].to_i
  if m[MODIFIER_SIGNED_INDEX] == '-'
    if skill >= modifier
      skill -= modifier
    else
      modifier -= skill
      skill = 0
      if gear >= modifier
        gear -= modifier
      else
        modifier -= gear
        gear = 0
        if attribute >= modifier
          attribute -= modifier
        else
          attribute = 0
        end
      end
    end
  else
    skill += modifier
  end

  @total_success_dice = 0

  dice_pool = attribute
  ability_dice_text, success_dice, botch_dice = make_dice_roll(dice_pool)

  @total_success_dice += success_dice
  @total_botch_dice += botch_dice
  @base_botch_dice += botch_dice # 能力ダメージ
  @push_dice += (dice_pool - (success_dice + botch_dice))

  dice_count_text = "(#{dice_pool}D6)"
  dice_text = ability_dice_text

  if m[SKILL_INDEX]
    dice_pool = skill
    skill_dice_text, success_dice, botch_dice = make_dice_roll(dice_pool)

    @total_success_dice += success_dice
    @total_botch_dice += botch_dice
    @skill_botch_dice += botch_dice # 技能ダイスの1はpushで振り直し可能(例えマイナス技能でも)
    @push_dice += (dice_pool - success_dice) # 技能ダイスのみ1を含むので、ここでは1を計算に入れない

    dice_count_text += "+(#{dice_pool}D6)"
    dice_text += "+#{skill_dice_text}"
  end

  if m[GEAR_INDEX]
    dice_pool = gear
    gear_dice_text, success_dice, botch_dice = make_dice_roll(dice_pool)

    @total_success_dice += success_dice
    @total_botch_dice += botch_dice
    @gear_botch_dice += botch_dice # ギアダメージ
    @push_dice += (dice_pool - (success_dice + botch_dice))

    dice_count_text += "+(#{dice_pool}D6)"
    dice_text += "+#{gear_dice_text}"
  end

  return make_result_with_yze(dice_count_text, dice_text)
end

#resolute_push_action(command) ⇒ Object



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

def resolute_push_action(command)
  m = /\A(\d+)?(MYZ)(\d+)((\+|-)(\d+))?(\+(\d+))?/.match(command)
  unless m
    return nil
  end

  dice_info_init

  @difficulty = m[DIFFICULTY_INDEX].to_i

  @total_success_dice = 0

  dice_pool = m[ABILITY_INDEX].to_i
  ability_dice_text, success_dice, botch_dice = make_dice_roll(dice_pool)

  @total_success_dice += success_dice
  @total_botch_dice += botch_dice
  @base_botch_dice += botch_dice # 能力ダメージ
  @push_dice += (dice_pool - (success_dice + botch_dice))

  dice_count_text = "(#{dice_pool}D6)"
  dice_text = ability_dice_text

  if m[SKILL_INDEX]
    dice_pool = m[SKILL_INDEX].to_i
    skill_dice_text, success_dice, botch_dice = make_dice_roll(dice_pool)

    skill_unsigned = m[SKILL_SIGNED_INDEX]
    if skill_unsigned == '-'
      @total_success_dice -= success_dice # マイナス技能の成功は通常の成功と相殺される
    else
      @total_success_dice += success_dice
    end

    @total_botch_dice += botch_dice
    @skill_botch_dice += botch_dice # 技能ダイスの1はpushで振り直し可能(例えマイナス技能でも)
    @push_dice += (dice_pool - success_dice) # 技能ダイスのみ1を含むので、ここでは1を計算に入れない

    dice_count_text += "#{skill_unsigned}(#{dice_pool}D6)"
    dice_text += "#{skill_unsigned}#{skill_dice_text}"
  end

  if m[GEAR_INDEX]
    dice_pool = m[GEAR_INDEX].to_i
    gear_dice_text, success_dice, botch_dice = make_dice_roll(dice_pool)

    @total_success_dice += success_dice
    @total_botch_dice += botch_dice
    @gear_botch_dice += botch_dice # ギアダメージ
    @push_dice += (dice_pool - (success_dice + botch_dice))

    dice_count_text += "+(#{dice_pool}D6)"
    dice_text += "+#{gear_dice_text}"
  end

  return make_result_with_myz(dice_count_text, dice_text)
end

#resolute_step_action(command) ⇒ Object



275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
# File 'lib/bcdice/game_system/YearZeroEngine.rb', line 275

def resolute_step_action(command)
  m = /\A(\d+)?(YZS)(\d+)((\+)(\d+))?((\+|-)(\d+))?(A|D)?/.match(command)
  unless m
    return nil
  end

  dice_info_init

  @difficulty = m[DIFFICULTY_INDEX].to_i
  attribute = m[ABILITY_INDEX].to_i
  skill = m[SKILL_INDEX].to_i
  modifier = m[7].to_i
  advantage = m[10]

  dice_count_text = ""
  dice_text = ""

  dice_type1, dice_type2 = get_rolling_dice(attribute, skill, modifier)

  if dice_type1 <= dice_type2
    if advantage
      if advantage == "A" && (dice_type1 > 4)
        ability_dice_text, botch_dice = make_dice_a_roll(2, dice_type1)

        @base_botch_dice += botch_dice # 能力ダメージ
        dice_count_text = "(2D#{dice_type1})"
        dice_text = ability_dice_text
      end
    else
      if dice_type1 > 4
        ability_dice_text, botch_dice = make_dice_a_roll(1, dice_type1)

        @base_botch_dice += botch_dice # 能力ダメージ
        dice_count_text = "(1D#{dice_type1})"
        dice_text = ability_dice_text
      end
    end
    if dice_type2 > 4
      skill_dice_text, botch_dice = make_dice_a_roll(1, dice_type2)

      @skill_botch_dice += botch_dice
      dice_count_text += "+" unless dice_count_text == ""
      dice_text += "+" unless dice_text == ""
      dice_count_text += "(1D#{dice_type2})"
      dice_text += skill_dice_text
    end
  else
    if dice_type1 > 4
      ability_dice_text, botch_dice = make_dice_a_roll(1, dice_type1)

      @base_botch_dice += botch_dice # 能力ダメージ
      dice_count_text = "(1D#{dice_type1})"
      dice_text = ability_dice_text
    end
    if advantage
      if advantage == "A" && (dice_type2 > 4)
        skill_dice_text, botch_dice = make_dice_a_roll(2, dice_type2)

        @skill_botch_dice += botch_dice
        dice_count_text += "+(2D#{dice_type2})"
        dice_text += "+#{skill_dice_text}"
      end
    else
      if dice_type2 > 4
        skill_dice_text, botch_dice = make_dice_a_roll(1, dice_type2)

        @skill_botch_dice += botch_dice
        dice_count_text += "+(1D#{dice_type2})"
        dice_text += "+#{skill_dice_text}"
      end
    end
  end

  return make_result_with_myz(dice_count_text, dice_text)
end