Exemplo n.º 1
0
 def _on_yes_selected(_: Any):
     CommonBuffUtils.remove_buff(sim_info, _buff_id)
     # noinspection PyUnresolvedReferences
     CommonBasicNotification(
         S4CMSimControlMenuStringId.REMOVED_BUFF_TITLE,
         S4CMSimControlMenuStringId.REMOVED_BUFF_DESCRIPTION,
         title_tokens=(chosen_buff.buff_name(sim_info),
                       str(_buff_id)),
         description_tokens=(
             CommonSimUtils.get_sim_instance(sim_info),
             chosen_buff.buff_name(sim_info), str(_buff_id),
             CommonBuffUtils.get_buff_name(chosen_buff))).show(
                 icon=IconInfoData(obj_instance=CommonSimUtils.
                                   get_sim_instance(sim_info)))
     _reopen()
    def buff_id(self) -> int:
        """The decimal identifier of the Buff.

        :return: The decimal identifier of the Buff.
        :rtype: int
        """
        return CommonBuffUtils.get_buff_id(self.buff)
 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)
     sim_buffs = ', '.join(
         CommonBuffUtils.get_buff_names(
             CommonBuffUtils.get_buffs(target_sim_info)))
     text = ''
     text += 'Active Buffs:\n{}\n\n'.format(sim_buffs)
     CommonBasicNotification(
         CommonLocalizationUtils.create_localized_string(
             '{} Active Buffs'.format(target_sim_name)),
         CommonLocalizationUtils.create_localized_string(text)).show(
             icon=IconInfoData(obj_instance=interaction_target))
     return True
 def on_started(self, interaction_sim: Sim, interaction_target: Sim) -> bool:
     self.log.format_with_message('Running \'{}\' on_started.'.format(self.__class__.__name__), interaction_sim=interaction_sim, interaction_target=interaction_target)
     target_sim_info = CommonSimUtils.get_sim_info(interaction_target)
     target_sim_name = CommonSimNameUtils.get_full_name(target_sim_info)
     buff_id = CommonSimPregnancyUtils.get_in_labor_buff(target_sim_info)
     if buff_id != -1:
         self.log.debug('The baby wants out now! Labor induced in \'{}\'. Chosen buff identifier: {}'.format(target_sim_name, str(buff_id)))
         return CommonBuffUtils.add_buff(target_sim_info, buff_id)
     self.log.debug('Failed to induce labor in \'{}\'.'.format(target_sim_name))
     return False
Exemplo n.º 5
0
    def is_dying(sim_info: SimInfo) -> bool:
        """is_dying(sim_info)

        Determine if a Sim is currently dying.

        :param sim_info: The Sim to check.
        :type sim_info: SimInfo
        :return: True, if the Sim is dying. False, if the Sim is not dying.
        :rtype: bool
        """
        return CommonBuffUtils.has_buff(sim_info, CommonBuffId.SIM_IS_DYING)
    def is_wearing_towel(sim_info: SimInfo) -> bool:
        """is_wearing_towel(sim_info)

        Determine if a Sim is currently wearing a towel.

        :param sim_info: The Sim to check.
        :type sim_info: SimInfo
        :return: True, if the sim is wearing a towel. False, if not.
        :rtype: bool
        """
        return CommonBuffUtils.has_buff(sim_info, CommonBuffId.IS_WEARING_TOWEL)
Exemplo n.º 7
0
    def apply_no_quick_meals_buff(self) -> bool:
        """ Apply a buff that disables Quick Meals. """
        self.log.debug('Attempting to apply NQM buff.')

        def _is_valid_sim(_sim_info: SimInfo) -> bool:
            return CommonSpeciesUtils.is_human(
                _sim_info) and not CommonAgeUtils.is_baby(_sim_info)

        for sim_info in CommonSimUtils.get_instanced_sim_info_for_all_sims_generator(
                include_sim_callback=_is_valid_sim):
            sim_name = CommonSimNameUtils.get_full_name(sim_info)
            if CommonBuffUtils.has_buff(sim_info,
                                        NQMBuffId.QUICK_MEALS_INAPPROPRIATE):
                self.log.debug(
                    'Ignoring, \'{}\' already has NQM buff.'.format(sim_name))
                continue
            self.log.debug('Adding NQM buff to \'{}\'.'.format(sim_name))
            CommonBuffUtils.add_buff(sim_info,
                                     NQMBuffId.QUICK_MEALS_INAPPROPRIATE)
        self.log.debug('Done adding NQM buff.')
        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)
     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
