示例#1
0
文件: eft.py 项目: zzwpower/Pyfa
    def __makeModule(self, itemSpec):
        # Mutate item if needed
        m = None
        if itemSpec.mutationIdx in self.mutations:
            mutaItem, mutaAttrs = self.mutations[itemSpec.mutationIdx]
            mutaplasmid = getDynamicItem(mutaItem.ID)
            if mutaplasmid:
                try:
                    m = Module(mutaplasmid.resultingItem, itemSpec.item,
                               mutaplasmid)
                except ValueError:
                    pass
                else:
                    for attrID, mutator in m.mutators.items():
                        if attrID in mutaAttrs:
                            mutator.value = mutaAttrs[attrID]
        # If we still don't have item (item is not mutated or we
        # failed to construct mutated item), try to make regular item
        if m is None:
            try:
                m = Module(itemSpec.item)
            except ValueError:
                return None

        if itemSpec.charge is not None and m.isValidCharge(itemSpec.charge):
            m.charge = itemSpec.charge
        if itemSpec.offline and m.isValidState(FittingModuleState.OFFLINE):
            m.state = FittingModuleState.OFFLINE
        elif m.isValidState(FittingModuleState.ACTIVE):
            m.state = activeStateLimit(m.item)
        return m
示例#2
0
    def __makeModule(self, itemSpec):
        # Mutate item if needed
        m = None
        if itemSpec.mutationIdx in self.mutations:
            mutaItem, mutaAttrs = self.mutations[itemSpec.mutationIdx]
            mutaplasmid = getDynamicItem(mutaItem.ID)
            if mutaplasmid:
                try:
                    m = Module(mutaplasmid.resultingItem, itemSpec.item, mutaplasmid)
                except ValueError:
                    pass
                else:
                    for attrID, mutator in m.mutators.items():
                        if attrID in mutaAttrs:
                            mutator.value = mutaAttrs[attrID]
        # If we still don't have item (item is not mutated or we
        # failed to construct mutated item), try to make regular item
        if m is None:
            try:
                m = Module(itemSpec.item)
            except ValueError:
                return None

        if itemSpec.charge is not None and m.isValidCharge(itemSpec.charge):
            m.charge = itemSpec.charge
        if itemSpec.offline and m.isValidState(FittingModuleState.OFFLINE):
            m.state = FittingModuleState.OFFLINE
        elif m.isValidState(FittingModuleState.ACTIVE):
            m.state = activeStateLimit(m.item)
        return m
示例#3
0
class FitReplaceModuleCommand(wx.Command):
    """"
    Fitting command that changes an existing module into another.

    from sFit.changeModule
    """
    def __init__(self, fitID, position, itemID):
        wx.Command.__init__(self, True, "Change Module")
        self.fitID = fitID
        self.itemID = itemID
        self.position = position
        self.module = None  # the module version of itemID
        self.old_module = None

    def Do(self):
        fit = eos.db.getFit(self.fitID)

        mod = fit.modules[self.position]
        if not mod.isEmpty:
            self.old_module = ModuleInfoCache(mod.modPosition, mod.item.ID,
                                              mod.state, mod.charge,
                                              mod.baseItemID,
                                              mod.mutaplasmidID)

        return self.change_module(self.fitID, self.position, self.itemID)

    def Undo(self):
        if self.old_module is None:
            fit = eos.db.getFit(self.fitID)
            fit.modules.toDummy(self.position)
            return True
        self.change_module(self.fitID, self.position, self.old_module.itemID)
        self.module.state = self.old_module.state
        self.module.charge = self.old_module.charge
        return True

    def change_module(self, fitID, position, itemID):
        fit = eos.db.getFit(fitID)

        # We're trying to add a charge to a slot, which won't work. Instead, try to add the charge to the module in that slot.
        # todo: evaluate if this is still a thing
        # actually, this seems like it should be handled higher up...
        #
        # if self.isAmmo(itemID):
        #     module = fit.modules[self.position]
        #     if not module.isEmpty:
        #         self.setAmmo(fitID, itemID, [module])
        #     return True

        pyfalog.debug(
            "Changing position of module from position ({0}) for fit ID: {1}",
            self.position, fitID)

        item = eos.db.getItem(itemID, eager=("attributes", "group.category"))
        mod = fit.modules[self.position]

        try:
            self.module = Module(item)
        except ValueError:
            pyfalog.warning("Invalid item: {0}", itemID)
            return False

        if self.module.slot != mod.slot:
            return False

        # Dummy it out in case the next bit fails
        fit.modules.toDummy(self.position)

        if not self.module.fits(fit):
            self.Undo()
            return False

        self.module.owner = fit
        fit.modules.toModule(self.position, self.module)
        if self.module.isValidState(FittingModuleState.ACTIVE):
            self.module.state = FittingModuleState.ACTIVE

        if self.old_module and self.old_module.charge and self.module.isValidCharge(
                self.old_module.charge):
            self.module.charge = self.old_module.charge

        # Then, check states of all modules and change where needed. This will recalc if needed
        # self.checkStates(fit, m)

        # fit.fill()
        eos.db.commit()
        return True
