Exemple #1
0
 def validate(self):
     tainted_holders = {}
     # Go through restricted holders
     for holder in self.__restricted_holders:
         # Container for skill requirement errors
         # for current holder
         skill_requirement_errors = []
         # Check each skill requirement
         for required_skill_id in holder.item.required_skills:
             required_skill_level = holder.item.required_skills[
                 required_skill_id]
             # Get skill level with None as fallback value for case
             # when we don't have such skill in fit
             try:
                 skill_level = self._fit.skills[required_skill_id].level
             except KeyError:
                 skill_level = None
             # Last check - if skill level is lower than expected, current holder
             # is tainted; mark it so and move to the next one
             if skill_level is None or skill_level < required_skill_level:
                 skill_requirement_error = SkillRequirementErrorData(
                     skill=required_skill_id,
                     level=skill_level,
                     required_level=required_skill_level)
                 skill_requirement_errors.append(skill_requirement_error)
         if skill_requirement_errors:
             tainted_holders[holder] = tuple(skill_requirement_errors)
     if tainted_holders:
         raise RegisterValidationError(tainted_holders)
Exemple #2
0
 def validate(self):
     ship_holder = self._fit.ship
     # No ship - no restriction
     try:
         ship_item = ship_holder.item
     except AttributeError:
         return
     # Set with allowed groups
     allowed_groups = set()
     # Find out if we have restriction, and which drone groups it allows
     for restriction_attr in RESTRICTION_ATTRS:
         allowed_groups.add(ship_item.attributes.get(restriction_attr))
     allowed_groups.discard(None)
     # No allowed group attributes - no restriction
     if not allowed_groups:
         return
     tainted_holders = {}
     # 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
     allowed_groups = tuple(allowed_groups)
     for holder in self.__restricted_holders:
         # Taint holders, whose group is not allowed
         holder_group = holder.item.group
         if holder_group not in allowed_groups:
             tainted_holders[holder] = DroneGroupErrorData(
                 holder_group=holder_group, allowed_groups=allowed_groups)
     if tainted_holders:
         raise RegisterValidationError(tainted_holders)
Exemple #3
0
 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
     ship_holder = self._fit.ship
     try:
         ship_type_id = ship_holder.item.id
         ship_group = ship_holder.item.group
     except AttributeError:
         ship_type_id = None
         ship_group = None
     # Container for tainted holders
     tainted_holders = {}
     # Go through all known restricted holders
     for holder in self.__restricted_holders:
         allowed_data = self.__restricted_holders[holder]
         # If ship's type isn't in allowed types and ship's
         # group isn't in allowed groups, holder is tainted
         if ship_type_id not in allowed_data.types and ship_group not in allowed_data.groups:
             tainted_holders[holder] = ShipTypeGroupErrorData(
                 ship_type=ship_type_id,
                 ship_group=ship_group,
                 allowed_types=allowed_data.types,
                 allowed_groups=allowed_data.groups
             )
     # Raise error if there're any tainted holders
     if tainted_holders:
         raise RegisterValidationError(tainted_holders)
Exemple #4
0
    def validate(self):
        stat_name = self.__stat_name
        tainted_holders = {}
        # Loop through the module registered to the slot
        for idx, module in enumerate(self._slot_consumers):
            hipower = medpower = lowpower = False

            # Loop through the effects on each module
            for module_effect in module.item.effects:
                if module_effect.id == Effect.low_power and stat_name == 'high_slots':  # hiPower Effect
                    hipower = True
                    break
                elif module_effect.id == Effect.med_power and stat_name == 'med_slots':  # medPower Effect
                    medpower = True
                    break
                elif module_effect.id == Effect.lo_power and stat_name == 'low_slots':  # lowPower Effect
                    lowpower = True
                    break

            # Continue to the next module if we could not find a
            # matching slot and restriction type
            if hipower or medpower or lowpower:
                continue
            else:
                tainted_holders[module] = ModuleSlotErrorData(
                    module_slot=stat_name, matching_slot=False)

        # If number of holders which take this slot is bigger
        # than number of available slots, then at least some
        # holders in container are tainted
        if tainted_holders:
            raise RegisterValidationError(tainted_holders)
Exemple #5
0
 def validate(self):
     tainted_holders = {}
     for holder in self.__holders:
         if holder.state > holder.item.max_state:
             allowed_states = tuple(filter(lambda s: s <= holder.item.max_state, State))
             tainted_holders[holder] = StateErrorData(
                 current_state=holder.state,
                 allowed_states=allowed_states
             )
     if tainted_holders:
         raise RegisterValidationError(tainted_holders)
Exemple #6
0
 def validate(self):
     tainted_holders = {}
     for slot_index in self.__slotted_holders:
         slot_index_holders = self.__slotted_holders[slot_index]
         # If more than one item occupies the same slot, all
         # holders in this slot are tainted
         if len(slot_index_holders) > 1:
             for holder in slot_index_holders:
                 tainted_holders[holder] = SlotIndexErrorData(holder_slot_index=slot_index)
     if tainted_holders:
         raise RegisterValidationError(tainted_holders)
Exemple #7
0
 def validate(self):
     tainted_holders = {}
     # If holder has charge and its group is not allowed,
     # taint charge (not container) holder
     for container, allowed_groups in self.__restricted_containers.items():
         charge = container.charge
         if charge is None:
             continue
         if charge.item.group not in allowed_groups:
             tainted_holders[charge] = ChargeGroupErrorData(
                 holder_group=charge.item.group,
                 allowed_groups=allowed_groups)
     if tainted_holders:
         raise RegisterValidationError(tainted_holders)
