Example #1
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
Example #2
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
Example #3
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
Example #4
0
 def _load_statistic_instance(
         statistic_id: Union[int,
                             CommonStatisticId]) -> Union[Statistic, None]:
     statistic_instance = CommonResourceUtils.load_instance(
         Types.STATISTIC, statistic_id)
     if statistic_instance is None:
         return None
     return statistic_instance
Example #5
0
    def get_venue_of_current_lot() -> Venue:
        """get_venue_of_current_lot()

        Retrieve a Venue for the current lot.

        :return: The Venue of the current lot.
        :rtype: Venue
        """
        return CommonResourceUtils.load_instance(Types.VENUE, CommonLocationUtils.get_current_venue_type())
Example #6
0
 def _opposite_display_name(self) -> int:
     if self.__opposite_display_name is None:
         relationship_bit_id: int = self.opposite_relationship_bit_id
         relationship_bit: RelationshipBit = CommonResourceUtils.load_instance(
             Types.RELATIONSHIP_BIT, relationship_bit_id)
         if relationship_bit is None:
             self.__opposite_display_name = 0
         # noinspection PyUnresolvedReferences
         self.__opposite_display_name = relationship_bit.display_name
     return self.__opposite_display_name
    def load_interaction_by_id(interaction_id: Union[int, CommonInteractionId]) -> Union[Interaction, None]:
        """load_interaction_by_id(interaction_id)

        Load an instance of an Interaction by its decimal identifier.

        :param interaction_id: The decimal identifier of an Interaction.
        :type interaction_id: Union[int, CommonInteractionId]
        :return: An instance of an Interaction matching the decimal identifier or None if not found.
        :rtype: Union[Interaction, None]
        """
        return CommonResourceUtils.load_instance(Types.INTERACTION, interaction_id)
Example #8
0
    def load_statistic_by_id(
            statistic_id: Union[int,
                                CommonStatisticId]) -> Union[Statistic, None]:
        """load_statistic(statistic_id)

        Load an instance of a Statistic by its decimal identifier.

        :param statistic_id: The decimal identifier of a Statistic.
        :type statistic_id: Union[int, CommonStatisticId]
        :return: An instance of a Statistic matching the decimal identifier or None if not found.
        :rtype: Union[Statistic, None]
        """
        return CommonResourceUtils.load_instance(Types.STATISTIC, statistic_id)
Example #9
0
    def load_situation_by_id(situation_id: Union[int, CommonSituationId]) -> Union[Situation, None]:
        """load_situation_by_id(situation_id)

        Load an instance of a Situation by its decimal identifier.

        :param situation_id: The decimal identifier of a Situation.
        :type situation_id: Union[int, CommonSituationId]
        :return: An instance of a Situation matching the decimal identifier or None if not found.
        :rtype: Union[Situation, None]
        """
        from sims4.resources import Types
        from sims4communitylib.utils.common_resource_utils import CommonResourceUtils
        return CommonResourceUtils.load_instance(Types.SITUATION, situation_id)
Example #10
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)
    def load_trait_by_id(trait_id: Union[int, CommonTraitId]) -> Union[Trait, None]:
        """load_trait_by_id(trait_id)

        Load an instance of a Trait by its decimal identifier.

        :param trait_id: The decimal identifier of a Trait.
        :type trait_id: Union[int, CommonTraitId]
        :return: An instance of a Trait matching the decimal identifier or None if not found.
        :rtype: Union[Trait, None]
        """
        from sims4.resources import Types
        from sims4communitylib.utils.common_resource_utils import CommonResourceUtils
        return CommonResourceUtils.load_instance(Types.TRAIT, trait_id)
