def on_test(cls, interaction_sim: Sim, interaction_target: Any, interaction_context: InteractionContext, **kwargs) -> TestResult: cls.get_log().format_with_message( 'Running \'{}\' on_test.'.format(cls.__name__), interaction_sim=interaction_sim, interaction_target=interaction_target, interaction_context=interaction_context, kwargles=kwargs) if interaction_target is None or not CommonTypeUtils.is_sim_instance( interaction_target): cls.get_log().debug('Failed, Target is not a Sim.') return TestResult.NONE sim_info = CommonSimUtils.get_sim_info(interaction_sim) if not OCSettingUtils.is_enabled_for_interactions(sim_info): cls.get_log().debug( 'Failed, Active Sim is not available for Outfit Customization.' ) return TestResult.NONE target_sim_info = CommonSimUtils.get_sim_info(interaction_target) if not OCSettingUtils.is_enabled_for_interactions(target_sim_info): cls.get_log().debug( 'Failed, Target Sim is not available for Outfit Customization.' ) return TestResult.NONE cls.get_log().debug('Success.') return TestResult.TRUE
def on_started(self, interaction_sim: Sim, interaction_target: Any) -> bool: sim_info = CommonSimUtils.get_sim_info(interaction_sim) target_sim_info = CommonSimUtils.get_sim_info(interaction_target) CommonSimSpawnUtils.hard_reset(target_sim_info, ResetReason.RESET_EXPECTED, source=interaction_sim, cause='S4CM: Teleporting Sim') active_sim_location = CommonSimLocationUtils.get_location(sim_info) return CommonSimLocationUtils.set_location(target_sim_info, active_sim_location)
def on_started(self, interaction_sim: Sim, interaction_target: Any) -> bool: target_location = CommonObjectLocationUtils.get_location( interaction_target) def _on_submit(chosen_sim_info_list: Tuple[SimInfo]) -> None: if chosen_sim_info_list is None or not chosen_sim_info_list: return for chosen_sim_info in chosen_sim_info_list: # noinspection PyBroadException try: CommonSimSpawnUtils.hard_reset( chosen_sim_info, ResetReason.RESET_EXPECTED, source=interaction_sim, cause='S4CM: Teleporting Sim') CommonSimLocationUtils.set_location( chosen_sim_info, target_location) except: pass dialog = CommonPremadeChooseSimsOptionDialog( S4CMStringId.CHOOSE_SIMS_TO_TELEPORT, 0, instanced_sims_only=True, mod_identity=self.mod_identity) if not dialog.has_options(): return False # Sort the Sims in the dialog by their name. dialog._internal_dialog._rows = tuple( sorted(dialog._internal_dialog._rows, key=lambda row: CommonSimNameUtils.get_full_name( CommonSimUtils.get_sim_info(row.sim_id)))) dialog.show(on_submit=_on_submit, max_selectable=dialog.option_count) return True
def get_sim_info_of_all_sims_with_relationship_bits_generator(sim_info: SimInfo, relationship_bit_ids: Iterator[int]) -> Iterator[SimInfo]: """ Retrieve an Iterator of SimInfo for all Sims that have the specified relationship bits with the specified Sim. Note: For UNIDIRECTIONAL relationship bits, the direction is sim_info has relationship bit with target_sim_info Caregiver example: The Caregiver has a relationship bit pointed at Toddler (The Caregiver would show "caregiving ward" when hovering over the toddler in the relationships panel) The toddler would NOT have the relationship bit. Sim is Caregiver of Toddler. """ sim_id = CommonSimUtils.get_sim_id(sim_info) for relationship in sim_info.relationship_tracker: if relationship.sim_id_a != sim_id: target_sim_id = relationship.sim_id_a else: target_sim_id = relationship.sim_id_b target_sim_info = CommonSimUtils.get_sim_info(target_sim_id) if target_sim_info is None or CommonSimUtils.get_sim_instance(target_sim_info) is None: continue for relationship_bit_id in relationship_bit_ids: relationship_bit_instance = CommonResourceUtils.load_instance(Types.RELATIONSHIP_BIT, relationship_bit_id) if relationship_bit_instance is None: continue if relationship.has_bit(sim_id, relationship_bit_instance): yield target_sim_info break
def on_started(self, interaction_sim: Sim, interaction_target: Sim) -> bool: self.log.format_with_message('Running \'{}\' on_started.'.format( self.__class__.__name__), interaction_sim=interaction_sim, interaction_target=interaction_target) target_sim_info = CommonSimUtils.get_sim_info(interaction_target) target_sim_name = CommonSimNameUtils.get_full_name(target_sim_info) from sims4communitylib.utils.sims.common_sim_interaction_utils import CommonSimInteractionUtils from sims4communitylib.utils.resources.common_interaction_utils import CommonInteractionUtils running_interaction_names = ', '.join( CommonInteractionUtils.get_interaction_short_names( CommonSimInteractionUtils.get_running_interactions_gen( target_sim_info))) queued_interaction_names = ', '.join( CommonInteractionUtils.get_interaction_short_names( CommonSimInteractionUtils.get_queued_interactions_gen( target_sim_info))) text = '' text += 'Running Interactions:\n{}\n\n'.format( running_interaction_names) text += 'Queued Interactions:\n{}\n\n'.format(queued_interaction_names) CommonBasicNotification( CommonLocalizationUtils.create_localized_string( '{} Running and Queued Interactions'.format(target_sim_name)), CommonLocalizationUtils.create_localized_string(text)).show( icon=IconInfoData(obj_instance=interaction_target)) return True
def run( self, sim_info: SimInfo, on_completed: Callable[[bool], None] = CommonFunctionUtils.noop) -> bool: def _on_chosen(chosen_sim_info: SimInfo) -> None: if chosen_sim_info is None: on_completed(False) return self.run_with_sims(sim_info, chosen_sim_info, on_completed=on_completed) def _is_allowed(target_sim_info: SimInfo): return self.can_run_with_sims(sim_info, target_sim_info) dialog = CommonPremadeChooseSimOptionDialog( S4CMSimControlMenuStringId.SET_FAMILY_RELATIONS, 0, title_tokens=(sim_info, ), include_sim_callback=_is_allowed, instanced_sims_only=False, mod_identity=ModInfo.get_identity(), on_sim_chosen=_on_chosen, on_close=lambda: on_completed(False)) if not dialog.has_options(): on_completed(False) return False # Sort the Sims in the dialog by their name. dialog._internal_dialog._rows = tuple( sorted(dialog._internal_dialog._rows, key=lambda row: CommonSimNameUtils.get_full_name( CommonSimUtils.get_sim_info(row.sim_id)))) dialog.show(sim_info=sim_info) return True
def run( self, sim_info: SimInfo, on_completed: Callable[[bool], None] = CommonFunctionUtils.noop) -> bool: def _on_submit(chosen_sim_info_list: Tuple[SimInfo]) -> None: if chosen_sim_info_list is None or not chosen_sim_info_list: on_completed(False) return on_completed(self._run_with_sims(sim_info, chosen_sim_info_list)) def _has_relationship(target_sim_info: SimInfo) -> bool: return self.can_run_with_sims(sim_info, target_sim_info) dialog = CommonPremadeChooseSimsOptionDialog( S4CMSimControlMenuStringId.REMOVE_HAS_MET, S4CMSimControlMenuStringId.CHOOSE_SIMS_TO_REMOVE_HAS_MET, include_sim_callback=_has_relationship, description_tokens=(sim_info, ), instanced_sims_only=False, mod_identity=self.mod_identity) if not dialog.has_options(): return False # Sort the Sims in the dialog by their name. dialog._internal_dialog._rows = tuple( sorted(dialog._internal_dialog._rows, key=lambda row: CommonSimNameUtils.get_full_name( CommonSimUtils.get_sim_info(row.sim_id)))) dialog.show(on_submit=_on_submit, max_selectable=dialog.option_count)
def on_started(self, interaction_sim: Sim, interaction_target: Any) -> bool: target_location = CommonObjectLocationUtils.get_location( interaction_sim) # noinspection PyUnresolvedReferences picked_sim_info = CommonSimUtils.get_sim_info( self.get_participant(ParticipantType.PickedSim)) if picked_sim_info is None: return False if CommonSimUtils.get_sim_instance(picked_sim_info) is not None: if CommonAgeUtils.is_baby(picked_sim_info): # Sim is spawned, so let's move them to the Active Sim. CommonSimLocationUtils.set_location(picked_sim_info, target_location) else: # Sim is not spawned, so let's spawn them. if CommonAgeUtils.is_baby(picked_sim_info): from sims.baby.baby_utils import create_and_place_baby create_and_place_baby( picked_sim_info, position=target_location.transform.translation, routing_surface=target_location.routing_surface) else: CommonSimSpawnUtils.spawn_sim(picked_sim_info, location=target_location) return True
def get_score(cls, resolver: Resolver) -> int: """get_score(resolver) Calculate the score. """ try: yield_to_irq() cls.get_verbose_log().format_with_message('Retrieving score.', class_name=cls.__name__) source_sim = resolver.get_participant(ParticipantType.Actor) if source_sim is None or not CommonTypeUtils.is_sim_or_sim_info( source_sim): cls.get_verbose_log().format_with_message( 'Failed, the Source was not a Sim.', source=source_sim) return cls.get_default_score() source_sim_info = CommonSimUtils.get_sim_info(source_sim) interaction_instance = resolver.interaction or getattr( resolver, 'affordance', None) score = cls.calculate_score(resolver, source_sim_info, interaction_instance) cls.get_verbose_log().format_with_message( 'Retrieved score for Sim.', source_sim=source_sim_info, score=score) return score except Exception as ex: cls.get_verbose_log().error( 'Error occurred while retrieving score.', exception=ex) return cls.get_default_score()
def is_available_for(self, source_sim_info: SimInfo, target: Any = None) -> bool: self.log.debug( 'Checking if OC menu is available for \'{}\' and Target \'{}\'.' .format(CommonSimNameUtils.get_full_name(source_sim_info), target)) if target is None or not CommonTypeUtils.is_sim_or_sim_info( target): self.log.debug('Target is not a Sim.') return False if not OCSettingUtils.is_enabled_for_interactions(source_sim_info): log.debug( 'Failed, Source Sim is not available for Outfit Customization.' ) return False target_sim_info = CommonSimUtils.get_sim_info(target) if not OCSettingUtils.is_enabled_for_interactions(target_sim_info): self.log.debug( 'Failed, Target Sim is not available for Outfit Customization.' ) return False self.log.debug( 'OC menu is available for Source Sim and Target Sim.') return True
def _on_sim_change_age(self, sim_info: SimInfo, new_age: Age, current_age: Age) -> bool: from sims4communitylib.utils.sims.common_sim_utils import CommonSimUtils return CommonEventRegistry.get().dispatch( S4CLSimChangedAgeEvent(CommonSimUtils.get_sim_info(sim_info), CommonAge.convert_from_vanilla(current_age), CommonAge.convert_from_vanilla(new_age)))
def _common_fix_full_name_returning_empty_string(original, self: SimInfo, *_, **__): original_value = original(self, *_, **__) if original_value == '': return CommonSimNameUtils.get_full_name( CommonSimUtils.get_sim_info(self)) return original_value
def _on_sim_spawned(self, sim_info: SimInfo, *_, **__): from sims4communitylib.events.zone_spin.common_zone_spin_event_dispatcher import CommonZoneSpinEventDispatcher if CommonZoneSpinEventDispatcher.get().game_loading: return False from sims4communitylib.utils.sims.common_sim_utils import CommonSimUtils return CommonEventRegistry.get().dispatch( S4CLSimSpawnedEvent(CommonSimUtils.get_sim_info(sim_info)))
def _on_skill_leveled_up(self, skill: Skill, old_skill_level: int, new_skill_level: int) -> None: if skill.tracker is None or skill.tracker._owner is None: return sim_info = CommonSimUtils.get_sim_info(skill.tracker._owner) CommonEventRegistry.get().dispatch( S4CLSimSkillLeveledUpEvent(sim_info, skill, old_skill_level, new_skill_level))
def _hkh_check_if_nice_interaction(event_data: S4CLInteractionQueuedEvent): interaction_sim = event_data.interaction.sim interaction_target = event_data.interaction.target if not CommonTypeUtils.is_sim_or_sim_info(interaction_target): return True sim_info = CommonSimUtils.get_sim_info(interaction_sim) target_sim_info = CommonSimUtils.get_sim_info(interaction_target) if event_data.interaction.is_user_directed: return True friendship_track = CommonRelationshipUtils.get_relationship_level_of_sims( sim_info, target_sim_info, CommonRelationshipTrackId.FRIENDSHIP) if friendship_track > -50.0: return True interaction_game_tags = event_data.interaction.get_category_tags() if CommonGameTag.INTERACTION_FRIENDLY in interaction_game_tags or CommonGameTag.INTERACTION_FUNNY in interaction_game_tags or CommonGameTag.SOCIAL_FLIRTY in interaction_game_tags: return False return True
def show(self, source_sim_info: SimInfo, *args, target: Any = None, on_close: Callable[..., Any] = CommonFunctionUtils.noop, **kwargs): self.log.debug('Showing OC Customize Outfit.') target_sim_info = CommonSimUtils.get_sim_info(target) OCCustomizeOutfitDialog(target_sim_info, on_close=on_close).open()
def on_started(self, interaction_sim: Sim, interaction_target: Sim) -> bool: self.log.format_with_message('Running \'{}\' on_started.'.format( self.__class__.__name__), interaction_sim=interaction_sim, interaction_target=interaction_target) target_sim_info = CommonSimUtils.get_sim_info(interaction_target) CMChangeMotivesDialog().open(target_sim_info) return True
def show(self, source_sim_info: SimInfo, *args, target: Any = None, on_close: Callable[..., Any] = CommonFunctionUtils.noop, **kwargs): self.log.debug('Showing CSF Settings.') target_sim_info = CommonSimUtils.get_sim_info(target) CSFCustomizeSlidersDialog(on_close=on_close).open(target_sim_info)
def on_started(self, interaction_sim: Sim, interaction_target: Sim) -> bool: self.log.format_with_message('Running \'{}\' on_started.'.format(self.__class__.__name__), interaction_sim=interaction_sim, interaction_target=interaction_target) target_sim_info = CommonSimUtils.get_sim_info(interaction_target) target_sim_name = CommonSimNameUtils.get_full_name(target_sim_info) buff_id = CommonSimPregnancyUtils.get_in_labor_buff(target_sim_info) if buff_id != -1: self.log.debug('The baby wants out now! Labor induced in \'{}\'. Chosen buff identifier: {}'.format(target_sim_name, str(buff_id))) return CommonBuffUtils.add_buff(target_sim_info, buff_id) self.log.debug('Failed to induce labor in \'{}\'.'.format(target_sim_name)) return False
def on_started(self, interaction_sim: Sim, interaction_target: Any) -> bool: self.log.debug('Running \'{}\' on_started.'.format( OpenCustomGenderSettingsInteraction.__name__)) if not CommonTypeUtils.is_sim_instance(interaction_target): self.log.debug('Target is not a sim.') return False CommonTimeUtils.pause_the_game() target_sim_info = CommonSimUtils.get_sim_info(interaction_target) CustomGenderSettingsDialog(target_sim_info).open() return True
def on_test(cls, interaction_sim: Sim, interaction_target: Any, interaction_context: InteractionContext, *args, **kwargs) -> CommonTestResult: source_sim_info = CommonSimUtils.get_sim_info(interaction_sim) if not cls.get_mod_settings_registry().has_menu_items_available_for( source_sim_info, target=interaction_target): cls.get_log().debug( 'No menu items were available for \'{}\''.format( interaction_target)) return cls.create_test_result(False) cls.get_log().debug('Success, can open mod settings.') return cls.create_test_result(True)
def on_test(cls, interaction_sim: Sim, interaction_target: Any, interaction_context: InteractionContext, **kwargs) -> TestResult: cls.get_log().debug('Running \'{}\' on_test.'.format( OpenCustomGenderSettingsInteraction.__name__)) if interaction_target is None or not CommonTypeUtils.is_sim_instance( interaction_target): cls.get_log().debug('Failed, Target is not a Sim.') return TestResult.NONE sim_info = CommonSimUtils.get_sim_info(interaction_sim) if not cls._get_setting_utils().is_enabled_for_interactions(sim_info): cls.get_log().debug( 'Failed, Active Sim is not enabled for CGS interactions.') return TestResult.NONE target_sim_info = CommonSimUtils.get_sim_info(interaction_target) if not cls._get_setting_utils().is_enabled_for_interactions( target_sim_info): cls.get_log().debug( 'Failed, Target Sim is not enabled for CGS interactions.') return TestResult.NONE cls.get_log().debug('Success, can open Custom Gender Settings.') return TestResult.TRUE
def on_started(self, interaction_sim: Sim, interaction_target: Any) -> bool: self.log.format_with_message('Running {} on_started.'.format( self.__class__.__name__), interaction_sim=interaction_sim, interaction_target=interaction_target) if interaction_target is None or not CommonTypeUtils.is_sim_or_sim_info( interaction_target): self.log.debug('Failed, Target is not a sim.') return TestResult.NONE target_sim_info = CommonSimUtils.get_sim_info(interaction_target) OCCustomizeOutfitDialog(target_sim_info).open() return True
def show(self, source_sim_info: SimInfo, *args, target: Any = None, on_close: Callable[..., Any] = CommonFunctionUtils.noop, **kwargs): self.log.debug('Showing Change Motives dialog.') if target is None: if on_close is not None: on_close() return target_sim_info = CommonSimUtils.get_sim_info(target) CMChangeMotivesDialog(on_close=on_close).open(target_sim_info)
def on_test(cls, interaction_sim: Sim, interaction_target: Any, interaction_context: InteractionContext, **kwargs) -> TestResult: if interaction_target is None or not CommonTypeUtils.is_sim_or_sim_info( interaction_target): cls.get_log().debug('Failed, Target was invalid.') return TestResult.NONE sim_info = CommonSimUtils.get_sim_info(interaction_target) active_sim_location = CommonSimLocationUtils.get_location(sim_info) if active_sim_location is None: cls.get_log().debug('Failed, No location for active Sim.') return TestResult.NONE cls.get_log().debug('Success, can teleport.') return TestResult.TRUE
def on_started(self, interaction_sim: Sim, interaction_target: Sim) -> bool: target_sim_info = CommonSimUtils.get_sim_info(interaction_target) bathing_outfit_category_and_index = (OutfitCategory.BATHING, 0) if not CommonOutfitUtils.has_outfit(target_sim_info, bathing_outfit_category_and_index): if not CommonOutfitUtils.generate_outfit( target_sim_info, bathing_outfit_category_and_index): self.log.format_with_message( 'Failed to generate the bathing outfit for Sim.', sim=target_sim_info) return False CommonOutfitUtils.set_current_outfit( target_sim_info, bathing_outfit_category_and_index) return True
def run( self, sim_info: SimInfo, on_completed: Callable[[bool], None] = CommonFunctionUtils.noop) -> bool: if CommonSimPregnancyUtils.is_pregnant(sim_info): on_completed(False) return False if not CommonSimPregnancyUtils.can_impregnate( sim_info) and not CommonSimPregnancyUtils.can_be_impregnated( sim_info): on_completed(False) return False def _on_chosen(chosen_sim_info: SimInfo) -> None: if chosen_sim_info is None: on_completed(False) return result = CommonSimPregnancyUtils.start_pregnancy( sim_info, chosen_sim_info) on_completed(result) def _can_create_pregnancy(partner_sim_info: SimInfo) -> bool: if sim_info is partner_sim_info: return False return S4CMSimPregnancyUtils.can_create_pregnancy_together( sim_info, partner_sim_info) dialog = CommonPremadeChooseSimOptionDialog( S4CMSimControlMenuStringId.WHO_WILL_IMPREGNATE_SIM, 0, title_tokens=(sim_info, ), include_sim_callback=_can_create_pregnancy, instanced_sims_only=False, mod_identity=ModInfo.get_identity(), on_sim_chosen=_on_chosen, on_close=lambda: on_completed(False)) if not dialog.has_options(): on_completed(False) return False # Sort the Sims in the dialog by their name. dialog._internal_dialog._rows = tuple( sorted(dialog._internal_dialog._rows, key=lambda row: CommonSimNameUtils.get_full_name( CommonSimUtils.get_sim_info(row.sim_id)))) dialog.show(sim_info=sim_info) return True
def get_sims_using_object(game_object: GameObject) -> Tuple[SimInfo]: """get_sims_using_object(game_object) Retrieve a collection of Sims using the object. :param game_object: An instance of an object. :type game_object: GameObject :return: A collection of Sims using the object. :rtype: Tuple[SimInfo] """ from sims4communitylib.utils.sims.common_sim_utils import CommonSimUtils if game_object is None: return tuple() sim_info_user_list: List[SimInfo] = [] for sim in game_object.get_users(sims_only=True): sim_info_user_list.append(CommonSimUtils.get_sim_info(sim)) return tuple(sim_info_user_list)
def _update_args(self, *args: Any) -> Tuple[Any]: if not args: return args from sims4communitylib.utils.common_type_utils import CommonTypeUtils from sims4communitylib.utils.sims.common_sim_name_utils import CommonSimNameUtils from sims4communitylib.utils.sims.common_sim_utils import CommonSimUtils new_args: List[Any] = list() for arg in args: if CommonTypeUtils.is_sim_or_sim_info(arg): sim_info = CommonSimUtils.get_sim_info(arg) if sim_info is None: new_args.append(arg) else: new_args.append('{} ({})'.format(CommonSimNameUtils.get_full_name(sim_info), str(CommonSimUtils.get_sim_id(sim_info)))) else: new_args.append(arg) return tuple(new_args)
def _update_kwargs(self, **kwargs: Any) -> Dict[str, Any]: if not kwargs: return kwargs new_kwargs: Dict[str, Any] = dict() from sims4communitylib.utils.common_type_utils import CommonTypeUtils from sims4communitylib.utils.sims.common_sim_name_utils import CommonSimNameUtils from sims4communitylib.utils.sims.common_sim_utils import CommonSimUtils for (key, val) in kwargs.items(): if CommonTypeUtils.is_sim_or_sim_info(val): sim_info = CommonSimUtils.get_sim_info(val) if sim_info is None: new_kwargs[key] = val else: new_kwargs[key] = '{} ({})'.format(CommonSimNameUtils.get_full_name(sim_info), str(CommonSimUtils.get_sim_id(sim_info))) else: new_kwargs[key] = val return new_kwargs