Esempio n. 1
0
 def getRepairData(fit, sFit):
     modGroupNames = [
         "Shield Booster",
         "Armor Repair Unit",
         "Ancillary Shield Booster",
         "Ancillary Armor Repairer",
         "Hull Repair Unit",
         "Capacitor Booster",
     ]
     repairMods = EfsPort.getModsInGroups(fit, modGroupNames)
     repairs = []
     for mod in repairMods:
         stats = {}
         EfsPort.attrDirectMap(["duration", "capacitorNeed"], stats, mod)
         if mod.item.group.name in [
                 "Armor Repair Unit", "Ancillary Armor Repairer"
         ]:
             stats["type"] = "Armor Repairer"
             EfsPort.attrDirectMap(["armorDamageAmount"], stats, mod)
             if mod.item.group.name == "Ancillary Armor Repairer":
                 stats["numShots"] = mod.numShots
                 EfsPort.attrDirectMap(
                     ["reloadTime", "chargedArmorDamageMultiplier"], stats,
                     mod)
         elif mod.item.group.name in [
                 "Shield Booster", "Ancillary Shield Booster"
         ]:
             stats["type"] = "Shield Booster"
             EfsPort.attrDirectMap(["shieldBonus"], stats, mod)
             if mod.item.group.name == "Ancillary Shield Booster":
                 stats["numShots"] = mod.numShots
                 EfsPort.attrDirectMap(["reloadTime"], stats, mod)
                 c = mod.charge
                 if c:
                     sFit.recalc(fit)
                     CalcChangeModuleChargesCommand(fit.ID,
                                                    projected=False,
                                                    chargeMap={
                                                        mod.position: None
                                                    },
                                                    recalc=False).Do()
                     sFit.recalc(fit)
                     stats[
                         "unloadedCapacitorNeed"] = mod.getModifiedItemAttr(
                             "capacitorNeed")
                     CalcChangeModuleChargesCommand(fit.ID,
                                                    projected=False,
                                                    chargeMap={
                                                        mod.position:
                                                        c.typeID
                                                    },
                                                    recalc=False).Do()
                     sFit.recalc(fit)
         elif mod.item.group.name == "Capacitor Booster":
             # The capacitorNeed is negative, which provides the boost.
             stats["type"] = "Capacitor Booster"
             stats["numShots"] = mod.numShots
             EfsPort.attrDirectMap(["reloadTime"], stats, mod)
         repairs.append(stats)
     return repairs
Esempio n. 2
0
 def Do(self):
     cmd = CalcChangeModuleChargesCommand(fitID=self.fitID, projected=True, chargeMap={p: self.chargeItemID for p in self.positions})
     success = self.internalHistory.submit(cmd)
     sFit = Fit.getInstance()
     sFit.recalc(self.fitID)
     sFit.fill(self.fitID)
     wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID))
     return success
