Пример #1
0
 def Do(self):
     sFit = Fit.getInstance()
     fit = sFit.getFit(self.fitID)
     results = []
     for position in sorted(self.positions, reverse=True):
         drone = fit.drones[position]
         if drone.itemID == self.newItemID:
             continue
         info = DroneInfo.fromDrone(drone)
         info.itemID = self.newItemID
         cmdRemove = CalcRemoveLocalDroneCommand(
             fitID=self.fitID,
             position=position,
             amount=math.inf,
             commit=False)
         cmdAdd = CalcAddLocalDroneCommand(
             fitID=self.fitID,
             droneInfo=info,
             forceNewStack=True,
             ignoreRestrictions=True,
             commit=False)
         results.append(self.internalHistory.submitBatch(cmdRemove, cmdAdd))
     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
Пример #2
0
 def Do(self):
     sFit = Fit.getInstance()
     fit = sFit.getFit(self.fitID)
     drone = fit.drones[self.position]
     if self.amount >= drone.amount:
         return False
     info = DroneInfo.fromDrone(drone)
     info.amount = self.amount
     info.amountActive = min(self.amount, info.amountActive)
     commands = []
     commands.append(CalcRemoveLocalDroneCommand(
         fitID=self.fitID,
         position=self.position,
         amount=self.amount))
     commands.append(CalcAddLocalDroneCommand(
         fitID=self.fitID,
         droneInfo=info,
         forceNewStack=True,
         ignoreRestrictions=True))
     success = self.internalHistory.submitBatch(*commands)
     eos.db.flush()
     sFit.recalc(self.fitID)
     sFit.fill(self.fitID)
     eos.db.commit()
     wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID))
     return success
Пример #3
0
 def Do(self):
     sFit = Fit.getInstance()
     fit = sFit.getFit(self.fitID)
     drone = fit.drones[self.position]
     if self.amount >= drone.amount:
         return False
     info = DroneInfo.fromDrone(drone)
     info.amount = self.amount
     info.amountActive = min(self.amount, info.amountActive)
     commands = []
     commands.append(
         CalcRemoveLocalDroneCommand(fitID=self.fitID,
                                     position=self.position,
                                     amount=self.amount,
                                     commit=False))
     commands.append(
         CalcAddLocalDroneCommand(fitID=self.fitID,
                                  droneInfo=info,
                                  forceNewStack=True,
                                  commit=False))
     success = self.internalHistory.submitBatch(*commands)
     eos.db.commit()
     sFit.recalc(fit)
     wx.PostEvent(gui.mainFrame.MainFrame.getInstance(),
                  GE.FitChanged(fitID=self.fitID))
     return success
Пример #4
0
 def Do(self):
     sFit = Fit.getInstance()
     fit = sFit.getFit(self.fitID)
     results = []
     for itemID in self.itemIDs:
         drone = next(
             (pd for pd in fit.projectedDrones if pd.itemID == itemID),
             None)
         if drone is None:
             continue
         if drone.itemID == self.newItemID:
             continue
         info = DroneInfo.fromDrone(drone)
         info.itemID = self.newItemID
         cmdRemove = CalcRemoveProjectedDroneCommand(fitID=self.fitID,
                                                     itemID=itemID,
                                                     amount=math.inf,
                                                     commit=False)
         cmdAdd = CalcAddProjectedDroneCommand(fitID=self.fitID,
                                               droneInfo=info,
                                               commit=False)
         results.append(self.internalHistory.submitBatch(cmdRemove, cmdAdd))
     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
