Exemple #1
0
    def get_buffs(sim_info: SimInfo) -> List[Buff]:
        """get_buffs(sim_info)

        Retrieve all buffs currently active on a Sim.

        :param sim_info: The Sim to retrieve the buffs of.
        :type sim_info: SimInfo
        :return: A collection of currently active buffs on the Sim.
        :rtype: Tuple[Buff]
        """
        if sim_info is None:
            CommonExceptionHandler.log_exception(
                ModInfo.get_identity(),
                'Argument \'sim_info\' was \'None\' for \'{}\' of class \'{}\''
                .format(CommonBuffUtils.get_buffs.__name__,
                        CommonBuffUtils.__name__))
            return list()
        if not CommonComponentUtils.has_component(sim_info,
                                                  CommonComponentType.BUFF):
            return list()
        from objects.components.buff_component import BuffComponent
        buff_component: BuffComponent = CommonComponentUtils.get_component(
            sim_info, CommonComponentType.BUFF)
        buffs = list()
        for buff in buff_component:
            if buff is None or not isinstance(buff, Buff):
                continue
            buffs.append(buff)
        return buffs
    def remove_buff(sim_info: SimInfo, *buff_ids: int) -> bool:
        """remove_buff(sim_info, *buff_ids)

        Remove the specified buffs from a sim.

        :param sim_info: The sim to remove the specified buffs from.
        :type sim_info: SimInfo
        :param buff_ids: The decimal identifiers of Buffs to remove.
        :type buff_ids: int
        :return: True, if all of the specified buffs were successfully removed. False, if not.
        :rtype: bool
        """
        if sim_info is None:
            CommonExceptionHandler.log_exception(ModInfo.get_identity().name, 'Argument \'sim_info\' was \'None\' for \'{}\' of class \'{}\''.format(CommonBuffUtils.remove_buff.__name__, CommonBuffUtils.__name__))
            return False
        if not CommonComponentUtils.has_component(sim_info, CommonComponentType.BUFF):
            return False
        success = True
        for buff_identifier in buff_ids:
            buff_instance = CommonBuffUtils._load_buff_instance(buff_identifier)
            if buff_instance is None:
                continue
            if not sim_info.remove_buff_by_type(buff_instance):
                success = False
        return success
 def is_allowed_on_current_lot(sim_info: SimInfo) -> bool:
     """ Determine if a Sim is allowed on the current lot. """
     from sims4communitylib.utils.common_component_utils import CommonComponentUtils
     from sims4communitylib.enums.types.component_types import CommonComponentType
     from sims4communitylib.utils.sims.common_sim_utils import CommonSimUtils
     if CommonSimLocationUtils.is_at_home(sim_info):
         return True
     if CommonSimLocationUtils.is_renting_current_lot(sim_info):
         return True
     if CommonSimTypeUtils.is_player_sim(sim_info) and (
             CommonLocationUtils.current_venue_allows_role_state_routing()
             or not CommonLocationUtils.
             current_venue_requires_player_greeting()):
         return True
     sim = CommonSimUtils.get_sim_instance(sim_info)
     autonomy_component: AutonomyComponent = CommonComponentUtils.get_component(
         sim, CommonComponentType.AUTONOMY)
     if autonomy_component is None or not hasattr(autonomy_component,
                                                  'active_roles'):
         return False
     for role_state_instance in autonomy_component.active_roles():
         if CommonSimTypeUtils.is_non_player_sim(sim_info):
             if role_state_instance._portal_disallowance_tags or not role_state_instance._allow_npc_routing_on_active_lot:
                 return False
         elif role_state_instance._portal_disallowance_tags:
             return False
     return True
Exemple #4
0
    def has_all_free_slots(
        game_object: GameObject, slot_types: Iterator[CommonSlotType] = ()
    ) -> bool:
        """has_all_free_slots(game_object, slot_types=())

        Determine if an Object has all of the specified slots available for use.

        :param game_object: An instance of an object.
        :type game_object: GameObject
        :param slot_types: A collection of CommonSlotTypes. Default is an empty collection.
        :type slot_types: Tuple[CommonSlotTypes], optional
        :return: True, if all of the specified slots are free on the Object. False, if not.
        :rtype: bool
        """
        slot_types = tuple(slot_types)
        game_object = CommonObjectUtils.get_root_parent(game_object)
        slot_component: SlotComponent = CommonComponentUtils.get_component(
            game_object, CommonComponentType.SLOT)
        if slot_component is None:
            return True
        for runtime_slot in slot_component.get_runtime_slots_gen():
            if runtime_slot.empty:
                continue
            if not slot_types:
                return False
            if not runtime_slot.slot_types:
                continue
            for slot_type in runtime_slot.slot_types:
                if slot_type.__name__ in slot_types:
                    return False
        return True
