def _on_interaction_cancelled(self,
                               interaction: Interaction,
                               finishing_type: FinishingType,
                               cancel_reason_msg: str,
                               ignore_must_run: bool = False,
                               **kwargs) -> Union[bool, None]:
     if finishing_type is None:
         return None
     try:
         if not CommonEventRegistry.get().dispatch(
                 S4CLInteractionCancelledEvent(
                     interaction,
                     finishing_type,
                     cancel_reason_msg,
                     ignore_must_run=ignore_must_run,
                     **kwargs)):
             return False
     except Exception as ex:
         CommonExceptionHandler.log_exception(
             ModInfo.get_identity(),
             'Error occurred while running _on_interaction_cancelled for interaction {} with short name {} and display name {}'
             .format(
                 pformat(interaction),
                 CommonInteractionUtils.get_interaction_short_name(
                     interaction),
                 CommonInteractionUtils.get_interaction_display_name(
                     interaction)),
             exception=ex)
     return None
Beispiel #2
0
 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 _on_interaction_cancelled(self,
                               interaction: Interaction,
                               finishing_type: FinishingType,
                               cancel_reason_msg: str,
                               ignore_must_run: bool = False,
                               **__) -> None:
     if finishing_type is None:
         return None
     try:
         CommonEventRegistry().dispatch(
             S4CLInteractionCancelledEvent(interaction,
                                           finishing_type,
                                           cancel_reason_msg,
                                           ignore_must_run=ignore_must_run,
                                           **__))
     except Exception as ex:
         self.log.error(
             'Error occurred while running _on_interaction_cancelled for interaction {} with short name \'{}\' and display name {}. Finishing Type: {}, Cancel Reason: {}, Ignore Must Run: {}, Kwargs: {}'
             .format(
                 pformat(interaction),
                 CommonInteractionUtils.get_interaction_short_name(
                     interaction),
                 CommonInteractionUtils.get_interaction_display_name(
                     interaction), finishing_type, cancel_reason_msg,
                 ignore_must_run, __),
             exception=ex)
     return None
def _common_on_interaction_queued(original, self, interaction: Interaction, *_,
                                  **__) -> TestResult:
    try:
        result = CommonInteractionEventDispatcherService(
        )._on_interaction_queued(self, interaction, *_, **__)
        if result is None or result is True:
            original_result = original(self, interaction, *_, **__)
            CommonInteractionEventDispatcherService(
            )._on_interaction_post_queued(self, interaction, original_result,
                                          *_, **__)
            return original_result
        return result
    except Exception as ex:
        CommonExceptionHandler.log_exception(
            ModInfo.get_identity(),
            'Error occurred while running _on_interaction_queued for interaction {} with short name \'{}\' and display name {}. Args: {}, Kwargs: {}'
            .format(
                pformat(interaction),
                CommonInteractionUtils.get_interaction_short_name(interaction),
                CommonInteractionUtils.get_interaction_display_name(
                    interaction), _, __),
            exception=ex)
    return TestResult(
        False,
        'Interaction \'{}\' with short name \'{}\' Failed to Queue'.format(
            pformat(interaction),
            CommonInteractionUtils.get_interaction_short_name(interaction)))
Beispiel #5
0
def _common_broadcaster_apply(original, self: Broadcaster, *_, **__) -> None:
    try:
        return original(self, *_, **__)
    except Exception as ex:
        if self.interaction is not None:
            interaction = self.interaction
            # noinspection PyTypeChecker
            CommonExceptionHandler.log_exception(
                None,
                'Error occurred while running apply_broadcaster_effect for broadcaster {} for interaction {} with short name {} and display name {}'
                .format(
                    pformat(self), pformat(interaction),
                    CommonInteractionUtils.get_interaction_short_name(
                        interaction),
                    CommonInteractionUtils.get_interaction_display_name(
                        interaction)),
                exception=ex)
        elif self.broadcasting_object is not None:
            broadcasting_object = self.broadcasting_object
            # noinspection PyTypeChecker
            CommonExceptionHandler.log_exception(
                None,
                'Error occurred while running apply_broadcaster_effect for broadcaster {} from object {}'
                .format(pformat(self), pformat(broadcasting_object)),
                exception=ex)
        else:
            # noinspection PyTypeChecker
            CommonExceptionHandler.log_exception(
                None,
                'Error occurred while running apply_broadcaster_effect for broadcaster {}'
                .format(pformat(self)),
                exception=ex)
    return None
 def should_allow_interaction(self, interaction: Interaction) -> bool:
     """ Block interactions in the queue. """
     interaction_id = CommonInteractionUtils.get_interaction_id(interaction)
     if interaction_id in self.get_quick_meal_interactions():
         self.log.debug('Interaction is quick meal!')
         return False
     interaction_name = CommonInteractionUtils.get_interaction_short_name(
         interaction)
     if interaction_name is None:
         return True
     if self._is_quick_meal(interaction_name):
         return False
     return True