Пример #5
0
 def Do(self):
     pyfalog.debug('Doing addition of projected drone {} to fit {}'.format(self.droneInfo, self.fitID))
     fit = Fit.getInstance().getFit(self.fitID)
     drone = next((pd for pd in fit.projectedDrones if pd.itemID == self.droneInfo.itemID), None)
     # Changing existing stack
     if drone is not None:
         self.savedDroneInfo = DroneInfo.fromDrone(drone)
         # Ignore drone info's active amount parameter if we're adding to existing stack,
         # and decide based on stack's state
         drone.amount += self.droneInfo.amount
         if drone.amountActive > 0:
             drone.amountActive += self.droneInfo.amount
         eos.db.commit()
         return True
     # Making new stack
     drone = self.droneInfo.toDrone()
     if drone is None:
         return False
     if not drone.item.isType('projected'):
         pyfalog.debug('Drone is not projectable')
         return False
     try:
         fit.projectedDrones.append(drone)
     except HandledListActionError:
         pyfalog.warning('Failed to append to list')
         eos.db.commit()
         return False
     eos.db.commit()
     return True
Пример #6
0
 def Do(self):
     sFit = Fit.getInstance()
     fit = sFit.getFit(self.fitID)
     results = []
     for position in sorted(self.positions, reverse=True):
         drone = fit.drones[position]
         if drone.itemID == self.newItemID:
             continue
         info = DroneInfo.fromDrone(drone)
         info.itemID = self.newItemID
         cmdRemove = CalcRemoveLocalDroneCommand(
             fitID=self.fitID,
             position=position,
             amount=math.inf)
         cmdAdd = CalcAddLocalDroneCommand(
             fitID=self.fitID,
             droneInfo=info,
             forceNewStack=True,
             ignoreRestrictions=True)
         results.append(self.internalHistory.submitBatch(cmdRemove, cmdAdd))
     success = any(results)
     eos.db.flush()
     sFit.recalc(self.fitID)
     sFit.fill(self.fitID)
     eos.db.commit()
     wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID))
     return success
Пример #7
0
 def Do(self):
     pyfalog.debug('Doing addition of local drone {} to fit {}'.format(self.droneInfo, self.fitID))
     fit = Fit.getInstance().getFit(self.fitID)
     item = Market.getInstance().getItem(self.droneInfo.itemID, eager=("attributes", "group.category"))
     # If we're not adding any active drones, check if there's an inactive stack
     # with enough space for new drones and use it
     if not self.forceNewStack and self.droneInfo.amountActive == 0:
         maxStack = droneStackLimit(fit, item)
         for drone in fit.drones.find(item):
             if (
                 drone is not None and drone.amountActive == 0 and
                 drone.amount + self.droneInfo.amount <= maxStack
             ):
                 self.savedDroneInfo = DroneInfo.fromDrone(drone)
                 self.savedPosition = fit.drones.index(drone)
                 drone.amount += self.droneInfo.amount
                 return True
     # Do new stack otherwise
     drone = self.droneInfo.toDrone()
     if drone is None:
         return False
     if not self.ignoreRestrictions and not drone.fits(fit):
         pyfalog.warning('Drone does not fit')
         return False
     fit.drones.append(drone)
     if drone not in fit.drones:
         pyfalog.warning('Failed to append to list')
         return False
     self.savedPosition = fit.drones.index(drone)
     return True
Пример #8
0
 def Do(self):
     sFit = Fit.getInstance()
     fit = sFit.getFit(self.fitID)
     try:
         drone = fit.drones[self.position]
     except IndexError:
         return False
     if drone.isMutated:
         return False
     info = DroneInfo(
         amount=drone.amount,
         amountActive=drone.amountActive,
         itemID=self.itemID,
         baseItemID=drone.item.ID,
         mutaplasmidID=self.mutaplasmidID,
         mutations={})
     cmdRemove = CalcRemoveLocalDroneCommand(
         fitID=self.fitID,
         position=self.position,
         amount=math.inf)
     cmdAdd = CalcAddLocalDroneCommand(
         fitID=self.fitID,
         droneInfo=info,
         forceNewStack=True,
         ignoreRestrictions=True)
     success = self.internalHistory.submitBatch(cmdRemove, cmdAdd)
     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
Пример #9
0
 def Do(self):
     cmd = CalcAddLocalDroneCommand(fitID=self.fitID, droneInfo=DroneInfo(itemID=self.itemID, amount=self.amount, amountActive=0))
     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
