Пример #1
0
 def _on_submit(amount: int, outcome: CommonChoiceOutcome):
     if outcome == CommonChoiceOutcome.ERROR:
         self.run(sim_info, on_completed=on_completed)
         return
     elif CommonChoiceOutcome.is_error_or_cancel(outcome):
         on_completed(False)
         return
     CommonHouseholdUtils.get_household(sim_info).funds.add(amount, Consts_pb2.FUNDS_MONEY_CHEAT)
     on_completed(True)
     return True
    def travel_to_home_lot_of_active_sim(sim_info: SimInfo):
        """travel_to_home_lot_of_active_sim(sim_info)

        Travel with the specified Sim to the home lot of the Active Sim.

        :param sim_info: The Sim to travel with.
        :type sim_info: SimInfo
        """
        lot_id = CommonHouseholdUtils.get_household_home_zone_id(
            CommonHouseholdUtils.get_active_household())
        CommonTravelUtils.travel_to_lot(sim_info, lot_id)
Пример #3
0
 def _on_submit(amount: int, outcome: CommonChoiceOutcome):
     if outcome == CommonChoiceOutcome.ERROR:
         self.run(sim_info, on_completed=on_completed)
         return
     elif CommonChoiceOutcome.is_error_or_cancel(outcome):
         on_completed(False)
         return
     CommonHouseholdUtils.get_household(sim_info).funds.try_remove(
         amount,
         Consts_pb2.FUNDS_MONEY_CHEAT,
         sim=CommonSimUtils.get_sim_instance(sim_info),
         require_full_amount=False)
     on_completed(True)
     return True
Пример #4
0
    def is_at_home(sim_info: SimInfo) -> bool:
        """is_at_home(sim_info)

        Determine if a Sim is on their home Lot.

        :param sim_info: The Sim to check.
        :type sim_info: SimInfo
        :return: True, if the Sim is on their home Lot. False, if not.
        :rtype: bool
        """
        sim = CommonSimUtils.get_sim_instance(sim_info)
        if sim is None or not CommonHouseholdUtils.has_household(sim_info):
            return False
        return sim.on_home_lot or (CommonLocationUtils.get_current_zone_id() == CommonHouseholdUtils.get_household_zone_id(sim_info) and CommonSimLocationUtils.is_on_current_lot(sim_info))
 def is_at_home(sim_info: SimInfo) -> bool:
     """ Determine if a Sim is currently at home. """
     active_lot = CommonLocationUtils.get_current_lot()
     return CommonLocationUtils.get_current_zone_id(
     ) == CommonHouseholdUtils.get_household_lot_id(
         sim_info) and active_lot.is_position_on_lot(
             CommonSimLocationUtils.get_position(sim_info))
    def start_pregnancy(
            sim_info: SimInfo,
            partner_sim_info: SimInfo,
            pregnancy_origin: PregnancyOrigin = PregnancyOrigin.DEFAULT
    ) -> bool:
        """start_pregnancy(sim_info, partner_sim_info, pregnancy_origin=PregnancyOrigin.DEFAULT)

        Start a pregnancy between a Sim and a Partner Sim.

        :param sim_info: The Sim getting pregnant.
        :type sim_info: SimInfo
        :param partner_sim_info: The Sim that is getting the other Sim pregnant.
        :type partner_sim_info: SimInfo
        :param pregnancy_origin: The origin of the pregnancy. Default is PregnancyOrigin.DEFAULT.
        :type pregnancy_origin: PregnancyOrigin, optional
        :return: True, if the Sim is successfully impregnated by the Partner Sim. False, if not.
        :rtype: bool
        """
        if not CommonHouseholdUtils.has_free_household_slots(sim_info):
            return False
        pregnancy_tracker = CommonSimPregnancyUtils._get_pregnancy_tracker(
            sim_info)
        if pregnancy_tracker is None:
            return False
        pregnancy_tracker.start_pregnancy(sim_info,
                                          partner_sim_info,
                                          pregnancy_origin=pregnancy_origin)
        pregnancy_tracker.clear_pregnancy_visuals()
        CommonSimStatisticUtils.set_statistic_value(
            sim_info, CommonStatisticId.PREGNANCY, 1.0)
        return True