def _common_on_super_interaction_cancelled(original, self, *_, **__) -> Any:
    try:
        CommonInteractionEventDispatcherService.get(
        )._on_super_interaction_cancelled(self, *_, **__)
        return original(self, *_, **__)
    except Exception as ex:
        CommonExceptionHandler.log_exception(
            ModInfo.get_identity(),
            'Error occurred while running _on_super_interaction_cancelled for interaction {} with short name {} and display name {}'
            .format(pformat(self),
                    CommonInteractionUtils.get_interaction_short_name(self),
                    CommonInteractionUtils.get_interaction_display_name(self)),
            exception=ex)
    return None
def _common_on_interaction_outcome(original, self, *_, **__) -> Any:
    try:
        CommonInteractionEventDispatcherService()._on_interaction_outcome(
            self, *_, **__)
        return original(self, *_, **__)
    except Exception as ex:
        CommonExceptionHandler.log_exception(
            ModInfo.get_identity(),
            'Error occurred while running _on_interaction_outcome for interaction {} with short name \'{}\' and display name {}. Args: {}, Kwargs: {}'
            .format(pformat(self),
                    CommonInteractionUtils.get_interaction_short_name(self),
                    CommonInteractionUtils.get_interaction_display_name(self),
                    _, __),
            exception=ex)
    return False
 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)
     self.log.enable()
     self.log.debug('Interactions that can be performed on \'{}\':'.format(
         interaction_target))
     interactions = CommonObjectInteractionUtils.get_all_interactions_registered_to_object_gen(
         interaction_target)
     interaction_short_names: List[str] = list()
     for interaction in interactions:
         try:
             interaction_short_names.append(
                 CommonInteractionUtils.get_interaction_short_name(
                     interaction))
         except Exception as ex:
             self.log.error(
                 'Problem while attempting to handle interaction {}'.format(
                     pformat(interaction)),
                 exception=ex)
             continue
     sorted_short_names = sorted(interaction_short_names, key=lambda x: x)
     self.log.debug(pformat(sorted_short_names))
     self.log.debug('Done Logging Available Interactions.'.format())
     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
 def _on_interaction_outcome(self, interaction: Interaction,
                             outcome: InteractionOutcome,
                             result: OutcomeResult) -> None:
     if interaction.sim is None:
         return None
     try:
         CommonEventRegistry().dispatch(
             S4CLInteractionOutcomeEvent(interaction, outcome, result))
     except Exception as ex:
         self.log.error(
             'Error occurred while running _on_interaction_outcome for interaction {} with short name \'{}\' and display name {}. Outcome: {}, Result: {}'
             .format(
                 pformat(interaction),
                 CommonInteractionUtils.get_interaction_short_name(
                     interaction),
                 CommonInteractionUtils.get_interaction_display_name(
                     interaction), outcome, result),
             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)
        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
 def _on_interaction_run(self, interaction_queue: InteractionQueue,
                         timeline: Timeline, interaction: Interaction, *_,
                         **__) -> Union[bool, None]:
     if interaction is None or interaction.sim is None:
         return None
     try:
         return CommonEventRegistry.get().dispatch(
             S4CLInteractionRunEvent(interaction, interaction_queue))
     except Exception as ex:
         CommonExceptionHandler.log_exception(
             ModInfo.get_identity(),
             'Error occurred while running _on_interaction_run for interaction {} with short name {} and display name {}'
             .format(
                 pformat(interaction),
                 CommonInteractionUtils.get_interaction_short_name(
                     interaction),
                 CommonInteractionUtils.get_interaction_display_name(
                     interaction)),
             exception=ex)
     return False
 def _on_interaction_outcome(self, interaction: Interaction,
                             outcome: InteractionOutcome,
                             result: OutcomeResult) -> Union[bool, Any]:
     if interaction.sim is None:
         return False
     try:
         return CommonEventRegistry.get().dispatch(
             S4CLInteractionOutcomeEvent(interaction, outcome, result))
     except Exception as ex:
         CommonExceptionHandler.log_exception(
             ModInfo.get_identity(),
             'Error occurred while running _on_interaction_outcome for interaction {} with short name {} and display name {}'
             .format(
                 pformat(interaction),
                 CommonInteractionUtils.get_interaction_short_name(
                     interaction),
                 CommonInteractionUtils.get_interaction_display_name(
                     interaction)),
             exception=ex)
     return False
 def _on_interaction_run(self, interaction_queue: InteractionQueue,
                         timeline: Timeline, interaction: Interaction,
                         run_result: bool, *_, **__) -> None:
     if interaction is None or interaction.sim is None:
         return None
     try:
         CommonEventRegistry().dispatch(
             S4CLInteractionRunEvent(interaction, interaction_queue,
                                     run_result))
     except Exception as ex:
         self.log.error(
             'Error occurred while running _on_interaction_run for interaction {} with short name \'{}\' and display name {}. Original Run Result: {}, Args: {}, Kwargs: {}'
             .format(
                 pformat(interaction),
                 CommonInteractionUtils.get_interaction_short_name(
                     interaction),
                 CommonInteractionUtils.get_interaction_display_name(
                     interaction), str(run_result), _, __),
             exception=ex)
     return None
    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
 def _on_interaction_pre_run(self, interaction_queue: InteractionQueue,
                             timeline: Timeline, interaction: Interaction,
                             *_, **__) -> Union[bool, None]:
     if interaction is None or interaction.sim is None:
         return None
     try:
         if not CommonEventRegistry().dispatch(
                 S4CLInteractionPreRunEvent(interaction, interaction_queue,
                                            timeline)):
             return False
     except Exception as ex:
         self.log.error(
             'Error occurred while running _on_interaction_pre_run for interaction {} with short name \'{}\' and display name {}. Args: {}, Kwargs: {}'
             .format(
                 pformat(interaction),
                 CommonInteractionUtils.get_interaction_short_name(
                     interaction),
                 CommonInteractionUtils.get_interaction_display_name(
                     interaction), _, __),
             exception=ex)
     return None
 def _on_interaction_post_queued(self, interaction_queue: InteractionQueue,
                                 interaction: Interaction,
                                 queue_result: TestResult, *_,
                                 **__) -> None:
     if interaction is None or interaction.sim is None:
         return None
     try:
         CommonEventRegistry().dispatch(
             S4CLInteractionPostQueuedEvent(interaction, interaction_queue,
                                            queue_result))
     except Exception as ex:
         self.log.error(
             'Error occurred while running _on_interaction_post_queued for interaction {} with short name \'{}\' and display name {}. Queue Result: {}, Args: {}, Kwargs: {}'
             .format(
                 pformat(interaction),
                 CommonInteractionUtils.get_interaction_short_name(
                     interaction),
                 CommonInteractionUtils.get_interaction_display_name(
                     interaction), queue_result, _, __),
             exception=ex)
     return None
