def switch_sim_from_household_to_target_household(self, sim_info, starting_household, destination_household, destroy_if_empty_household=True):
     active_household = services.active_household()
     if services.hidden_sim_service().is_hidden(sim_info.id):
         services.hidden_sim_service().unhide(sim_info.id)
     if starting_household is destination_household:
         logger.error('Trying to run AddToHousehold basic extra on a sim who is already in the destination household.')
         return False
     if not destination_household.can_add_sim_info(sim_info):
         logger.error('Trying to run AddToHousehold basic extra when there is no room in the destination household.')
         return False
     starting_household.remove_sim_info(sim_info, destroy_if_empty_household=destroy_if_empty_household, assign_to_none=False)
     destination_household.add_sim_info_to_household(sim_info)
     client = services.client_manager().get_first_client()
     if destination_household is active_household:
         client.add_selectable_sim_info(sim_info)
         sim_info.apply_fixup_actions(SimInfoFixupActionTiming.ON_ADDED_TO_ACTIVE_HOUSEHOLD)
     else:
         client.remove_selectable_sim_info(sim_info)
     if sim_info.career_tracker is not None:
         sim_info.career_tracker.remove_invalid_careers()
     sim = sim_info.get_sim_instance()
     if sim is not None:
         sim.update_intended_position_on_active_lot(update_ui=True)
         situation_manager = services.get_zone_situation_manager()
         for situation in situation_manager.get_situations_sim_is_in(sim):
             if destination_household is active_household and situation.is_user_facing:
                 continue
             situation_manager.remove_sim_from_situation(sim, situation.id)
         services.daycare_service().on_sim_spawn(sim_info)
     return True
Exemple #2
0
 def _clear_missing_pet_data(self, pet_id):
     self._missing_pet_id = 0
     self._alert_posted = False
     if self._return_alarm is not None:
         alarms.cancel_alarm(self._return_alarm)
         self._return_alarm = None
     sim_filter_service = services.sim_filter_service()
     global_blacklist = sim_filter_service.get_global_blacklist()
     if pet_id in global_blacklist:
         sim_filter_service.remove_sim_id_from_global_blacklist(pet_id, SimFilterGlobalBlacklistReason.MISSING_PET)
     services.hidden_sim_service().unhide_sim(pet_id)
     services.get_first_client().send_selectable_sims_update()
Exemple #3
0
 def _get_selector_visual_type(self, sim_info):
     if sim_info.is_baby:
         return (Sims_pb2.SimPB.BABY, None)
     if sim_info.is_toddler and services.daycare_service(
     ).is_sim_info_at_daycare(sim_info):
         return (Sims_pb2.SimPB.AT_DAYCARE, None)
     if sim_info.household.missing_pet_tracker.is_pet_missing(sim_info):
         return (Sims_pb2.SimPB.PET_MISSING, None)
     sim = sim_info.get_sim_instance(allow_hidden_flags=ALL_HIDDEN_REASONS)
     for career in sim_info.careers.values():
         if career.currently_at_work:
             if career.is_at_active_event and sim is None:
                 return (Sims_pb2.SimPB.MISSING_ACTIVE_WORK,
                         career.career_category)
             return (Sims_pb2.SimPB.AT_WORK, career.career_category)
         if career.is_late:
             if not career.taking_day_off:
                 return (Sims_pb2.SimPB.LATE_FOR_WORK,
                         career.career_category)
     if services.get_rabbit_hole_service(
     ).should_override_selector_visual_type(sim_info.id):
         return (Sims_pb2.SimPB.OTHER, None)
     if sim is not None and sim.has_hidden_flags(
             HiddenReasonFlag.RABBIT_HOLE):
         return (Sims_pb2.SimPB.OTHER, None)
     if services.hidden_sim_service().is_hidden(sim_info.id):
         return (Sims_pb2.SimPB.OTHER, None)
     tutorial_service = services.get_tutorial_service()
     if tutorial_service is not None and tutorial_service.is_sim_unselectable(
             sim_info):
         return (Sims_pb2.SimPB.OTHER, None)
     return (Sims_pb2.SimPB.NORMAL, None)