Пример #7
0
    def run(
        self,
        sim_info: SimInfo,
        on_completed: Callable[[bool],
                               None] = CommonFunctionUtils.noop) -> bool:
        if not CommonHouseholdUtils.has_household(sim_info):
            on_completed(False)
            return False

        def _on_submit(amount: int, outcome: CommonChoiceOutcome):
            if outcome == CommonChoiceOutcome.ERROR:
                self.run(sim_info, on_completed=on_completed)
                return
            elif CommonChoiceOutcome.is_error_or_cancel(outcome):
                on_completed(False)
                return
            CommonHouseholdUtils.get_household(sim_info).funds.try_remove(
                amount,
                Consts_pb2.FUNDS_MONEY_CHEAT,
                sim=CommonSimUtils.get_sim_instance(sim_info),
                require_full_amount=False)
            on_completed(True)
            return True

        from sims4communitylib.dialogs.common_input_integer_dialog import CommonInputIntegerDialog
        dialog = CommonInputIntegerDialog(
            S4CMSimControlMenuStringId.HOW_MANY_SIMOLEONS,
            0,
            1000,
            min_value=1,
            mod_identity=ModInfo.get_identity())
        dialog.show(on_submit=_on_submit)
        return True
    def _setup_dialog(self, option_dialog: CommonChooseButtonOptionDialog,
                      on_close: Callable[[],
                                         None], on_previous: Callable[[],
                                                                      None],
                      reopen: Callable[[], None], **__) -> bool:
        def _operation_run(operation: S4CMSingleSimOperation):
            def _on_operation_complete(_: bool) -> None:
                reopen()

            operation.run(self._sim_info, on_completed=_on_operation_complete)

        is_pregnant = CommonSimPregnancyUtils.is_pregnant(self._sim_info)

        can_produce_pregnancy = S4CMSimPregnancyUtils.can_create_pregnancy(
            self._sim_info)

        create_pregnancy_disabled_text = None
        if is_pregnant:
            create_pregnancy_disabled_text = S4CMSimControlMenuStringId.SIM_IS_ALREADY_PREGNANT
        elif not can_produce_pregnancy:
            create_pregnancy_disabled_text = S4CMSimControlMenuStringId.SIM_IS_UNABLE_TO_CREATE_PREGNANCY
        elif not CommonHouseholdUtils.has_free_household_slots(self._sim_info):
            create_pregnancy_disabled_text = S4CMSimControlMenuStringId.TOO_MANY_SIMS_IN_HOUSEHOLD_ALREADY

        option_dialog.add_option(
            CommonDialogButtonOption(
                'CreatePregnancy',
                None,
                CommonDialogResponseOptionContext(
                    S4CMSimControlMenuStringId.CREATE_PREGNANCY,
                    disabled_text_identifier=create_pregnancy_disabled_text,
                    disabled_text_tokens=(self._sim_info, )),
                on_chosen=lambda *_, **__: _operation_run(
                    S4CMCreatePregnancyOp())))

        option_dialog.add_option(
            CommonDialogButtonOption(
                'InduceLabor',
                None,
                CommonDialogResponseOptionContext(
                    S4CMSimControlMenuStringId.INDUCE_LABOR,
                    disabled_text_identifier=S4CMSimControlMenuStringId.
                    SIM_IS_NOT_PREGNANT if not is_pregnant else None,
                    disabled_text_tokens=(self._sim_info, )),
                on_chosen=lambda *_, **__: _operation_run(S4CMInduceLaborOp()))
        )

        option_dialog.add_option(
            CommonDialogButtonOption(
                'ClearPregnancy',
                None,
                CommonDialogResponseOptionContext(
                    S4CMSimControlMenuStringId.CLEAR_PREGNANCY,
                    disabled_text_identifier=S4CMSimControlMenuStringId.
                    SIM_IS_NOT_PREGNANT if not is_pregnant else None,
                    disabled_text_tokens=(self._sim_info, )),
                on_chosen=lambda *_, **__: _operation_run(S4CMClearPregnancyOp(
                ))))
        return True
    def travel_to_home_lot_of(sim_info: SimInfo):
        """travel_to_home_lot_of(sim_info)

        Travel to the home lot of a Sim.

        :param sim_info: The owner of the home lot to travel to.
        :type sim_info: SimInfo
        """
        lot_id = CommonHouseholdUtils.get_household_zone_id(sim_info)
        CommonTravelUtils.travel_to_lot(sim_info, lot_id)
    def create_human_sim_info(gender: Gender = None,
                              age: Age = None,
                              first_name: str = None,
                              last_name: str = None,
                              trait_ids: Tuple[int] = (),
                              household: Household = None,
                              source: str = 'testing') -> Union[SimInfo, None]:
        """create_human_sim_info(\
            gender=None,\
            age=None,\
            species=None,\
            first_name=None,\
            last_name=None,\
            trait_ids=(),\
            household=None,\
            source='testing'\
        )

        Create SimInfo for a Human Sim.

        :param gender: The Gender of the created Sim.
        :type gender: Gender, optional
        :param age: The Age of the created Sim.
        :type age: Age, optional
        :param first_name: The First Name of the created Sim.
        :type first_name: str, optional
        :param last_name: The Last Name of the created Sim.
        :type last_name: str, optional
        :param trait_ids: The decimal identifiers of the Traits to add to the created Sim.
        :type trait_ids: Tuple[int], optional
        :param household: The household to place the created Sim in. If None, the Sim will be placed in a hidden household.
        :type household: Household, optional
        :param source: The reason for the Sims creation.
        :type source: str, optional
        :return: The SimInfo of the created Sim or None if the Sim failed to be created.
        :rtype: SimInfo
        """
        from sims4communitylib.utils.sims.common_household_utils import CommonHouseholdUtils
        household = household or CommonHouseholdUtils.create_empty_household(
            as_hidden_household=True)
        sim_creator = SimCreator(
            gender=gender,
            age=age,
            first_name=first_name
            or SimSpawner.get_random_first_name(gender, Species.HUMAN),
            last_name=last_name,
            traits=trait_ids)
        (sim_info_list, _) = SimSpawner.create_sim_infos(
            (sim_creator, ),
            household=household,
            generate_deterministic_sim=True,
            creation_source=source)
        if not sim_info_list:
            return None
        return sim_info_list[0]
 def save(self,
          mod_identity: CommonModIdentity,
          data: Dict[str, Any],
          identifier: str = None) -> bool:
     data_name = self._format_data_name(mod_identity, identifier=identifier)
     self.log.format_with_message('Saving data.', data_name=data_name)
     self.log.format_with_message('Attempting to locate data.',
                                  data_name=data_name)
     persisted_data_storage = CommonHouseholdUtils.locate_household_by_name(
         data_name)
     if persisted_data_storage is None:
         self.log.debug(
             'No persisted data found, creating new persisted data.')
         persisted_data_storage = CommonHouseholdUtils.create_empty_household(
             as_hidden_household=True)
         if persisted_data_storage is None:
             self.log.debug('Failed to persisted data.')
             return False
         self.log.debug(
             'Persisted data created successfully. Setting properties.')
         persisted_data_storage.name = data_name
         persisted_data_storage.creator_id = 0
         persisted_data_storage.creator_name = data_name
         persisted_data_storage.creator_uuid = b''
     else:
         self.log.format_with_message(
             'Found persisted data. Attempting to save data.',
             data=persisted_data_storage)
     self.log.format_with_message('Attempting to save data.',
                                  data=persisted_data_storage)
     try:
         self.log.format(data_being_saved=data)
         json_save_data = json.dumps(data)
         persisted_data_storage.description = json_save_data
     except Exception as ex:
         self.log.format_error_with_message('Failed to save data.',
                                            data_name=data_name,
                                            exception=ex)
         raise ex
     self.log.format_with_message('Done saving data.', data_name=data_name)
     return True