def _common_on_interaction_run(original, self, timeline: Timeline,
                               interaction: Interaction, *_, **__) -> bool:
    try:
        result = CommonInteractionEventDispatcherService(
        )._on_interaction_pre_run(self, timeline, interaction, *_, **__)
        if result is None or result is True:
            original_result = original(self, timeline, interaction, *_, **__)
            CommonInteractionEventDispatcherService()._on_interaction_run(
                self, timeline, interaction, original_result, *_, **__)
            return original_result
        return result
    except Exception as ex:
        CommonExceptionHandler.log_exception(
            ModInfo.get_identity(),
            'Error occurred while running _on_interaction_run for interaction {} with short name \'{}\' and display name {}. Args: {}, Kwargs: {}'
            .format(
                pformat(interaction),
                CommonInteractionUtils.get_interaction_short_name(interaction),
                CommonInteractionUtils.get_interaction_display_name(
                    interaction), _, __),
            exception=ex)
    return False
 def _on_interaction_queued(self, interaction_queue: InteractionQueue,
                            interaction: Interaction, *_,
                            **__) -> Union[TestResult, None]:
     if interaction is None or interaction.sim is None:
         return None
     try:
         if not CommonEventRegistry().dispatch(
                 S4CLInteractionQueuedEvent(interaction,
                                            interaction_queue)):
             return TestResult(
                 False, 'Interaction \'{}\' Failed to Queue'.format(
                     pformat(interaction)))
     except Exception as ex:
         self.log.error(
             'Error occurred while running _on_interaction_queued for interaction {} with short name \'{}\' and display name {}. Args: {}, Kwargs: {}'
             .format(
                 pformat(interaction),
                 CommonInteractionUtils.get_interaction_short_name(
                     interaction),
                 CommonInteractionUtils.get_interaction_display_name(
                     interaction), _, __),
             exception=ex)
     return None
    def test_super_interaction(
        sim_info: SimInfo,
        super_interaction_id: int,
        target: Any=None,
        interaction_context: InteractionContext=None,
        **kwargs
    ) -> TestResult:
        """test_super_interaction(\
            sim_info,\
            super_interaction_id,\
            target=None,\
            interaction_context=None,\
            **kwargs\
        )

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

        :param sim_info: An instance of a Sim.
        :type sim_info: SimInfo
        :param super_interaction_id: The decimal identifier of a super interaction.
        :type 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
        """
        sim = CommonSimUtils.get_sim_instance(sim_info)
        if sim is None:
            return TestResult.NONE

        if target is not None and CommonTypeUtils.is_sim_or_sim_info(target):
            target = CommonSimUtils.get_sim_instance(target)

        interaction_context = interaction_context or CommonSimInteractionUtils.create_interaction_context(sim_info)
        super_interaction_instance = CommonInteractionUtils._load_interaction_instance(super_interaction_id)
        if super_interaction_instance is None:
            return TestResult.NONE

        return sim.test_super_affordance(
            super_interaction_instance,
            target,
            interaction_context,
            picked_object=target,
            **kwargs
        )
