Class: BCDice::GameSystem::AFF2e

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

Constant Summary collapse

ID =

ゲームシステムの識別子

'AFF2e'
NAME =

ゲームシステム名

'ADVANCED FIGHTING FANTASY 2nd Edition'
SORT_KEY =

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

'あとはんすとふあいていんくふあんたしい2'
HELP_MESSAGE =

ダイスボットの使い方

<<~MESSAGETEXT
  対抗なしロール\tFF{目標値}+{補正}
  対抗ロール\tFR{能力値}+{補正}
  武器ロール\tFD[2,3,3,3,3,3,4]+{補正}
  防具ロール\tFD[0,0,0,0,1+1,1+1,2+2]+{補正}
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, #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

#clamp(i, min, max) ⇒ Object



62
63
64
65
66
67
68
69
70
# File 'lib/bcdice/game_system/AFF2e.rb', line 62

def clamp(i, min, max)
  if i < min
    min
  elsif i > max
    max
  else
    i
  end
end

#critical(total) ⇒ Object



53
54
55
56
57
58
59
60
# File 'lib/bcdice/game_system/AFF2e.rb', line 53

def critical(total)
  case total
  when  2
    'ファンブル!'
  when 12
    '強打!'
  end
end

#eval_game_system_specific_command(command) ⇒ Object



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/AFF2e.rb', line 72

def eval_game_system_specific_command(command)
  case command
  when /\AFF/
    # 対抗なしロール
    # '成功' or '失敗' を出力する
    #
    md = Regexp.last_match
    term = md.post_match

    # 目標値
    diff = eval_term(term)

    dice_command = "2D6<=#{diff}"
    dice_list = @randomizer.roll_barabara(2, 6)
    total = dice_list.sum()
    dice_str = dice_list.join(",")
    expr = "#{total}[#{dice_str}]"
    succ = successful_or_failed(total, diff)
    sequence = [parentheses(dice_command), expr, succ]
  when /\AFR/
    # 対抗ロール
    # 値を出力する
    #
    md = Regexp.last_match
    term = md.post_match

    # 補正値
    corr = eval_term(term)

    dice_command = "2D6#{explicit_sign corr}"
    dice_list = @randomizer.roll_barabara(2, 6)
    total = dice_list.sum()
    dice_str = dice_list.join(",")
    expr = "#{total}[#{dice_str}]#{explicit_sign corr}"
    crit = critical(total)
    sequence = [parentheses(dice_command), expr, crit, total + corr].compact
  when /\AFD/
    # 武器防具ロール
    # ダメージを出力する
    #
    md = Regexp.last_match
    term = md.post_match
    md = /\A\[(.+)\]/.match(term)
    unless md
      return 'ダメージスロットは必須です。'
    end

    term = md.post_match
    damage_slots = md[1].split(',').map { |t| eval_term(t) }
    if damage_slots.size != 7
      return 'ダメージスロットの長さに誤りがあります。'
    end

    # 補正値
    corr = eval_term(term)

    dice_command = "1D6#{explicit_sign corr}"
    total = @randomizer.roll_once(6)
    expr = "#{total}#{explicit_sign corr}"
    slot_number = clamp(total + corr, 1, 7)
    damage = damage_slots[slot_number - 1]
    sequence = [parentheses(dice_command), expr, total + corr, "#{damage}ダメージ"]
  end

  result = sequence.join('')
  return result
end

#eval_term(term) ⇒ Object



30
31
32
33
34
35
36
# File 'lib/bcdice/game_system/AFF2e.rb', line 30

def eval_term(term)
  value = 0
  term.scan(/[+-]?\d+/) do |fact|
    value += fact.to_i
  end
  value
end

#explicit_sign(i) ⇒ Object



26
27
28
# File 'lib/bcdice/game_system/AFF2e.rb', line 26

def explicit_sign(i)
  format('%+d', i)
end

#parentheses(str) ⇒ Object



38
39
40
# File 'lib/bcdice/game_system/AFF2e.rb', line 38

def parentheses(str)
  '(' + str + ')'
end

#successful_or_failed(total, diff) ⇒ Object



42
43
44
45
46
47
48
49
50
51
# File 'lib/bcdice/game_system/AFF2e.rb', line 42

def successful_or_failed(total, diff)
  case total
  when  2
    diff <=  1 ? '成功(大成功ではない)' : '大成功!'
  when 12
    diff >= 12 ? '失敗(大失敗ではない)' : '大失敗!'
  else
    total <= diff ? '成功' : '失敗'
  end
end