Class: Mgmg::Equip

Inherits:
Object
  • Object
show all
Defined in:
lib/mgmg/equip.rb,
lib/mgmg/reinforce.rb

Constant Summary collapse

ParamList =
%w|攻撃 物防 魔防 HP MP 腕力 器用 素早 魔力|
ElementList =
%w|  |
EqPosList =
%w|     |
Zero =
self.new(28, 0, Vec.new(6, 0).freeze, 12, 12, Vec.new(9, 0).freeze, Vec.new(3, 0).freeze)

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(kind, weight, star, main_m, sub_m, para, element) ⇒ Equip

Returns a new instance of Equip.



9
10
11
12
13
# File 'lib/mgmg/equip.rb', line 9

def initialize(kind, weight, star, main_m, sub_m, para, element)
	@kind, @weight, @star, @main, @sub, @para, @element = kind, weight, star, main_m, sub_m, para, element
	@total_cost = Vec[0, 0, 0]
	@history, @min_levels = [self], Hash.new
end

Instance Attribute Details

#elementObject

Returns the value of attribute element.



14
15
16
# File 'lib/mgmg/equip.rb', line 14

def element
  @element
end

#historyObject

Returns the value of attribute history.



14
15
16
# File 'lib/mgmg/equip.rb', line 14

def history
  @history
end

#kindObject

Returns the value of attribute kind.



14
15
16
# File 'lib/mgmg/equip.rb', line 14

def kind
  @kind
end

#mainObject

Returns the value of attribute main.



14
15
16
# File 'lib/mgmg/equip.rb', line 14

def main
  @main
end

#paraObject

Returns the value of attribute para.



14
15
16
# File 'lib/mgmg/equip.rb', line 14

def para
  @para
end

#starObject

Returns the value of attribute star.



14
15
16
# File 'lib/mgmg/equip.rb', line 14

def star
  @star
end

#subObject

Returns the value of attribute sub.



14
15
16
# File 'lib/mgmg/equip.rb', line 14

def sub
  @sub
end

#total_costObject

Returns the value of attribute total_cost.



14
15
16
# File 'lib/mgmg/equip.rb', line 14

def total_cost
  @total_cost
end

#weightObject

Returns the value of attribute weight.



14
15
16
# File 'lib/mgmg/equip.rb', line 14

def weight
  @weight
end

Class Method Details

.build(str, s_level, c_level, left_associative: true, include_system_equips: true) ⇒ Object



206
207
208
209
210
211
# File 'lib/mgmg/equip.rb', line 206

def build(str, s_level, c_level, left_associative: true, include_system_equips: true)
	str = Mgmg.check_string(str)
	stack = []
	stack, str = build_sub0(stack, str) if include_system_equips
	build_sub(stack, str, s_level, c_level, left_associative)
end

.compose(main, sub, level, outsourcing) ⇒ Object



242
243
244
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
# File 'lib/mgmg/equip.rb', line 242

def compose(main, sub, level, outsourcing)
	main_k, sub_k = main.kind, sub.kind
	main_s, sub_s = main.star, sub.star
	main_main, sub_main = main.main, sub.main
	main_sub, sub_sub = main.sub, sub.sub
	para = Vec.new(9, 0)
	ele = Vec.new(3, 0)
	
	# 9パラメータ
	coef = Equip9[main_k].dup
	para[] = coef
	para.add!(level).e_div!(2)
	para.e_mul!(sub.para).e_div!(100)
	coef.sub!(Equip9[sub_k])
	coef.add!( 100 + (main_s-sub_s)*5 - ( ( main_main==sub_main && main_main != 9 ) ? 30 : 0 ) )
	coef.add!(Material9[main_main]).sub!(Material9[sub_main])
	coef.e_mul!(EquipFilter[main_k])
	para.e_mul!(coef).e_div!( main_k==sub_k ? 200 : 100 )
	para.add!(main.para)
	
	# エレメント
	ele[] = sub.element
	ele.e_mul!([75, level].min).e_div!( main_k==sub_k ? 200 : 100 )
	ele.add!(main.element)
	
	ret = new(main_k, main.weight+sub.weight, main_s+sub_s, main_sub, sub_main, para, ele)
	ret.total_cost.add!(main.total_cost).add!(sub.total_cost)
	cc = ret.comp_cost(outsourcing)
	ret.total_cost[1] += cc
	ret.total_cost[main_k < 8 ? 0 : 2] += cc
	ret.min_levels.merge!(main.min_levels, sub.min_levels)
	ret.history = [*main.history, *sub.history, ret]
	ret