Beispiel #21
0
    def queue_super_interaction(sim_info: SimInfo,
                                super_interaction_id: Union[
                                    int, CommonInteractionId],
                                target: Any = None,
                                interaction_context: InteractionContext = None,
                                **kwargs) -> EnqueueResult:
        """queue_super_interaction(\
            sim_info,\
            super_interaction_id,\
            target=None,\
            interaction_context=None,\
            **kwargs\
        )

        Push a Super Interaction into the queue of a Sim.

        :param sim_info: An instance of a Sim.
        :type sim_info: SimInfo
        :param super_interaction_id: The decimal identifier of a super interaction.
        :type super_interaction_id: Union[int, CommonInteractionId]
        :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 pushing the interaction to the queue of a Sim.
        :rtype: EnqueueResult
        """
        sim = CommonSimUtils.get_sim_instance(sim_info)
        if sim is None:
            return EnqueueResult.NONE

        if target is not None and CommonTypeUtils.is_sim_or_sim_info(target):
            target = CommonSimUtils.get_sim_instance(target)

        interaction_context = interaction_context or CommonSimInteractionUtils.create_interaction_context(
            sim_info)
        super_interaction_instance = CommonInteractionUtils.load_interaction_by_id(
            super_interaction_id)
        if super_interaction_instance is None:
            return EnqueueResult.NONE

        return sim.push_super_affordance(super_interaction_instance,
                                         target,
                                         interaction_context,
                                         picked_object=target,
                                         **kwargs)
    def has_interactions_queued(sim_info: SimInfo, interaction_ids: Iterator[int]) -> bool:
        """has_interactions_queued(sim_info, interaction_ids)

        Determine if a Sim has any of the specified interactions in their interaction queue.

        :param sim_info: The Sim to check.
        :type sim_info: SimInfo
        :param interaction_ids: An iterable of identifiers of the interactions to check for.
        :type interaction_ids: int
        :return: True, if the Sim has any of the specified interactions queued. False, if not.
        :rtype: bool
        """
        for interaction in CommonSimInteractionUtils.get_queued_interactions_gen(sim_info):
            interaction_id = CommonInteractionUtils.get_interaction_id(interaction)
            if interaction_id in interaction_ids:
                return True
        return False