示例#4
0
    def importEft(eftString):
        sMkt = Market.getInstance()
        offineSuffix = " /OFFLINE"

        fit = Fit()
        eftString = eftString.strip()
        lines = re.split('[\n\r]+', eftString)
        info = lines[0][1:-1].split(",", 1)

        if len(info) == 2:
            shipType = info[0].strip()
            fitName = info[1].strip()
        else:
            shipType = info[0].strip()
            fitName = "Imported %s" % shipType

        try:
            ship = sMkt.getItem(shipType)
            try:
                fit.ship = Ship(ship)
            except ValueError:
                fit.ship = Citadel(ship)
            fit.name = fitName
        except:
            return

        # maintain map of drones and their quantities
        droneMap = {}
        cargoMap = {}
        moduleList = []
        for i in range(1, len(lines)):
            ammoName = None
            extraAmount = None

            line = lines[i].strip()
            if not line:
                continue

            setOffline = line.endswith(offineSuffix)
            if setOffline is True:
                # remove offline suffix from line
                line = line[:len(line) - len(offineSuffix)]

            modAmmo = line.split(",")
            # matches drone and cargo with x{qty}
            modExtra = modAmmo[0].split(" x")

            if len(modAmmo) == 2:
                # line with a module and ammo
                ammoName = modAmmo[1].strip()
                modName = modAmmo[0].strip()
            elif len(modExtra) == 2:
                # line with drone/cargo and qty
                extraAmount = modExtra[1].strip()
                modName = modExtra[0].strip()
            else:
                # line with just module
                modName = modExtra[0].strip()

            try:
                # get item information. If we are on a Drone/Cargo line, throw out cargo
                item = sMkt.getItem(modName, eager="group.category")
            except:
                # if no data can be found (old names)
                continue

            if item.category.name == "Drone":
                extraAmount = int(
                    extraAmount) if extraAmount is not None else 1
                if modName not in droneMap:
                    droneMap[modName] = 0
                droneMap[modName] += extraAmount
            if len(modExtra) == 2 and item.category.name != "Drone":
                extraAmount = int(
                    extraAmount) if extraAmount is not None else 1
                if modName not in cargoMap:
                    cargoMap[modName] = 0
                cargoMap[modName] += extraAmount
            elif item.category.name == "Implant":
                fit.implants.append(Implant(item))
            # elif item.category.name == "Subsystem":
            #     try:
            #         subsystem = Module(item)
            #     except ValueError:
            #         continue
            #
            #     if subsystem.fits(fit):
            #         fit.modules.append(subsystem)
            else:
                try:
                    m = Module(item)
                except ValueError:
                    continue
                # Add subsystems before modules to make sure T3 cruisers have subsystems installed
                if item.category.name == "Subsystem":
                    if m.fits(fit):
                        fit.modules.append(m)
                else:
                    if ammoName:
                        try:
                            ammo = sMkt.getItem(ammoName)
                            if m.isValidCharge(ammo) and m.charge is None:
                                m.charge = ammo
                        except:
                            pass

                    if setOffline is True and m.isValidState(State.OFFLINE):
                        m.state = State.OFFLINE
                    elif m.isValidState(State.ACTIVE):
                        m.state = State.ACTIVE

                    moduleList.append(m)

        # Recalc to get slot numbers correct for T3 cruisers
        Fit.getInstance().recalc(fit)

        for m in moduleList:
            if m.fits(fit):
                m.owner = fit
                if not m.isValidState(m.state):
                    print("Error: Module", m, "cannot have state", m.state)

                fit.modules.append(m)

        for droneName in droneMap:
            d = Drone(sMkt.getItem(droneName))
            d.amount = droneMap[droneName]
            fit.drones.append(d)

        for cargoName in cargoMap:
            c = Cargo(sMkt.getItem(cargoName))
            c.amount = cargoMap[cargoName]
            fit.cargo.append(c)

        return fit
