Esempio n. 1
0
 def validate(self):
     tainted_items = {}
     skills = self.__fit.skills
     # Go through restricted items
     for item in self.__restricted_items:
         # Container for skill requirement errors for current item
         skillrq_errors = []
         # Check each skill requirement
         for skillrq_type_id, skillrq_level in (
                 item._type.required_skills.items()):
             # Get skill level with None as fallback value for case when we
             # don't have such skill or it's not loaded
             try:
                 skill = skills[skillrq_type_id]
             except KeyError:
                 skill_level = None
             else:
                 if skill._is_loaded:
                     skill_level = skill.level
                 else:
                     skill_level = None
             # Last check - if skill level is lower than expected, current
             # item is tainted; mark it so and move to the next one
             if skill_level is None or skill_level < skillrq_level:
                 skill_requirement_error = SkillRequirementErrorData(
                     skill_type_id=skillrq_type_id,
                     level=skill_level,
                     required_level=skillrq_level)
                 skillrq_errors.append(skill_requirement_error)
         if skillrq_errors:
             tainted_items[item] = tuple(skillrq_errors)
     if tainted_items:
         raise RestrictionValidationError(tainted_items)
Esempio n. 2
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 items can't contain None in its values anyway
     try:
         ship_type_id = self.__fit.ship._type_id
         ship_group_id = self.__fit.ship._type.group_id
     except AttributeError:
         ship_type_id = None
         ship_group_id = None
     # Container for tainted items
     tainted_items = {}
     # Go through all known restricted items
     for item in self.__restricted_items:
         allowed_data = self.__restricted_items[item]
         # If ship's type isn't in allowed types and ship's group isn't in
         # allowed groups, item is tainted
         if (ship_type_id not in allowed_data.type_ids
                 and ship_group_id not in allowed_data.group_ids):
             tainted_items[item] = ShipTypeGroupErrorData(
                 ship_type_id=ship_type_id,
                 ship_group_id=ship_group_id,
                 allowed_type_ids=allowed_data.type_ids,
                 allowed_group_ids=allowed_data.group_ids)
     # Raise error if there're any tainted items
     if tainted_items:
         raise RestrictionValidationError(tainted_items)
Esempio n. 3
0
 def validate(self):
     used, total = self._slot_stats
     if used > total:
         tainted_items = {}
         for item in self._container:
             tainted_items[item] = SlotQuantityErrorData(used=used,
                                                         total=total)
         raise RestrictionValidationError(tainted_items)
Esempio n. 4
0
 def validate(self):
     stats = self._slot_stats
     if stats.used > stats.total:
         tainted_items = {}
         for item in stats._users:
             tainted_items[item] = SlotQuantityErrorData(used=stats.used,
                                                         total=stats.total)
         raise RestrictionValidationError(tainted_items)
Esempio n. 5
0
 def validate(self):
     tainted_items = {}
     # User has no direct control over autoitems, so skip them
     for item in self.__fit._item_iter(skip_autoitems=True):
         if not item._is_loaded:
             tainted_items[item] = LoadedItemErrorData()
     if tainted_items:
         raise RestrictionValidationError(tainted_items)
Esempio n. 6
0
 def validate(self):
     tainted_items = {}
     for item in self.__restricted_items:
         if item.state > item._type.max_state:
             allowed_states = tuple(s for s in State
                                    if s <= item._type.max_state)
             tainted_items[item] = StateErrorData(
                 state=item.state, allowed_states=allowed_states)
     if tainted_items:
         raise RestrictionValidationError(tainted_items)
Esempio n. 7
0
 def validate(self):
     tainted_items = {}
     for slot_index, slot_index_items in self.__index_item_map.items():
         # If more than one item occupies the same slot, all items in this
         # slot are tainted
         if len(slot_index_items) > 1:
             for item in slot_index_items:
                 tainted_items[item] = SlotIndexErrorData(
                     slot_index=slot_index)
     if tainted_items:
         raise RestrictionValidationError(tainted_items)