Beispiel #23
0
    def has_interactions_running(sim_info: SimInfo,
                                 interaction_ids: Iterator[int]) -> bool:
        """has_interactions_running(sim_info, interaction_ids)

        Determine if a Sim is running any of the specified interactions.

        :param sim_info: The Sim to check.
        :type sim_info: SimInfo
        :param interaction_ids: An iterable of identifiers of the interactions to check for.
        :type interaction_ids: Union[int, CommonInteractionId]
        :return: True, if the Sim has any of the specified interactions running. False, if not.
        :rtype: bool
        """
        for interaction in CommonSimInteractionUtils.get_running_interactions_gen(
                sim_info):
            interaction_id = CommonInteractionUtils.get_interaction_id(
                interaction)
            if interaction_id in interaction_ids:
                return True
        return False
    def test_interaction(
        sim_info: SimInfo,
        interaction_id: int,
        social_super_interaction_id: int=None,
        target: Any=None,
        interaction_context: InteractionContext=None,
        **kwargs
    ) -> TestResult:
        """test_interaction(\
            sim_info,\
            interaction_id,\
            social_super_interaction_id=None,\
            target=None,\
            interaction_context,\
            skip_if_running=False,\
            **kwargs\
        )

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

        :param sim_info: An instance of a Sim.
        :type sim_info: SimInfo
        :param interaction_id: The decimal identifier of an interaction.
        :type interaction_id: int
        :param social_super_interaction_id: The decimal identifier of a social super interaction to queue the interaction under. Default is None
        :type social_super_interaction_id: int, optional
        :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
        """
        sim = CommonSimUtils.get_sim_instance(sim_info)
        if sim is None or sim.si_state is None or sim.queue is None or sim.posture_state is None or sim.posture is None:
            return TestResult.NONE
        interaction_instance = CommonInteractionUtils._load_interaction_instance(interaction_id)
        if interaction_instance is None:
            return TestResult.NONE

        interaction_context = interaction_context or CommonSimInteractionUtils.create_interaction_context(
            sim_info,
            insert_strategy=QueueInsertStrategy.LAST
        )

        if CommonInteractionUtils.is_super_interaction(interaction_instance):
            return CommonSimInteractionUtils.test_super_interaction(
                sim_info,
                interaction_id,
                target=target,
                interaction_context=interaction_context,
                **kwargs
            )

        if CommonInteractionUtils.is_social_mixer_interaction(interaction_instance):
            return CommonSimInteractionUtils.test_social_mixer_interaction(
                sim_info,
                interaction_id,
                social_super_interaction_id,
                target=target,
                interaction_context=interaction_context,
                **kwargs
            )

        return CommonSimInteractionUtils.test_mixer_interaction(
            sim_info,
            interaction_id,
            target=target,
            interaction_context=interaction_context
        )
    def queue_interaction(
        sim_info: SimInfo,
        interaction_id: int,
        social_super_interaction_id: int=None,
        target: Any=None,
        interaction_context: InteractionContext=None,
        skip_if_running: bool=False,
        **kwargs
    ) -> EnqueueResult:
        """queue_interaction(\
            sim_info,\
            interaction_id,\
            social_super_interaction_id=None,\
            target=None,\
            interaction_context,\
            skip_if_running=False,\
            **kwargs\
        )

        Push an Interaction into the queue of a Sim.

        :param sim_info: An instance of a Sim.
        :type sim_info: SimInfo
        :param interaction_id: The decimal identifier of an interaction.
        :type interaction_id: int
        :param social_super_interaction_id: The decimal identifier of a social super interaction to queue the interaction under. Default is None
        :type social_super_interaction_id: int, optional
        :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
        :param skip_if_running: If True, the interaction will not be queued, if it is already queued or running. If False, the interaction will be queued, even if it is already queued or running.
        :return: The result of pushing the interaction to the queue of a Sim.
        :rtype: EnqueueResult
        """
        sim = CommonSimUtils.get_sim_instance(sim_info)
        if sim is None or sim.si_state is None or sim.queue is None or sim.posture_state is None or sim.posture is None:
            return EnqueueResult.NONE
        interaction_instance = CommonInteractionUtils._load_interaction_instance(interaction_id)
        if interaction_instance is None:
            return EnqueueResult.NONE
        if skip_if_running and CommonSimInteractionUtils.has_interaction_running_or_queued(sim_info, interaction_id):
            return EnqueueResult.NONE

        interaction_context = interaction_context or CommonSimInteractionUtils.create_interaction_context(
            sim_info,
            insert_strategy=QueueInsertStrategy.LAST
        )

        if CommonInteractionUtils.is_super_interaction(interaction_instance):
            return CommonSimInteractionUtils.queue_super_interaction(
                sim_info,
                interaction_id,
                target=target,
                interaction_context=interaction_context,
                **kwargs
            )

        if CommonInteractionUtils.is_social_mixer_interaction(interaction_instance):
            return CommonSimInteractionUtils.queue_social_mixer_interaction(
                sim_info,
                interaction_id,
                social_super_interaction_id,
                target=target,
                interaction_context=interaction_context,
                **kwargs
            )

        return CommonSimInteractionUtils.queue_mixer_interaction(
            sim_info,
            interaction_id,
            target=target,
            interaction_context=interaction_context
        )
    def test_mixer_interaction(
        sim_info: SimInfo,
        mixer_interaction_id: int,
        target: Any=None,
        interaction_context: InteractionContext=None,
        **kwargs
    ) -> TestResult:
        """test_mixer_interaction(\
            sim_info,\
            mixer_interaction_id,\
            target=None,\
            interaction_context=None,\
            **kwargs\
        )

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

        :param sim_info: An instance of a Sim.
        :type sim_info: SimInfo
        :param mixer_interaction_id: The decimal identifier of a mixer interaction.
        :type mixer_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
        """
        from autonomy.content_sets import get_valid_aops_gen

        sim = CommonSimUtils.get_sim_instance(sim_info)
        if sim is None:
            return TestResult.NONE
        if sim.posture is None:
            return TestResult.NONE
        if target is not None and CommonTypeUtils.is_sim_or_sim_info(target):
            target = CommonSimUtils.get_sim_instance(target)
        mixer_interaction_instance = CommonInteractionUtils._load_interaction_instance(mixer_interaction_id)
        if mixer_interaction_instance is None:
            return TestResult.NONE
        source_interaction = sim.posture.source_interaction
        if source_interaction is None:
            return TestResult.NONE
        if hasattr(mixer_interaction_instance, 'lock_out_time') and mixer_interaction_instance.lock_out_time:
            sim_specific_lockout = mixer_interaction_instance.lock_out_time.target_based_lock_out
        else:
            sim_specific_lockout = False

        if sim_specific_lockout and sim.is_sub_action_locked_out(mixer_interaction_instance):
            return TestResult.NONE

        super_interaction_instance = source_interaction.super_affordance
        interaction_context = interaction_context or CommonSimInteractionUtils.create_interaction_context(sim_info)
        for (aop, test_result) in get_valid_aops_gen(
            target,
            mixer_interaction_instance,
            super_interaction_instance,
            source_interaction,
            interaction_context,
            False,
            push_super_on_prepare=False
        ):
            test_result: TestResult = test_result
            if test_result is None or test_result.result:
                continue
            interaction_constraint = aop.constraint_intersection(sim=sim, posture_state=None)
            # noinspection PyPropertyAccess
            posture_constraint = sim.posture_state.posture_constraint_strict
            constraint_intersection = interaction_constraint.intersect(posture_constraint)
            if not constraint_intersection.valid:
                continue
            return aop.test(interaction_context, **kwargs)
    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)