Exemple #5
0
    def has_buff(sim_info: SimInfo, *buff_ids: Union[int,
                                                     CommonBuffId]) -> bool:
        """has_buff(sim_info, *buff_ids)

        Determine if any of the specified buffs are currently active on a sim.

        :param sim_info: The sim being checked.
        :type sim_info: SimInfo
        :param buff_ids: The decimal identifiers of Buffs.
        :type buff_ids: int
        :return: True if the sim has any of the specified buffs.
        :rtype: int
        """
        if sim_info is None:
            raise AssertionError('Argument sim_info was None')
        if not CommonComponentUtils.has_component(sim_info,
                                                  CommonComponentType.BUFF):
            return False
        if not buff_ids:
            return False
        sim_buffs = CommonBuffUtils.get_buffs(sim_info)
        for buff in sim_buffs:
            buff_id = CommonBuffUtils.get_buff_id(buff)
            if buff_id in buff_ids:
                return True
        return False
Exemple #6
0
    def add_buff(
        sim_info: SimInfo,
        *buff_ids: Union[int, CommonBuffId],
        buff_reason: Union[int, str, LocalizedString, CommonStringId] = None
    ) -> bool:
        """add_buff(sim_info, *buff_ids, buff_reason=None)

        Add the specified buffs to a sim.

        :param sim_info: The sim to add the specified buffs to.
        :type sim_info: SimInfo
        :param buff_ids: The decimal identifiers of buffs to add.
        :type buff_ids: int
        :param buff_reason: The text that will display when the player hovers over the buffs. What caused the buffs to be added.
        :type buff_reason: Union[int, str, LocalizedString, CommonStringId], optional
        :return: True, if all of the specified buffs were successfully added. False, if not.
        :rtype: bool
        """
        if sim_info is None:
            raise AssertionError('Argument sim_info was None')
        if not CommonComponentUtils.has_component(sim_info,
                                                  CommonComponentType.BUFF):
            return False
        localized_buff_reason = CommonLocalizationUtils.create_localized_string(
            buff_reason)
        success = True
        for buff_identifier in buff_ids:
            buff_instance = CommonBuffUtils.load_buff_by_id(buff_identifier)
            if buff_instance is None:
                continue
            if not sim_info.add_buff_from_op(
                    buff_instance, buff_reason=localized_buff_reason):
                success = False
        return success