Esempio n. 8
0
 def validate(self):
     tainted_items = {}
     # User has no direct control over autoitems, so skip them
     for item in self.__fit._loaded_item_iter(skip_autoitems=True):
         # Get validator function for class of passed item. If it is not
         # found or fails, seek for 'right' item class for the item type
         try:
             validator_func = CLASS_VALIDATORS[type(item)]
         except KeyError:
             tainted_items[item] = self.__get_error_data(item)
         else:
             if validator_func(item._type) is not True:
                 tainted_items[item] = self.__get_error_data(item)
     if tainted_items:
         raise RestrictionValidationError(tainted_items)
Esempio n. 9
0
 def validate(self):
     tainted_items = {}
     # Go through containers with charges, and if their sizes mismatch, taint
     # charge items
     for container in self.__restricted_containers:
         charge = container.charge
         if charge is None or not charge._is_loaded:
             continue
         container_size = container._type_attrs[AttrId.charge_size]
         charge_size = charge._type_attrs.get(AttrId.charge_size)
         if container_size != charge_size:
             tainted_items[charge] = ChargeSizeErrorData(
                 size=charge_size, allowed_size=container_size)
     if tainted_items:
         raise RestrictionValidationError(tainted_items)
Esempio n. 10
0
 def validate(self):
     tainted_items = {}
     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._type_attrs.get(AttrId.volume, 0)
         container_capacity = container._type_attrs.get(AttrId.capacity, 0)
         if charge_volume > container_capacity:
             tainted_items[charge] = ChargeVolumeErrorData(
                 volume=charge_volume,
                 max_allowed_volume=container_capacity)
     if tainted_items:
         raise RestrictionValidationError(tainted_items)
Esempio n. 11
0
 def validate(self):
     # Skip validation only if ship has special special attribute set value
     # which is evaluated as True
     ship = self.__fit.ship
     if ship is not None and ship._type_attrs.get(AttrId.is_capital_size):
         return
     # If we got here, then we're dealing with non-capital ship, and all
     # registered items are tainted
     if self.__capital_items:
         tainted_items = {}
         for item in self.__capital_items:
             item_type_volume = item._type_attrs[AttrId.volume]
             tainted_items[item] = CapitalItemErrorData(
                 item_volume=item_type_volume,
                 max_subcap_volume=MAX_SUBCAP_VOLUME)
         raise RestrictionValidationError(tainted_items)
Esempio n. 12
0
 def validate(self):
     # Do not apply restriction when fit doesn't have ship and when ship
     # doesn't have restriction attribute
     try:
         allowed_rig_size = self.__fit.ship._type_attrs[AttrId.rig_size]
     except (AttributeError, KeyError):
         return
     tainted_items = {}
     for item in self.__restricted_items:
         rig_size = item._type_attrs[AttrId.rig_size]
         # If rig size specification on item and ship differs, then item is
         # tainted
         if rig_size != allowed_rig_size:
             tainted_items[item] = RigSizeErrorData(
                 size=rig_size, allowed_size=allowed_rig_size)
     if tainted_items:
         raise RestrictionValidationError(tainted_items)
Esempio n. 13
0
 def validate(self):
     tainted_items = {}
     # If item has charge and its group is not allowed, taint charge item
     # (not container)
     for container, allowed_group_ids in (
         self.__restricted_containers.items()
     ):
         charge = container.charge
         if charge is None or not charge._is_loaded:
             continue
         group_id = charge._type.group_id
         if group_id not in allowed_group_ids:
             tainted_items[charge] = ChargeGroupErrorData(
                 group_id=group_id,
                 allowed_group_ids=allowed_group_ids)
     if tainted_items:
         raise RestrictionValidationError(tainted_items)
Esempio n. 14
0
 def validate(self):
     # Container for tainted items
     tainted_items = {}
     # Go through all restricted items
     for item in self.__restricted_items:
         # Get quantity of registered items, assigned to group of current
         # restricted item, and item's restriction value
         group_id = item._type.group_id
         quantity = len(self.__group_item_map.get(group_id, ()))
         max_allowed_quantity = item._type_attrs[self._max_group_attr_id]
         if quantity > max_allowed_quantity:
             tainted_items[item] = MaxGroupErrorData(
                 group_id=group_id,
                 quantity=quantity,
                 max_allowed_quantity=max_allowed_quantity)
     # Raise error if we detected any tainted items
     if tainted_items:
         raise RestrictionValidationError(tainted_items)