예제 #1
0
 def can_run_with_sims(self, sim_info_a: SimInfo,
                       sim_info_b: SimInfo) -> bool:
     if not super().can_run_with_sims(sim_info_a, sim_info_b):
         return False
     sim_a_id = CommonSimUtils.get_sim_id(sim_info_a)
     sim_b_id = CommonSimUtils.get_sim_id(sim_info_b)
     return sim_info_a is not sim_info_b and any(
         services.relationship_service().get_all_bits(
             sim_a_id, target_sim_id=sim_b_id)) or any(
                 services.relationship_service().get_all_bits(
                     sim_b_id, target_sim_id=sim_a_id))
    def _setup_dialog_rows(
        self,
        sim_info: SimInfo,
        _dialog: UiOutfitPicker,
        outfit_list: Iterator[Tuple[OutfitCategory, int]]=()
    ):
        self.log.debug('Adding rows.')
        sim_id = CommonSimUtils.get_sim_id(sim_info)
        added_rows = False
        current_outfit = CommonOutfitUtils.get_current_outfit(sim_info)
        for (outfit_category, outfit_index) in outfit_list:
            # noinspection PyTypeChecker
            if not CommonOutfitUtils.has_outfit(sim_info, (outfit_category, outfit_index)) and not CommonOutfitUtils.has_outfit(sim_info, (int(outfit_category), outfit_index)):
                self.log.format_with_message('Sim does not have outfit.', sim=sim_info, outfit_category_and_index=(outfit_category, outfit_index))
                continue
            added_rows = True
            _dialog.add_row(
                OutfitPickerRow(
                    sim_id,
                    outfit_category,
                    outfit_index,
                    is_enable=True,
                    is_selected=(outfit_category, outfit_index) == current_outfit,
                    tag=(outfit_category, outfit_index)
                )
            )

        for row in self.rows:
            _dialog.add_row(row)

        if not added_rows and len(self.rows) == 0:
            raise AssertionError('No rows have been provided. Add rows to the dialog before attempting to display it.')
예제 #3
0
 def is_hidden(sim_info: SimInfo) -> bool:
     """
         Determine if a sim is hidden.
     """
     sim = CommonSimUtils.get_sim_instance(sim_info)
     sim_id = CommonSimUtils.get_sim_id(sim_info)
     return sim_id is None or sim is None or services.hidden_sim_service().is_hidden(sim_id) or sim.is_hidden() or sim.opacity == 0
예제 #4
0
    def remove_relationship_bit(
        sim_info: SimInfo,
        target_sim_info: SimInfo,
        relationship_bit_id: int
    ) -> bool:
        """remove_relationship_bit(sim_info, target_sim_info, relationship_bit_id)

        Remove a relationship bit between two sims.

        .. note::

            If the relationship bit is UNIDIRECTIONAL, it will only be removed from sim_info in the direction of the Target.
            i.e. Sim will have no longer have relationship bit towards Target, but Target will still have relationship bit towards Sim.

            One example is the Caregiver relationship:

            - Sim is caregiver of Target.
            - Target is being cared for by Sim.

        :param sim_info: The source Sim of the Relationship Bit.
        :type sim_info: SimInfo
        :param target_sim_info: The target Sim of the Relationship Bit.
        :type target_sim_info: SimInfo
        :param relationship_bit_id: The identifier of the Relationship Bit to remove.
        :type relationship_bit_id: int
        :return: True, if the relationship bit was removed successfully. False, if not.
        :rtype: bool
        """
        relationship_bit_instance = CommonResourceUtils.load_instance(Types.RELATIONSHIP_BIT, relationship_bit_id)
        if relationship_bit_instance is None:
            return False
        target_sim_id = CommonSimUtils.get_sim_id(target_sim_info)
        sim_info.relationship_tracker.remove_relationship_bit(target_sim_id, relationship_bit_instance)
        return True
