def getTestSet(setType): def getT2ItemsWhere(additionalFilter, mustBeOffensive=False, category="Module"): # Used to obtain a smaller subset of items while still containing examples of each group. T2_META_LEVEL = 5 categoryID = getCategory(category).categoryID result = gamedata_session.query(Item).join(ItemEffect, Group, Attribute).\ filter( additionalFilter, Item.metaLevel == T2_META_LEVEL, Group.categoryID == categoryID, ).all() if mustBeOffensive: result = filter(lambda t: t.offensive is True, result) return list(result) def getChargeType(item, setType): if setType == "turret": return str(item.attributes["chargeGroup1"].value) + "-" + str( item.attributes["chargeSize"].value) return str(item.attributes["chargeGroup1"].value) if setType in EfsPort.wepTestSet.keys(): return EfsPort.wepTestSet[setType] else: EfsPort.wepTestSet[setType] = [] modSet = EfsPort.wepTestSet[setType] if setType == "drone": ilist = getT2ItemsWhere(True, True, "Drone") for item in ilist: drone = Drone(item) drone.amount = 1 drone.amountActive = 1 drone.itemModifiedAttributes.parent = drone modSet.append(drone) return modSet turretFittedEffectID = gamedata_session.query(Effect).filter( Effect.name == "turretFitted").first().effectID launcherFittedEffectID = gamedata_session.query(Effect).filter( Effect.name == "launcherFitted").first().effectID if setType == "launcher": effectFilter = ItemEffect.effectID == launcherFittedEffectID reqOff = False else: effectFilter = ItemEffect.effectID == turretFittedEffectID reqOff = True ilist = getT2ItemsWhere(effectFilter, reqOff) previousChargeTypes = [] # Get modules from item list for item in ilist: chargeType = getChargeType(item, setType) # Only add turrets if we don"t already have one with the same size and ammo type. if setType == "launcher" or chargeType not in previousChargeTypes: previousChargeTypes.append(chargeType) mod = Module(item) modSet.append(mod) sMkt = Market.getInstance() # Due to typed missile damage bonuses we"ll need to add extra launchers to cover all four types. additionalLaunchers = [] for mod in modSet: clist = list( gamedata_session.query(Item).options().filter( Item.groupID == mod.getModifiedItemAttr( "chargeGroup1")).all()) mods = [mod] charges = [clist[0]] if setType == "launcher": # We don"t want variations of missiles we already have prevCharges = list(sMkt.getVariationsByItems(charges)) testCharges = [] for charge in clist: if charge not in prevCharges: testCharges.append(charge) prevCharges += sMkt.getVariationsByItems([charge]) for c in testCharges: charges.append(c) additionalLauncher = Module(mod.item) mods.append(additionalLauncher) for i in range(len(mods)): mods[i].charge = charges[i] mods[i].reloadForce = True mods[i].state = 2 if setType == "launcher" and i > 0: additionalLaunchers.append(mods[i]) modSet += additionalLaunchers return modSet
class FitAddModuleCommand(wx.Command): """" Fitting command that appends a module to a fit using the first available slot. In the case of a Subsystem, it checks if there is already a subsystem with the same slot, and runs the replace command instead. from sFit.appendModule """ def __init__(self, fitID, itemID, mutaplasmidID=None, baseID=None): wx.Command.__init__(self, True) self.fitID = fitID self.itemID = itemID self.mutaplasmidID = mutaplasmidID self.baseID = baseID self.new_position = None self.change = None self.replace_cmd = None def Do(self): sFit = Fit.getInstance() fitID = self.fitID itemID = self.itemID fit = eos.db.getFit(fitID) item = eos.db.getItem(itemID, eager=("attributes", "group.category")) bItem = eos.db.getItem(self.baseID) if self.baseID else None mItem = next( (x for x in bItem.mutaplasmids if x.ID == self.mutaplasmidID)) if self.mutaplasmidID else None try: self.module = Module(item, bItem, mItem) except ValueError: pyfalog.warning("Invalid module: {}", item) return False # If subsystem and we need to replace, run the replace command instead and bypass the rest of this command if self.module.item.category.name == "Subsystem": for mod in fit.modules: if mod.getModifiedItemAttr( "subSystemSlot") == self.module.getModifiedItemAttr( "subSystemSlot"): from .fitReplaceModule import FitReplaceModuleCommand self.replace_cmd = FitReplaceModuleCommand( self.fitID, mod.modPosition, itemID) return self.replace_cmd.Do() if self.module.fits(fit): pyfalog.debug("Adding {} as module for fit {}", self.module, fit) self.module.owner = fit numSlots = len(fit.modules) fit.modules.append(self.module) if self.module.isValidState(State.ACTIVE): self.module.state = State.ACTIVE # todo: fix these # As some items may affect state-limiting attributes of the ship, calculate new attributes first # self.recalc(fit) # Then, check states of all modules and change where needed. This will recalc if needed sFit.checkStates(fit, self.module) # fit.fill() eos.db.commit() self.change = numSlots != len(fit.modules) self.new_position = self.module.modPosition else: return False return True def Undo(self): # We added a subsystem module, which actually ran the replace command. Run the undo for that guy instead if self.replace_cmd: return self.replace_cmd.Undo() from .fitRemoveModule import FitRemoveModuleCommand # Avoid circular import if self.new_position: cmd = FitRemoveModuleCommand(self.fitID, [self.new_position]) cmd.Do() return True
def getTestSet(setType): def getT2ItemsWhere(additionalFilter, mustBeOffensive=False, category="Module"): # Used to obtain a smaller subset of items while still containing examples of each group. T2_META_LEVEL = 5 metaLevelAttrID = getAttributeInfo("metaLevel").attributeID categoryID = getCategory(category).categoryID result = gamedata_session.query(Item).join(ItemEffect, Group, Attribute).\ filter( additionalFilter, Attribute.attributeID == metaLevelAttrID, Attribute.value == T2_META_LEVEL, Group.categoryID == categoryID, ).all() if mustBeOffensive: result = filter(lambda t: t.offensive is True, result) return list(result) def getChargeType(item, setType): if setType == "turret": return str(item.attributes["chargeGroup1"].value) + "-" + str(item.attributes["chargeSize"].value) return str(item.attributes["chargeGroup1"].value) if setType in EfsPort.wepTestSet.keys(): return EfsPort.wepTestSet[setType] else: EfsPort.wepTestSet[setType] = [] modSet = EfsPort.wepTestSet[setType] if setType == "drone": ilist = getT2ItemsWhere(True, True, "Drone") for item in ilist: drone = Drone(item) drone.amount = 1 drone.amountActive = 1 drone.itemModifiedAttributes.parent = drone modSet.append(drone) return modSet turretFittedEffectID = gamedata_session.query(Effect).filter(Effect.name == "turretFitted").first().effectID launcherFittedEffectID = gamedata_session.query(Effect).filter(Effect.name == "launcherFitted").first().effectID if setType == "launcher": effectFilter = ItemEffect.effectID == launcherFittedEffectID reqOff = False else: effectFilter = ItemEffect.effectID == turretFittedEffectID reqOff = True ilist = getT2ItemsWhere(effectFilter, reqOff) previousChargeTypes = [] # Get modules from item list for item in ilist: chargeType = getChargeType(item, setType) # Only add turrets if we don"t already have one with the same size and ammo type. if setType == "launcher" or chargeType not in previousChargeTypes: previousChargeTypes.append(chargeType) mod = Module(item) modSet.append(mod) sMkt = Market.getInstance() # Due to typed missile damage bonuses we"ll need to add extra launchers to cover all four types. additionalLaunchers = [] for mod in modSet: clist = list(gamedata_session.query(Item).options(). filter(Item.groupID == mod.getModifiedItemAttr("chargeGroup1")).all()) mods = [mod] charges = [clist[0]] if setType == "launcher": # We don"t want variations of missiles we already have prevCharges = list(sMkt.getVariationsByItems(charges)) testCharges = [] for charge in clist: if charge not in prevCharges: testCharges.append(charge) prevCharges += sMkt.getVariationsByItems([charge]) for c in testCharges: charges.append(c) additionalLauncher = Module(mod.item) mods.append(additionalLauncher) for i in range(len(mods)): mods[i].charge = charges[i] mods[i].reloadForce = True mods[i].state = 2 if setType == "launcher" and i > 0: additionalLaunchers.append(mods[i]) modSet += additionalLaunchers return modSet
class FitAddModuleCommand(wx.Command): """" Fitting command that appends a module to a fit using the first available slot. In the case of a Subsystem, it checks if there is already a subsystem with the same slot, and runs the replace command instead. from sFit.appendModule """ def __init__(self, fitID, itemID, mutaplasmidID=None, baseID=None): wx.Command.__init__(self, True) self.fitID = fitID self.itemID = itemID self.mutaplasmidID = mutaplasmidID self.baseID = baseID self.new_position = None self.change = None self.replace_cmd = None def Do(self): sFit = Fit.getInstance() fitID = self.fitID itemID = self.itemID fit = eos.db.getFit(fitID) item = eos.db.getItem(itemID, eager=("attributes", "group.category")) bItem = eos.db.getItem(self.baseID) if self.baseID else None mItem = next((x for x in bItem.mutaplasmids if x.ID == self.mutaplasmidID)) if self.mutaplasmidID else None try: self.module = Module(item, bItem, mItem) except ValueError: pyfalog.warning("Invalid module: {}", item) return False # If subsystem and we need to replace, run the replace command instead and bypass the rest of this command if self.module.item.category.name == "Subsystem": for mod in fit.modules: if mod.getModifiedItemAttr("subSystemSlot") == self.module.getModifiedItemAttr("subSystemSlot"): from .fitReplaceModule import FitReplaceModuleCommand self.replace_cmd = FitReplaceModuleCommand(self.fitID, mod.modPosition, itemID) return self.replace_cmd.Do() if self.module.fits(fit): pyfalog.debug("Adding {} as module for fit {}", self.module, fit) self.module.owner = fit numSlots = len(fit.modules) fit.modules.append(self.module) if self.module.isValidState(State.ACTIVE): self.module.state = State.ACTIVE # todo: fix these # As some items may affect state-limiting attributes of the ship, calculate new attributes first # self.recalc(fit) # Then, check states of all modules and change where needed. This will recalc if needed sFit.checkStates(fit, self.module) # fit.fill() eos.db.commit() self.change = numSlots != len(fit.modules) self.new_position = self.module.modPosition else: return False return True def Undo(self): # We added a subsystem module, which actually ran the replace command. Run the undo for that guy instead if self.replace_cmd: return self.replace_cmd.Undo() from .fitRemoveModule import FitRemoveModuleCommand # Avoid circular import if self.new_position: cmd = FitRemoveModuleCommand(self.fitID, [self.new_position]) cmd.Do() return True