Class: BCDice::GameSystem::AssaultEngine

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

Constant Summary collapse

ID =

ゲームシステムの識別子

'AssaultEngine'
NAME =

ゲームシステム名

'アサルトエンジン'
SORT_KEY =

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

'あさるとえんしん'
HELP_MESSAGE =

ダイスボットの使い方

<<~MESSAGETEXT
  ・判定 AEt (t目標値)
      例: AE45 (目標値45)
  ・リロール nAEt (nロール前の値、t目標値)
      例: 76AE45 (目標値45で、76を振り直す)

  ・スワップ(t目標値) エネミーブックP11
      例: AES45 (目標値45、スワップ表示あり)
MESSAGETEXT

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

Returns a new instance of AssaultEngine.



28
29
30
31
# File 'lib/bcdice/game_system/AssaultEngine.rb', line 28

def initialize(command)
  super(command)
  @round_type = RoundType::FLOOR # 端数切り捨て
end

Instance Method Details

#eval_game_system_specific_command(command) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/bcdice/game_system/AssaultEngine.rb', line 33

def eval_game_system_specific_command(command)
  cmd = Command::Parser.new(/AES?/, round_type: round_type).enable_prefix_number
                       .has_suffix_number.parse(command)
  return nil unless cmd

  target = cmd.suffix_number
  target = 99 if target >= 100

  if cmd.command.include?("AES") # SWAP初回
    total = @randomizer.roll_once(100) % 100 # 0-99
    swap = (total % 10) * 10 + (total / 10)
    r1 = judge(target, total)
    r2 = judge(target, swap)
    text = "(AES#{format00(target)}) > #{r1.text} / スワップ#{r2.text}"
    return_result(r1, r2, text)
  elsif cmd.prefix_number.nil? # 初回ロール
    total = @randomizer.roll_once(100) % 100 # 0-99
    judge(target, total).tap do |r|
      r.text = "(AE#{format00(target)}) > #{r.text}"
    end
  else # リロール
    now = cmd.prefix_number
    die = @randomizer.roll_once(10) % 10 # 0-9
    new1 = judge(target, (now / 10 * 10) + die)    # 1の位を振り直す
    new2 = judge(target, now % 10 + die * 10)      # 10の位を振り直す

    text = "(#{format00(now)}AE#{format00(target)}) > #{die}#{new1.text} / #{new2.text}"
    return_result(new1, new2, text)
  end
end

#format00(dice) ⇒ Object



64
65
66
# File 'lib/bcdice/game_system/AssaultEngine.rb', line 64

def format00(dice)
  format("%02d", dice)
end

#judge(target, total) ⇒ Object



80
81
82
83
84
85
86
87
88
# File 'lib/bcdice/game_system/AssaultEngine.rb', line 80

def judge(target, total)
  double = (total / 10) == (total % 10)
  total_text = format00(total)
  if total <= target
    double ? Result.critical("(#{total_text})クリティカル") : Result.success("(#{total_text})成功")
  else
    double ? Result.fumble("(#{total_text})ファンブル") : Result.failure("(#{total_text})失敗")
  end
end

#return_result(result1, result2, text) ⇒ Object



68
69
70
71
72
73
74
75
76
77
78
# File 'lib/bcdice/game_system/AssaultEngine.rb', line 68

def return_result(result1, result2, text)
  if result1.critical? || result2.critical?
    Result.critical(text)
  elsif result1.success? || result2.success?
    Result.success(text)
  elsif result1.fumble? && result2.fumble?
    Result.fumble(text)
  else
    Result.failure(text)
  end
end