예제 #5
0
    def change_relationship_level_of_sims(
        sim_info: SimInfo,
        target_sim_info: SimInfo,
        relationship_track_id: int,
        level: float
    ) -> bool:
        """change_relationship_level_of_sims(sim_info, target_sim_info, relationship_track_id, level)

        Change the level of a relationship track between two Sims.

        :param sim_info: The sim that owns the relationship track.
        :type sim_info: SimInfo
        :param target_sim_info: The target of the relationship track.
        :type target_sim_info: SimInfo
        :param relationship_track_id: The identifier of the Relationship Track to change.
        :type relationship_track_id: int
        :param level: The amount to add to the relationship track (Can be positive or negative).
        :type level: float
        :return: True, if the relationship track was changed successfully. False, if not.
        :rtype: bool
        """
        relationship_track = CommonResourceUtils.load_instance(Types.STATISTIC, relationship_track_id)
        if relationship_track is None:
            return False
        target_sim_id = CommonSimUtils.get_sim_id(target_sim_info)
        sim_info.relationship_tracker.add_relationship_score(target_sim_id, level, relationship_track)
        return True
예제 #6
0
    def sim_id(self) -> int:
        """The id of the Sim in this option.

        :return: The id of the Sim within the option.
        :rtype: int
        """
        return CommonSimUtils.get_sim_id(self.value)
예제 #7
0
    def has_relationship_bits_with_sim(
        sim_info: SimInfo,
        target_sim_info: SimInfo,
        relationship_bit_ids: Iterator[int],
    ) -> bool:
        """has_relationship_bits_with_sim(sim_info, target_sim_info, relationship_bit_ids)

        Determine if two sims have any of the specified relationship bits with each other.

        :param sim_info: The Sim to check.
        :type sim_info: SimInfo
        :param target_sim_info: The Target Sim of the relationship bit (The target is especially important for Unidirectional/One Way Relationship Bits).
        :type target_sim_info: SimInfo
        :param relationship_bit_ids: A collection of identifier of Relationship Bits to check for.
        :type relationship_bit_ids: int
        :return: True, if the Sim has any of the specified Relationship Bits with the Target Sim. False, if not.
        :rtype: bool
        """
        target_sim_id = CommonSimUtils.get_sim_id(target_sim_info)
        relationship_bits = sim_info.relationship_tracker.get_all_bits(target_sim_id)
        for relationship_bit in relationship_bits:
            relationship_bit_id = getattr(relationship_bit, 'guid64', None)
            if relationship_bit_id in relationship_bit_ids:
                return True
        return False
예제 #8
0
    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
예제 #9
0
    def _create_dialog(
        self,
        picker_type: UiObjectPicker.
        UiObjectPickerObjectPickerType = UiObjectPicker.
        UiObjectPickerObjectPickerType.OBJECT,
        target_sim_info_to_receive_objects: SimInfo = None,
        categories: Iterator[CommonDialogObjectOptionCategory] = (),
        object_delivery_method:
        CommonObjectDeliveryMethod = CommonObjectDeliveryMethod.INVENTORY
    ) -> Union[UiPurchasePicker, None]:
        try:
            category_type = namedtuple('category_type',
                                       ('tag', 'icon', 'tooltip'))
            dialog_categories = list()
            for category in tuple(categories):
                dialog_categories.append(
                    category_type(
                        category.object_category,
                        CommonIconUtils._load_icon(category.icon),
                        CommonLocalizationUtils.create_localized_string(
                            category.category_name)))

            inventory_target_id = CommonSimUtils.get_sim_id(
                target_sim_info_to_receive_objects
                or CommonSimUtils.get_active_sim_info())
            purchase_objects: List[int] = list()
            dialog = UiPurchasePicker.TunableFactory().default(
                target_sim_info_to_receive_objects
                or CommonSimUtils.get_active_sim_info(),
                text=lambda *_, **__: self.description,
                title=lambda *_, **__: self.title,
                categories=dialog_categories,
                max_selectable=UiDialogObjectPicker._MaxSelectableUnlimited())
            purchase_picker_data = PurchasePickerData()
            if object_delivery_method == CommonObjectDeliveryMethod.MAIL:
                purchase_picker_data.mailmain_delivery = True
            elif object_delivery_method == CommonObjectDeliveryMethod.INVENTORY:
                purchase_picker_data.inventory_owner_id_to_purchase_to = inventory_target_id
            for purchase_object in purchase_objects:
                purchase_picker_data.add_definition_to_purchase(
                    purchase_object)
            dialog.object_id = purchase_picker_data.inventory_owner_id_to_purchase_to
            dialog.mailman_purchase = purchase_picker_data.mailmain_delivery
            dialog.inventory_object_id = purchase_picker_data.inventory_owner_id_to_purchase_from
            dialog.purchase_by_object_ids = purchase_picker_data.use_obj_ids_in_response
            dialog.show_description = 1
            dialog.show_description_tooltip = 1
            dialog.use_dialog_pick_response = False
            dialog.max_selectable_num = len(self.rows)
            dialog.use_dropdown_filter = len(dialog_categories) > 0
            right_custom_text = None
            if right_custom_text is not None:
                dialog.right_custom_text = right_custom_text
            return dialog
        except Exception as ex:
            self.log.error('_create_dialog', exception=ex)
        return None