Пример #10
0
 def __init__(self, fitID, drones):
     wx.Command.__init__(self, True, 'Import Local Drones')
     self.internalHistory = InternalCommandHistory()
     self.fitID = fitID
     self.droneInfos = []
     for itemID, amount, mutation in drones:
         if mutation:
             mutaplasmid, attrs = mutation
             self.droneInfos.append(
                 DroneInfo(itemID=mutaplasmid.resultingItem.ID,
                           amount=amount,
                           amountActive=0,
                           baseItemID=itemID,
                           mutaplasmidID=mutaplasmid.ID,
                           mutations=attrs))
         else:
             self.droneInfos.append(
                 DroneInfo(itemID=itemID, amount=amount, amountActive=0))
Пример #11
0
 def Do(self):
     cmd = CalcAddProjectedDroneCommand(fitID=self.fitID,
                                        droneInfo=DroneInfo(
                                            itemID=self.itemID,
                                            amount=1,
                                            amountActive=1))
     success = self.internalHistory.submit(cmd)
     Fit.getInstance().recalc(self.fitID)
     wx.PostEvent(gui.mainFrame.MainFrame.getInstance(),
                  GE.FitChanged(fitID=self.fitID))
     return success
Пример #12
0
 def __init__(self, fitID, baseItem, mutaplasmid, mutations, amount):
     wx.Command.__init__(self, True, 'Import Local Mutated Drone')
     self.internalHistory = InternalCommandHistory()
     self.fitID = fitID
     self.newDroneInfo = DroneInfo(
         amount=amount,
         amountActive=0,
         itemID=mutaplasmid.resultingItem.ID,
         baseItemID=baseItem.ID,
         mutaplasmidID=mutaplasmid.ID,
         mutations=mutations)
Пример #13
0
 def Do(self):
     pyfalog.debug('Doing change of local drone amount to {} at position {} on fit {}'.format(self.amount, self.position, self.fitID))
     fit = Fit.getInstance().getFit(self.fitID)
     drone = fit.drones[self.position]
     self.savedDroneInfo = DroneInfo.fromDrone(drone)
     if self.amount == self.savedDroneInfo.amount:
         return False
     drone.amount = self.amount
     if drone.amountActive > 0:
         difference = self.amount - self.savedDroneInfo.amount
         drone.amount = self.amount
         drone.amountActive = max(min(drone.amountActive + difference, drone.amount), 0)
     return True
Пример #14
0
 def Do(self):
     sFit = Fit.getInstance()
     fit = sFit.getFit(self.fitID)
     try:
         drone = fit.drones[self.position]
     except IndexError:
         return False
     info = DroneInfo.fromDrone(drone)
     cmd = CalcAddLocalDroneCommand(fitID=self.fitID, droneInfo=info, forceNewStack=True)
     success = self.internalHistory.submit(cmd)
     sFit.recalc(self.fitID)
     sFit.fill(self.fitID)
     wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID))
     return success
Пример #15
0
 def Do(self):
     pyfalog.debug('Doing removal of {} projected drones {} from fit {}'.format(self.amountToRemove, self.itemID, self.fitID))
     fit = Fit.getInstance().getFit(self.fitID)
     drone = next((pd for pd in fit.projectedDrones if pd.itemID == self.itemID), None)
     if drone is None:
         pyfalog.warning('Unable to find projected drone')
         return False
     self.savedDroneInfo = DroneInfo.fromDrone(drone)
     drone.amount = max(drone.amount - self.amountToRemove, 0)
     # Remove stack if we have no items remaining
     if drone.amount == 0:
         fit.projectedDrones.remove(drone)
     else:
         if drone.amountActive > 0:
             drone.amountActive = min(drone.amountActive, drone.amount)
     return True
Пример #16
0
    def Do(self):
        pyfalog.debug('Doing removal of {} local drones at position {} from fit {}'.format(self.amountToRemove, self.position, self.fitID))
        fit = Fit.getInstance().getFit(self.fitID)
        drone = fit.drones[self.position]
        self.savedDroneInfo = DroneInfo.fromDrone(drone)

        drone.amount = max(drone.amount - self.amountToRemove, 0)
        if drone.amountActive > 0:
            drone.amountActive = min(drone.amountActive, drone.amount)

        if drone.amount == 0:
            fit.drones.remove(drone)
            self.removedStack = True
        else:
            self.removedStack = False

        return True