end

.min_comp(str, opt: Option.new) ⇒ Object



331
332
333
334
335
336
# File 'lib/mgmg/equip.rb', line 331

def min_comp(str, opt: Option.new)
	str = Mgmg.check_string(str)
	stack = []
	stack, str = minc_sub0(stack, str) if opt.include_system_equips
	(minc_sub(stack, str, opt.left_associative)[1]-1)*3
end

.min_level(str, weight = 1) ⇒ Object



313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
# File 'lib/mgmg/equip.rb', line 313

def min_level(str, weight=1)
	str = Mgmg.check_string(str)
	key = [str.dup.freeze, weight].freeze
	return CacheML[key] if CacheML.has_key?(key)
	unless m = /\A(.+)\((.+\d+),?(.+\d+)\)\Z/.match(str)
		raise InvalidSmithError.new(str)
	end
	kind = EquipIndex[m[1].to_sym]
	main_m, main_s, = Mgmg.parse_material(m[2])
	sub_m, sub_s, = Mgmg.parse_material(m[3])
	
	q, r = ((weight+1)*10000).divmod(MainWeight[main_m])
	l = ( EquipWeight[kind] + SubWeight[sub_m] - q + ( r==0 ? 1 : 0 ) )*2
	ret = [(main_s-1)*3, (sub_s-1)*3, l].max
	CacheML.store(key, ret)
	ret
end

.min_smith(str, opt: Option.new) ⇒ Object



361
362
363
364
365
366
367
# File 'lib/mgmg/equip.rb', line 361

def min_smith(str, opt: Option.new)
	str = Mgmg.check_string(str)
	stack = []
	stack, str = mins_sub0(stack, str) if opt.include_system_equips
	ret = (([mins_sub(stack, str, opt.left_associative)]+stack).max-1)*3
	ret < 0 ? -1 : ret
end

.smith(str, level, outsourcing) ⇒ Object



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
# File 'lib/mgmg/equip.rb', line 277

def smith(str, level, outsourcing)
	str = Mgmg.check_string(str)
	return Cache[str].dup if level==0 && Cache.has_key?(str)
	unless m = /\A(.+)\((.+\d+),?(.+\d+)\)\Z/.match(str)
		raise InvalidSmithError.new(str)
	end
	kind = EquipIndex[m[1].to_sym]
	unless kind
		raise InvalidEquipClassError.new(m[1])
	end
	main_m, main_s, main_mc = Mgmg.parse_material(m[2])
	sub_m, sub_s, sub_mc = Mgmg.parse_material(m[3])
	para = Vec.new(9, 0)
	ele = Vec.new(3, 0)
	
	# 9パラメータ
	para[] = Equip9[kind]
	para.e_mul!(Main9[main_m]).e_div!(100)
	coef = Sub9[sub_m].dup
	coef.add!(level)
	para.e_mul!(coef).e_div!( main_mc==sub_mc ? 200 : 100 )
	
	# エレメント
	ele[] = MainEL[main_m]
	ele.e_mul!(SubEL[sub_m]).e_div!(6)
	
	# 重量
	weight = ( ( EquipWeight[kind] + SubWeight[sub_m] - level.div(2) ) * ( MainWeight[main_m] ) ).div(10000)
	
	ret = new(kind, ( weight<1 ? 1 : weight ), (main_s+sub_s).div(2), main_mc, sub_mc, para, ele)
	ret.total_cost[kind < 8 ? 0 : 2] += ret.smith_cost(outsourcing)
	ret.min_levels.store(str, Equip.min_level(str))
	Cache.store(str, ret.freeze) if level==0
	ret.dup