예제 #10
0
 def _run_with_sims(self, sim_info: SimInfo,
                    sim_info_list: Tuple[SimInfo]) -> bool:
     sim_id = CommonSimUtils.get_sim_id(sim_info)
     for other_sim_info in sim_info_list:
         other_sim_id = CommonSimUtils.get_sim_id(other_sim_info)
         # noinspection PyBroadException
         try:
             CommonSimGenealogyUtils.remove_family_relations_with(
                 sim_info, other_sim_info)
             CommonSimGenealogyUtils.remove_family_relations_with(
                 other_sim_info, sim_info)
             services.relationship_service().destroy_relationship(
                 sim_id, other_sim_id, notify_client=True)
             services.relationship_service().destroy_relationship(
                 other_sim_id, sim_id, notify_client=True)
         except:
             pass
     return True
예제 #11
0
def _cgs_command_print_sim_data(_connection: int = None):
    output = CheatOutput(_connection)
    sim_info = CommonSimUtils.get_active_sim_info()
    output('Sim Data for Sim: Name: \'{}\' Id: \'{}\''.format(
        CommonSimNameUtils.get_full_name(sim_info),
        CommonSimUtils.get_sim_id(sim_info)))
    sim_storage = CGSSimData(sim_info)
    for (key, value) in sim_storage._data.items():
        output(' > {}: {}'.format(pformat(key), pformat(value)))
 def __call__(cls, sim_info: SimInfo) -> Union['_CommonSimDataStorageMetaclass', None]:
     mod_identity = cls.get_mod_identity()
     sim_id = CommonSimUtils.get_sim_id(sim_info)
     mod_name = mod_identity.name
     if mod_name is None:
         return None
     if mod_name not in cls._sim_storage_instances:
         cls._sim_storage_instances[mod_name] = dict()
     if sim_id not in cls._sim_storage_instances[mod_name]:
         cls._sim_storage_instances[mod_name][sim_id] = super(_CommonSimDataStorageMetaclass, cls).__call__(sim_info)
     return cls._sim_storage_instances[mod_name][sim_id]
def _common_testing_show_choose_sims_dialog(_connection: int = None):
    output = sims4.commands.CheatOutput(_connection)
    output('Showing test choose sims dialog.')

    def _on_chosen(choice: Union[Tuple[SimInfo], None],
                   outcome: CommonChoiceOutcome):
        output('Chose {} with result: {}.'.format(
            CommonSimNameUtils.get_full_names(choice), pformat(outcome)))

    try:
        # LocalizedStrings within other LocalizedStrings
        title_tokens = (CommonLocalizationUtils.create_localized_string(
            CommonStringId.TESTING_SOME_TEXT_FOR_TESTING,
            text_color=CommonLocalizedStringColor.GREEN), )
        description_tokens = (CommonLocalizationUtils.create_localized_string(
            CommonStringId.TESTING_TEST_TEXT_WITH_SIM_FIRST_AND_LAST_NAME,
            tokens=(CommonSimUtils.get_active_sim_info(), ),
            text_color=CommonLocalizedStringColor.BLUE), )
        from sims4communitylib.utils.common_icon_utils import CommonIconUtils
        current_count = 0
        count = 25
        options = []
        for sim_info in CommonSimUtils.get_sim_info_for_all_sims_generator():
            if current_count >= count:
                break
            sim_id = CommonSimUtils.get_sim_id(sim_info)
            is_enabled = random.choice((True, False))
            options.append(
                SimPickerRow(sim_id,
                             select_default=False,
                             tag=sim_info,
                             is_enable=is_enabled))
            current_count += 1

        dialog = CommonChooseSimsDialog(
            CommonStringId.TESTING_TEST_TEXT_WITH_STRING_TOKEN,
            CommonStringId.TESTING_TEST_TEXT_WITH_STRING_TOKEN,
            tuple(options),
            title_tokens=title_tokens,
            description_tokens=description_tokens)
        dialog.show(on_chosen=_on_chosen,
                    column_count=5,
                    min_selectable=2,
                    max_selectable=6)
    except Exception as ex:
        CommonExceptionHandler.log_exception(ModInfo.get_identity().name,
                                             'Failed to show dialog',
                                             exception=ex)
        output(
            'Failed to show dialog, please locate your exception log file and upload it to the appropriate thread.'
        )
    output('Done showing.')