Пример #17
0
 def Do(self):
     results = []
     for itemID, amount in self.drones:
         cmd = CalcAddLocalDroneCommand(fitID=self.fitID,
                                        droneInfo=DroneInfo(itemID=itemID,
                                                            amount=amount,
                                                            amountActive=0),
                                        forceNewStack=True)
         results.append(self.internalHistory.submit(cmd))
     success = any(results)
     eos.db.flush()
     sFit = Fit.getInstance()
     sFit.recalc(self.fitID)
     sFit.fill(self.fitID)
     eos.db.commit()
     wx.PostEvent(gui.mainFrame.MainFrame.getInstance(),
                  GE.FitChanged(fitIDs=(self.fitID, )))
     return success
Пример #18
0
 def Do(self):
     pyfalog.debug(
         'Doing change of local drone amount to {} at position {} on fit {}'
         .format(self.amount, self.position, self.fitID))
     fit = Fit.getInstance().getFit(self.fitID)
     drone = fit.drones[self.position]
     self.savedDroneInfo = DroneInfo.fromDrone(drone)
     if self.amount == self.savedDroneInfo.amount:
         return False
     drone.amount = self.amount
     if drone.amountActive > 0:
         difference = self.amount - self.savedDroneInfo.amount
         drone.amount = self.amount
         drone.amountActive = max(
             min(drone.amountActive + difference, drone.amount), 0)
     if self.commit:
         eos.db.commit()
     return True
Пример #19
0
 def Do(self):
     sFit = Fit.getInstance()
     fit = sFit.getFit(self.fitID)
     drone = fit.drones[self.position]
     if drone.itemID == self.newItemID:
         return False
     info = DroneInfo.fromDrone(drone)
     info.itemID = self.newItemID
     cmdRemove = CalcRemoveLocalDroneCommand(fitID=self.fitID,
                                             position=self.position,
                                             amount=math.inf)
     cmdAdd = CalcAddLocalDroneCommand(fitID=self.fitID,
                                       droneInfo=info,
                                       forceNewStack=True)
     success = self.internalHistory.submitBatch(cmdRemove, cmdAdd)
     sFit.recalc(fit)
     wx.PostEvent(gui.mainFrame.MainFrame.getInstance(),
                  GE.FitChanged(fitID=self.fitID))
     return success
Пример #20
0
    def Do(self):
        pyfalog.debug(
            'Doing removal of {} local drones at position {} from fit {}'.
            format(self.amountToRemove, self.position, self.fitID))
        fit = Fit.getInstance().getFit(self.fitID)
        drone = fit.drones[self.position]
        self.savedDroneInfo = DroneInfo.fromDrone(drone)

        drone.amount = max(drone.amount - self.amountToRemove, 0)
        if drone.amountActive > 0:
            drone.amountActive = min(drone.amountActive, drone.amount)

        if drone.amount == 0:
            fit.drones.remove(drone)
            self.removedStack = True
        else:
            self.removedStack = False

        return True
Пример #21
0
 def Do(self):
     pyfalog.debug(
         'Doing removal of {} projected drones {} from fit {}'.format(
             self.amountToRemove, self.itemID, self.fitID))
     fit = Fit.getInstance().getFit(self.fitID)
     drone = next(
         (pd for pd in fit.projectedDrones if pd.itemID == self.itemID),
         None)
     if drone is None:
         pyfalog.warning('Unable to find projected drone')
         return False
     self.savedDroneInfo = DroneInfo.fromDrone(drone)
     drone.amount = max(drone.amount - self.amountToRemove, 0)
     # Remove stack if we have no items remaining
     if drone.amount == 0:
         fit.projectedDrones.remove(drone)
     else:
         if drone.amountActive > 0:
             drone.amountActive = min(drone.amountActive, drone.amount)
     return True
