def Do(self):
        sFit = Fit.getInstance()
        fit = sFit.getFit(self.fitID)
        fit.ignoreRestrictions = not fit.ignoreRestrictions

        success = True
        if not fit.ignoreRestrictions:
            results = []
            for position, mod in sorted(enumerate(fit.modules),
                                        key=lambda i: i[0],
                                        reverse=True):
                if not mod.isEmpty and not mod.fits(fit, hardpointLimit=False):
                    cmd = CalcRemoveLocalModulesCommand(fitID=self.fitID,
                                                        positions=[position],
                                                        commit=False)
                    results.append(self.internalHistory.submit(cmd))
            if len(results) > 0:
                success = any(results)

        eos.db.commit()
        sFit.recalc(self.fitID)
        sFit.fill(self.fitID)
        wx.PostEvent(gui.mainFrame.MainFrame.getInstance(),
                     GE.FitChanged(fitID=self.fitID))
        return success
Beispiel #2
0
    def getT2MwdSpeed(fit, sFit):
        fitID = fit.ID
        propID = None
        shipHasMedSlots = fit.ship.getModifiedItemAttr("medSlots") > 0
        shipPower = fit.ship.getModifiedItemAttr("powerOutput")
        # Monitors have a 99% reduction to prop mod power requirements
        if fit.ship.typeName == "Monitor":
            shipPower *= 100
        rigSize = fit.ship.getModifiedItemAttr("rigSize")
        if not shipHasMedSlots:
            return None

        filterVal = Item.groupID == getGroup("Propulsion Module").ID
        propMods = gamedata_session.query(Item).options().filter(
            filterVal).all()
        mapPropData = lambda propName: \
                      next(map(lambda propMod: {"id": propMod.typeID, "powerReq": propMod.attributes["power"].value},
                               (filter(lambda mod: mod.typeName == propName, propMods))))
        mwd5mn = mapPropData("5MN Microwarpdrive II")
        mwd50mn = mapPropData("50MN Microwarpdrive II")
        mwd500mn = mapPropData("500MN Microwarpdrive II")
        mwd50000mn = mapPropData("50000MN Microwarpdrive II")
        if rigSize == PortEftRigSize.SMALL or rigSize is None:
            propID = mwd5mn["id"] if shipPower > mwd5mn["powerReq"] else None
        elif rigSize == PortEftRigSize.MEDIUM:
            propID = mwd50mn[
                "id"] if shipPower > mwd50mn["powerReq"] else mwd5mn["id"]
        elif rigSize == PortEftRigSize.LARGE:
            propID = mwd500mn[
                "id"] if shipPower > mwd500mn["powerReq"] else mwd50mn["id"]
        elif rigSize == PortEftRigSize.CAPITAL:
            propID = mwd50000mn[
                "id"] if shipPower > mwd50000mn["powerReq"] else mwd500mn["id"]

        if propID is None:
            return None
        cmd = CalcAddLocalModuleCommand(fitID, ModuleInfo(itemID=propID))
        cmd.Do()
        if cmd.needsGuiRecalc:
            sFit.recalc(fit)
        fit = eos.db.getFit(fitID)
        mwdPropSpeed = fit.maxSpeed
        mwdPosition = list(
            filter(lambda mod: mod.item and mod.item.ID == propID,
                   fit.modules))[0].position
        cmd = CalcRemoveLocalModulesCommand(fitID, [mwdPosition])
        cmd.Do()
        if cmd.needsGuiRecalc:
            sFit.recalc(fit)
        fit = eos.db.getFit(fitID)
        return mwdPropSpeed
Beispiel #3
0
 def Do(self):
     sFit = Fit.getInstance()
     fit = sFit.getFit(self.fitID)
     self.savedTypeIDs = {m.itemID for m in fit.modules if not m.isEmpty}
     cmd = CalcRemoveLocalModulesCommand(fitID=self.fitID,
                                         positions=self.positions)
     success = self.internalHistory.submit(cmd)
     sFit.recalc(self.fitID)
     wx.PostEvent(
         gui.mainFrame.MainFrame.getInstance(),
         GE.FitChanged(
             fitID=self.fitID, action='moddel', typeID=self.savedTypeIDs) if
         success and self.savedTypeIDs else GE.FitChanged(fitID=self.fitID))
     return success
