mgmg 1.4.1 → 1.4.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/README.md +12 -2
- data/lib/mgmg/cuisine.rb +140 -0
- data/lib/mgmg/ir.rb +407 -373
- data/lib/mgmg/poly.rb +2 -2
- data/lib/mgmg/reinforce.rb +70 -0
- data/lib/mgmg/search.rb +21 -21
- data/lib/mgmg/utils.rb +25 -0
- data/lib/mgmg/version.rb +1 -1
- data/lib/mgmg.rb +29 -13
- data/reference.md +100 -15
- metadata +5 -3
data/lib/mgmg/ir.rb
CHANGED
@@ -1,373 +1,407 @@
|
|
1
|
-
module Mgmg
|
2
|
-
using Refiner
|
3
|
-
class IR
|
4
|
-
class Const
|
5
|
-
def initialize(value)
|
6
|
-
@value = value
|
7
|
-
end
|
8
|
-
attr_accessor :value
|
9
|
-
def initialize_copy(other)
|
10
|
-
@value = other.value
|
11
|
-
end
|
12
|
-
def evaluate(s, c)
|
13
|
-
@value
|
14
|
-
end
|
15
|
-
def evaluate3(s, a, c)
|
16
|
-
@value
|
17
|
-
end
|
18
|
-
def to_s
|
19
|
-
@value.to_s
|
20
|
-
end
|
21
|
-
end
|
22
|
-
class Smith
|
23
|
-
def initialize(sub9, coef, den, sa=nil)
|
24
|
-
@sub9, @coef, @den, @sa = sub9, coef, den, sa
|
25
|
-
end
|
26
|
-
attr_accessor :sub9, :coef, :den, :sa
|
27
|
-
def initialize_copy(other)
|
28
|
-
@sub9, @coef, @den, @sa = other.sub9, other.coef, other.den, other.sa
|
29
|
-
end
|
30
|
-
def evaluate(s, c)
|
31
|
-
((s+@sub9)*@coef).div(@den)
|
32
|
-
end
|
33
|
-
def evaluate3(s, a, c)
|
34
|
-
if sa==:a
|
35
|
-
((a+@sub9)*@coef).div(@den)
|
36
|
-
else
|
37
|
-
((s+@sub9)*@coef).div(@den)
|
38
|
-
end
|
39
|
-
end
|
40
|
-
def to_s
|
41
|
-
if sa==:a
|
42
|
-
"[#{@coef}(a+#{@sub9})/#{den}]"
|
43
|
-
else
|
44
|
-
"[#{@coef}(s+#{@sub9})/#{den}]"
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
48
|
-
class Compose
|
49
|
-
def initialize(main, sub, equip9, coef, den)
|
50
|
-
@main, @sub, @equip9, @coef, @den = main, sub, equip9, coef, den
|
51
|
-
end
|
52
|
-
attr_accessor :main, :sub, :equip9, :coef, :den
|
53
|
-
def initialize_copy(other)
|
54
|
-
@main, @sub = other.main.dup, other.sub.dup
|
55
|
-
@equip9, @coef, @den = other.equip9, other.coef, other.den
|
56
|
-
end
|
57
|
-
def evaluate(s, c)
|
58
|
-
@main.evaluate(s, c) + ( ( @sub.evaluate(s, c) * (c+@equip9).div(2) ).cdiv(100) * @coef ).cdiv(@den)
|
59
|
-
end
|
60
|
-
def evaluate3(s, a, c)
|
61
|
-
@main.evaluate3(s, a, c) + ( ( @sub.evaluate3(s, a, c) * (c+@equip9).div(2) ).cdiv(100) * @coef ).cdiv(@den)
|
62
|
-
end
|
63
|
-
def to_s
|
64
|
-
ms, ss = @main.to_s, @sub.to_s
|
65
|
-
if ss == '0'
|
66
|
-
ms
|
67
|
-
else
|
68
|
-
if ms == '0'
|
69
|
-
"[[#{ss}[(c+#{@equip9})/2]/100]/#{@den}]"
|
70
|
-
else
|
71
|
-
"#{ms}+[[#{ss}[(c+#{@equip9})/2]/100]/#{@den}]"
|
72
|
-
end
|
73
|
-
end
|
74
|
-
end
|
75
|
-
end
|
76
|
-
class Multi
|
77
|
-
def initialize(body)
|
78
|
-
@body = body
|
79
|
-
end
|
80
|
-
attr_accessor :body
|
81
|
-
def initialize_copy(other)
|
82
|
-
@body = other.body.dup
|
83
|
-
end
|
84
|
-
def evaluate(s, c)
|
85
|
-
@body.sum do |e|
|
86
|
-
e.evaluate(s, c)
|
87
|
-
end
|
88
|
-
end
|
89
|
-
def evaluate3(s, a, c)
|
90
|
-
@body.sum do |e|
|
91
|
-
e.evaluate3(s, a, c)
|
92
|
-
end
|
93
|
-
end
|
94
|
-
def to_s
|
95
|
-
@body.map(&:to_s).join('+')
|
96
|
-
end
|
97
|
-
end
|
98
|
-
class << Multi
|
99
|
-
def sum(a, b)
|
100
|
-
unconsts, const = [], Const.new(0)
|
101
|
-
case a
|
102
|
-
when Multi
|
103
|
-
if a.body[0].kind_of?(Const)
|
104
|
-
const.value += a.body[0].value
|
105
|
-
unconsts = a.body[1..(-1)]
|
106
|
-
else
|
107
|
-
unconsts = a.body.dup
|
108
|
-
end
|
109
|
-
when Const
|
110
|
-
const.value += a.value
|
111
|
-
else
|
112
|
-
unconsts << a
|
113
|
-
end
|
114
|
-
case b
|
115
|
-
when Multi
|
116
|
-
if b.body[0].kind_of?(Const)
|
117
|
-
const.value += b.body[0].value
|
118
|
-
unconsts.concat(b.body[1..(-1)])
|
119
|
-
else
|
120
|
-
unconsts.concat(b.body)
|
121
|
-
end
|
122
|
-
when Const
|
123
|
-
const.value += b.value
|
124
|
-
else
|
125
|
-
unconsts << b
|
126
|
-
end
|
127
|
-
body = ( const.value == 0 ? unconsts : [const, *unconsts] )
|
128
|
-
case body.size
|
129
|
-
when 0
|
130
|
-
const
|
131
|
-
when 1
|
132
|
-
body[0]
|
133
|
-
else
|
134
|
-
new(body)
|
135
|
-
end
|
136
|
-
end
|
137
|
-
end
|
138
|
-
def initialize(kind, star, main_m, sub_m, para)
|
139
|
-
@kind, @star, @main, @sub, @para = kind, star, main_m, sub_m, para
|
140
|
-
|
141
|
-
|
142
|
-
def
|
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
|
-
end
|
182
|
-
end
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
end
|
201
|
-
def
|
202
|
-
|
203
|
-
end
|
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
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
end
|
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
|
-
|
273
|
-
|
274
|
-
|
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
|
-
end
|
340
|
-
def
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
end
|
1
|
+
module Mgmg
|
2
|
+
using Refiner
|
3
|
+
class IR
|
4
|
+
class Const
|
5
|
+
def initialize(value)
|
6
|
+
@value = value
|
7
|
+
end
|
8
|
+
attr_accessor :value
|
9
|
+
def initialize_copy(other)
|
10
|
+
@value = other.value
|
11
|
+
end
|
12
|
+
def evaluate(s, c)
|
13
|
+
@value
|
14
|
+
end
|
15
|
+
def evaluate3(s, a, c)
|
16
|
+
@value
|
17
|
+
end
|
18
|
+
def to_s
|
19
|
+
@value.to_s
|
20
|
+
end
|
21
|
+
end
|
22
|
+
class Smith
|
23
|
+
def initialize(sub9, coef, den, sa=nil)
|
24
|
+
@sub9, @coef, @den, @sa = sub9, coef, den, sa
|
25
|
+
end
|
26
|
+
attr_accessor :sub9, :coef, :den, :sa
|
27
|
+
def initialize_copy(other)
|
28
|
+
@sub9, @coef, @den, @sa = other.sub9, other.coef, other.den, other.sa
|
29
|
+
end
|
30
|
+
def evaluate(s, c)
|
31
|
+
((s+@sub9)*@coef).div(@den)
|
32
|
+
end
|
33
|
+
def evaluate3(s, a, c)
|
34
|
+
if sa==:a
|
35
|
+
((a+@sub9)*@coef).div(@den)
|
36
|
+
else
|
37
|
+
((s+@sub9)*@coef).div(@den)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
def to_s
|
41
|
+
if sa==:a
|
42
|
+
"[#{@coef}(a+#{@sub9})/#{den}]"
|
43
|
+
else
|
44
|
+
"[#{@coef}(s+#{@sub9})/#{den}]"
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
class Compose
|
49
|
+
def initialize(main, sub, equip9, coef, den)
|
50
|
+
@main, @sub, @equip9, @coef, @den = main, sub, equip9, coef, den
|
51
|
+
end
|
52
|
+
attr_accessor :main, :sub, :equip9, :coef, :den
|
53
|
+
def initialize_copy(other)
|
54
|
+
@main, @sub = other.main.dup, other.sub.dup
|
55
|
+
@equip9, @coef, @den = other.equip9, other.coef, other.den
|
56
|
+
end
|
57
|
+
def evaluate(s, c)
|
58
|
+
@main.evaluate(s, c) + ( ( @sub.evaluate(s, c) * (c+@equip9).div(2) ).cdiv(100) * @coef ).cdiv(@den)
|
59
|
+
end
|
60
|
+
def evaluate3(s, a, c)
|
61
|
+
@main.evaluate3(s, a, c) + ( ( @sub.evaluate3(s, a, c) * (c+@equip9).div(2) ).cdiv(100) * @coef ).cdiv(@den)
|
62
|
+
end
|
63
|
+
def to_s
|
64
|
+
ms, ss = @main.to_s, @sub.to_s
|
65
|
+
if ss == '0'
|
66
|
+
ms
|
67
|
+
else
|
68
|
+
if ms == '0'
|
69
|
+
"[[#{ss}[(c+#{@equip9})/2]/100]/#{@den}]"
|
70
|
+
else
|
71
|
+
"#{ms}+[[#{ss}[(c+#{@equip9})/2]/100]/#{@den}]"
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
class Multi
|
77
|
+
def initialize(body)
|
78
|
+
@body = body
|
79
|
+
end
|
80
|
+
attr_accessor :body
|
81
|
+
def initialize_copy(other)
|
82
|
+
@body = other.body.dup
|
83
|
+
end
|
84
|
+
def evaluate(s, c)
|
85
|
+
@body.sum do |e|
|
86
|
+
e.evaluate(s, c)
|
87
|
+
end
|
88
|
+
end
|
89
|
+
def evaluate3(s, a, c)
|
90
|
+
@body.sum do |e|
|
91
|
+
e.evaluate3(s, a, c)
|
92
|
+
end
|
93
|
+
end
|
94
|
+
def to_s
|
95
|
+
@body.map(&:to_s).join('+')
|
96
|
+
end
|
97
|
+
end
|
98
|
+
class << Multi
|
99
|
+
def sum(a, b)
|
100
|
+
unconsts, const = [], Const.new(0)
|
101
|
+
case a
|
102
|
+
when Multi
|
103
|
+
if a.body[0].kind_of?(Const)
|
104
|
+
const.value += a.body[0].value
|
105
|
+
unconsts = a.body[1..(-1)]
|
106
|
+
else
|
107
|
+
unconsts = a.body.dup
|
108
|
+
end
|
109
|
+
when Const
|
110
|
+
const.value += a.value
|
111
|
+
else
|
112
|
+
unconsts << a
|
113
|
+
end
|
114
|
+
case b
|
115
|
+
when Multi
|
116
|
+
if b.body[0].kind_of?(Const)
|
117
|
+
const.value += b.body[0].value
|
118
|
+
unconsts.concat(b.body[1..(-1)])
|
119
|
+
else
|
120
|
+
unconsts.concat(b.body)
|
121
|
+
end
|
122
|
+
when Const
|
123
|
+
const.value += b.value
|
124
|
+
else
|
125
|
+
unconsts << b
|
126
|
+
end
|
127
|
+
body = ( const.value == 0 ? unconsts : [const, *unconsts] )
|
128
|
+
case body.size
|
129
|
+
when 0
|
130
|
+
const
|
131
|
+
when 1
|
132
|
+
body[0]
|
133
|
+
else
|
134
|
+
new(body)
|
135
|
+
end
|
136
|
+
end
|
137
|
+
end
|
138
|
+
def initialize(kind, star, main_m, sub_m, para, rein=[])
|
139
|
+
@kind, @star, @main, @sub, @para = kind, star, main_m, sub_m, para
|
140
|
+
add_reinforcement(rein)
|
141
|
+
end
|
142
|
+
def add_reinforcement(rein)
|
143
|
+
@rein = if rein.kind_of?(Array)
|
144
|
+
rein.map do |r|
|
145
|
+
Reinforcement.compile(r)
|
146
|
+
end
|
147
|
+
else
|
148
|
+
[Reinforcement.compile(rein)]
|
149
|
+
end
|
150
|
+
self
|
151
|
+
end
|
152
|
+
attr_accessor :kind, :star, :main, :sub, :para, :rein
|
153
|
+
def initialize_copy(other)
|
154
|
+
@kind = other.kind
|
155
|
+
@star = other.star
|
156
|
+
@main = other.main
|
157
|
+
@sub = other.sub
|
158
|
+
@para = other.para.dup
|
159
|
+
@rein = other.rein.dup
|
160
|
+
end
|
161
|
+
|
162
|
+
def compose(other)
|
163
|
+
self.class.compose(self, other)
|
164
|
+
end
|
165
|
+
|
166
|
+
def to_s
|
167
|
+
par = @para.map.with_index{|e, i| e.to_s=='0' ? nil : "#{Mgmg::Equip::ParamList[i]}:#{e.to_s}"}.compact
|
168
|
+
if @kind == 28
|
169
|
+
ep = @star.map.with_index{|e, i| e==0 ? nil : "#{Mgmg::Equip::EqPosList[i]}:#{e}"}.compact
|
170
|
+
"複数装備(#{ep.join(', ')})<#{par.join(', ')}>#{@rein.empty? ? '' : '{'+@rein.join(',')+'}'}"
|
171
|
+
else
|
172
|
+
"#{EquipName[@kind]}☆#{@star}(#{MaterialClass[@main]}#{MaterialClass[@sub]})<#{par.join(', ')}>#{@rein.empty? ? '' : '{'+@rein.join(',')+'}'}"
|
173
|
+
end
|
174
|
+
end
|
175
|
+
|
176
|
+
def para_call(para, s, ac, x=nil)
|
177
|
+
if x.nil?
|
178
|
+
method(para).call(s, ac)
|
179
|
+
else
|
180
|
+
method(para).call(s, ac, x)
|
181
|
+
end
|
182
|
+
end
|
183
|
+
|
184
|
+
%i|attack phydef magdef hp mp str dex speed magic|.each.with_index do |sym, i|
|
185
|
+
define_method(sym) do |s=nil, ac=s, x=nil|
|
186
|
+
ret = if s.nil?
|
187
|
+
@para[i]
|
188
|
+
elsif x.nil?
|
189
|
+
@para[i].evaluate(s, ac)
|
190
|
+
else
|
191
|
+
@para[i].evaluate3(s, ac, x)
|
192
|
+
end
|
193
|
+
@rein.each do |r|
|
194
|
+
if r.vec[i] != 0
|
195
|
+
ret *= (100+r.vec[i]).quo(100)
|
196
|
+
end
|
197
|
+
end
|
198
|
+
ret
|
199
|
+
end
|
200
|
+
end
|
201
|
+
def atkstr(s, ac, x=nil)
|
202
|
+
attack(s, ac, x)+str(s, ac, x)
|
203
|
+
end
|
204
|
+
def atk_sd(s, ac, x=nil)
|
205
|
+
attack(s, ac, x)+str(s, ac, x).quo(2)+dex(s, ac, x).quo(2)
|
206
|
+
end
|
207
|
+
def dex_as(s, ac, x=nil)
|
208
|
+
attack(s, ac, x).quo(2)+str(s, ac, x).quo(2)+dex(s, ac, x)
|
209
|
+
end
|
210
|
+
def mag_das(s, ac, x=nil)
|
211
|
+
magic(s, ac, x)+dex_as(s, ac, x).quo(2)
|
212
|
+
end
|
213
|
+
def magic2(s, ac, x=nil)
|
214
|
+
magic(s, ac, x)*2
|
215
|
+
end
|
216
|
+
def magmag(s, ac, x=nil)
|
217
|
+
magdef(s, ac, x)+magic(s, ac, x).quo(2)
|
218
|
+
end
|
219
|
+
def pmdef(s, ac, x=nil)
|
220
|
+
[phydef(s, ac, x), magmag(s, ac, x)].min
|
221
|
+
end
|
222
|
+
|
223
|
+
def power(s, a=s, c=a.tap{a=s})
|
224
|
+
case @kind
|
225
|
+
when 0, 1
|
226
|
+
atk_sd(s, c)
|
227
|
+
when 2, 3
|
228
|
+
atkstr(s, c)
|
229
|
+
when 4
|
230
|
+
[dex_as(s, c), mag_das(s, c)].max
|
231
|
+
when 5
|
232
|
+
dex_as(s, c)
|
233
|
+
when 6, 7
|
234
|
+
[magic(s, c)*2, atkstr(s, c)].max
|
235
|
+
when 28
|
236
|
+
@para.enum_for(:sum).with_index do |e, i|
|
237
|
+
x = e.evaluate3(s, a, c)
|
238
|
+
@rein.each do |r|
|
239
|
+
if r.vec[i] != 0
|
240
|
+
x *= (100+r.vec[i]).quo(100)
|
241
|
+
end
|
242
|
+
end
|
243
|
+
x
|
244
|
+
end-((hp(s, a, c)+mp(s, a, c))*3.quo(4))
|
245
|
+
else
|
246
|
+
ret = @para.map.with_index do |e, i|
|
247
|
+
x = e.evaluate3(s, a, c)
|
248
|
+
@rein.each do |r|
|
249
|
+
if r.vec[i] != 0
|
250
|
+
x *= (100+r.vec[i]).quo(100)
|
251
|
+
end
|
252
|
+
end
|
253
|
+
x
|
254
|
+
end.max
|
255
|
+
if ret == magdef(s, a, c)
|
256
|
+
ret+magic(s, a, c).quo(2)
|
257
|
+
else
|
258
|
+
ret
|
259
|
+
end
|
260
|
+
end
|
261
|
+
end
|
262
|
+
def fpower(s, a=s, c=a.tap{a=s})
|
263
|
+
power(s, a, c).to_f
|
264
|
+
end
|
265
|
+
|
266
|
+
def smith_cost(s, c=s, outsourcing=false)
|
267
|
+
if outsourcing
|
268
|
+
if @kind < 8
|
269
|
+
(@star**2)*2+@para.sum{|e| e.evaluate(s, c)}+hp(s, c).cdiv(4)-hp(s, c)+mp(s, c).cdiv(4)-mp(s, c)
|
270
|
+
else
|
271
|
+
(@star**2)+@para.sum{|e| e.evaluate(s, c)}+hp(s, c).cdiv(4)-hp(s, c)+mp(s, c).cdiv(4)-mp(s, c)
|
272
|
+
end
|
273
|
+
else
|
274
|
+
if @kind < 8
|
275
|
+
((@star**2)*2+@para.sum{|e| e.evaluate(s, c)}+hp(s, c).cdiv(4)-hp(s, c)+mp(s, c).cdiv(4)-mp(s, c)).div(2)
|
276
|
+
else
|
277
|
+
((@star**2)+@para.sum{|e| e.evaluate(s, c)}+hp(s, c).cdiv(4)-hp(s, c)+mp(s, c).cdiv(4)-mp(s, c)).div(2)
|
278
|
+
end
|
279
|
+
end
|
280
|
+
end
|
281
|
+
def comp_cost(s, c=s, outsourcing=false)
|
282
|
+
if outsourcing
|
283
|
+
[(@star**2)*5+@para.sum{|e| e.evaluate(s, c)}+hp().cdiv(4)-hp()+mp().cdiv(4)-mp(), 0].max.div(2)
|
284
|
+
else
|
285
|
+
[((@star**2)*5+@para.sum{|e| e.evaluate(s, c)}+hp().cdiv(4)-hp()+mp().cdiv(4)-mp()).div(2), 0].max.div(2)
|
286
|
+
end
|
287
|
+
end
|
288
|
+
alias :cost :comp_cost
|
289
|
+
|
290
|
+
def add!(other)
|
291
|
+
if @kind == 28
|
292
|
+
if other.kind == 28
|
293
|
+
@star.add!(other.star)
|
294
|
+
else
|
295
|
+
@star[EquipPosition[other.kind]] += 1
|
296
|
+
end
|
297
|
+
else
|
298
|
+
@star = Vec.new(6, 0)
|
299
|
+
@star[EquipPosition[@kind]] = 1
|
300
|
+
@kind = 28
|
301
|
+
if other.kind == 28
|
302
|
+
@star.add!(other.star)
|
303
|
+
else
|
304
|
+
@star[EquipPosition[other.kind]] += 1
|
305
|
+
end
|
306
|
+
end
|
307
|
+
@main, @sub = 12, 12
|
308
|
+
@para = Array.new(9) do |i|
|
309
|
+
Multi.sum(self.para[i], other.para[i])
|
310
|
+
end
|
311
|
+
self
|
312
|
+
end
|
313
|
+
def +(other)
|
314
|
+
self.dup.add!(other)
|
315
|
+
end
|
316
|
+
def coerce(other)
|
317
|
+
if other == 0
|
318
|
+
zero = self.class.new(28, Vec.new(6, 0), 12, 12, Array.new(9){Const.new(0)})
|
319
|
+
[zero, self]
|
320
|
+
else
|
321
|
+
raise TypeError, "Mgmg::IR can't be coerced into other than 0"
|
322
|
+
end
|
323
|
+
end
|
324
|
+
end
|
325
|
+
class << IR
|
326
|
+
def build(str, left_associative: true, reinforcement: [])
|
327
|
+
str = Mgmg.check_string(str)
|
328
|
+
stack, str = build_sub0([], str)
|
329
|
+
build_sub(stack, str, left_associative).add_reinforcement(reinforcement)
|
330
|
+
end
|
331
|
+
private def build_sub0(stack, str)
|
332
|
+
SystemEquip.each do |k, v|
|
333
|
+
if Regexp.compile(k).match(str)
|
334
|
+
stack << from_equip(v)
|
335
|
+
str = str.gsub(k, "<#{stack.length-1}>")
|
336
|
+
end
|
337
|
+
end
|
338
|
+
[stack, str]
|
339
|
+
end
|
340
|
+
private def build_sub(stack, str, lassoc)
|
341
|
+
if m = /\A(.*\+?)\[([^\[\]]+)\](\+?[^\[]*)\Z/.match(str)
|
342
|
+
stack << build_sub(stack, m[2], lassoc)
|
343
|
+
build_sub(stack, "#{m[1]}<#{stack.length-1}>#{m[3]}", lassoc)
|
344
|
+
elsif m = ( lassoc ? /\A(.+)\+(.+?)\Z/ : /\A(.+?)\+(.+)\Z/ ).match(str)
|
345
|
+
compose(build_sub(stack, m[1], lassoc), build_sub(stack, m[2], lassoc))
|
346
|
+
elsif m = /\A\<(\d+)\>\Z/.match(str)
|
347
|
+
stack[m[1].to_i]
|
348
|
+
else
|
349
|
+
smith(str)
|
350
|
+
end
|
351
|
+
end
|
352
|
+
|
353
|
+
def compose(main, sub)
|
354
|
+
main_k, sub_k = main.kind, sub.kind
|
355
|
+
main_s, sub_s = main.star, sub.star
|
356
|
+
main_main, sub_main = main.main, sub.main
|
357
|
+
main_sub, sub_sub = main.sub, sub.sub
|
358
|
+
|
359
|
+
coef = Equip9[main_k].dup
|
360
|
+
coef.sub!(Equip9[sub_k])
|
361
|
+
coef.add!( 100 + (main_s-sub_s)*5 - ( ( main_main==sub_main && main_main != 9 ) ? 30 : 0 ) )
|
362
|
+
coef.add!(Material9[main_main]).sub!(Material9[sub_main])
|
363
|
+
den = ( main_k==sub_k ? 200 : 100 )
|
364
|
+
para = Array.new(9) do |i|
|
365
|
+
if EquipFilter[main_k][i] == 0
|
366
|
+
main.para[i]
|
367
|
+
else
|
368
|
+
Mgmg::IR::Compose.new(main.para[i], sub.para[i], Equip9[main_k][i], coef[i], den)
|
369
|
+
end
|
370
|
+
end
|
371
|
+
|
372
|
+
new(main_k, main_s+sub_s, main_sub, sub_main, para)
|
373
|
+
end
|
374
|
+
def smith(str)
|
375
|
+
str = Mgmg.check_string(str)
|
376
|
+
unless m = /\A(.+)\((.+\d+),?(.+\d+)\)\Z/.match(str)
|
377
|
+
raise InvalidSmithError.new(str)
|
378
|
+
end
|
379
|
+
kind = EquipIndex[m[1].to_sym]
|
380
|
+
unless kind
|
381
|
+
raise InvalidEquipClassError.new(m[1])
|
382
|
+
end
|
383
|
+
main_m, main_s, main_mc = Mgmg.parse_material(m[2])
|
384
|
+
sub_m, sub_s, sub_mc = Mgmg.parse_material(m[3])
|
385
|
+
sa = ( Mgmg::EquipPosition[kind] == 0 ? :s : :a )
|
386
|
+
|
387
|
+
coef = Equip9[kind].dup
|
388
|
+
coef.e_mul!(Main9[main_m]).e_div!(100)
|
389
|
+
den = ( main_mc==sub_mc ? 200 : 100 )
|
390
|
+
para = Array.new(9) do |i|
|
391
|
+
if coef[i] == 0
|
392
|
+
Mgmg::IR::Const.new(0)
|
393
|
+
else
|
394
|
+
Mgmg::IR::Smith.new(Sub9[sub_m][i], coef[i], den, sa)
|
395
|
+
end
|
396
|
+
end
|
397
|
+
|
398
|
+
new(kind, (main_s+sub_s).div(2), main_mc, sub_mc, para)
|
399
|
+
end
|
400
|
+
def from_equip(equip)
|
401
|
+
para = equip.para.map do |value|
|
402
|
+
Mgmg::IR::Const.new(value)
|
403
|
+
end
|
404
|
+
new(equip.kind, equip.star, equip.main, equip.sub, para)
|
405
|
+
end
|
406
|
+
end
|
407
|
+
end
|