Example #12
0
    def load_buff_by_id(
            buff_id: Union[int, CommonBuffId]) -> Union[Buff, None]:
        """load_buff_by_id(buff_id)

        Load an instance of a Buff by its decimal identifier.

        :param buff_id: The decimal identifier of a Buff.
        :type buff_id: Union[int, CommonBuffId]
        :return: An instance of a Buff matching the decimal identifier or None if not found.
        :rtype: Union[Buff, None]
        """
        from sims4.resources import Types
        from sims4communitylib.utils.common_resource_utils import CommonResourceUtils
        return CommonResourceUtils.load_instance(Types.BUFF, buff_id)
Example #13
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
Example #14
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
Example #15
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 _load_trait_instance(trait_id: int) -> Union[Trait, None]:
     from sims4.resources import Types
     from sims4communitylib.utils.common_resource_utils import CommonResourceUtils
     return CommonResourceUtils.load_instance(Types.TRAIT, trait_id)
 def _load_interaction_instance(
         interaction_identifier: int) -> Union[Interaction, None]:
     if interaction_identifier is None:
         return None
     return CommonResourceUtils.load_instance(Types.INTERACTION,
                                              interaction_identifier)
Example #18
0
    def run_with_sims(self,
                      sim_info_a: SimInfo,
                      sim_info_b: SimInfo,
                      on_completed: Callable[[bool],
                                             None] = CommonFunctionUtils.noop):
        relationship_track_id = self._determine_relationship_track(
            sim_info_a, sim_info_b)
        if relationship_track_id == -1:
            self.log.format_with_message(
                'No relationship track id found between Sims.',
                sim=sim_info_a,
                chosen_sim=sim_info_b)
            on_completed(False)
            return
        relationship_track = CommonResourceUtils.load_instance(
            Types.STATISTIC, relationship_track_id)
        if relationship_track is None:
            self.log.format_with_message('No relationship track found.',
                                         sim=sim_info_a,
                                         chosen_sim=sim_info_b)
            on_completed(False)
            return
        relationship_options = self._load_relationship_options(
            relationship_track)
        if not relationship_options:
            self.log.format_with_message('No relationship options found.',
                                         sim=sim_info_a,
                                         chosen_sim=sim_info_b)
            on_completed(False)
            return

        def _on_bit_chosen(_: Any, chosen_option: S4CMRelationshipOption):
            if _ is None or chosen_option is None:
                on_completed(False)
                return
            self.log.format_with_message(
                'Chose relationship bit.',
                sim=sim_info_a,
                chosen_sim=sim_info_b,
                chosen_option=chosen_option,
                required_minimum=chosen_option.required_minimum)
            CommonRelationshipUtils.add_relationship_bit(
                sim_info_a, sim_info_b, CommonRelationshipBitId.HAS_MET)
            CommonRelationshipUtils.set_relationship_level_of_sims(
                sim_info_a, sim_info_b, relationship_track_id,
                chosen_option.required_minimum)
            on_completed(True)

        option_dialog = CommonChooseButtonOptionDialog(
            ModInfo.get_identity(),
            S4CMSimControlMenuStringId.CHOOSE_LEVEL,
            0,
            include_previous_button=True,
            on_previous=lambda: on_completed(False),
            on_close=lambda: on_completed(False))
        for relationship_option in relationship_options:
            option_dialog.add_option(
                CommonDialogButtonOption(relationship_option,
                                         relationship_option,
                                         CommonDialogResponseOptionContext(
                                             relationship_option.display_name),
                                         on_chosen=_on_bit_chosen))

        if not option_dialog.has_options():
            on_completed(False)
            return

        option_dialog.show(sim_info=sim_info_a)
Example #19
0
 def _load_buff_instance(buff_identifier: int) -> Union[Buff, None]:
     from sims4.resources import Types
     from sims4communitylib.utils.common_resource_utils import CommonResourceUtils
     return CommonResourceUtils.load_instance(Types.BUFF, buff_identifier)
Example #20
0
 def _load_reward_instance(reward_definition_id: int) -> Reward:
     return CommonResourceUtils.load_instance(Types.REWARD,
                                              reward_definition_id)