(fit, module, context, projectionRange, **kwargs)
| 16431 | |
| 16432 | @staticmethod |
| 16433 | def handler(fit, module, context, projectionRange, **kwargs): |
| 16434 | # pyfalog = Logger(__name__) |
| 16435 | |
| 16436 | damagePattern = module.rahPatternOverride if module.rahPatternOverride is not None else fit.damagePattern |
| 16437 | # pyfalog.debug('==============================') |
| 16438 | |
| 16439 | if damagePattern == 'disable': |
| 16440 | for attr in ('armorEmDamageResonance', 'armorThermalDamageResonance', 'armorKineticDamageResonance', 'armorExplosiveDamageResonance'): |
| 16441 | fit.ship.multiplyItemAttr(attr, module.getModifiedItemAttr(attr), stackingPenalties=True, penaltyGroup='preMul') |
| 16442 | return |
| 16443 | |
| 16444 | # Skip if there is no damage pattern. Example: projected ships or fleet boosters |
| 16445 | if damagePattern: |
| 16446 | |
| 16447 | # Populate a tuple with the damage profile modified by current armor resists. |
| 16448 | baseDamageTaken = ( |
| 16449 | damagePattern.emAmount * fit.ship.getModifiedItemAttr('armorEmDamageResonance'), |
| 16450 | damagePattern.thermalAmount * fit.ship.getModifiedItemAttr('armorThermalDamageResonance'), |
| 16451 | damagePattern.kineticAmount * fit.ship.getModifiedItemAttr('armorKineticDamageResonance'), |
| 16452 | damagePattern.explosiveAmount * fit.ship.getModifiedItemAttr('armorExplosiveDamageResonance'), |
| 16453 | ) |
| 16454 | # pyfalog.debug('Damage Adjusted for Armor Resists: %f/%f/%f/%f' % (baseDamageTaken[0], baseDamageTaken[1], baseDamageTaken[2], baseDamageTaken[3])) |
| 16455 | |
| 16456 | resistanceShiftAmount = module.getModifiedItemAttr( |
| 16457 | 'resistanceShiftAmount') / 100 # The attribute is in percent and we want a fraction |
| 16458 | RAHResistance = [ |
| 16459 | module.getModifiedItemAttr('armorEmDamageResonance'), |
| 16460 | module.getModifiedItemAttr('armorThermalDamageResonance'), |
| 16461 | module.getModifiedItemAttr('armorKineticDamageResonance'), |
| 16462 | module.getModifiedItemAttr('armorExplosiveDamageResonance'), |
| 16463 | ] |
| 16464 | |
| 16465 | # Simulate RAH cycles until the RAH either stops changing or enters a loop. |
| 16466 | # The number of iterations is limited to prevent an infinite loop if something goes wrong. |
| 16467 | cycleList = [] |
| 16468 | loopStart = -20 |
| 16469 | for num in range(50): |
| 16470 | # pyfalog.debug('Starting cycle %d.' % num) |
| 16471 | # The strange order is to emulate the ingame sorting when different types have taken the same amount of damage. |
| 16472 | # This doesn't take into account stacking penalties. In a few cases fitting a Damage Control causes an inaccurate result. |
| 16473 | damagePattern_tuples = [ |
| 16474 | (0, baseDamageTaken[0] * RAHResistance[0], RAHResistance[0]), |
| 16475 | (3, baseDamageTaken[3] * RAHResistance[3], RAHResistance[3]), |
| 16476 | (2, baseDamageTaken[2] * RAHResistance[2], RAHResistance[2]), |
| 16477 | (1, baseDamageTaken[1] * RAHResistance[1], RAHResistance[1]), |
| 16478 | ] |
| 16479 | |
| 16480 | # Sort the tuple to drop the highest damage value to the bottom |
| 16481 | sortedDamagePattern_tuples = sorted(damagePattern_tuples, key=lambda damagePattern: damagePattern[1]) |
| 16482 | |
| 16483 | if sortedDamagePattern_tuples[2][1] == 0: |
| 16484 | # One damage type: the top damage type takes from the other three |
| 16485 | # Since the resistances not taking damage will end up going to the type taking damage we just do the whole thing at once. |
| 16486 | change0 = 1 - sortedDamagePattern_tuples[0][2] |
| 16487 | change1 = 1 - sortedDamagePattern_tuples[1][2] |
| 16488 | change2 = 1 - sortedDamagePattern_tuples[2][2] |
| 16489 | change3 = -(change0 + change1 + change2) |
| 16490 | elif sortedDamagePattern_tuples[1][1] == 0: |
nothing calls this directly
no test coverage detected