Class: Mgmg::IR
- Inherits:
-
Object
- Object
- Mgmg::IR
- Defined in:
- lib/mgmg/ir.rb
Defined Under Namespace
Classes: Compose, Const, Multi, Reined, Smith
Constant Summary collapse
- Cache =
Hash.new
- Zero =
self.new(28, Vec.new(6, 0).freeze, 12, 12, Array.new(9){Const.new(0)}.freeze, Array.new(9, nil).freeze)
Instance Attribute Summary collapse
-
#eo ⇒ Object
Returns the value of attribute eo.
-
#kind ⇒ Object
Returns the value of attribute kind.
-
#main ⇒ Object
Returns the value of attribute main.
-
#para ⇒ Object
Returns the value of attribute para.
-
#rein ⇒ Object
Returns the value of attribute rein.
-
#star ⇒ Object
Returns the value of attribute star.
-
#sub ⇒ Object
Returns the value of attribute sub.
Class Method Summary collapse
- .build(str, left_associative: true, reinforcement: [], include_system_equips: true) ⇒ Object
- .compose(main, sub) ⇒ Object
- .eo_add(eo0, eo1) ⇒ Object
- .eo_mul(eq, seo) ⇒ Object
- .from_equip(equip) ⇒ Object
- .smith(str) ⇒ Object
Instance Method Summary collapse
- #+(other) ⇒ Object
- #add!(other) ⇒ Object
- #add_reinforcement(rein) ⇒ Object
- #atk_sd(s, ac, x = nil) ⇒ Object
- #atkstr(s, ac, x = nil) ⇒ Object
- #comp_cost(s, c = s, outsourcing = false) ⇒ Object (also: #cost)
- #compose(other) ⇒ Object
- #dex_as(s, ac, x = nil) ⇒ Object
- #eo_para(para) ⇒ Object
- #fpower(s, a = s, c = a.tap{a=s}) ⇒ Object
- #hs(s, ac, x = nil) ⇒ Object
-
#initialize(kind, star, main_m, sub_m, para, eo, rein = []) ⇒ IR
constructor
A new instance of IR.
- #initialize_copy(other) ⇒ Object
- #mag_das(s, ac, x = nil) ⇒ Object
- #magic2(s, ac, x = nil) ⇒ Object
- #magmag(s, ac, x = nil) ⇒ Object
- #para_call(para, s, ac, x = nil) ⇒ Object
- #pmdef(s, ac, x = nil) ⇒ Object
- #power(s, a = s, c = a.tap{a=s}) ⇒ Object
- #smith_cost(s, c = s, outsourcing = false) ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(kind, star, main_m, sub_m, para, eo, rein = []) ⇒ IR
Returns a new instance of IR.
177 178 179 180 |
# File 'lib/mgmg/ir.rb', line 177 def initialize(kind, star, main_m, sub_m, para, eo, rein=[]) @kind, @star, @main, @sub, @para, @eo = kind, star, main_m, sub_m, para, eo add_reinforcement(rein) end |
Instance Attribute Details
#eo ⇒ Object
Returns the value of attribute eo.
191 192 193 |
# File 'lib/mgmg/ir.rb', line 191 def eo @eo end |
#kind ⇒ Object
Returns the value of attribute kind.
191 192 193 |
# File 'lib/mgmg/ir.rb', line 191 def kind @kind end |
#main ⇒ Object
Returns the value of attribute main.
191 192 193 |
# File 'lib/mgmg/ir.rb', line 191 def main @main end |
#para ⇒ Object
Returns the value of attribute para.
191 192 193 |
# File 'lib/mgmg/ir.rb', line 191 def para @para end |
#rein ⇒ Object
Returns the value of attribute rein.
191 192 193 |
# File 'lib/mgmg/ir.rb', line 191 def rein @rein end |
#star ⇒ Object
Returns the value of attribute star.
191 192 193 |
# File 'lib/mgmg/ir.rb', line 191 def star @star end |
#sub ⇒ Object
Returns the value of attribute sub.
191 192 193 |
# File 'lib/mgmg/ir.rb', line 191 def sub @sub end |
Class Method Details
.build(str, left_associative: true, reinforcement: [], include_system_equips: true) ⇒ Object
396 397 398 399 400 401 |
# File 'lib/mgmg/ir.rb', line 396 def build(str, left_associative: true, reinforcement: [], include_system_equips: true) str = Mgmg.check_string(str) stack = [] stack, str = build_sub0(stack, str) if include_system_equips build_sub(stack, str, left_associative).add_reinforcement(reinforcement) end |
.compose(main, sub) ⇒ Object
424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 |
# File 'lib/mgmg/ir.rb', line 424 def compose(main, sub) 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 coef = Equip9[main_k].dup 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]) den = ( main_k==sub_k ? 200 : 100 ) para = Array.new(9) do |i| if EquipFilter[main_k][i] == 0 main.para[i] else Mgmg::IR::Compose.new(main.para[i], sub.para[i], Equip9[main_k][i], coef[i], den) end end eo = Array.new(9) do |i| if EquipFilter[main_k][i] == 0 main.eo[i] else eo_add(main.eo[i], eo_mul(2**(Equip9[main_k][i]&1), sub.eo[i])) end end new(main_k, main_s+sub_s, main_sub, sub_main, para, eo) end |
.eo_add(eo0, eo1) ⇒ Object
504 505 506 507 508 509 510 511 512 513 514 |
# File 'lib/mgmg/ir.rb', line 504 def eo_add(eo0, eo1) if eo0 if eo1 eo0 | eo1 else eo0 end else eo1 end end |
.eo_mul(eq, seo) ⇒ Object
515 516 517 518 519 520 521 |
# File 'lib/mgmg/ir.rb', line 515 def eo_mul(eq, seo) if seo eq | seo else nil end end |
.from_equip(equip) ⇒ Object
490 491 492 493 494 495 496 497 498 499 500 501 502 |
# File 'lib/mgmg/ir.rb', line 490 def from_equip(equip) para = equip.para.map do |value| Mgmg::IR::Const.new(value) end eo = equip.para.map do |value| if value == 0 nil else 0 end end new(equip.kind, equip.star, equip.main, equip.sub, para, eo) end |
.smith(str) ⇒ Object
453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 |
# File 'lib/mgmg/ir.rb', line 453 def smith(str) str = Mgmg.check_string(str) return Cache[str].dup if 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]) sa = ( Mgmg::EquipPosition[kind] == 0 ? :s : :a ) coef = Equip9[kind].dup coef.e_mul!(Main9[main_m]).e_div!(100) den = ( main_mc==sub_mc ? 200 : 100 ) para = Array.new(9) do |i| if coef[i] == 0 Mgmg::IR::Const.new(0) else Mgmg::IR::Smith.new(Sub9[sub_m][i], coef[i], den, sa) end end eo = Array.new(9) do |i| if coef[i] == 0 nil else 0 end end ret = new(kind, (main_s+sub_s).div(2), main_mc, sub_mc, para, eo) Cache.store(str, ret.freeze) ret.dup end |
Instance Method Details
#+(other) ⇒ Object
389 390 391 |
# File 'lib/mgmg/ir.rb', line 389 def +(other) self.dup.add!(other) end |
#add!(other) ⇒ Object
363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 |
# File 'lib/mgmg/ir.rb', line 363 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 @main, @sub = 12, 12 @para = Array.new(9) do |i| Multi.sum(self.para[i], other.para[i]) end @eo.map!.with_index do |seo, i| self.class.eo_add(seo, other.eo[i]) end self end |
#add_reinforcement(rein) ⇒ Object
181 182 183 184 185 186 187 188 189 190 |
# File 'lib/mgmg/ir.rb', line 181 def add_reinforcement(rein) @rein = if rein.kind_of?(Array) rein.map do |r| Reinforcement.compile(r) end else [Reinforcement.compile(rein)] end self end |
#atk_sd(s, ac, x = nil) ⇒ Object
274 275 276 |
# File 'lib/mgmg/ir.rb', line 274 def atk_sd(s, ac, x=nil) ( attack(s, ac, x)+str(s, ac, x).quo(2)+dex(s, ac, x).quo(2) ).to_ii end |
#atkstr(s, ac, x = nil) ⇒ Object
271 272 273 |
# File 'lib/mgmg/ir.rb', line 271 def atkstr(s, ac, x=nil) attack(s, ac, x)+str(s, ac, x) end |
#comp_cost(s, c = s, outsourcing = false) ⇒ Object Also known as: cost
354 355 356 357 358 359 360 |
# File 'lib/mgmg/ir.rb', line 354 def comp_cost(s, c=s, outsourcing=false) if outsourcing [(@star**2)*5+@para.sum{|e| e.evaluate(s, c)}+hp().cdiv(4)-hp()+mp().cdiv(4)-mp(), 0].max.div(2) else [((@star**2)*5+@para.sum{|e| e.evaluate(s, c)}+hp().cdiv(4)-hp()+mp().cdiv(4)-mp()).div(2), 0].max.div(2) end end |
#compose(other) ⇒ Object
202 203 204 |
# File 'lib/mgmg/ir.rb', line 202 def compose(other) self.class.compose(self, other) end |
#dex_as(s, ac, x = nil) ⇒ Object
277 278 279 |
# File 'lib/mgmg/ir.rb', line 277 def dex_as(s, ac, x=nil) ( attack(s, ac, x).quo(2)+str(s, ac, x).quo(2)+dex(s, ac, x) ).to_ii end |
#eo_para(para) ⇒ Object
224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 |
# File 'lib/mgmg/ir.rb', line 224 def eo_para(para) case para when :atkstr self.class.eo_add(eo_para(:attack), eo_para(:str)) when :atk_sd self.class.eo_add(self.class.eo_add(eo_para(:attack), eo_para(:str)), eo_para(:dex)) when :dex_as self.class.eo_add(self.class.eo_add(eo_para(:dex), eo_para(:attack)), eo_para(:str)) when :mag_das self.class.eo_add(eo_para(:magic), eo_para(:dex_as)) when :magic2 eo_para(:magic) when :magmag self.class.eo_add(eo_para(:magdef), eo_para(:magic)) when :pmdef self.class.eo_add(eo_para(:phydef), eo_para(:magmag)) when :hs self.class.eo_add(eo_para(:hp), eo_para(:str)) when :cost ret = nil @eo.each do |foo| ret = self.class.eo_add(ret, foo) end ret else @eo[%i|attack phydef magdef hp mp str dex speed magic|.index(para)] end end |
#fpower(s, a = s, c = a.tap{a=s}) ⇒ Object
335 336 337 |
# File 'lib/mgmg/ir.rb', line 335 def fpower(s, a=s, c=a.tap{a=s}) power(s, a, c).to_f end |
#hs(s, ac, x = nil) ⇒ Object
292 293 294 |
# File 'lib/mgmg/ir.rb', line 292 def hs(s, ac, x=nil) hp(s, ac, x)+str(s, ac, x) end |
#initialize_copy(other) ⇒ Object
192 193 194 195 196 197 198 199 200 |
# File 'lib/mgmg/ir.rb', line 192 def initialize_copy(other) @kind = other.kind @star = other.star.dup @main = other.main @sub = other.sub @para = other.para.dup @eo = other.eo.dup @rein = other.rein.dup end |
#mag_das(s, ac, x = nil) ⇒ Object
280 281 282 |
# File 'lib/mgmg/ir.rb', line 280 def mag_das(s, ac, x=nil) ( magic(s, ac, x)+dex_as(s, ac, x).quo(2) ).to_ii end |
#magic2(s, ac, x = nil) ⇒ Object
283 284 285 |
# File 'lib/mgmg/ir.rb', line 283 def magic2(s, ac, x=nil) magic(s, ac, x)*2 end |
#magmag(s, ac, x = nil) ⇒ Object
286 287 288 |
# File 'lib/mgmg/ir.rb', line 286 def magmag(s, ac, x=nil) ( magdef(s, ac, x)+magic(s, ac, x).quo(2) ).to_ii end |
#para_call(para, s, ac, x = nil) ⇒ Object
216 217 218 219 220 221 222 |
# File 'lib/mgmg/ir.rb', line 216 def para_call(para, s, ac, x=nil) if x.nil? method(para).call(s, ac) else method(para).call(s, ac, x) end end |
#pmdef(s, ac, x = nil) ⇒ Object
289 290 291 |
# File 'lib/mgmg/ir.rb', line 289 def pmdef(s, ac, x=nil) [phydef(s, ac, x), magmag(s, ac, x)].min end |
#power(s, a = s, c = a.tap{a=s}) ⇒ Object
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 |
# File 'lib/mgmg/ir.rb', line 296 def power(s, a=s, c=a.tap{a=s}) case @kind when 0, 1 atk_sd(s, c) when 2, 3 atkstr(s, c) when 4 [dex_as(s, c), mag_das(s, c)].max when 5 dex_as(s, c) when 6, 7 [magic(s, c)*2, atkstr(s, c)].max when 28 ( @para.enum_for(:sum).with_index do |e, i| x = e.evaluate3(s, a, c) @rein.each do |r| if r.vec[i] != 0 x *= (100+r.vec[i]).quo(100) end end x end - ((hp(s, a, c)+mp(s, a, c))*3.quo(4)) ).to_ii else ret = @para.map.with_index do |e, i| x = e.evaluate3(s, a, c) @rein.each do |r| if r.vec[i] != 0 x *= (100+r.vec[i]).quo(100) end end x end.max.to_ii if ret == magdef(s, a, c) ( ret+magic(s, a, c).quo(2) ).to_ii else ret end end end |
#smith_cost(s, c = s, outsourcing = false) ⇒ Object
339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 |
# File 'lib/mgmg/ir.rb', line 339 def smith_cost(s, c=s, outsourcing=false) if outsourcing if @kind < 8 (@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) else (@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) end else if @kind < 8 ((@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) else ((@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) end end end |
#to_s ⇒ Object
206 207 208 209 210 211 212 213 214 |
# File 'lib/mgmg/ir.rb', line 206 def to_s par = @para.map.with_index{|e, i| e.to_s=='0' ? nil : "#{Mgmg::Equip::ParamList[i]}:#{e.to_s}"}.compact if @kind == 28 ep = @star.map.with_index{|e, i| e==0 ? nil : "#{Mgmg::Equip::EqPosList[i]}:#{e}"}.compact "複数装備(#{ep.join(', ')})<#{par.join(', ')}>#{@rein.empty? ? '' : '{'+@rein.join(',')+'}'}" else "#{EquipName[@kind]}☆#{@star}(#{MaterialClass[@main]}#{MaterialClass[@sub]})<#{par.join(', ')}>#{@rein.empty? ? '' : '{'+@rein.join(',')+'}'}" end end |