def validate(self): # Get ship's resource output, setting it to 0 # if fitting doesn't have ship assigned, # or ship doesn't have resource output attribute shipHolder = self._tracker._fit.ship try: shipHolderAttribs = shipHolder.attributes except AttributeError: resourceOutput = 0 else: try: resourceOutput = shipHolderAttribs[self.__outputAttr] except KeyError: resourceOutput = 0 # Calculate resource consumption of all holders on ship totalResourceConsumption = 0 # Also use the same loop to compose set of holders, # which actually consume resource (have positive non-null # usage) resourceConsumerData = {} for resourceUser in self.__resourceUsers: resourceUse = resourceUser.attributes[self.__usageAttr] totalResourceConsumption += resourceUse if resourceUse > 0: resourceConsumerData[resourceUser] = resourceUse # If we're out of resource, raise error # with holders-resource-consumers if totalResourceConsumption > resourceOutput: taintedHolders = {} for holder in resourceConsumerData: taintedHolders[holder] = ResourceErrorData( output=resourceOutput, totalUsage=totalResourceConsumption, holderConsumption=resourceConsumerData[holder]) raise RegisterValidationError(taintedHolders)
def validate(self): taintedHolders = {} # Go through restricted holders for holder in self.__restrictedHolders: # Container for skill requirement errors skillRequirementErrors = [] # Check each skill requirement for requiredSkillId in holder.item.requiredSkills: requiredSkillLevel = holder.item.requiredSkills[ requiredSkillId] skillHolders = self.__skillHolders.get(requiredSkillId) or () # Pick max level of all skill holders, absence of skill # is considered as skill level set to None skillLevel = None for skillHolder in skillHolders: skillHolderLevel = skillHolder.level if skillLevel is None: skillLevel = skillHolderLevel elif skillHolderLevel is not None: skillLevel = max(skillLevel, skillHolderLevel) # Last check - if skill level is lower than expected, current holder # is tainted; mark it so and move to the next one if skillLevel is None or skillLevel < requiredSkillLevel: skillRequirementError = SkillRequirementErrorData( skill=requiredSkillId, level=skillLevel, requiredLevel=requiredSkillLevel) skillRequirementErrors.append(skillRequirementError) if skillRequirementErrors: taintedHolders[holder] = tuple(skillRequirementErrors) if taintedHolders: raise RegisterValidationError(taintedHolders)
def validate(self): launchedDrones = len(self.__restrictedHolders) # Do not check anything if we don't have any launched drones if not launchedDrones: return # Get number of drones fit can have in space; consider # it as 0 if fitting doesn't have character, or # attribute isn't available characterHolder = self._tracker._fit.character try: characterHolderAttribs = characterHolder.attributes except AttributeError: maxLaunchedDrones = 0 else: try: maxLaunchedDrones = characterHolderAttribs[ Attribute.maxActiveDrones] except KeyError: maxLaunchedDrones = 0 # If number of registered drones exceeds number of maximum number # of allowed drones, raise error if launchedDrones > maxLaunchedDrones: taintedHolders = {} for holder in self.__restrictedHolders: taintedHolders[holder] = LaunchedDroneErrorData( maxLaunchedDrones=maxLaunchedDrones, launchedDrones=launchedDrones) raise RegisterValidationError(taintedHolders)
def validate(self): shipHolder = self._tracker._fit.ship # No ship - no restriction try: shipItem = shipHolder.item except AttributeError: return # Set with allowed groups allowedGroups = set() # Find out if we have restriction, and which drone groups it allows for restrictionAttr in (Attribute.allowedDroneGroup1, Attribute.allowedDroneGroup2): try: allowedGroup = shipItem.attributes[restrictionAttr] except KeyError: continue allowedGroups.add(allowedGroup) # No allowed group attributes - no restriction if not allowedGroups: return taintedHolders = {} # Convert set to tuple, this way we can use it # multiple times in error data, making sure that # it can't be modified by validation caller allowedGroups = tuple(allowedGroups) for holder in self.__restrictedHolders: # Taint holders, whose group is not allowed holderGroup = holder.item.groupId if holderGroup not in allowedGroups: taintedHolders[holder] = DroneGroupErrorData( allowedGroups=allowedGroups, droneGroup=holderGroup) if taintedHolders: raise RegisterValidationError(taintedHolders)
def validate(self): # Get type ID and group ID of ship, if no ship # available, assume they're None; it's safe to set # them to None because our primary data container # with restricted holders can't contain None in its # values anyway shipHolder = self._tracker._fit.ship try: shipTypeId = shipHolder.item.id shipGroupId = shipHolder.item.groupId except AttributeError: shipTypeId = None shipGroupId = None # Container for tainted holders taintedHolders = {} # Go through all known restricted holders for holder in self.__restrictedHolders: allowedData = self.__restrictedHolders[holder] # If ship's type isn't in allowed types and ship's # group isn't in allowed groups, holder is tainted if shipTypeId not in allowedData.types and shipGroupId not in allowedData.groups: allowedTypes = tuple(allowedData.types) allowedGroups = tuple(allowedData.groups) taintedHolders[holder] = ShipTypeGroupErrorData(allowedTypes=allowedTypes, allowedGroups=allowedGroups, shipType=shipTypeId, shipGroup=shipGroupId) # Raise error if there're any tainted holders if taintedHolders: raise RegisterValidationError(taintedHolders)
def validate(self): # Get number of tracked slots ship provides, # if fit doesn't have ship or ship doesn't # have corresponding slot attribute, assume number # of provided slots is 0 shipHolder = self._tracker._fit.ship try: shipHolderAttribs = shipHolder.attributes except AttributeError: slotsMax = 0 else: try: slotsMax = shipHolderAttribs[self.__slotAmountAttr] except KeyError: slotsMax = 0 # Assuming each holder takes exactly one slot, check # if we have enough of them; if number of holders which # take this slot is bigger than number of available slots, # then all holders in container are tainted slotsUsed = len(self.__slotConsumers) if slotsUsed > slotsMax: taintedHolders = {} for holder in self.__slotConsumers: taintedHolders[holder] = SlotNumberErrorData( slotsMax=slotsMax, slotsUsed=slotsUsed) raise RegisterValidationError(taintedHolders)
def validate(self): taintedHolders = {} # Go through all skill IDs for skillId in self.__skillHolders: skillHolders = self.__skillHolders[skillId] # If there's at least two skills with the same ID, # taint these holders if len(skillHolders) > 1: for holder in skillHolders: taintedHolders[holder] = SkillUniquenessErrorData(skill=skillId) if taintedHolders: raise RegisterValidationError(taintedHolders)
def validate(self): taintedHolders = {} for slotIndex in self.__slottedHolders: slotIndexHolders = self.__slottedHolders[slotIndex] # If more than one item occupies the same slot, all # holders in this slot are tainted if len(slotIndexHolders) > 1: for holder in slotIndexHolders: taintedHolders[holder] = SlotIndexErrorData( holderSlotIndex=slotIndex) if taintedHolders: raise RegisterValidationError(taintedHolders)
def validate(self): # Container for tainted holders taintedHolders = {} # Go through all restricted holders for holder in self.__maxGroupRestricted: # Get number of registered holders, assigned to group of current # restricted holder, and holder's restriction value groupId = holder.item.groupId groupHolders = len(self.__groupAll.get(groupId) or ()) maxGroupRestriction = holder.item.attributes[self.__maxGroupAttr] # If number of registered holders from this group is bigger, # then current holder is tainted if groupHolders > maxGroupRestriction: taintedHolders[holder] = MaxGroupErrorData( maxGroup=maxGroupRestriction, holderGroup=groupId, groupHolders=groupHolders) # Raise error if we detected any tainted holders if taintedHolders: raise RegisterValidationError(taintedHolders)
def validate(self): # Skip validation only if ship has capital # ships requirement, else carry on shipHolder = self._tracker._fit.ship try: shipItem = shipHolder.item except AttributeError: pass else: if Type.capitalShips in shipItem.requiredSkills: return # If we got here, then we're dealing with non-capital # ship, and all registered holders are tainted if self.__capitalHolders: taintedHolders = {} for holder in self.__capitalHolders: holderVolume = holder.item.attributes[Attribute.volume] taintedHolders[holder] = CapitalItemErrorData( allowedVolume=self._maxSubcapVolume, holderVolume=holderVolume) raise RegisterValidationError(taintedHolders)
def validate(self): shipHolder = self._tracker._fit.ship # Do not apply restriction when fit doesn't # have ship try: shipItem = shipHolder.item except AttributeError: return # If ship doesn't have restriction attribute, # allow all rigs - skip validation try: allowedRigSize = shipItem.attributes[Attribute.rigSize] except KeyError: return taintedHolders = {} for holder in self.__restrictedHolders: holderRigSize = holder.item.attributes[Attribute.rigSize] # If rig size specification on holder and ship differs, # then holder is tainted if holderRigSize != allowedRigSize: taintedHolders[holder] = RigSizeErrorData( allowedSize=allowedRigSize, holderSize=holderRigSize) if taintedHolders: raise RegisterValidationError(taintedHolders)