end

Instance Method Details

#+(other) ⇒ Object



198
199
200
# File 'lib/mgmg/equip.rb', line 198

def +(other)
	self.dup.add!(other)
end

#add!(other) ⇒ Object



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
197
# File 'lib/mgmg/equip.rb', line 172

def add!(other)
	if @kind == 28
		if other.kind == 28
			@star.add!(other.star)
		else
			@star[EquipPosition[other.kind]] += 1
		end
	else
		@star = Vec.new(6, 0)
		@star[EquipPosition[@kind]] = 1
		@kind = 28
		if other.kind == 28
			@star.add!(other.star)
		else
			@star[EquipPosition[other.kind]] += 1
		end
	end
	@weight += other.weight
	@main, @sub = 12, 12
	@para.add!(other.para)
	@element.add!(other.element)
	@total_cost.add!(other.total_cost)
	@history.concat(other.history)
	@min_levels.merge!(other.min_levels)
	self
end

#atk_sdObject



96
97
98
# File 'lib/mgmg/equip.rb', line 96

def atk_sd
	( attack()+str().quo(2)+dex().quo(2) ).to_ii
end

#atkstrObject



93
94
95
# File 'lib/mgmg/equip.rb', line 93

def atkstr
	attack()+str()
end

#comp_cost(outsourcing = false) ⇒ Object Also known as: cost



163
164
165
166
167
168
169
# File 'lib/mgmg/equip.rb', line 163

def comp_cost(outsourcing=false)
	if outsourcing
		[(@star**2)*5+@para.sum+hp().cdiv(4)-hp()+mp().cdiv(4)-mp(), 0].max.div(2)
	else
		[((@star**2)*5+@para.sum+hp().cdiv(4)-hp()+mp().cdiv(4)-mp()).div(2), 0].max.div(2)
	end
end

#compose(other, level, outsourcing = false) ⇒ Object



28
29
30
# File 'lib/mgmg/equip.rb', line 28

def compose(other, level, outsourcing=false)
	self.class.compose(self, other, level, outsourcing)
end

#dex_asObject



99
100
101
# File 'lib/mgmg/equip.rb', line 99

def dex_as
	( attack().quo(2)+str().quo(2)+dex() ).to_ii
end

#fpowerObject



141
142
143
# File 'lib/mgmg/equip.rb', line 141

def fpower
	power().to_f
end

#hsObject



108
109
110
# File 'lib/mgmg/equip.rb', line 108

def hs
	hp()+str()
end

#initialize_copy(other) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/mgmg/equip.rb', line 15

def initialize_copy(other)
	@kind = other.kind
	@weight = other.weight
	@star = other.star.dup
	@main = other.main
	@sub = other.sub
	@para = other.para.dup
	@element = other.element.dup
	@total_cost = other.total_cost.dup
	@history = other.history.dup
	@min_levels = other.min_levels.dup
end

#inspectObject



45
46
47
48
49
50
51
52
53
54
55
# File 'lib/mgmg/equip.rb', line 45

def inspect
	par = @para.map.with_index{|e, i| "#{ParamList[i]}:#{e}"}
	par << ( "EL:" + @element.map.with_index{|e, i| "#{ElementList[i]}#{e}"}.join('') )
	tc = "<コスト:" + @total_cost.map.with_index{|e, i| "#{ElementList[i]}#{e}"}.join('') + '>'
	if @kind == 28
		ep = @star.map.with_index{|e, i| "#{EqPosList[i]}:#{e}"}
		"複数装備#{@weight}(#{ep.join(', ')})[#{par.join(', ')}]#{tc}"
	else
		"#{EquipName[@kind]}#{@weight}#{@star}(#{MaterialClass[@main]}#{MaterialClass[@sub]})[#{par.join(', ')}]#{tc}"
	end
end

#mag_dasObject



102
103
104
# File 'lib/mgmg/equip.rb', line 102