Exemple #4
0
 def is_hidden(sim_info: SimInfo) -> bool:
     """
         Determine if a sim is hidden.
     """
     sim = CommonSimUtils.get_sim_instance(sim_info)
     sim_id = CommonSimUtils.get_sim_id(sim_info)
     return sim_id is None or sim is None or services.hidden_sim_service().is_hidden(sim_id) or sim.is_hidden() or sim.opacity == 0
Exemple #5
0
 def _bring_home_resident_if_overdue(self, sim_info):
     current_zone = services.current_zone()
     if sim_info.zone_id == current_zone.id:
         return
     if sim_info.is_pet and not any(household_sim_info.is_human and (household_sim_info.is_child_or_older and sim_info.zone_id == household_sim_info.zone_id) for household_sim_info in sim_info.household.sim_info_gen()):
         self._bring_sim_home(sim_info)
         return
     current_region = current_zone.region
     sim_region = region.get_region_instance_from_zone_id(sim_info.zone_id)
     if sim_region is not None and not sim_region.is_region_compatible(current_region):
         return
     if sim_info.career_tracker is None:
         logger.error('Career Tracker for resident Sim {} is unexpectedly None.'.format(sim_info))
     else:
         career = sim_info.career_tracker.get_at_work_career()
         if career is not None and career.is_at_active_event:
             return
     if services.hidden_sim_service().is_hidden(sim_info.id):
         return
     if sim_info.zone_id == 0 or sim_info.game_time_bring_home is None:
         self._bring_sim_home(sim_info)
         return
     bring_home_time = DateAndTime(sim_info.game_time_bring_home)
     current_time = services.time_service().sim_now
     if current_time >= bring_home_time:
         self._bring_sim_home(sim_info)
     else:
         time_till_spawn = bring_home_time - current_time
         self._return_sim_to_home_lot_alarm_handles.add(alarms.add_alarm(sim_info, time_till_spawn, self._return_sim_to_current_lot))
Exemple #6
0
 def run_away_succeeded(self, pet_info):
     self._running_away = False
     if self._missing_pet_id != 0:
         return
     self._missing_pet_id = pet_info.id
     pet_info.add_trait(self.MISSING_PET_TRAIT)
     away_action = self.DEFAULT_AWAY_ACTIONS.get(pet_info.species)
     services.hidden_sim_service().hide_sim(pet_info.id, default_away_action=away_action)
     if self._test_alarm:
         alarms.cancel_alarm(self._test_alarm)
         self._test_alarm = None
     return_interval = clock.interval_in_sim_minutes(self.RETURN_INTERVAL)
     self._add_return_alarm(return_interval)
     for sim_info in self._household.sim_info_gen():
         if sim_info.id != pet_info.id:
             resolver = DoubleSimResolver(sim_info, pet_info)
             self.RUN_AWAY_LOOT_FOR_HOUSEHOLD.apply_to_resolver(resolver)
     sim_filter_service = services.sim_filter_service()
     sim_filter_service.add_sim_id_to_global_blacklist(pet_info.id, SimFilterGlobalBlacklistReason.MISSING_PET)
     services.get_first_client().send_selectable_sims_update()
Exemple #7
0
    def is_hidden(sim_info: SimInfo) -> bool:
        """is_hidden(sim_info)

        Determine if a Sim is hidden.

        :param sim_info: The Sim to check.
        :type sim_info: SimInfo
        :return: True, if the Sim is hidden. False, if the Sim is not hidden.
        :rtype: bool
        """
        sim = CommonSimUtils.get_sim_instance(sim_info)
        sim_id = CommonSimUtils.get_sim_id(sim_info)
        return sim_id is None or sim is None or services.hidden_sim_service().is_hidden(sim_id) or sim.is_hidden() or sim.opacity == 0