예제 #14
0
    def is_hidden(sim_info: SimInfo) -> bool:
        """is_hidden(sim_info)

        Determine if a Sim is hidden.

        :param sim_info: The Sim to check.
        :type sim_info: SimInfo
        :return: True, if the Sim is hidden. False, if the Sim is not hidden.
        :rtype: bool
        """
        sim = CommonSimUtils.get_sim_instance(sim_info)
        sim_id = CommonSimUtils.get_sim_id(sim_info)
        return sim_id is None or sim is None or services.hidden_sim_service().is_hidden(sim_id) or sim.is_hidden() or sim.opacity == 0
예제 #15
0
 def get_relationship_level_of_sims(
     sim_info: SimInfo,
     target_sim_info: SimInfo,
     relationship_track_id: int
 ) -> float:
     """
         Retrieve the level of a relationship track between two sims.
     """
     relationship_track = CommonResourceUtils.load_instance(Types.STATISTIC, relationship_track_id)
     if relationship_track is None:
         return 0.0
     target_sim_id = CommonSimUtils.get_sim_id(target_sim_info)
     return sim_info.relationship_tracker.get_relationship_score(target_sim_id, relationship_track)
예제 #16
0
 def has_relationship_bits_with_sim(
     sim_info: SimInfo,
     target_sim_info: SimInfo,
     relationship_bit_ids: Iterator[int],
 ) -> bool:
     """
         Determine if two sims have any of the specified relationship bits with each other.
     """
     target_sim_id = CommonSimUtils.get_sim_id(target_sim_info)
     relationship_bits = sim_info.relationship_tracker.get_all_bits(target_sim_id)
     for relationship_bit in relationship_bits:
         relationship_bit_id = getattr(relationship_bit, 'guid64', None)
         if relationship_bit_id in relationship_bit_ids:
             return True
     return False
 def _create_dialog(
         self, sim_info: SimInfo,
         target_sim_info: SimInfo) -> Union[UiDialogOkCancel, None]:
     try:
         return UiDialogOkCancel.TunableFactory().default(
             sim_info,
             text=lambda *_, **__: self.description,
             text_ok=lambda *_, **__: self.ok_text,
             text_cancel=lambda *_, **__: self.cancel_text,
             target_sim_id=CommonSimUtils.get_sim_id(target_sim_info),
             resolver=DoubleSimResolver(sim_info, target_sim_info))
     except Exception as ex:
         CommonExceptionHandler.log_exception(self.mod_identity.name,
                                              '_create_dialog',
                                              exception=ex)
     return None
 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
예제 #20
0
 def add_relationship_bit(
     sim_info: SimInfo,
     target_sim_info: SimInfo,
     relationship_bit_id: int
 ) -> bool:
     """
         Add a relationship bit between two sims.
         Note: If the relationship bit is UNIDIRECTIONAL, it will only be added to sim_info in the direction of the Target.
         i.e. Sim will have relationship bit towards Target, but Target will not have relationship bit towards Sim.
         One example is the Caregiver relationship:
         - Sim is caregiver of Target.
         - Target is being cared for by Sim.
     """
     relationship_bit_instance = CommonResourceUtils.load_instance(Types.RELATIONSHIP_BIT, relationship_bit_id)
     if relationship_bit_instance is None:
         return False
     target_sim_id = CommonSimUtils.get_sim_id(target_sim_info)
     sim_info.relationship_tracker.add_relationship_bit(target_sim_id, relationship_bit_instance)
     return True
    def on_started(self, interaction_sim: Sim,
                   interaction_target: Sim) -> bool:
        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_strings: List[str] = list()
        for interaction in CommonSimInteractionUtils.get_running_interactions_gen(
                target_sim_info):
            interaction_name = CommonInteractionUtils.get_interaction_short_name(
                interaction)
            interaction_id = CommonInteractionUtils.get_interaction_id(
                interaction)
            running_interaction_strings.append('{} ({})'.format(
                interaction_name, interaction_id))
        running_interaction_strings = sorted(running_interaction_strings,
                                             key=lambda x: x)
        running_interaction_names = ', '.join(running_interaction_strings)

        queued_interaction_strings: List[str] = list()
        for interaction in CommonSimInteractionUtils.get_queued_interactions_gen(
                target_sim_info):
            interaction_name = CommonInteractionUtils.get_interaction_short_name(
                interaction)
            interaction_id = CommonInteractionUtils.get_interaction_id(
                interaction)
            queued_interaction_strings.append('{} ({})'.format(
                interaction_name, interaction_id))
        queued_interaction_strings = sorted(queued_interaction_strings,
                                            key=lambda x: x)
        queued_interaction_names = ', '.join(queued_interaction_strings)
        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,
                    CommonSimUtils.get_sim_id(target_sim_info))),
            CommonLocalizationUtils.create_localized_string(text)).show(
                icon=IconInfoData(obj_instance=interaction_target))
        return True