Пример #22
0
 def Do(self):
     sFit = Fit.getInstance()
     fit = sFit.getFit(self.fitID)
     drone = next(
         (pd for pd in fit.projectedDrones if pd.itemID == self.itemID),
         None)
     if drone is None:
         return False
     if drone.itemID == self.newItemID:
         return False
     info = DroneInfo.fromDrone(drone)
     info.itemID = self.newItemID
     cmdRemove = CalcRemoveProjectedDroneCommand(fitID=self.fitID,
                                                 itemID=self.itemID,
                                                 amount=math.inf)
     cmdAdd = CalcAddProjectedDroneCommand(fitID=self.fitID, droneInfo=info)
     success = self.internalHistory.submitBatch(cmdRemove, cmdAdd)
     sFit.recalc(fit)
     wx.PostEvent(gui.mainFrame.MainFrame.getInstance(),
                  GE.FitChanged(fitID=self.fitID))
     return success
Пример #23
0
 def Do(self):
     pyfalog.debug(
         'Doing change of projected drone {} amount to {} on fit {}'.format(
             self.itemID, self.amount, self.fitID))
     fit = Fit.getInstance().getFit(self.fitID)
     drone = next(
         (pd for pd in fit.projectedDrones if pd.itemID == self.itemID),
         None)
     if drone is None:
         pyfalog.warning('Cannot find projected drone')
         return False
     self.savedDroneInfo = DroneInfo.fromDrone(drone)
     if self.amount == self.savedDroneInfo.amount:
         return False
     drone.amount = self.amount
     if drone.amountActive > 0:
         difference = self.amount - self.savedDroneInfo.amount
         drone.amount = self.amount
         drone.amountActive = max(
             min(drone.amountActive + difference, drone.amount), 0)
     return True
Пример #24
0
 def Do(self):
     sFit = Fit.getInstance()
     fit = sFit.getFit(self.fitID)
     results = []
     for itemID in self.itemIDs:
         drone = next((pd for pd in fit.projectedDrones if pd.itemID == itemID), None)
         if drone is None:
             continue
         if drone.itemID == self.newItemID:
             continue
         info = DroneInfo.fromDrone(drone)
         info.itemID = self.newItemID
         cmdRemove = CalcRemoveProjectedDroneCommand(fitID=self.fitID, itemID=itemID, amount=math.inf)
         cmdAdd = CalcAddProjectedDroneCommand(fitID=self.fitID, droneInfo=info)
         results.append(self.internalHistory.submitBatch(cmdRemove, cmdAdd))
     success = any(results)
     eos.db.flush()
     sFit.recalc(self.fitID)
     sFit.fill(self.fitID)
     eos.db.commit()
     wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID))
     return success
Пример #25
0
 def Do(self):
     pyfalog.debug('Doing addition of local drone {} to fit {}'.format(
         self.droneInfo, self.fitID))
     fit = Fit.getInstance().getFit(self.fitID)
     item = Market.getInstance().getItem(self.droneInfo.itemID,
                                         eager=("attributes",
                                                "group.category"))
     # If we're not adding any active drones, check if there's an inactive stack
     # with enough space for new drones and use it
     if not self.forceNewStack and self.droneInfo.amountActive == 0:
         for drone in fit.drones.find(item):
             if (drone is not None and drone.amountActive == 0
                     and drone.amount + self.droneInfo.amount) <= max(
                         5, fit.extraAttributes["maxActiveDrones"]):
                 self.savedDroneInfo = DroneInfo.fromDrone(drone)
                 self.savedPosition = fit.drones.index(drone)
                 drone.amount += self.droneInfo.amount
                 if self.commit:
                     eos.db.commit()
                 return True
     # Do new stack otherwise
     drone = self.droneInfo.toDrone()
     if drone is None:
         return False
     if not drone.fits(fit):
         pyfalog.warning('Drone does not fit')
         return False
     try:
         fit.drones.append(drone)
     except HandledListActionError:
         pyfalog.warning('Failed to append to list')
         if self.commit:
             eos.db.commit()
         return False
     if self.commit:
         eos.db.commit()
     self.savedPosition = fit.drones.index(drone)
     return True