Пример #12
0
 def start_pregnancy(sim_info: SimInfo, partner_sim_info: SimInfo) -> bool:
     """ Start a pregnancy between a Sim and a Partner Sim. """
     if not CommonHouseholdUtils.has_free_household_slots(sim_info):
         return False
     pregnancy_tracker = CommonSimPregnancyUtils._get_pregnancy_tracker(
         sim_info)
     if pregnancy_tracker is None:
         return False
     pregnancy_tracker.start_pregnancy(sim_info, partner_sim_info)
     pregnancy_tracker.clear_pregnancy_visuals()
     CommonSimStatisticUtils.set_statistic_value(
         sim_info, CommonStatisticId.PREGNANCY, 1.0)
     return True
 def on_test(cls, interaction_sim: Sim, interaction_target: Any,
             interaction_context: InteractionContext,
             **kwargs) -> TestResult:
     if interaction_target is None or not CommonTypeUtils.is_sim_or_sim_info(
             interaction_target):
         cls.get_log().debug('Target is not a Sim.')
         return TestResult.NONE
     target_sim_info = CommonSimUtils.get_sim_info(interaction_target)
     if not CommonHouseholdUtils.is_part_of_active_household(
             target_sim_info):
         cls.get_log().format_with_message(
             'Failed, Target Sim is not a part of the Active Household.',
             target_sim=target_sim_info)
         return TestResult.NONE
     if CommonHouseholdUtils.get_number_of_sims_in_household_of_sim(
             CommonSimUtils.get_active_sim_info()) <= 1:
         cls.get_log().format_with_message(
             'Failed, Target Sim is the last Sim in their household. They cannot be removed!',
             target_sim=target_sim_info)
         return TestResult.NONE
     cls.get_log().debug(
         'Success, can remove Target Sim from the Active Household.')
     return TestResult.TRUE
    def is_at_home(sim_info: SimInfo) -> bool:
        """is_at_home(sim_info)

        Determine if a Sim is currently at home.

        :param sim_info: The Sim to check.
        :type sim_info: SimInfo
        :return: True, if the Sim is at their home lot. False, if not.
        :rtype: bool
        """
        active_lot = CommonLocationUtils.get_current_lot()
        return CommonLocationUtils.get_current_zone_id(
        ) == CommonHouseholdUtils.get_household_lot_id(
            sim_info) and active_lot.is_position_on_lot(
                CommonSimLocationUtils.get_position(sim_info))
 def remove(self,
            mod_identity: CommonModIdentity,
            identifier: str = None) -> bool:
     data_name = self._format_data_name(mod_identity, identifier=identifier)
     self.log.format_with_message('Removing data.', data_name=data_name)
     self.log.format_with_message('Attempting to remove data.',
                                  data_name=data_name)
     result = CommonHouseholdUtils.delete_households_with_name(
         data_name, allow_partial_match=True)
     if not result:
         self.log.format_with_message('Failed to delete data.',
                                      data_name=data_name)
         return result
     self.log.format_with_message('Data deleted successfully.',
                                  data_name=data_name)
     return result
    def start_pregnancy(sim_info: SimInfo, partner_sim_info: SimInfo) -> bool:
        """start_pregnancy(sim_info, partner_sim_info)

        Start a pregnancy between a Sim and a Partner Sim.

        :param sim_info: The Sim getting pregnant.
        :type sim_info: SimInfo
        :param partner_sim_info: The Sim that is getting the other Sim pregnant.
        :type partner_sim_info: SimInfo
        :return: True, if successful. False, if not.
        :rtype: bool
        """
        if not CommonHouseholdUtils.has_free_household_slots(sim_info):
            return False
        pregnancy_tracker = CommonSimPregnancyUtils._get_pregnancy_tracker(
            sim_info)
        if pregnancy_tracker is None:
            return False
        pregnancy_tracker.start_pregnancy(sim_info, partner_sim_info)
        pregnancy_tracker.clear_pregnancy_visuals()
        CommonSimStatisticUtils.set_statistic_value(
            sim_info, CommonStatisticId.PREGNANCY, 1.0)
        return True