예제 #22
0
    def get_sim_info_of_all_sims_with_relationship_bits_generator(sim_info: SimInfo, relationship_bit_ids: Iterator[int], instanced_only: bool=True) -> Iterator[SimInfo]:
        """get_sim_info_of_all_sims_with_relationship_bits_generator(sim_info, relationship_bit_ids, instanced_only=True)

        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.

        :param sim_info: The Sim to locate relationship bits on.
        :type sim_info: SimInfo
        :param relationship_bit_ids: A collection of identifiers for relationship bits to locate connections with.
        :type relationship_bit_ids: Iterator[int]
        :param instanced_only: If True, only Sims that are currently loaded will be returned.
        :type instanced_only: bool, optional
        :return: An iterable of Sims that have any of the specified relationship bits with the specified Sim.
        :rtype: Iterator[SimInfo]
        """
        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:
                continue
            if instanced_only and 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: Any) -> bool:
        self.log.enable()
        object_id = CommonObjectUtils.get_object_id(interaction_target) if interaction_target is not None else -1
        definition_id = -1
        if isinstance(interaction_target, Sim):
            object_id = CommonSimUtils.get_sim_id(interaction_target)
        elif isinstance(interaction_target, GameObject):
            definition = CommonObjectUtils.get_game_object_definition(interaction_target)
            if definition is not None:
                definition_id = definition.id
        self.log.debug('Interactions that can be performed on \'{}\' id:{} def_id:{}:'.format(interaction_target, object_id, definition_id))
        interactions = CommonObjectInteractionUtils.get_all_interactions_registered_to_object_gen(interaction_target)
        interaction_target: GameObject = interaction_target
        interaction_short_names: List[str] = list()
        for interaction in interactions:
            interaction: Interaction = interaction
            try:
                interaction_short_names.append('{} ({})'.format(CommonInteractionUtils.get_interaction_short_name(interaction), CommonInteractionUtils.get_interaction_id(interaction)))
            except Exception as ex:
                self.log.error('Problem while attempting to handle interaction {}'.format(pformat(interaction)), exception=ex)
                continue
        for component in interaction_target.components:
            if not hasattr(component, 'component_super_affordances_gen'):
                continue
            for affordance in component.component_super_affordances_gen():
                try:
                    interaction_short_names.append('{} ({})'.format(CommonInteractionUtils.get_interaction_short_name(affordance), CommonInteractionUtils.get_interaction_id(affordance)))
                except Exception as ex:
                    self.log.error('Problem while attempting to handle affordance {}'.format(pformat(affordance)), exception=ex)
                    continue

        sorted_short_names = sorted(interaction_short_names, key=lambda x: x)
        self.log.format(interactions=sorted_short_names)
        self.log.debug('Done Logging Available Interactions.')
        self.log.disable()
        CommonBasicNotification(
            CommonStringId.S4CL_LOG_ALL_INTERACTIONS,
            CommonStringId.S4CL_DONE_LOGGING_ALL_INTERACTIONS,
            description_tokens=(CommonLogUtils.get_message_file_path(self.mod_identity), )
        ).show()
        return True