Exemplo n.º 9
0
 def _is_buff_allowed_for_removal(self, buff: Buff) -> bool:
     buff_id = CommonBuffUtils.get_buff_id(buff)
     if buff_id is None:
         self.log.format_with_message('Missing buff id for Buff.',
                                      buff=buff)
         return False
     return buff_id not in (CommonBuffId.ALIEN_IS_ALIEN,
                            CommonBuffId.TRAIT_BABY,
                            CommonBuffId.TRAIT_TODDLER,
                            CommonBuffId.TRAIT_CHILD,
                            CommonBuffId.TRAIT_TEEN,
                            CommonBuffId.TRAIT_YOUNG_ADULT,
                            CommonBuffId.TRAIT_ADULT,
                            CommonBuffId.TRAIT_ELDER)
Exemplo n.º 10
0
 def run(
     self,
     sim_info: SimInfo,
     on_completed: Callable[[bool],
                            None] = CommonFunctionUtils.noop) -> bool:
     if not CommonSimPregnancyUtils.is_pregnant(sim_info):
         on_completed(False)
         return False
     buff_id = CommonSimPregnancyUtils.get_in_labor_buff(sim_info)
     if buff_id == -1:
         on_completed(False)
         return False
     result = CommonBuffUtils.add_buff(
         sim_info, buff_id, buff_reason=S4CMStringId.DEBUG_COMMAND)
     on_completed(result)
     return result
Exemplo n.º 11
0
        def _on_chosen(_buff_id: int, chosen_buff: Buff):
            if chosen_buff is None:
                on_completed(False)
                return

            def _on_yes_selected(_: Any):
                CommonBuffUtils.remove_buff(sim_info, _buff_id)
                # noinspection PyUnresolvedReferences
                CommonBasicNotification(
                    S4CMSimControlMenuStringId.REMOVED_BUFF_TITLE,
                    S4CMSimControlMenuStringId.REMOVED_BUFF_DESCRIPTION,
                    title_tokens=(chosen_buff.buff_name(sim_info),
                                  str(_buff_id)),
                    description_tokens=(
                        CommonSimUtils.get_sim_instance(sim_info),
                        chosen_buff.buff_name(sim_info), str(_buff_id),
                        CommonBuffUtils.get_buff_name(chosen_buff))).show(
                            icon=IconInfoData(obj_instance=CommonSimUtils.
                                              get_sim_instance(sim_info)))
                _reopen()

            def _on_no_selected(_: Any):
                _reopen()

            # noinspection PyUnresolvedReferences
            confirmation = CommonOkCancelDialog(
                S4CMStringId.CONFIRMATION,
                S4CMSimControlMenuStringId.
                ARE_YOU_SURE_YOU_WANT_TO_REMOVE_BUFF,
                description_tokens=(chosen_buff.buff_name(sim_info),
                                    str(_buff_id),
                                    CommonBuffUtils.get_buff_name(chosen_buff),
                                    CommonSimUtils.get_sim_instance(sim_info)),
                ok_text_identifier=S4CMStringId.YES,
                cancel_text_identifier=S4CMStringId.NO,
                mod_identity=self.mod_identity)
            confirmation.show(on_ok_selected=_on_yes_selected,
                              on_cancel_selected=_on_no_selected)
Exemplo n.º 12
0
 def is_dying(sim_info: SimInfo) -> bool:
     """
         Determine if a sim is currently dying.
     """
     return CommonBuffUtils.has_buff(sim_info, CommonBuffId.SIM_IS_DYING)
 def is_wearing_towel(sim_info: SimInfo) -> bool:
     """
         Determine if a sim is currently wearing a towel.
     """
     return CommonBuffUtils.has_buff(sim_info,
                                     CommonBuffId.IS_WEARING_TOWEL)
