| 33 | |
| 34 | |
| 35 | class Ammo: |
| 36 | |
| 37 | instance = None |
| 38 | |
| 39 | @classmethod |
| 40 | def getInstance(cls): |
| 41 | if cls.instance is None: |
| 42 | cls.instance = Ammo() |
| 43 | |
| 44 | return cls.instance |
| 45 | |
| 46 | @staticmethod |
| 47 | def getModuleFlatAmmo(mod): |
| 48 | sMkt = Market.getInstance() |
| 49 | if mod is None or mod.isEmpty: |
| 50 | return set() |
| 51 | chargeSet = set() |
| 52 | # Do not try to grab it for t3d modes which can also be passed as part of selection |
| 53 | if isinstance(mod, Module): |
| 54 | for charge in mod.getValidCharges(): |
| 55 | if sMkt.getPublicityByItem(charge): |
| 56 | chargeSet.add(charge) |
| 57 | return chargeSet |
| 58 | |
| 59 | @classmethod |
| 60 | def getModuleStructuredAmmo(cls, mod, ammo=None): |
| 61 | chargesFlat = cls.getModuleFlatAmmo(mod) if ammo is None else ammo |
| 62 | # Make sure we do not consider mining turrets as combat turrets |
| 63 | if mod.hardpoint == FittingHardpoint.TURRET and not mod.getModifiedItemAttr('miningAmount'): |
| 64 | |
| 65 | def turretSorter(charge): |
| 66 | damage = 0 |
| 67 | range_ = (mod.item.getAttribute('maxRange')) * \ |
| 68 | (charge.getAttribute('weaponRangeMultiplier') or 1) |
| 69 | falloff = (mod.item.getAttribute('falloff') or 0) * \ |
| 70 | (charge.getAttribute('fallofMultiplier') or 1) |
| 71 | for type_ in DmgTypes.names(): |
| 72 | d = charge.getAttribute('%sDamage' % type_, default=0) |
| 73 | if d > 0: |
| 74 | damage += d |
| 75 | # Take optimal and falloff as range factor |
| 76 | rangeFactor = range_ + falloff |
| 77 | return -rangeFactor, charge.typeName.rsplit()[-2:], damage, charge.name |
| 78 | |
| 79 | all = OrderedDict() |
| 80 | sub = [] |
| 81 | prevNameBase = None |
| 82 | prevRange = None |
| 83 | for charge in sorted(chargesFlat, key=turretSorter): |
| 84 | if 'civilian' in charge.typeName.lower(): |
| 85 | continue |
| 86 | currNameBase = ' '.join(charge.typeName.rsplit()[-2:]) |
| 87 | currRange = charge.getAttribute('weaponRangeMultiplier') |
| 88 | if sub and (currRange != prevRange or currNameBase != prevNameBase): |
| 89 | all[sub[0].name] = sub |
| 90 | sub = [] |
| 91 | sub.append(charge) |
| 92 | prevNameBase = currNameBase |