def register_service(self, service, is_init_critical=False): required_packs = service.required_packs if any(not is_available_pack(pack) for pack in required_packs): return False if not isinstance(service, Service): service = service() self.services.append(service) if is_init_critical: self._init_critical_services.append(service)
def refresh_pregnancy_data(self, on_create=None): if not self.is_pregnant: self.clear_pregnancy() return traits_pack_tuple = self.PREGNANCY_ORIGIN_TRAIT_MAPPING.get( self._origin) if traits_pack_tuple is not None and not is_available_pack( traits_pack_tuple.pack): self._create_and_name_offspring(on_create=on_create) self.clear_pregnancy() self.enable_pregnancy()
def open_reward(self, sim_info, **kwargs): if self.bucks_type is None or not ( self.bucks_type == BucksType.INVALID or not is_available_pack( _get_pack_from_enum_value(int(self.bucks_type)))): return if sim_info.is_npc: return tracker = BucksUtils.get_tracker_for_bucks_type(self.bucks_type, sim_info.id, add_if_none=True) if tracker is None: logger.error( 'Failed to open a TunableRewardBucks of buck type {} for Sim {}.', self.bucks_type, sim_info) return tracker.try_modify_bucks(self.bucks_type, self.amount)
def load_data_into_class_instances(self): logger.info('Loading {:4} tuning class instances managed by {}.', len(self._tuned_classes), self, owner='manus') for (key, cls) in tuple(self._tuned_classes.items()): try: tuned_classes_key = key if key in self._remapped_keys: key = self._remapped_keys[key] (tuning_callback_helpers, verify_tunable_callback_helpers) = sims4.tuning.serialization.load_from_xml(key, self.TYPE, cls) additional_pack = getattr(cls, 'additional_pack', None) if additional_pack is not None: if not is_available_pack(cls.additional_pack): del self._tuned_classes[tuned_classes_key] continue self._callback_helper[cls] = tuning_callback_helpers except Exception: logger.exception('Exception while finalizing tuning for {}.', cls, owner='manus') self._remapped_keys = None
def finalize(cls, *tuned_elements): with cls.make_mutable(): if not hasattr(cls, '_static_index'): cls._static_index = len(cls) - 1 index = cls._static_index + 1 items = tuple(cls.items()) for (item_name, item_value) in items[index:]: delattr(cls, item_name) del cls.name_to_value[item_name] del cls.value_to_name[item_value] for element in tuned_elements: enum_name = element.enum_name raw_value = element.enum_value if cls.partitioned and not cls.locked and not is_available_pack( _get_pack_from_enum_value(raw_value)): continue cls._add_new_enum_value(enum_name, raw_value)
def _CreateSessionInformation(self) -> str: try: installedPacks = list() # type: typing.List[str] for packTuple in common.Pack.items( ): # type: typing.Tuple[str, common.Pack] if packTuple[1] == common.Pack.BASE_GAME: continue packAvailable = common.is_available_pack(packTuple[1]) if packAvailable: prefixExpansionPairs = { "EP": "Expansion Pack ", "GP": "Game Pack ", "SP": "Stuff Pack " } # type: typing.Dict[str, str] packText = packTuple[0] # type: str for prefix, prefixExpansion in prefixExpansionPairs.items( ): # type: str if packText.startswith(prefix): packText = packText.replace( prefix, prefixExpansion, 1) break installedPacks.append(packText) sessionDictionary = { "SessionID": str(self.GetSessionID()), "SessionStartTime": self.GetSessionStartTime().isoformat(), "IsContinuation": self.IsContinuation(), "OS": platform.system(), "OSVersion": platform.version(), "InstalledPacks": installedPacks } return json.JSONEncoder(indent="\t").encode(sessionDictionary) except Exception as e: return "Failed to get session information\n" + FormatException(e)
def is_valid_pack(self, component): required_packs = component.required_packs if required_packs is not None and any(not is_available_pack(pack) for pack in required_packs): return False return True
def situation_meets_starting_requirements(cls, **kwargs): if cls.starting_entitlement is None: return True return is_available_pack(cls.starting_entitlement)
def supporting_pack_installed(self): pack = TestableGameOptions.REQUIRED_PACK_BY_OPTION.get(self, None) return pack is None or is_available_pack(pack)
def situation_meets_starting_requirements(cls, **kwargs): if not cls.valid_regions.test_item(services.current_region()): return False if cls.starting_entitlement is None: return True return is_available_pack(cls.starting_entitlement)
def _create_all_transforms_and_portals_for_initial_transforms( self, initial_transforms, lot_transforms=False, prior_lengths=None, store_portal_ids=None): portal_component = self.get_component(PORTAL_COMPONENT) if portal_component is None: return def _store_transforms(species, ages, interval, transforms): for age in ages: key = (species, age, interval) if key in self._constraint_starts: if prior_lengths is not None: prior_lengths[key] = len(self._constraint_starts[key]) self._constraint_starts[key].extend(transforms) else: if prior_lengths is not None: prior_lengths[key] = 0 self._constraint_starts[key] = transforms routing_surface = SurfaceIdentifier(services.current_zone_id(), 0, SurfaceType.SURFACETYPE_WORLD) edge_transforms = adjust_locations_for_coastline(initial_transforms) def _get_water_depth_at_edge(i): transform = edge_transforms[i] translation = transform.translation + transform.orientation.transform_vector( Ocean.EDGE_TEST_POINT_OFFSET) return get_water_depth(translation.x, translation.z) for (species, age_data) in OceanTuning.OCEAN_DATA.items(): required_pack = SpeciesExtended.get_required_pack(species) if required_pack is not None and not is_available_pack( required_pack): continue for age_ocean_data in age_data: ocean_data = age_ocean_data.ocean_data beach_portal = ocean_data.beach_portal_data wading_depth = ocean_data.wading_interval.lower_bound max_wading_depth = wading_depth + ocean_data.water_depth_error swim_depth = ocean_data.wading_interval.upper_bound min_swim_depth = swim_depth - ocean_data.water_depth_error transforms = adjust_locations_for_target_water_depth( wading_depth, ocean_data.water_depth_error, initial_transforms) wading_transforms = [] for i in range(len(transforms) - 1): transform = transforms[i] if transform.translation == VECTOR3_ZERO: depth = _get_water_depth_at_edge(i) if depth <= max_wading_depth: wading_transforms.append(edge_transforms[i]) wading_transforms.append(transform) else: wading_transforms.append(transform) transforms = adjust_locations_for_target_water_depth( swim_depth, ocean_data.water_depth_error, initial_transforms) portal_transforms = [] for i in range(len(transforms) - 1): transform = transforms[i] if transform.translation == VECTOR3_ZERO: depth = _get_water_depth_at_edge(i) if min_swim_depth <= depth: edge_transform = edge_transforms[i] translation = edge_transform.translation + edge_transform.orientation.transform_vector( Ocean.EDGE_PORTAL_BACKSET) portal_transforms.append( Transform(translation, edge_transform.orientation)) else: portal_transforms.append(transform) _store_transforms(species, age_ocean_data.ages, WaterDepthIntervals.WET, edge_transforms.copy()) _store_transforms(species, age_ocean_data.ages, WaterDepthIntervals.WADE, wading_transforms) _store_transforms(species, age_ocean_data.ages, WaterDepthIntervals.SWIM, portal_transforms) if beach_portal is None: pass else: if lot_transforms: portal_transforms = self._reorient_lot_transforms( portal_transforms) portal_creation_mask = SpeciesExtended.get_portal_flag( species) for portal_transform in portal_transforms: portal_location = Location( portal_transform, routing_surface=routing_surface) portal_ids = portal_component.add_custom_portal( OceanPoint(portal_location), beach_portal, portal_creation_mask) add_portals = [] remove_portals = [] for portal_id in portal_ids: portal_instance = portal_component.get_portal_by_id( portal_id) if portal_instance is not None: location = None if portal_id == portal_instance.there: location = portal_instance.there_entry elif portal_id == portal_instance.back: location = portal_instance.back_exit if location and build_buy.is_location_natural_ground( location.position, location.routing_surface.secondary_id): add_portals.append(portal_id) else: remove_portals.append(portal_id) if remove_portals: portal_component.remove_custom_portals( remove_portals) if add_portals and store_portal_ids is not None: store_portal_ids.extend(add_portals)
def is_required_pack_installed(sim_info_gameplay_option): pack = REQUIRED_PACK_BY_OPTION.get(sim_info_gameplay_option, None) if pack is None: return True return is_available_pack(pack)