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
Пример #2
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 _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)
Пример #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
Пример #5
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)
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
Пример #7
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
Пример #10
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