Exemple #8
0
    def move_sim_to_household(sim_info: SimInfo,
                              household_id: int = None,
                              destroy_if_empty_household: bool = True) -> bool:
        """move_sim_to_household(sim_info, household_id=None, destroy_if_empty_household=True)

        Move a Sim to the specified household or a new household if no Household is specified.

        :param sim_info: The Sim to add.
        :type sim_info: SimInfo
        :param household_id: The identifier of the Household to add the Sim to.
        :type household_id: int
        :param destroy_if_empty_household: If True, if the Sim comes from a household containing only them, then it will be destroyed after they are moved.
        :type destroy_if_empty_household: bool, optional
        :return: True, if the Sim was added to the Household successfully. False, if not.
        :rtype: bool
        """
        active_household = services.active_household()
        starting_household = sim_info.household
        log.format_info('Moving a Sim to a new household.',
                        sim=CommonSimNameUtils.get_full_name(sim_info),
                        household_id=household_id,
                        starting_household=starting_household)
        if household_id is None:
            log.info(
                'No destination household specified, creating a household for the sim.'
            )
            destination_household = services.household_manager(
            ).create_household(sim_info.account)
        else:
            log.info('Household was specified, getting household of the sim.')
            destination_household = services.household_manager().get(
                household_id)
        if destination_household is None:
            raise AssertionError('Destination Household not specified!')
        log.format_info('Destination household acquired',
                        destination_household=destination_household)
        if CommonSimStateUtils.is_hidden(sim_info):
            log.info('Making hidden Sim visible.')
            services.hidden_sim_service().unhide(sim_info.id)
        if starting_household is destination_household:
            raise AssertionError(
                'The Sim being moved is already in the destination household.')
        if not destination_household.can_add_sim_info(sim_info):
            raise AssertionError(
                'The destination household has no room for additions.')
        log.info('Removing Sim from the starting household.')
        starting_household.remove_sim_info(
            sim_info, destroy_if_empty_household=destroy_if_empty_household)
        log.info('Adding Sim to the destination household.')
        destination_household.add_sim_info_to_household(sim_info)
        client = services.client_manager().get_first_client()
        if destination_household is active_household:
            log.info(
                'The destination household is the active household. Changing the Sim to be selectable.'
            )
            client.add_selectable_sim_info(sim_info)
        else:
            log.info(
                'The destination household is different from the active household. Removing the selectability of the sim.'
            )
            client.remove_selectable_sim_info(sim_info)
        if sim_info.career_tracker is not None:
            log.info('Removing invalid careers.')
            sim_info.career_tracker.remove_invalid_careers()
            log.info('Invalid careers removed.')
        sim = sim_info.get_sim_instance()
        if sim is not None:
            log.info('Updating sims intended position on the active Lot.')
            sim.update_intended_position_on_active_lot(update_ui=True)
            situation_manager = services.get_zone_situation_manager()
            log.info('Removing Sim from currently active situations.')
            for situation in situation_manager.get_situations_sim_is_in(sim):
                if destination_household is active_household and situation.is_user_facing:
                    pass
                else:
                    log.format_info('Removing situation',
                                    situation_id=situation.id)
                    situation_manager.remove_sim_from_situation(
                        sim, situation.id)
            log.info(
                'Done removing situations. Updating daycare service information.'
            )
            services.daycare_service().on_sim_spawn(sim_info)
        log.info('Done moving Sim to household.')
        return True
Exemple #9
0
 def _is_sim_available(self, sim_info, household, current_zone_id):
     if sim_info.zone_id == household.home_zone_id:
         if sim_info.zone_id != current_zone_id:
             if sim_info.career_tracker is None or sim_info.career_tracker.currently_at_work or services.hidden_sim_service().is_hidden(sim_info.id):
                 return False
             return True
         elif sim_info not in self._unavailable_sims:
             return True
     return False