Пример #17
0
 def travel_to_home_lot_of_active_sim(sim_info: SimInfo):
     """
         Send the specified Sim to the Home Lot of the Active Sim.
     """
     lot_id = CommonHouseholdUtils.get_active_household().home_zone_id
     CommonTravelUtils.travel_to_lot(sim_info, lot_id)
 def on_started(self, interaction_sim: Sim,
                interaction_target: Sim) -> bool:
     target_sim_info = CommonSimUtils.get_sim_info(interaction_target)
     return CommonHouseholdUtils.move_sim_to_household(target_sim_info)
def _nrd_testing_show_household_relationship_decay(_connection: int=None):
    output = CheatOutput(_connection)
    output('Showing Household Relationship Decay Values.')
    _NRDRelationshipUtils().show_relationships(CommonHouseholdUtils.get_sim_info_of_all_sims_in_active_household_generator())
    output('Done')
Пример #20
0
 def travel_to_home_lot_of(sim_info: SimInfo):
     """
         Send the specified Sim to their Home Lot.
     """
     lot_id = CommonHouseholdUtils.get_household_lot_id(sim_info)
     CommonTravelUtils.travel_to_lot(sim_info, lot_id)
    def load(self,
             mod_identity: CommonModIdentity,
             identifier: str = None) -> Dict[str, Any]:
        data_name = self._format_data_name(mod_identity, identifier=identifier)
        all_households = tuple(
            CommonHouseholdUtils.get_all_households_generator())
        if not all_households:
            raise Exception(
                f'Households have not been loaded yet, but data with name {data_name} is attempting to be loaded! Please try to use the data after the households have been loaded instead. (Households are available when the S4CLZoneLateLoadEvent event is dispatched)'
            )

        self.log.format_with_message('Loading data.', data_name=data_name)
        loaded_data: Dict[str, Any] = None
        loaded_household: Household = None

        def _load_data_from_household(household: Household) -> Dict[str, Any]:
            # noinspection PyPropertyAccess
            _household_name = household.name
            # noinspection PyPropertyAccess
            self.log.format_with_message(
                'Attempting to read data stored within household.',
                household_name=_household_name,
                household_id=household.id)
            # noinspection PyPropertyAccess
            raw_data = household.description
            if not raw_data:
                self.log.format_with_message(
                    'No raw data found, returning default data.',
                    data=household)
                return dict()
            self.log.debug('Data found, attempting to parse data.')
            return json.loads(raw_data)

        self.log.format_with_message('Attempting to locate data by exact name',
                                     data_name=data_name)
        located_household = CommonHouseholdUtils.locate_household_by_name(
            data_name)
        if located_household is not None:
            self.log.format_with_message('Located data with exact name.',
                                         data_name=data_name)
            loaded_data = _load_data_from_household(located_household)
            if loaded_data is not None:
                loaded_household = located_household

        self.log.format_with_message(
            'Attempting to locate data containing name.', data_name=data_name)
        for persisted_household in CommonHouseholdUtils.locate_households_by_name_generator(
                data_name, allow_partial_match=True):
            if persisted_household is None or (
                    loaded_household is not None
                    and persisted_household is loaded_household):
                self.log.debug('Household does not match.')
                continue
            # noinspection PyPropertyAccess
            household_name = persisted_household.name
            if loaded_data is not None:
                # noinspection PyPropertyAccess
                self.log.format_with_message(
                    'Duplicate household found, attempting to remove duplicate.',
                    household_name=household_name,
                    household_id=persisted_household.id)
                if CommonHouseholdUtils.delete_household(persisted_household):
                    self.log.format_with_message(
                        'Successfully deleted duplicate household.',
                        household_name=household_name)
                else:
                    self.log.format_with_message(
                        'Failed to delete duplicate household.',
                        household_name=household_name)
                continue
            loaded_data = _load_data_from_household(persisted_household)
            if loaded_data is not None:
                loaded_household = persisted_household
        if loaded_data is None:
            return dict()
        self.log.format_with_message('Done loading data.',
                                     data_name=data_name,
                                     loaded_data=loaded_data)
        return loaded_data