Exemple #8
0
 def validate(self):
     # Use stats module to get max and used amount of slots
     stats = getattr(self._fit.stats, self.__stat_name)
     slots_used = stats.used
     # Can be None, so fall back to 0 in this case
     slots_max = stats.total or 0
     # If number of holders which take this slot is bigger
     # than number of available slots, then at least some
     # holders in container are tainted
     if slots_used > slots_max:
         tainted_holders = {}
         for holder in self._get_tainted_holders(slots_max):
             tainted_holders[holder] = SlotAmountErrorData(
                 slots_used=slots_used, slots_max_allowed=slots_max)
         raise RegisterValidationError(tainted_holders)
Exemple #9
0
 def validate(self):
     tainted_holders = {}
     for holder in self.__holders:
         # Get validator function for class of passed holder.
         # If it is not found or fails, seek for 'right'
         # holder types for the item
         try:
             validator_func = CLASS_VALIDATORS[type(holder)]
         except KeyError:
             tainted_holders[holder] = self.__get_error_data(holder)
         else:
             if validator_func(holder.item) is not True:
                 tainted_holders[holder] = self.__get_error_data(holder)
     if tainted_holders:
         raise RegisterValidationError(tainted_holders)
Exemple #10
0
 def validate(self):
     tainted_holders = {}
     # Go through containers with charges, and if their
     # sizes mismatch - taint charge holders
     for container in self.__restricted_containers:
         charge = container.charge
         if charge is None:
             continue
         container_size = container.item.attributes[Attribute.charge_size]
         charge_size = charge.item.attributes.get(Attribute.charge_size)
         if container_size != charge_size:
             tainted_holders[charge] = ChargeSizeErrorData(
                 holder_size=charge_size, allowed_size=container_size)
     if tainted_holders:
         raise RegisterValidationError(tainted_holders)
Exemple #11
0
 def validate(self):
     tainted_holders = {}
     for container in self.__containers:
         charge = container.charge
         if charge is None:
             continue
         # Get volume and capacity with 0 as fallback, and
         # compare them, raising error when charge can't fit
         charge_volume = charge.item.attributes.get(Attribute.volume, 0)
         container_capacity = container.item.attributes.get(
             Attribute.capacity, 0)
         if charge_volume > container_capacity:
             tainted_holders[charge] = ChargeVolumeErrorData(
                 holder_volume=charge_volume,
                 max_allowed_volume=container_capacity)
     if tainted_holders:
         raise RegisterValidationError(tainted_holders)
Exemple #12
0
 def validate(self):
     # Use stats module to get resource use and output
     stats = getattr(self._fit.stats, self.__stat_name)
     total_use = stats.used
     # Can be None, so fall back to 0 in this case
     output = stats.output or 0
     # If we're not out of resource, do nothing
     if total_use <= output:
         return
     tainted_holders = {}
     for holder in self.__resource_users:
         resource_use = holder.attributes[self.__usage_attr]
         # Ignore holders which do not actually
         # consume resource
         if resource_use <= 0:
             continue
         tainted_holders[holder] = ResourceErrorData(
             total_use=total_use, output=output, holder_use=resource_use)
     raise RegisterValidationError(tainted_holders)
Exemple #13
0
 def validate(self):
     # Skip validation only if ship has capital
     # ships requirement, else carry on
     ship_holder = self._fit.ship
     try:
         ship_item = ship_holder.item
     except AttributeError:
         pass
     else:
         if Type.capital_ships in ship_item.required_skills:
             return
     # If we got here, then we're dealing with non-capital
     # ship, and all registered holders are tainted
     if self.__capital_holders:
         tainted_holders = {}
         for holder in self.__capital_holders:
             holder_volume = holder.item.attributes[Attribute.volume]
             tainted_holders[holder] = CapitalItemErrorData(
                 holder_volume=holder_volume,
                 max_allowed_volume=MAX_SUBCAP_VOLUME)
         raise RegisterValidationError(tainted_holders)
Exemple #14
0
 def validate(self):
     # Container for tainted holders
     tainted_holders = {}
     # Go through all restricted holders
     for holder in self.__group_restricted:
         # Get number of registered holders, assigned to group of current
         # restricted holder, and holder's restriction value
         group = holder.item.group
         group_holders = len(self.__group_all.get(group) or ())
         max_group_restriction = holder.item.attributes[
             self.__max_group_attr]
         # If number of registered holders from this group is bigger,
         # then current holder is tainted
         if group_holders > max_group_restriction:
             tainted_holders[holder] = MaxGroupErrorData(
                 holder_group=group,
                 max_group=max_group_restriction,
                 group_holders=group_holders)
     # Raise error if we detected any tainted holders
     if tainted_holders:
         raise RegisterValidationError(tainted_holders)
Exemple #15
0
 def validate(self):
     ship_holder = self._fit.ship
     # Do not apply restriction when fit doesn't
     # have ship
     try:
         ship_item = ship_holder.item
     except AttributeError:
         return
     # If ship doesn't have restriction attribute,
     # allow all rigs - skip validation
     try:
         allowed_rig_size = ship_item.attributes[Attribute.rig_size]
     except KeyError:
         return
     tainted_holders = {}
     for holder in self.__restricted_holders:
         holder_rig_size = holder.item.attributes[Attribute.rig_size]
         # If rig size specification on holder and ship differs,
         # then holder is tainted
         if holder_rig_size != allowed_rig_size:
             tainted_holders[holder] = RigSizeErrorData(
                 holder_size=holder_rig_size, allowed_size=allowed_rig_size)
     if tainted_holders:
         raise RegisterValidationError(tainted_holders)