Esempio n. 3
0
 def Do(self):
     sFit = Fit.getInstance()
     fit = sFit.getFit(self.fitID)
     for mod in fit.modules:
         if mod.itemID in self.rebaseMap:
             cmd = CalcRebaseItemCommand(fitID=self.fitID,
                                         containerName='modules',
                                         position=fit.modules.index(mod),
                                         itemID=self.rebaseMap[mod.itemID],
                                         commit=False)
             self.internalHistory.submit(cmd)
         if mod.chargeID in self.rebaseMap:
             cmd = CalcChangeModuleChargesCommand(
                 fitID=self.fitID,
                 projected=False,
                 chargeMap={
                     fit.modules.index(mod): self.rebaseMap[mod.chargeID]
                 },
                 commit=False)
             self.internalHistory.submit(cmd)
     for containerName in ('drones', 'fighters', 'implants', 'boosters'):
         container = getattr(fit, containerName)
         for obj in container:
             if obj.itemID in self.rebaseMap:
                 cmd = CalcRebaseItemCommand(
                     fitID=self.fitID,
                     containerName=containerName,
                     position=container.index(obj),
                     itemID=self.rebaseMap[obj.itemID],
                     commit=False)
                 self.internalHistory.submit(cmd)
     # Need to process cargo separately as we want to merge items when needed,
     # e.g. FN iron and CN iron into single stack of CN iron
     for cargo in fit.cargo:
         if cargo.itemID in self.rebaseMap:
             amount = cargo.amount
             cmdRemove = CalcRemoveCargoCommand(fitID=self.fitID,
                                                cargoInfo=CargoInfo(
                                                    itemID=cargo.itemID,
                                                    amount=amount),
                                                commit=False)
             cmdAdd = CalcAddCargoCommand(
                 fitID=self.fitID,
                 cargoInfo=CargoInfo(itemID=self.rebaseMap[cargo.itemID],
                                     amount=amount),
                 commit=False)
             self.internalHistory.submitBatch(cmdRemove, cmdAdd)
     eos.db.commit()
     sFit.recalc(fit)
     sFit.fill(self.fitID)
     wx.PostEvent(gui.mainFrame.MainFrame.getInstance(),
                  GE.FitChanged(fitID=self.fitID))
     return len(self.internalHistory) > 0
Esempio n. 4
0
 def Do(self):
     cmd = CalcChangeModuleChargesCommand(
         fitID=self.fitID,
         projected=False,
         chargeMap={p: self.chargeItemID
                    for p in self.positions})
     success = self.internalHistory.submit(cmd)
     sFit = Fit.getInstance()
     if cmd.needsGuiRecalc:
         eos.db.flush()
         sFit.recalc(self.fitID)
     sFit.fill(self.fitID)
     eos.db.commit()
     wx.PostEvent(gui.mainFrame.MainFrame.getInstance(),
                  GE.FitChanged(fitIDs=(self.fitID, )))
     return success