示例#5
0
class FitReplaceModuleCommand(wx.Command):
    """"
    Fitting command that changes an existing module into another.

    from sFit.changeModule
    """
    def __init__(self, fitID, position, itemID):
        wx.Command.__init__(self, True, "Change Module")
        self.fitID = fitID
        self.itemID = itemID
        self.position = position
        self.module = None  # the module version of itemID
        self.old_module = None

    def Do(self):
        fit = eos.db.getFit(self.fitID)

        mod = fit.modules[self.position]
        if not mod.isEmpty:
            self.old_module = ModuleInfoCache(mod.modPosition, mod.item.ID, mod.state, mod.charge, mod.baseItemID,
                                              mod.mutaplasmidID)

        return self.change_module(self.fitID, self.position, self.itemID)

    def Undo(self):
        if self.old_module is None:
            fit = eos.db.getFit(self.fitID)
            fit.modules.toDummy(self.position)
            return True
        self.change_module(self.fitID, self.position, self.old_module.itemID)
        self.module.state = self.old_module.state
        self.module.charge = self.old_module.charge
        return True

    def change_module(self, fitID, position, itemID):
        fit = eos.db.getFit(fitID)

        # We're trying to add a charge to a slot, which won't work. Instead, try to add the charge to the module in that slot.
        # todo: evaluate if this is still a thing
        # actually, this seems like it should be handled higher up...
        #
        # if self.isAmmo(itemID):
        #     module = fit.modules[self.position]
        #     if not module.isEmpty:
        #         self.setAmmo(fitID, itemID, [module])
        #     return True

        pyfalog.debug("Changing position of module from position ({0}) for fit ID: {1}", self.position, fitID)

        item = eos.db.getItem(itemID, eager=("attributes", "group.category"))
        mod = fit.modules[self.position]

        try:
            self.module = Module(item)
        except ValueError:
            pyfalog.warning("Invalid item: {0}", itemID)
            return False

        if self.module.slot != mod.slot:
            return False

        # Dummy it out in case the next bit fails
        fit.modules.toDummy(self.position)

        if self.module.fits(fit):
            self.module.owner = fit
            fit.modules.toModule(self.position, self.module)
            if self.module.isValidState(State.ACTIVE):
                self.module.state = State.ACTIVE

            if self.old_module and self.old_module.charge and self.module.isValidCharge(self.old_module.charge):
                self.module.charge = self.old_module.charge

            # Then, check states of all modules and change where needed. This will recalc if needed
            # self.checkStates(fit, m)

            # fit.fill()
            eos.db.commit()
            return True
        return False