예제 #24
0
 def _create_dialog(
     self,
     dialog_options: UiDialogOption = 0,
     sim_info: SimInfo = None,
     target_sim_info: SimInfo = None
 ) -> Union[CommonUiResponseDialog, None]:
     try:
         self.log.debug('Creating dialog.')
         return CommonUiResponseDialog.TunableFactory().default(
             sim_info or CommonSimUtils.get_active_sim_info(),
             tuple(),
             dialog_options=dialog_options,
             text=lambda *_, **__: self.description,
             title=lambda *_, **__: self.title,
             target_sim_id=CommonSimUtils.get_sim_id(target_sim_info)
             if target_sim_info is not None else None,
             resolver=DoubleSimResolver(sim_info, target_sim_info) if
             sim_info is not None and target_sim_info is not None else None)
     except Exception as ex:
         self.log.error('_create_dialog', exception=ex)
     return None
 def on_started(self, interaction_sim: Sim,
                interaction_target: Sim) -> bool:
     target_sim_info = CommonSimUtils.get_sim_info(interaction_target)
     target_sim_name = CommonSimNameUtils.get_full_name(target_sim_info)
     sim_buff_strings: List[str] = list()
     for buff in CommonBuffUtils.get_buffs(target_sim_info):
         buff_name = CommonBuffUtils.get_buff_name(buff)
         buff_id = CommonBuffUtils.get_buff_id(buff)
         sim_buff_strings.append('{} ({})'.format(buff_name, buff_id))
     sim_buff_strings = sorted(sim_buff_strings, key=lambda x: x)
     sim_buffs = ', '.join(sim_buff_strings)
     text = ''
     text += 'Active Buffs:\n{}\n\n'.format(sim_buffs)
     CommonBasicNotification(
         CommonLocalizationUtils.create_localized_string(
             '{} Active Buffs ({})'.format(
                 target_sim_name,
                 CommonSimUtils.get_sim_id(target_sim_info))),
         CommonLocalizationUtils.create_localized_string(text)).show(
             icon=IconInfoData(obj_instance=interaction_target))
     return True
예제 #26
0
    def get_relationship_level_of_sims(
        sim_info: SimInfo,
        target_sim_info: SimInfo,
        relationship_track_id: int
    ) -> float:
        """get_relationship_level_of_sims(sim_info, target_sim_info, relationship_track_id)

        Retrieve the level of a relationship track between two sims.

        :param sim_info: The Sim to check.
        :type sim_info: SimInfo
        :param target_sim_info: The Target Sim of the relationship track.
        :type target_sim_info: SimInfo
        :param relationship_track_id: An identifier for a Relationship Track to retrieve.
        :type relationship_track_id: int
        :return: The current level between two Sims for the specified Relationship Track.
        :rtype: float
        """
        relationship_track = CommonResourceUtils.load_instance(Types.STATISTIC, relationship_track_id)
        if relationship_track is None:
            return 0.0
        target_sim_id = CommonSimUtils.get_sim_id(target_sim_info)
        return sim_info.relationship_tracker.get_relationship_score(target_sim_id, relationship_track)
def _common_show_known_traits(target_sim_id: int=None, _connection: int=None):
    output = CheatOutput(_connection)
    output('Doing')
    active_sim_info = CommonSimUtils.get_active_sim_info()
    active_sim_id = CommonSimUtils.get_sim_id(active_sim_info)
    output('Active sim id: {}'.format(active_sim_id))
    if target_sim_id is None:
        output('No target specified.')
        return
    target_sim_info = CommonSimUtils.get_sim_info(target_sim_id)
    if target_sim_info is None:
        output('Target with id not found: {}'.format(target_sim_id))
        return
    output('Getting relationship {}'.format(CommonSimNameUtils.get_full_name(target_sim_info)))
    relationship_tracker: RelationshipTracker = active_sim_info.relationship_tracker
    output('Getting knowledge')
    knowledge: SimKnowledge = relationship_tracker.get_knowledge(target_sim_id, initialize=False)
    output('Printing knowledge')
    if knowledge.known_traits is None:
        output('No known traits.')
        return
    output('Known Traits:')
    output(pformat(knowledge.known_traits))
    output('Done')