Esempio n. 5
0
 def Do(self):
     sFit = Fit.getInstance()
     fit = sFit.getFit(self.fitID)
     srcCargo = next(
         (c for c in fit.cargo if c.itemID == self.srcCargoItemID), None)
     if srcCargo is None:
         return
     dstMod = fit.modules[self.dstModPosition]
     # Moving/copying charge from cargo to fit
     if srcCargo.item.isCharge and not dstMod.isEmpty:
         newCargoChargeItemID = dstMod.chargeID
         newCargoChargeAmount = dstMod.numCharges
         newModChargeItemID = self.srcCargoItemID
         newModChargeAmount = dstMod.getNumCharges(srcCargo.item)
         if newCargoChargeItemID == newModChargeItemID:
             return False
         commands = []
         if not self.copy:
             commands.append(
                 CalcRemoveCargoCommand(fitID=self.fitID,
                                        cargoInfo=CargoInfo(
                                            itemID=newModChargeItemID,
                                            amount=newModChargeAmount),
                                        commit=False))
         if newCargoChargeItemID is not None:
             commands.append(
                 CalcAddCargoCommand(fitID=self.fitID,
                                     cargoInfo=CargoInfo(
                                         itemID=newCargoChargeItemID,
                                         amount=newCargoChargeAmount),
                                     commit=False))
         commands.append(
             CalcChangeModuleChargesCommand(
                 fitID=self.fitID,
                 projected=False,
                 chargeMap={dstMod.modPosition: self.srcCargoItemID},
                 commit=False))
         success = self.internalHistory.submitBatch(*commands)
     # Moving/copying/replacing module
     elif srcCargo.item.isModule:
         dstModItemID = dstMod.itemID
         dstModSlot = dstMod.slot
         if self.srcCargoItemID == dstModItemID:
             return False
         # To keep all old item properties, copy them over from old module
         newModInfo = ModuleInfo.fromModule(dstMod)
         newModInfo.itemID = self.srcCargoItemID
         if dstMod.isEmpty:
             newCargoModItemID = None
             dstModChargeItemID = None
             dstModChargeAmount = None
         else:
             # We cannot put mutated items to cargo, so use unmutated item ID
             newCargoModItemID = ModuleInfo.fromModule(dstMod,
                                                       unmutate=True).itemID
             dstModChargeItemID = dstMod.chargeID
             dstModChargeAmount = dstMod.numCharges
         commands = []
         # Keep cargo only in case we were copying
         if not self.copy:
             commands.append(
                 CalcRemoveCargoCommand(fitID=self.fitID,
                                        cargoInfo=CargoInfo(
                                            itemID=self.srcCargoItemID,
                                            amount=1),
                                        commit=False))
         # Add item to cargo only if we copied/moved to non-empty slot
         if newCargoModItemID is not None:
             commands.append(
                 CalcAddCargoCommand(
                     fitID=self.fitID,
                     cargoInfo=CargoInfo(itemID=newCargoModItemID,
                                         amount=1),
                     commit=False))
         cmdReplace = CalcReplaceLocalModuleCommand(
             fitID=self.fitID,
             position=self.dstModPosition,
             newModInfo=newModInfo,
             unloadInvalidCharges=True,
             commit=False)
         commands.append(cmdReplace)
         # Submit batch now because we need to have updated info on fit to keep going
         success = self.internalHistory.submitBatch(*commands)
         newMod = fit.modules[self.dstModPosition]
         # Bail if drag happened to slot to which module cannot be dragged, will undo later
         if newMod.slot != dstModSlot:
             success = False
         if success:
             # If we had to unload charge, add it to cargo
             if cmdReplace.unloadedCharge and dstModChargeItemID is not None:
                 cmdAddCargoCharge = CalcAddCargoCommand(
                     fitID=self.fitID,
                     cargoInfo=CargoInfo(itemID=dstModChargeItemID,
                                         amount=dstModChargeAmount),
                     commit=False)
                 success = self.internalHistory.submit(cmdAddCargoCharge)
             # If we did not unload charge and there still was a charge, see if amount differs and process it
             elif not cmdReplace.unloadedCharge and dstModChargeItemID is not None:
                 # How many extra charges do we need to take from cargo
                 extraChargeAmount = newMod.numCharges - dstModChargeAmount
                 if extraChargeAmount > 0:
                     cmdRemoveCargoExtraCharge = CalcRemoveCargoCommand(
                         fitID=self.fitID,
                         cargoInfo=CargoInfo(itemID=dstModChargeItemID,
                                             amount=extraChargeAmount),
                         commit=False)
                     # Do not check if operation was successful or not, we're okay if we have no such
                     # charges in cargo
                     self.internalHistory.submit(cmdRemoveCargoExtraCharge)
                 elif extraChargeAmount < 0:
                     cmdAddCargoExtraCharge = CalcAddCargoCommand(
                         fitID=self.fitID,
                         cargoInfo=CargoInfo(itemID=dstModChargeItemID,
                                             amount=abs(extraChargeAmount)),
                         commit=False)
                     success = self.internalHistory.submit(
                         cmdAddCargoExtraCharge)
         if success:
             # Store info to properly send events later
             self.removedModItemID = dstModItemID
             self.addedModItemID = self.srcCargoItemID
         else:
             self.internalHistory.undoAll()
     else:
         return False
     eos.db.commit()
     sFit.recalc(fit)
     events = []
     if self.removedModItemID is not None:
         events.append(
             GE.FitChanged(fitID=self.fitID,
                           action='moddel',
                           typeID=self.removedModItemID))
     if self.addedModItemID is not None:
         events.append(
             GE.FitChanged(fitID=self.fitID,
                           action='modadd',
                           typeID=self.addedModItemID))
     if not events:
         events.append(GE.FitChanged(fitID=self.fitID))
     for event in events:
         wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), event)
     return success