Class: BCDice::GameSystem::OracleEngine
- Inherits:
-
Base
- Object
- Base
- BCDice::GameSystem::OracleEngine
show all
- Defined in:
- lib/bcdice/game_system/OracleEngine.rb
Constant Summary
collapse
- ID =
'OracleEngine'
- NAME =
'オラクルエンジン'
- SORT_KEY =
'おらくるえんしん'
- HELP_MESSAGE =
" \u30FB\u30AF\u30E9\u30C3\u30C1\u30ED\u30FC\u30EB \uFF08xCL+y>=z)\n \u30C0\u30A4\u30B9\u3092x\u500B\u632F\u308A\u30011\u500B\u4EE5\u4E0A\u76EE\u6A19\u30B7\u30D5\u30C8z\u306B\u5230\u9054\u3057\u305F\u304B\u5224\u5B9A\u3057\u307E\u3059\u3002\u4FEE\u6B63y\u306F\u5168\u3066\u306E\u30C0\u30A4\u30B9\u306B\u304B\u304B\u308A\u307E\u3059\u3002\n \u6210\u529F\u3057\u305F\u6642\u306F\u76EE\u6A19\u30B7\u30D5\u30C8\u3092\u3001\u5931\u6557\u3057\u305F\u6642\u306F\u30C0\u30A4\u30B9\u306E\u6700\u5927\u5024-1\u30B7\u30D5\u30C8\u3092\u8FD4\u3057\u307E\u3059\n z\u304C\u6307\u5B9A\u3055\u308C\u306A\u3044\u3068\u304D\u306F\u3001\u30C0\u30A4\u30B9\u3092x\u500B\u3092\u632F\u308A\u3001\u305D\u308C\u306B\u4FEE\u6B63y\u3057\u305F\u3082\u306E\u3092\u8FD4\u3057\u307E\u3059\u3002\n \u901A\u5E38\u3001\u6700\u4F4E\u30B7\u30D5\u30C8\u306F1\u3001\u6700\u5927\u30B7\u30D5\u30C8\u306F6\u3067\u3059\u3002\u76EE\u6A19\u30B7\u30D5\u30C8\u3082\u305D\u308D\u3048\u3089\u308C\u307E\u3059\u3002\n \u307E\u305F\u3001CL\u306E\u5F8C\u306B7\u3092\u5165\u308C\u3001(xCL7+y>=z)\u3068\u5165\u529B\u3059\u308B\u3068\u6700\u5927\u30B7\u30D5\u30C8\u304C7\u306B\u306A\u308A\u307E\u3059\u3002\n \u30FB\u5224\u5B9A (xR6+y@c#f$b>=z)\n \u30C0\u30A4\u30B9\u3092x\u500B\u632F\u308A\u3001\u5927\u304D\u3044\u3082\u306E2\u3064\u3060\u3051\u3092\u898B\u3066\u9054\u6210\u5024\u3092\u7B97\u51FA\u3057\u3001\u6210\u5426\u3092\u5224\u5B9A\u3057\u307E\u3059\u3002\u4FEE\u6B63y\u306F\u9054\u6210\u5024\u306B\u304B\u304B\u308A\u307E\u3059\u3002\n \u30C0\u30A4\u30B9\u30D6\u30EC\u30A4\u30AF\u3068\u3057\u3066b\u3092\u3001\u30AF\u30EA\u30C6\u30A3\u30AB\u30EB\u5024\u3068\u3057\u3066c\u3092\u3001\u30D5\u30A1\u30F3\u30D6\u30EB\u5024\u3068\u3057\u3066f\u3092\u6307\u5B9A\u3067\u304D\u307E\u3059\u3002\n \u305D\u308C\u305E\u308C\u6307\u5B9A\u3055\u308C\u306A\u3044\u6642\u30010,12,2\u306B\u306A\u308A\u307E\u3059\u3002\n \u30AF\u30EA\u30C6\u30A3\u30AB\u30EB\u5024\u306E\u4E0A\u9650\u306F\u306A\u3057\u3001\u4E0B\u9650\u306F2\u3002\u30D5\u30A1\u30F3\u30D6\u30EB\u5024\u306E\u4E0A\u9650\u306F12\u3001\u4E0B\u9650\u306F0\u3002\n z\u304C\u6307\u5B9A\u3055\u308C\u306A\u3044\u3068\u304D\u3001\u9054\u6210\u5024\u306E\u7B97\u51FA\u306E\u307F\u884C\u3044\u307E\u3059\u3002\n \u30FB\u30C0\u30E1\u30FC\u30B8\u30ED\u30FC\u30EB\u306E\u30C0\u30A4\u30B9\u30D6\u30EC\u30A4\u30AF (xD6+y$b)\n \u30C0\u30A4\u30B9\u3092x\u500B\u632F\u308A\u3001\u5408\u8A08\u5024\u3092\u51FA\u3057\u307E\u3059\u3002\u4FEE\u6B63y\u306F\u5408\u8A08\u5024\u306B\u304B\u304B\u308A\u307E\u3059\u3002\n \u30C0\u30A4\u30B9\u30D6\u30EC\u30A4\u30AF\u3068\u3057\u3066b\u3092\u6307\u5B9A\u3057\u307E\u3059\u3002\u5408\u8A08\u5024\u306F0\u672A\u6E80\u306B\u306A\u308A\u307E\u305B\u3093\u3002\n"
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
Returns a new instance of OracleEngine.
39
40
41
42
43
|
# File 'lib/bcdice/game_system/OracleEngine.rb', line 39
def initialize(command)
super(command)
@sort_add_dice = true
@sort_barabara_dice = true
end
|
Instance Method Details
#clamp(i, min, max) ⇒ Object
108
109
110
111
112
113
114
115
116
|
# File 'lib/bcdice/game_system/OracleEngine.rb', line 108
def clamp(i, min, max)
if i < min
min
elsif i > max
max
else
i
end
end
|
#clutch_roll(string) ⇒ Object
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
|
# File 'lib/bcdice/game_system/OracleEngine.rb', line 57
def clutch_roll(string)
debug("clutch_roll begin", string)
parser = Command::Parser.new(/\d+CL[67]?/, round_type: round_type)
.restrict_cmp_op_to(nil, :>=)
@cmd = parser.parse(string)
unless @cmd
return nil
end
@times, @max_shift = @cmd.command.split("CL").map(&:to_i)
@max_shift ||= 6
@cmd.target_number = clamp(@cmd.target_number, 1, @max_shift) if @cmd.cmp_op
if @times == 0
return nil
end
dice_list = @randomizer.roll_barabara(@times, 6).map { |x| clamp(x + @cmd.modify_number, 1, @max_shift) }.sort
sequence = [
expr_clutch(),
"[#{dice_list.join(', ')}]",
result_clutch(dice_list.last)
]
return sequence.join(' > ')
end
|
#damage_roll(string) ⇒ Object
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
|
# File 'lib/bcdice/game_system/OracleEngine.rb', line 213
def damage_roll(string)
parser = Command::Parser.new(/\d+D6/, round_type: round_type)
.restrict_cmp_op_to(nil)
.enable_dollar
@cmd = parser.parse(string)
return nil unless @cmd
@times = @cmd.command.to_i
@break = (@cmd.dollar || 0).abs
if @times == 0
return nil
end
dice_list = @randomizer.roll_barabara(@times, 6).sort
dice_broken = dice_list.pop(@break)
total_n = dice_list.inject(0, :+) + @cmd.modify_number
total_n = 0 if total_n < 0
sequence = [
expr_damage(),
result_damage(dice_list, dice_broken),
total_n
]
return sequence.join(' > ')
end
|
#dice_result_r(dice_total, dice_list, break_list) ⇒ Object
166
167
168
169
170
171
172
173
174
|
# File 'lib/bcdice/game_system/OracleEngine.rb', line 166
def dice_result_r(dice_total, dice_list, break_list)
modify_number_text = Format.modifier(@cmd.modify_number)
if break_list.empty?
"#{dice_total}[#{dice_list.join(', ')}]#{modify_number_text}"
else
"#{dice_total}[#{dice_list.join(', ')}]×[#{break_list.join(', ')}]#{modify_number_text}"
end
end
|
#eval_game_system_specific_command(command) ⇒ Object
45
46
47
48
49
50
51
52
53
54
|
# File 'lib/bcdice/game_system/OracleEngine.rb', line 45
def eval_game_system_specific_command(command)
case command
when /\d+CL.*/i
clutch_roll(command)
when /\d+D6.*\$[+\-]?\d.*/
damage_roll(command)
when /\d+R6/
r_roll(command)
end
end
|
#expr_clutch ⇒ Object
88
89
90
91
92
93
94
|
# File 'lib/bcdice/game_system/OracleEngine.rb', line 88
def expr_clutch()
max_shift = @max_shift == 7 ? 7 : nil
cmp_op = Format.comparison_operator(@cmd.cmp_op)
modify_number = Format.modifier(@cmd.modify_number)
"(#{@times}CL#{max_shift}#{modify_number}#{cmp_op}#{@cmd.target_number})"
end
|
#expr_damage ⇒ Object
242
243
244
245
246
247
|
# File 'lib/bcdice/game_system/OracleEngine.rb', line 242
def expr_damage()
modify_number = Format.modifier(@cmd.modify_number)
brak = @break == 0 ? "" : "b[#{@break}]"
"(#{@times}D6#{modify_number}#{brak})"
end
|
#expr_r ⇒ Object
156
157
158
159
160
161
162
163
164
|
# File 'lib/bcdice/game_system/OracleEngine.rb', line 156
def expr_r()
modify_number = Format.modifier(@cmd.modify_number)
critical = @critical == 12 ? "" : "c[#{@critical}]"
fumble = @fumble == 2 ? "" : "f[#{@fumble}]"
brak = @break == 0 ? "" : "b[#{@break}]"
cmp_op = Format.comparison_operator(@cmd.cmp_op)
"(#{@times}R6#{modify_number}#{critical}#{fumble}#{brak}#{cmp_op}#{@cmd.target_number})"
end
|
#normalize_critical(critical, string) ⇒ Object
192
193
194
195
196
197
198
199
200
201
202
|
# File 'lib/bcdice/game_system/OracleEngine.rb', line 192
def normalize_critical(critical, string)
if /@[+-]/.match(string)
critical = 12 + critical
end
if critical < 2
critical = 2
end
return critical
end
|
#normalize_fumble(fumble, string) ⇒ Object
204
205
206
207
208
209
210
|
# File 'lib/bcdice/game_system/OracleEngine.rb', line 204
def normalize_fumble(fumble, string)
if /#[+-]/.match(string)
fumble = 2 + fumble
end
return clamp(fumble, 0, 12)
end
|
#r_roll(string) ⇒ Object
119
120
121
122
123
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
|
# File 'lib/bcdice/game_system/OracleEngine.rb', line 119
def r_roll(string)
parser = Command::Parser.new(/\d+R6/, round_type: round_type)
.restrict_cmp_op_to(nil, :>=)
.enable_critical
.enable_fumble
.enable_dollar
@cmd = parser.parse(string)
unless @cmd
return nil
end
@times = @cmd.command.to_i
if @times == 0
return nil
end
@critical = normalize_critical(@cmd.critical || 12, string)
@fumble = normalize_fumble(@cmd.fumble || 2, string)
@break = (@cmd.dollar || 0).abs
dice_list = @randomizer.roll_barabara(@times, 6).sort
dice_broken = dice_list.pop(@break)
dice_total = dice_list.dup.pop(2).inject(0, :+)
total = dice_total + @cmd.modify_number
sequence = [
expr_r(),
dice_result_r(dice_total, dice_list, dice_broken),
result_r(dice_total, total)
]
return sequence.join(' > ')
end
|
#result_clutch(after_shift) ⇒ Object
96
97
98
99
100
101
102
103
104
105
106
|
# File 'lib/bcdice/game_system/OracleEngine.rb', line 96
def result_clutch(after_shift)
if @cmd.cmp_op != :>=
"シフト#{after_shift}"
elsif after_shift >= @cmd.target_number
"成功 シフト#{@cmd.target_number}"
else
after_shift -= 1
after_shift = 1 if after_shift < 1
"失敗 シフト#{after_shift}"
end
end
|
#result_damage(dice_list, break_list) ⇒ Object
249
250
251
252
253
254
255
256
257
258
|
# File 'lib/bcdice/game_system/OracleEngine.rb', line 249
def result_damage(dice_list, break_list)
dice_total = dice_list.inject(0, :+)
modify_number_text = Format.modifier(@cmd.modify_number)
if break_list.empty?
"#{dice_total}[#{dice_list.join(', ')}]#{modify_number_text}"
else
"#{dice_total}[#{dice_list.join(', ')}]×[#{break_list.join(', ')}]#{modify_number_text}"
end
end
|
#result_r(dice_total, total) ⇒ Object
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
|
# File 'lib/bcdice/game_system/OracleEngine.rb', line 176
def result_r(dice_total, total)
if dice_total <= @fumble
"ファンブル!"
elsif dice_total >= @critical
"クリティカル!"
elsif @cmd.cmp_op == :>=
if total >= @cmd.target_number
"#{total} 成功"
else
"#{total} 失敗"
end
else
total.to_s
end
end
|