예제 #28
0
 def __init__(self, sim_info: SimInfo):
     super().__init__()
     self._sim_id = CommonSimUtils.get_sim_id(sim_info)
     self._sim_info = sim_info
     self._data = dict()
    def on_started(self, interaction_sim: Sim, interaction_target: Sim) -> bool:
        target_sim_info = CommonSimUtils.get_sim_info(interaction_target)
        target_sim_name = CommonSimNameUtils.get_full_name(target_sim_info)
        trait_strings: List[str] = list()
        for trait in CommonTraitUtils.get_traits(target_sim_info):
            trait_name = CommonTraitUtils.get_trait_name(trait)
            trait_id = CommonTraitUtils.get_trait_id(trait)
            trait_strings.append('{} ({})'.format(trait_name, trait_id))

        trait_strings = sorted(trait_strings, key=lambda x: x)
        sim_traits = ', '.join(trait_strings)
        text = ''
        text += 'Traits:\n{}\n\n'.format(sim_traits)
        CommonBasicNotification(
            CommonLocalizationUtils.create_localized_string('{} Traits ({})'.format(target_sim_name, CommonSimUtils.get_sim_id(target_sim_info))),
            CommonLocalizationUtils.create_localized_string(text)
        ).show(
            icon=IconInfoData(obj_instance=interaction_target)
        )
        return True
    def test_social_mixer_interaction(
        sim_info: SimInfo,
        social_mixer_interaction_id: int,
        social_super_interaction_id: int,
        target: SimInfo=None,
        interaction_context: InteractionContext=None,
        **kwargs
    ) -> TestResult:
        """test_social_mixer_interaction(\
            sim_info,\
            social_mixer_interaction_id,\
            social_super_interaction_id,\
            target=None,\
            interaction_context=None,\
            **kwargs\
        )

        Test to see if a Social Mixer Interaction can be pushed into the queue of a Sim.

        :param sim_info: An instance of a Sim.
        :type sim_info: SimInfo
        :param social_mixer_interaction_id: The decimal identifier of a social mixer interaction.
        :type social_mixer_interaction_id: int
        :param social_super_interaction_id: The decimal identifier of a social super interaction to queue the social mixer interaction under.
        :type social_super_interaction_id: int
        :param target: The target of the interaction. Default is None.
        :type target: Any, optional
        :param interaction_context: The context to queue the interaction with. See also :func:`~create_interaction_context`. Default is None.
        :type interaction_context: InteractionContext, optional
        :return: The result of testing a push of the interaction to the queue of a Sim.
        :rtype: TestResult
        """
        if social_super_interaction_id is not None and social_mixer_interaction_id is None:
            return CommonSimInteractionUtils.test_super_interaction(social_super_interaction_id, target=target, interaction_context=interaction_context)
        sim = CommonSimUtils.get_sim_instance(sim_info)
        # noinspection PyTypeChecker
        super_affordance_instance = CommonInteractionUtils._load_interaction_instance(social_super_interaction_id)
        if super_affordance_instance is None:
            return TestResult.NONE
        mixer_affordance_instance = CommonInteractionUtils._load_interaction_instance(social_mixer_interaction_id)
        if mixer_affordance_instance is None:
            return TestResult.NONE

        def _get_existing_social_super_interaction(si_iter) -> Interaction:
            for si in si_iter:
                if si.super_affordance != super_affordance_instance:
                    continue
                if si.social_group is None:
                    continue
                target_sim = CommonSimUtils.get_sim_instance(target)
                if target_sim is not None and target_sim not in si.social_group:
                    continue
                return si.super_interaction

        interaction_context = interaction_context or CommonSimInteractionUtils.create_interaction_context(sim_info)
        super_interaction = _get_existing_social_super_interaction(sim.si_state) or _get_existing_social_super_interaction(sim.queue)
        if super_interaction is None:
            si_result = sim.test_super_affordance(
                super_affordance_instance,
                target,
                interaction_context,
                picked_object=target,
                **kwargs
            )
            if not si_result or not si_result.result:
                return TestResult.NONE
            super_interaction = si_result.interaction

        pick = super_interaction.context.pick
        preferred_objects = super_interaction.context.preferred_objects
        context = super_interaction.context.clone_for_continuation(
            super_interaction,
            insert_strategy=interaction_context.insert_strategy,
            source_interaction_id=super_interaction.id,
            source_interaction_sim_id=CommonSimUtils.get_sim_id(sim_info),
            pick=pick,
            preferred_objects=preferred_objects,
            must_run_next=interaction_context.must_run_next
        )
        aop = AffordanceObjectPair(
            mixer_affordance_instance,
            target,
            super_affordance_instance,
            super_interaction,
            picked_object=target,
            push_super_on_prepare=True
        )
        return aop.test(context)