Exemplo n.º 14
0
    def run(
        self,
        sim_info: SimInfo,
        on_completed: Callable[[bool],
                               None] = CommonFunctionUtils.noop) -> bool:
        def _reopen() -> None:
            self.run(sim_info, on_completed=on_completed)

        def _on_close() -> None:
            on_completed(False)

        @CommonExceptionHandler.catch_exceptions(self.mod_identity,
                                                 fallback_return=False)
        def _on_chosen(_buff_id: int, chosen_buff: Buff):
            if chosen_buff is None:
                on_completed(False)
                return

            def _on_yes_selected(_: Any):
                CommonBuffUtils.remove_buff(sim_info, _buff_id)
                # noinspection PyUnresolvedReferences
                CommonBasicNotification(
                    S4CMSimControlMenuStringId.REMOVED_BUFF_TITLE,
                    S4CMSimControlMenuStringId.REMOVED_BUFF_DESCRIPTION,
                    title_tokens=(chosen_buff.buff_name(sim_info),
                                  str(_buff_id)),
                    description_tokens=(
                        CommonSimUtils.get_sim_instance(sim_info),
                        chosen_buff.buff_name(sim_info), str(_buff_id),
                        CommonBuffUtils.get_buff_name(chosen_buff))).show(
                            icon=IconInfoData(obj_instance=CommonSimUtils.
                                              get_sim_instance(sim_info)))
                _reopen()

            def _on_no_selected(_: Any):
                _reopen()

            # noinspection PyUnresolvedReferences
            confirmation = CommonOkCancelDialog(
                S4CMStringId.CONFIRMATION,
                S4CMSimControlMenuStringId.
                ARE_YOU_SURE_YOU_WANT_TO_REMOVE_BUFF,
                description_tokens=(chosen_buff.buff_name(sim_info),
                                    str(_buff_id),
                                    CommonBuffUtils.get_buff_name(chosen_buff),
                                    CommonSimUtils.get_sim_instance(sim_info)),
                ok_text_identifier=S4CMStringId.YES,
                cancel_text_identifier=S4CMStringId.NO,
                mod_identity=self.mod_identity)
            confirmation.show(on_ok_selected=_on_yes_selected,
                              on_cancel_selected=_on_no_selected)

        option_dialog = CommonChooseObjectOptionDialog(
            S4CMSimControlMenuStringId.REMOVE_BUFFS,
            0,
            on_close=_on_close,
            mod_identity=self.mod_identity,
            per_page=20000)

        for buff in CommonBuffUtils.get_buffs(sim_info):
            buff: Buff = buff
            buff_id = CommonBuffUtils.get_buff_id(buff)
            if buff_id is None:
                self.log.format_with_message('Missing buff id for Buff.',
                                             buff=buff)
                continue
            try:
                # noinspection PyUnresolvedReferences
                display_name = buff.buff_name(sim_info)
                if display_name.hash == 0:
                    buff_name = CommonBuffUtils.get_buff_name(
                        buff) or 'Unknown Buff Name'
                    buff_name = buff_name[0].upper() + buff_name[1:]
                    # noinspection PyUnresolvedReferences
                    display_name = CommonLocalizationUtils.create_localized_string(
                        S4CMSimControlMenuStringId.STRING_SPACE_PAREN_STRING,
                        tokens=(buff_name, str(buff_id)))
                else:
                    # noinspection PyUnresolvedReferences
                    display_name = CommonLocalizationUtils.create_localized_string(
                        S4CMSimControlMenuStringId.STRING_SPACE_PAREN_STRING,
                        tokens=(display_name, str(buff_id)))
                # noinspection PyUnresolvedReferences
                description = CommonLocalizationUtils.create_localized_string(
                    buff.buff_description, tokens=(sim_info, ))
                # noinspection PyUnresolvedReferences
                icon = buff.icon or CommonIconUtils.load_question_mark_icon()
                # MISSING ICON Identifier
                _MISSING_IMAGE_ICON_ID = 3526464109639239417
                if icon.instance == 0 or icon.instance == _MISSING_IMAGE_ICON_ID:
                    icon = CommonIconUtils.load_question_mark_icon()
                option_dialog.add_option(
                    CommonDialogSelectOption(
                        buff_id,
                        buff,
                        CommonDialogOptionContext(
                            display_name,
                            description,
                            icon=icon,
                            is_enabled=self._is_buff_allowed_for_removal(
                                buff)),
                        on_chosen=_on_chosen))
            except Exception as ex:
                self.log.format_error_with_message(
                    'Failed to display buff.',
                    buff=buff,
                    buff_name=CommonBuffUtils.get_buff_name(buff),
                    buff_id=buff_id,
                    exception=ex)

        if not option_dialog.has_options():
            on_completed(False)
            return False
        option_dialog.show(sim_info=sim_info, sort_options=True)
        return True