Exemple #7
0
    def remove_buff(sim_info: SimInfo, *buff_ids: Union[int,
                                                        CommonBuffId]) -> bool:
        """remove_buff(sim_info, *buff_ids)

        Remove the specified buffs from a sim.

        :param sim_info: The sim to remove the specified buffs from.
        :type sim_info: SimInfo
        :param buff_ids: The decimal identifiers of Buffs to remove.
        :type buff_ids: int
        :return: True, if all of the specified buffs were successfully removed. False, if not.
        :rtype: bool
        """
        if sim_info is None:
            raise AssertionError('Argument sim_info was None')
        if not CommonComponentUtils.has_component(sim_info,
                                                  CommonComponentType.BUFF):
            return False
        success = True
        for buff_identifier in buff_ids:
            buff_instance = CommonBuffUtils.load_buff_by_id(buff_identifier)
            if buff_instance is None:
                continue
            if not sim_info.remove_buff_by_type(buff_instance):
                success = False
        return success
    def has_buff(sim_info: SimInfo, *buff_ids: int) -> bool:
        """has_buff(sim_info, *buff_ids)

        Determine if any of the specified buffs are currently active on a sim.

        :param sim_info: The sim being checked.
        :type sim_info: SimInfo
        :param buff_ids: The decimal identifiers of Buffs.
        :type buff_ids: int
        :return: True if the sim has any of the specified buffs.
        :rtype: int
        """
        if sim_info is None:
            CommonExceptionHandler.log_exception(ModInfo.get_identity().name, 'Argument \'sim_info\' was \'None\' for \'{}\' of class \'{}\''.format(CommonBuffUtils.has_buff.__name__, CommonBuffUtils.__name__))
            return False
        if not CommonComponentUtils.has_component(sim_info, CommonComponentType.BUFF):
            return False
        if not buff_ids:
            return False
        sim_buffs = CommonBuffUtils.get_buffs(sim_info)
        for buff in sim_buffs:
            buff_id = getattr(buff, 'guid64', None)
            if buff_id in buff_ids:
                return True
        return False
    def add_buff(sim_info: SimInfo, *buff_ids: int, buff_reason: Union[int, str, LocalizedString]=None) -> bool:
        """add_buff(sim_info, *buff_ids, buff_reason=None)

        Add the specified buffs to a sim.

        :param sim_info: The sim to add the specified buffs to.
        :type sim_info: SimInfo
        :param buff_ids: The decimal identifiers of buffs to add.
        :type buff_ids: int
        :param buff_reason: The text that will display when the player hovers over the buffs. What caused the buffs to be added.
        :type buff_reason: Union[int, str, LocalizedString], optional
        :return: True, if all of the specified buffs were successfully added. False, if not.
        :rtype: bool
        """
        if sim_info is None:
            CommonExceptionHandler.log_exception(ModInfo.get_identity().name, 'Argument \'sim_info\' was \'None\' for \'{}\' of class \'{}\''.format(CommonBuffUtils.add_buff.__name__, CommonBuffUtils.__name__))
            return False
        if not CommonComponentUtils.has_component(sim_info, CommonComponentType.BUFF):
            return False
        localized_buff_reason = CommonLocalizationUtils.create_localized_string(buff_reason)
        success = True
        for buff_identifier in buff_ids:
            buff_instance = CommonBuffUtils._load_buff_instance(buff_identifier)
            if buff_instance is None:
                continue
            if not sim_info.add_buff_from_op(buff_instance, buff_reason=localized_buff_reason):
                success = False
        return success
 def _get_inventory(
         sim_info: SimInfo) -> Union[SimInventoryComponent, None]:
     sim = CommonSimUtils.get_sim_instance(sim_info)
     if sim is None:
         return None
     return CommonComponentUtils.get_component(
         sim, CommonComponentType.INVENTORY)
Exemple #11
0
 def _get_statistics_tracker(sim_info: SimInfo, statistic_id: int, add_dynamic: bool=True) -> CommonGetStatisticTrackerResponse:
     if sim_info is None:
         return CommonGetStatisticTrackerResponse(None, None, None)
     statistic_instance = CommonStatisticUtils._load_statistic_instance(statistic_id)
     if statistic_instance is None:
         return CommonGetStatisticTrackerResponse(None, None, None)
     statistics_component: StatisticComponent = CommonComponentUtils.get_component(sim_info, CommonComponentType.STATISTIC, add_dynamic=add_dynamic)
     if statistics_component is None:
         return CommonGetStatisticTrackerResponse(None, statistic_instance, None)
     return CommonGetStatisticTrackerResponse(statistics_component.get_tracker(statistic_instance), statistic_instance, statistics_component)
Exemple #12
0
    def get_buffs(sim_info: SimInfo) -> List[Buff]:
        """get_buffs(sim_info)

        Retrieve all buffs currently active on a Sim.

        :param sim_info: The Sim to retrieve the buffs of.
        :type sim_info: SimInfo
        :return: A collection of currently active buffs on the Sim.
        :rtype: Tuple[Buff]
        """
        if sim_info is None:
            raise AssertionError('Argument sim_info was None')
        if not CommonComponentUtils.has_component(sim_info,
                                                  CommonComponentType.BUFF):
            return list()
        from objects.components.buff_component import BuffComponent
        buff_component: BuffComponent = CommonComponentUtils.get_component(
            sim_info, CommonComponentType.BUFF)
        buffs = list()
        for buff in buff_component:
            if buff is None or not isinstance(buff, Buff):
                continue
            buffs.append(buff)
        return buffs
def _common_register_buff_added_or_removed_on_sim_spawned(
        event_data: S4CLSimSpawnedEvent) -> bool:
    buff_component: BuffComponent = CommonComponentUtils.get_component(
        event_data.sim_info, CommonComponentType.BUFF)
    if not buff_component:
        return False

    dispatcher_service = CommonSimEventDispatcherService()
    if dispatcher_service._on_sim_buff_added not in buff_component.on_buff_added:
        buff_component.on_buff_added.append(
            dispatcher_service._on_sim_buff_added)

    if dispatcher_service._on_sim_buff_removed not in buff_component.on_buff_removed:
        buff_component.on_buff_removed.append(
            dispatcher_service._on_sim_buff_removed)
    return True
