Class: Mgmg::Equip
- Inherits:
-
Object
- Object
- Mgmg::Equip
- 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
-
#element ⇒ Object
Returns the value of attribute element.
-
#history ⇒ Object
Returns the value of attribute history.
-
#kind ⇒ Object
Returns the value of attribute kind.
-
#main ⇒ Object
Returns the value of attribute main.
-
#para ⇒ Object
Returns the value of attribute para.
-
#star ⇒ Object
Returns the value of attribute star.
-
#sub ⇒ Object
Returns the value of attribute sub.
-
#total_cost ⇒ Object
Returns the value of attribute total_cost.
-
#weight ⇒ Object
Returns the value of attribute weight.
Class Method Summary collapse
- .build(str, s_level, c_level, left_associative: true, include_system_equips: true) ⇒ Object
- .compose(main, sub, level, outsourcing) ⇒ Object
- .min_comp(str, opt: Option.new) ⇒ Object
- .min_level(str, weight = 1) ⇒ Object
- .min_smith(str, opt: Option.new) ⇒ Object
- .smith(str, level, outsourcing) ⇒ Object
Instance Method Summary collapse
- #+(other) ⇒ Object
- #add!(other) ⇒ Object
- #atk_sd ⇒ Object
- #atkstr ⇒ Object
- #comp_cost(outsourcing = false) ⇒ Object (also: #cost)
- #compose(other, level, outsourcing = false) ⇒ Object
- #dex_as ⇒ Object
- #fpower ⇒ Object
- #hs ⇒ Object
-
#initialize(kind, weight, star, main_m, sub_m, para, element) ⇒ Equip
constructor
A new instance of Equip.
- #initialize_copy(other) ⇒ Object
- #inspect ⇒ Object
- #mag_das ⇒ Object
- #magic2 ⇒ Object
- #magmag ⇒ Object
- #min_levels(w = 1) ⇒ Object
- #min_levels_max(w = 1) ⇒ Object
- #para_call(para) ⇒ Object
- #pmdef ⇒ Object
- #power ⇒ Object
- #reinforce(*arg) ⇒ Object
- #smith_cost(outsourcing = false) ⇒ Object
- #to_s ⇒ Object
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
#element ⇒ Object
Returns the value of attribute element.
14 15 16 |
# File 'lib/mgmg/equip.rb', line 14 def element @element end |
#history ⇒ Object
Returns the value of attribute history.
14 15 16 |
# File 'lib/mgmg/equip.rb', line 14 def history @history end |
#kind ⇒ Object
Returns the value of attribute kind.
14 15 16 |
# File 'lib/mgmg/equip.rb', line 14 def kind @kind end |
#main ⇒ Object
Returns the value of attribute main.
14 15 16 |
# File 'lib/mgmg/equip.rb', line 14 def main @main end |
#para ⇒ Object
Returns the value of attribute para.
14 15 16 |
# File 'lib/mgmg/equip.rb', line 14 def para @para end |
#star ⇒ Object
Returns the value of attribute star.
14 15 16 |
# File 'lib/mgmg/equip.rb', line 14 def star @star end |
#sub ⇒ Object
Returns the value of attribute sub.
14 15 16 |
# File 'lib/mgmg/equip.rb', line 14 def sub @sub end |
#total_cost ⇒ Object
Returns the value of attribute total_cost.
14 15 16 |
# File 'lib/mgmg/equip.rb', line 14 def total_cost @total_cost end |
#weight ⇒ Object
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_sd ⇒ Object
96 97 98 |
# File 'lib/mgmg/equip.rb', line 96 def atk_sd ( attack()+str().quo(2)+dex().quo(2) ).to_ii end |
#atkstr ⇒ Object
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_as ⇒ Object
99 100 101 |
# File 'lib/mgmg/equip.rb', line 99 def dex_as ( attack().quo(2)+str().quo(2)+dex() ).to_ii end |
#fpower ⇒ Object
141 142 143 |
# File 'lib/mgmg/equip.rb', line 141 def fpower power().to_f end |
#hs ⇒ Object
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 |
#inspect ⇒ Object
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_das ⇒ Object
102 103 104 |
# File 'lib/mgmg/equip.rb', line 102 def mag_das ( magic()+dex_as().quo(2) ).to_ii end |
#magic2 ⇒ Object
105 106 107 |
# File 'lib/mgmg/equip.rb', line 105 def magic2 magic()*2 end |
#magmag ⇒ Object
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 |
#pmdef ⇒ Object
144 145 146 |
# File 'lib/mgmg/equip.rb', line 144 def pmdef [phydef(), magmag()].min end |
#power ⇒ Object
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_s ⇒ Object
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 |