Beispiel #4
0
 def Do(self):
     sMkt = Market.getInstance()
     sFit = Fit.getInstance()
     fit = sFit.getFit(self.fitID)
     self.savedTypeIDs = {m.itemID for m in fit.modules if not m.isEmpty}
     cmd = CalcRemoveLocalModulesCommand(fitID=self.fitID,
                                         positions=self.positions)
     success = self.internalHistory.submit(cmd)
     for container in (cmd.savedSubInfos, cmd.savedModInfos):
         for position in sorted(container, reverse=True):
             modInfo = container[position]
             sMkt.storeRecentlyUsed(modInfo.itemID)
     if cmd.needsGuiRecalc:
         eos.db.flush()
         sFit.recalc(self.fitID)
     self.savedRemovedDummies = sFit.fill(self.fitID)
     eos.db.commit()
     wx.PostEvent(
         gui.mainFrame.MainFrame.getInstance(),
         GE.FitChanged(fitIDs=(self.fitID, ),
                       action='moddel',
                       typeID=self.savedTypeIDs) if success
         and self.savedTypeIDs else GE.FitChanged(fitIDs=(self.fitID, )))
     return success
 def Do(self):
     fit = Fit.getInstance().getFit(self.fitID)
     srcMod = fit.modules[self.srcModPosition]
     if srcMod.isEmpty:
         return False
     srcModItemID = srcMod.itemID
     dstCargo = next((c for c in fit.cargo if c.itemID == self.dstCargoItemID), None)
     success = False
     # Attempt to swap if we're moving our module onto a module in the cargo hold
     if not self.copy and dstCargo is not None and dstCargo.item.isModule:
         if srcModItemID == self.dstCargoItemID:
             return False
         srcModSlot = srcMod.slot
         newModInfo = ModuleInfo.fromModule(srcMod, unmutate=True)
         newModInfo.itemID = self.dstCargoItemID
         srcModChargeItemID = srcMod.chargeID
         srcModChargeAmount = srcMod.numCharges
         commands = []
         commands.append(CalcRemoveCargoCommand(
             fitID=self.fitID,
             cargoInfo=CargoInfo(itemID=self.dstCargoItemID, amount=1),
             commit=False))
         commands.append(CalcAddCargoCommand(
             fitID=self.fitID,
             # We cannot put mutated items to cargo, so use unmutated item ID
             cargoInfo=CargoInfo(itemID=ModuleInfo.fromModule(srcMod, unmutate=True).itemID, amount=1),
             commit=False))
         cmdReplace = CalcReplaceLocalModuleCommand(
             fitID=self.fitID,
             position=self.srcModPosition,
             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.srcModPosition]
         # Process charge changes if module is moved to proper slot
         if newMod.slot == srcModSlot:
             # If we had to unload charge, add it to cargo
             if cmdReplace.unloadedCharge and srcModChargeItemID is not None:
                 cmdAddCargoCharge = CalcAddCargoCommand(
                     fitID=self.fitID,
                     cargoInfo=CargoInfo(itemID=srcModChargeItemID, amount=srcModChargeAmount),
                     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 srcModChargeItemID is not None:
                 # How many extra charges do we need to take from cargo
                 extraChargeAmount = newMod.numCharges - srcModChargeAmount
                 if extraChargeAmount > 0:
                     cmdRemoveCargoExtraCharge = CalcRemoveCargoCommand(
                         fitID=self.fitID,
                         cargoInfo=CargoInfo(itemID=srcModChargeItemID, 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=srcModChargeItemID, amount=abs(extraChargeAmount)),
                         commit=False)
                     success = self.internalHistory.submit(cmdAddCargoExtraCharge)
             if success:
                 # Store info to properly send events later
                 self.removedModItemID = srcModItemID
                 self.addedModItemID = self.dstCargoItemID
         # If drag happened to module which cannot be fit into current slot - consider it as failure
         else:
             success = False
         # And in case of any failures, cancel everything to try to do move instead
         if not success:
             self.internalHistory.undoAll()
     # Just dump module and its charges into cargo when copying or moving to cargo
     if not success:
         commands = []
         commands.append(CalcAddCargoCommand(
             fitID=self.fitID,
             cargoInfo=CargoInfo(itemID=ModuleInfo.fromModule(srcMod, unmutate=True).itemID, amount=1),
             commit=False))
         if srcMod.chargeID is not None:
             commands.append(CalcAddCargoCommand(
                 fitID=self.fitID,
                 cargoInfo=CargoInfo(itemID=srcMod.chargeID, amount=srcMod.numCharges),
                 commit=False))
         if not self.copy:
             commands.append(CalcRemoveLocalModulesCommand(
                 fitID=self.fitID,
                 positions=[self.srcModPosition],
                 commit=False))
         success = self.internalHistory.submitBatch(*commands)
     eos.db.commit()
     Fit.getInstance().recalc(self.fitID)
     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