Exemple #14
0
    def get_autonomy_state(sim_info: SimInfo) -> AutonomyState:
        """get_autonomy_state_setting(sim_info)

        Retrieve the current autonomy state of a Sim.

        :param sim_info: An instance of a Sim.
        :type sim_info: SimInfo
        """
        from autonomy.autonomy_component import AutonomyComponent
        sim = CommonSimUtils.get_sim_instance(sim_info)
        if sim is None:
            return AutonomyState.UNDEFINED
        autonomy_component: AutonomyComponent = CommonComponentUtils.get_component(sim, CommonComponentType.AUTONOMY)
        if autonomy_component is None or not hasattr(autonomy_component, 'get_autonomy_state_setting'):
            return AutonomyState.UNDEFINED
        return autonomy_component.get_autonomy_state_setting()
    def can_drag_object_in_live_mode(game_object: GameObject) -> bool:
        """can_live_drag(game_object)

        Determine if an Object can be dragged in Live Mode.

        :param game_object: An instance of an Object.
        :type game_object: GameObject
        :return: True, if the Object can be dragged in Live Mode. False, if not.
        :rtype: bool
        """
        if game_object is None:
            return False
        live_drag_component: LiveDragComponent = CommonComponentUtils.get_component(game_object, CommonComponentType.LIVE_DRAG)
        if live_drag_component is None:
            return False
        return live_drag_component.can_live_drag
    def disable_object_drag_in_live_mode(game_object: GameObject) -> bool:
        """disable_object_drag_in_live_mode(game_object)

        Disable the draggability an Object in Live Mode.

        :param game_object: An instance of an Object.
        :type game_object: GameObject
        :return: True, if successful. False, if not.
        :rtype: bool
        """
        if game_object is None:
            return False
        live_drag_component: LiveDragComponent = CommonComponentUtils.get_component(game_object, CommonComponentType.LIVE_DRAG)
        if live_drag_component is None:
            return False
        live_drag_component._set_can_live_drag(False)
        return True
    def get_gender_preference_amount(sim_info: SimInfo, gender: Gender) -> int:
        """get_gender_preference_value(sim_info, gender)

        Retrieve the amount a Sim prefers the specified gender.

        :param sim_info: An instance of a Sim.
        :type sim_info: SimInfo
        :param gender: A Gender.
        :type gender: Gender
        :return: The amount the Sim prefers the specified Gender.
        :rtype: int
        """
        if not CommonComponentUtils.has_component(
                sim_info, CommonComponentType.STATISTIC):
            return 0
        gender_preference = sim_info.get_gender_preference(gender)
        if gender_preference is None:
            return 0
        return gender_preference.get_value()
    def set_gender_preference_amount(sim_info: SimInfo, gender: Gender,
                                     amount: int) -> bool:
        """set_gender_preference_amount(sim_info, gender, amount)

        Set the amount a Sim prefers the specified Gender.

        :param sim_info: An instance of a Sim.
        :type sim_info: SimInfo
        :param gender: A Gender.
        :type gender: Gender
        :param amount: The amount the Sim prefers the specified Gender.
        :type amount: int
        :return: True, if successfully set. False, it not.
        :rtype: bool
        """
        if not CommonComponentUtils.has_component(
                sim_info, CommonComponentType.STATISTIC):
            return False
        gender_preference = sim_info.get_gender_preference(gender)
        if gender_preference is None:
            return False
        gender_preference.set_value(amount)
        return True
Exemple #19
0
    def get_buff_ids(sim_info: SimInfo) -> List[int]:
        """get_buff_ids(sim_info)

        Retrieve decimal identifiers for all Buffs of a sim.

        :param sim_info: The sim to checked.
        :type sim_info: SimInfo
        :return: A collection of Buff identifiers on a Sim.
        :rtype: List[int]
        """
        if sim_info is None:
            raise AssertionError('Argument sim_info was None')
        if not CommonComponentUtils.has_component(sim_info,
                                                  CommonComponentType.BUFF):
            return list()
        buff_ids = list()
        sim_buffs = CommonBuffUtils.get_buffs(sim_info)
        for buff in sim_buffs:
            buff_id = CommonBuffUtils.get_buff_id(buff)
            if buff_id is None:
                continue
            buff_ids.append(buff_id)
        return buff_ids