def mag_das
	( magic()+dex_as().quo(2) ).to_ii
end

#magic2Object



105
106
107
# File 'lib/mgmg/equip.rb', line 105

def magic2
	magic()*2
end

#magmagObject



138
139
140
# File 'lib/mgmg/equip.rb', line 138

def magmag
	( magdef()+magic().quo(2) ).to_ii
end

#min_levels(w = 1) ⇒ Object



57
58
59
60
61
62
63
64
65
# File 'lib/mgmg/equip.rb', line 57

def min_levels(w=1)
	if w == 1
		@min_levels
	else
		@min_levels.map do |key, value|
			[key, Equip.min_level(key, w)]
		end.to_h
	end
end

#min_levels_max(w = 1) ⇒ Object



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/mgmg/equip.rb', line 66

def min_levels_max(w=1)
	if @kind == 28
		ret = [-1, -1]
		min_levels(w).each do |str, ml|
			if str.build.kind < 8
				if ret[0] < ml
					ret[0] = ml
				end
			else
				if ret[1] < ml
					ret[1] = ml
				end
			end
		end
		ret
	else
		min_levels(w).values.append(-1).max
	end
end

#para_call(para) ⇒ Object



86
87
88
# File 'lib/mgmg/equip.rb', line 86

def para_call(para)
	method(para).call
end

#pmdefObject



144
145
146
# File 'lib/mgmg/equip.rb', line 144

def pmdef
	[phydef(), magmag()].min
end

#powerObject



115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
# File 'lib/mgmg/equip.rb', line 115

def power
	case @kind
	when 0, 1
		atk_sd()
	when 2, 3
		atkstr()
	when 4
		[dex_as(), mag_das()].max
	when 5
		dex_as()
	when 6, 7
		[magic()*2, atkstr()].max
	when 28
		( @para.sum-((hp()+mp())*3.quo(4)) ).to_ii
	else
		ret = @para.max
		if ret == magdef()
			( ret+magic().quo(2) ).to_ii
		else
			ret
		end
	end
end

#reinforce(*arg) ⇒ Object



55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/mgmg/reinforce.rb', line 55

def reinforce(*arg)
	arg.each do |r|
		r = Reinforcement.compile(r)
		@para.map!.with_index do |pr, i|
			if r.vec[i] == 0
				pr
			else
				pr * (100+r.vec[i]).quo(100)
			end
		end
	end
	self
end

#smith_cost(outsourcing = false) ⇒ Object



148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
# File 'lib/mgmg/equip.rb', line 148

def smith_cost(outsourcing=false)
	if outsourcing
		if @kind < 8
			(@star**2)*2+@para.sum+hp().cdiv(4)-hp()+mp().cdiv(4)-mp()
		else
			(@star**2)+@para.sum+hp().cdiv(4)-hp()+mp().cdiv(4)-mp()
		end
	else
		if @kind < 8
			((@star**2)*2+@para.sum+hp().cdiv(4)-hp()+mp().cdiv(4)-mp()).div(2)
		else
			((@star**2)+@para.sum+hp().cdiv(4)-hp()+mp().cdiv(4)-mp()).div(2)
		end
	end
end

#to_sObject



32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/mgmg/equip.rb', line 32

def to_s
	par = @para.map.with_index{|e, i| e==0 ? nil : "#{ParamList[i]}:#{e.comma3}"}.compact
	elm = @element.map.with_index{|e, i| e==0 ? nil : "#{ElementList[i]}#{e}"}.compact
	unless elm.empty?
		par << "EL:#{elm.join('')}"
	end
	if @kind == 28
		ep = @star.map.with_index{|e, i| e==0 ? nil : "#{EqPosList[i]}:#{e}"}.compact
		"複数装備#{@weight}(#{ep.join(', ')})[#{par.join(', ')}]"
	else
		"#{EquipName[@kind]}#{@weight}#{@star}(#{MaterialClass[@main]}#{MaterialClass[@sub]})[#{par.join(', ')}]"
	end
end