Beispiel #1
0
 def on_enter(self):
     super().on_enter()
     zone = services.current_zone()
     zone.venue_service.build_buy_edit_mode = True
     services.household_manager().load_households()
     zone.on_households_and_sim_infos_loaded()
     client = zone.zone_spin_up_service._client_connect_data.client
     club_service = services.get_club_service()
     if club_service is not None:
         club_service.on_all_households_and_sim_infos_loaded(client)
     relationship_service = services.relationship_service()
     if relationship_service is not None:
         relationship_service.on_all_households_and_sim_infos_loaded(client)
     roommate_service = services.get_roommate_service()
     if roommate_service is not None:
         roommate_service.initialize_editmode_roommates()
     situation_manager = services.get_zone_situation_manager()
     situation_manager.spin_up_for_edit_mode()
     object_manager = services.object_manager()
     water_terrain_object_cache = object_manager.water_terrain_object_cache
     build_buy.register_build_buy_exit_callback(
         water_terrain_object_cache.refresh)
     conditional_layer_service = services.conditional_layer_service()
     conditional_layer_service.on_zone_load(editmode=True)
     for obj in object_manager.values():
         footprint_component = obj.get_component(FOOTPRINT_COMPONENT)
         if footprint_component is not None:
             footprint_component.on_finalize_load()
     services.game_clock_service().restore_saved_clock_speed()
     return _ZoneSpinUpStateResult.DONE
Beispiel #2
0
 def _get_census(self):
     player_households = sum(1 for household in services.household_manager().get_all() if household.is_player_household)
     player_sims = sum(1 for sim_info in services.sim_info_manager().get_all() if sim_info.is_player_sim)
     households = len(services.household_manager())
     sims = len(services.sim_info_manager())
     lod_counts = {lod: services.sim_info_manager().get_num_sim_infos_with_lod(lod) for lod in SimInfoLODLevel}
     return (player_households, player_sims, households, sims, lod_counts)
 def create_sim_infos(cls, sim_creators, household=None, starting_funds=DEFAULT, tgt_client=None, account=None, generate_deterministic_sim=False, zone_id=None, creation_source:str='Unknown'):
     sim_info_list = []
     if account is None:
         account = cls._get_default_account()
     if household is None:
         household = sims.household.Household(account, starting_funds=starting_funds)
     sim_creation_dictionaries = tuple(sim_creator.build_creation_dictionary() for sim_creator in sim_creators)
     new_sim_data = generate_household(sim_creation_dictionaries=sim_creation_dictionaries, household_name=household.name, generate_deterministic_sim=generate_deterministic_sim)
     zone = services.current_zone()
     world_id = zone.world_id
     if zone_id is None:
         zone_id = zone.id
     language = cls._get_language_for_locale(account)
     family_name = cls._get_random_family_name(language)
     if household.id == 0:
         household.id = new_sim_data['id']
         services.household_manager().add(household)
         household.name = family_name
     for (index, sim_data) in enumerate(new_sim_data['sims']):
         sim_proto = serialization.SimData()
         sim_proto.ParseFromString(sim_data)
         first_name = sim_creators[index].first_name
         if not first_name and not sim_creators[index].full_name_key:
             first_name = cls._get_random_first_name(language, sim_proto.gender == Gender.FEMALE)
         last_name = sim_creators[index].last_name
         if not last_name and not sim_creators[index].full_name_key:
             last_name = cls._get_family_name_for_gender(language, family_name, sim_proto.gender == Gender.FEMALE)
         sim_proto.first_name = first_name
         sim_proto.last_name = last_name
         sim_proto.full_name_key = sim_creators[index].full_name_key
         sim_proto.age = sim_creators[index].age
         sim_proto.zone_id = zone_id
         sim_proto.world_id = world_id
         sim_proto.household_id = household.id
         sim_proto.gameplay_data.creation_source = creation_source
         sim_info = sims.sim_info.SimInfo(sim_proto.sim_id, account=account)
         sim_info.load_sim_info(sim_proto)
         if sim_creators[index].resource_key:
             sim_info.load_from_resource(sim_creators[index].resource_key)
             if not sim_info.first_name:
                 sim_info.first_name = sim_proto.first_name
             if not sim_info.last_name:
                 sim_info.last_name = sim_proto.last_name
             if not sim_info.full_name_key:
                 sim_info.full_name_key = sim_proto.full_name_key
         household.add_sim_info(sim_info)
         sim_info.assign_to_household(household)
         sim_info.save_sim()
         sim_info_list.append(sim_info)
         if tgt_client is not None and household is tgt_client.household:
             logger.info('Added {} Sims to the current client', len(sim_creators))
             tgt_client.set_next_sim()
         else:
             logger.info('Added {} Sims to household ID {}.', len(sim_creators), household.id)
         logger.info('Create Sims, sim_number={}; succeeded', len(sim_creators))
     household.save_data()
     return (sim_info_list, household)
Beispiel #4
0
 def remove_sim_info(self,
                     sim_info,
                     destroy_if_empty_gameplay_household=False):
     self._sim_infos.remove(sim_info)
     sim_info.assign_to_household(None, assign_is_npc=False)
     self.notify_dirty()
     services.get_event_manager().process_event(
         test_events.TestEvent.HouseholdChanged, sim_info=sim_info)
     if self._sim_infos or destroy_if_empty_gameplay_household and self.get_household_type(
     ) == HouseholdType.GAME_CREATED:
         services.get_persistence_service().del_household_proto_buff(
             self.id)
         services.household_manager().remove(self)
Beispiel #5
0
    def delete_household(household: Household) -> bool:
        """delete_household(household)

        Delete the specified household from the game.

        :param household: The Household to delete
        :type household: Household
        :return: True, if the Household was deleted successfully. False, if not.
        :rtype: bool
        """
        services.get_persistence_service().del_household_proto_buff(
            household.id)
        services.household_manager().remove(household)
        return True
def get_value(household_id, billable:bool=False, _connection=None):
    household = services.household_manager().get(household_id)
    if household is not None:
        value = household.household_net_worth(billable=billable)
        sims4.commands.output('Simoleon value of household {} is {}.'.format(household, value), _connection)
    else:
        sims4.commands.output('Invalid Household id: {}'.format(household_id), _connection)
 def add(self, obj, *args, **kwargs):
     super().add(obj, *args, **kwargs)
     if obj.objectage_component is None:
         services.current_zone().increment_object_count(obj)
         household_manager = services.household_manager()
         if household_manager is not None:
             household_manager.increment_household_object_count(obj.get_household_owner_id())
Beispiel #8
0
 def _find_households_to_rent_lot(self):
     possible_travel_groups = []
     household_manager = services.household_manager()
     for household in household_manager.values():
         if household.hidden:
             continue
         if household.any_member_in_travel_group():
             continue
         sim_infos_that_can_lead_travel_group = []
         sim_infos_available_for_vacation = []
         for sim_info in household:
             if sim_info.is_instanced():
                 continue
             resolver = SingleSimResolver(sim_info)
             if not _FillRentableLotRequest.CAN_RENT_TESTS.run_tests(
                     resolver):
                 continue
             if sim_info.is_young_adult_or_older and sim_info.is_human:
                 sim_infos_that_can_lead_travel_group.append(sim_info)
             if not sim_info.is_baby:
                 sim_infos_available_for_vacation.append(sim_info)
         if sim_infos_that_can_lead_travel_group:
             possible_travel_groups.append(
                 (sim_infos_that_can_lead_travel_group,
                  sim_infos_available_for_vacation))
     return possible_travel_groups
Beispiel #9
0
 def process_action(self, story_progression_flags):
     neighborhood_population_service = services.neighborhood_population_service(
     )
     if neighborhood_population_service is None:
         return
     households = services.household_manager().values()
     num_homeless_households = sum(1 for household in households
                                   if household.home_zone_id == 0)
     if num_homeless_households >= self._homeless_households.lower_bound:
         self._homeless_household_completed_callback(True)
     else:
         neighborhood_population_service.add_homeless_household_request(
             self._homeless_households.random_int(),
             self._homeless_household_completed_callback)
     neighborhood_proto_buff = self._get_neighborhood_proto()
     if neighborhood_proto_buff is None:
         return
     if StoryProgressionFlags.ALLOW_INITIAL_POPULATION not in story_progression_flags:
         self._zone_population_completed_callback(True)
         return
     if neighborhood_proto_buff.gameplay_data.npc_population_state != gameplay_neighborhood_data_constants.COMPLETED:
         neighborhood_proto_buff.gameplay_data.npc_population_state = gameplay_neighborhood_data_constants.STARTED
         desired_population_data = self._region_to_population_density.get(
             neighborhood_proto_buff.region_id, None)
         if desired_population_data is not None:
             self._add_population_request(desired_population_data,
                                          neighborhood_proto_buff, False)
         else:
             self._zone_population_completed_callback(True)
 def check_collection_complete(self, collection_id):
     collection_data = ObjectCollectionData.get_collection_data(collection_id)
     collection_count = len(collection_data.object_list)
     collected_count = sum(1 for collection in self._collections.values() if collection == collection_id)
     if not collection_count or not collected_count:
         return
     client = services.client_manager().get_client_by_household(self._owner)
     if client is not None and client.active_sim is not None:
         message_owner_info = client.active_sim.sim_info
     else:
         message_owner_info = None
     if collection_data.first_collected_notification is not None and message_owner_info is not None and collected_count == 1:
         dialog = collection_data.first_collected_notification(message_owner_info, None)
         dialog.show_dialog()
     if collection_count == collected_count:
         if client is not None:
             with telemetry_helper.begin_hook(collection_telemetry_writer, TELEMETRY_HOOK_COLLECTION_COMPLETE, household=client.household) as hook:
                 hook.write_int(TELEMETRY_COLLECTION_ID, collection_id)
             _sting = ObjectCollectionData.COLLECTION_COMPLETED_STING(client.active_sim)
             _sting.start()
         if message_owner_info is not None:
             dialog = collection_data.completed_award_notification(message_owner_info, None)
             dialog.show_dialog()
             if collection_data.screen_slam is not None:
                 collection_data.screen_slam.send_screen_slam_message(message_owner_info, collection_data.collection_name)
         lot = services.active_lot()
         if lot is not None:
             lot.create_object_in_hidden_inventory(collection_data.completed_award)
         household = services.household_manager().get(self._owner.id)
         if household is not None:
             household.funds.add(collection_data.completed_award_money, Consts_pb2.TELEMETRY_MONEY_ASPIRATION_REWARD, None)
     elif client is not None:
         _sting = ObjectCollectionData.COLLECTION_COLLECTED_STING(client.active_sim)
         _sting.start()
def create_lod_sim_infos(quantity: int = 1,
                         lod: SimInfoLODLevel = SimInfoLODLevel.MINIMUM,
                         _connection=None):
    output = sims4.commands.CheatOutput(_connection)
    account = services.client_manager().get(_connection).account
    for _ in range(quantity):
        gender = random.choice(list(Gender))
        age = random.choice([Age.TEEN, Age.YOUNGADULT, Age.ADULT, Age.ELDER])
        first_name = SimSpawner.get_random_first_name(gender)
        last_name = 'CheatFamilyLOD{}'.format(lod)
        sc = SimCreator(gender=gender,
                        age=age,
                        first_name=first_name,
                        last_name=last_name)
        household = services.household_manager().create_household(account)
        (si, _) = SimSpawner.create_sim_infos(
            (sc, ),
            household=household,
            zone_id=0,
            creation_source='cheat: LOD SimInfo')
        if not si[0].request_lod(lod):
            output('Failed to request {} lod for {}'.format(lod, si[0]))
        output('Created a SimInfo and requested {} LOD: {}.'.format(
            lod, si[0]))
    output('Created a total of {} SimInfos at {} LOD'.format(lod, quantity))
Beispiel #12
0
def sell_lot_response(dialog):
    if not dialog.accepted:
        return
    business_manager = services.business_service(
    ).get_business_manager_for_zone()
    current_zone = services.current_zone()
    lot = current_zone.lot
    lot_value = lot.furnished_lot_value
    business_manager.modify_funds(lot_value)
    business_manager.transfer_balance_to_household()
    services.get_zone_manager().clear_lot_ownership(current_zone.id)
    business_tracker = services.business_service(
    ).get_business_tracker_for_household(business_manager.owner_household_id,
                                         business_manager.business_type)
    if business_tracker is None:
        logger.warn(
            'Business tracker is None for household {} for business type {}',
            business_manager.owner_household_id,
            business_manager.business_type)
        return
    business_tracker.remove_owner(current_zone.id)
    current_zone.disown_household_objects()
    with telemetry_helper.begin_hook(
            business_telemetry_writer,
            TELEMETRY_HOOK_BUSINESS_SOLD,
            household=services.household_manager().get(
                business_manager.owner_household_id)) as hook:
        hook.write_enum(TELEMETRY_HOOK_BUSINESS_TYPE,
                        business_manager.business_type)
    msg = InteractionOps_pb2.SellRetailLot()
    msg.retail_zone_id = current_zone.id
    distributor.system.Distributor.instance().add_event(
        Consts_pb2.MSG_SELL_RETAIL_LOT, msg)
Beispiel #13
0
 def _close_business(self, play_sound=True):
     if not self._is_open:
         return
     if play_sound:
         sound = PlaySound(services.get_active_sim(), self.tuning_data.audio_sting_close.instance)
         sound.start()
     self._employee_manager.close_business()
     self.send_daily_profit_and_cost_update()
     self._send_business_closed_telemetry()
     if self._owner_household_id is not None:
         owner_household = services.household_manager().get(self._owner_household_id)
         owner_household.bucks_tracker.deactivate_all_temporary_perk_timers_of_type(self.tuning_data.bucks)
         self.modify_funds(-self._employee_manager.final_daily_wages(), from_item_sold=False)
     self.on_store_closed()
     services.get_event_manager().process_event(TestEvent.BusinessClosed)
     self._distribute_business_open_status(False)
     if self.business_zone_id == services.current_zone_id():
         self.tuning_data.lighting_helper_close.execute_lighting_helper(self)
         zone_director = services.venue_service().get_zone_director()
         if zone_director is not None:
             zone_director.refresh_open_street_director_status()
     else:
         self.run_off_lot_simulation()
         self._last_off_lot_update = None
     self._is_open = False
     self.show_summary_dialog(is_from_close=True)
     self._open_time = None
Beispiel #14
0
    def _do_behavior(self):
        obj = self.interaction.get_participant(self.participant)
        if obj is None:
            return
        sim = self.interaction.sim
        if sim is None:
            return
        stolen_component = obj.get_component(
            objects.components.types.STOLEN_COMPONENT)
        if stolen_component is None:
            logger.error(
                "Interaction: {} is attempting to use the ReturnStolenObject basic extra on an object that doesn't have the stolen component.",
                self.interaction)
            return
        obj.remove_from_client(fade_duration=obj.FADE_DURATION)
        stolen_from_household_id = stolen_component.stolen_from_household_id
        household = services.household_manager().get(stolen_from_household_id)
        if household is not None:
            obj.set_household_owner_id(household.id)

            def on_reservation_change(*_, **__):
                if not obj.in_use:
                    obj.unregister_on_use_list_changed(on_reservation_change)
                    object_location_type = ObjectOriginLocation.SIM_INVENTORY if obj.is_in_sim_inventory else ObjectOriginLocation.ON_LOT
                    if not build_buy.move_object_to_household_inventory(
                            obj, object_location_type=object_location_type):
                        obj.schedule_destroy_asap()

            if obj.in_use:
                obj.register_on_use_list_changed(on_reservation_change)
            elif not build_buy.move_object_to_household_inventory(obj):
                obj.schedule_destroy_asap()
        else:
            obj.make_transient()
Beispiel #15
0
 def _save_clean_up_destination_data(self, current_zone,
                                     objects_to_save_for_clean_up,
                                     save_game_protocol_buffer):
     household_manager = services.household_manager()
     travel_group_manager = services.travel_group_manager()
     clean_up_save_data = None
     for object_data in sorted(objects_to_save_for_clean_up,
                               key=lambda x: x.owner_id):
         owner_id = object_data.owner_id
         if clean_up_save_data is None or clean_up_save_data.household_id != owner_id:
             household = household_manager.get(owner_id)
             travel_group = None
             if household is not None:
                 travel_group = household.get_travel_group()
             for clean_up_save_data in save_game_protocol_buffer.destination_clean_up_data:
                 if clean_up_save_data.household_id != owner_id:
                     continue
                 if travel_group is not None:
                     if travel_group.id == clean_up_save_data.travel_group_id:
                         break
                 if clean_up_save_data.travel_group_id in travel_group_manager:
                     continue
                 break
         with ProtocolBufferRollback(
                 clean_up_save_data.object_clean_up_data_list
         ) as object_clean_up_data:
             if object_data.loc_type == ItemLocation.ON_LOT:
                 object_clean_up_data.zone_id = current_zone.id
             else:
                 object_clean_up_data.world_id = current_zone.open_street_id
             object_clean_up_data.object_data = object_data
Beispiel #16
0
 def send_household_region_telemetry(cls):
     household_manager = services.household_manager()
     if household_manager is None:
         return
     persistence_service = services.get_persistence_service()
     per_region_data = dict()
     for household in household_manager.values():
         is_townie_household = household.home_zone_id == 0
         region_description_id = 0 if is_townie_household else get_region_description_id_from_zone_id(
             household.home_zone_id)
         region_data = per_region_data.get(region_description_id, None)
         if region_data is None:
             region_data = HouseholdRegionTelemetryData(
                 region_description_id=region_description_id)
             per_region_data[region_description_id] = region_data
         if household.is_played_household:
             region_data.played_household_count += 1
             region_data.played_sim_info_count += len(household)
         if is_townie_household:
             region_data.townie_household_count += 1
             region_data.townie_sim_info_count += len(household)
         else:
             region_data.region_occupied_lot_count += 1
             if region_data.region_total_lot_count is None:
                 neighborhood_proto = persistence_service.get_neighborhood_proto_buf_from_zone_id(
                     household.home_zone_id)
                 region_data.region_total_lot_count = len(
                     neighborhood_proto.lots)
     for region_data in per_region_data.values():
         region_data._send_telemetry()
def set_num_sim_infos(quantity: int,
                      allow_player: bool = False,
                      _connection=None):
    output = sims4.commands.CheatOutput(_connection)
    sim_info_manager = services.sim_info_manager()
    household_manager = services.household_manager()
    all_sim_infos = list(sim_info_manager.objects)
    count = len(all_sim_infos)
    if quantity >= count:
        output('Current count {} < target count {}'.format(count, quantity))
        return True
    num_to_delete = count - quantity
    eligible = []
    for sim_info in all_sim_infos:
        immunity_reasons = set(sim_info.get_culling_immunity_reasons())
        if allow_player:
            immunity_reasons.discard(CullingReasons.PLAYER)
        if not immunity_reasons:
            eligible.append(sim_info)
    if len(eligible) < num_to_delete:
        output('Insufficient eligible Sims; deleting all {}'.format(
            len(eligible)))
        num_to_delete = len(eligible)
    doomed = random.sample(eligible, num_to_delete)
    for sim_info in doomed:
        household = sim_info.household
        sim_info.remove_permanently()
        if not len(household):
            household_manager.remove(household)
    output('Removed {} Sim infos.  Current count is {}'.format(
        num_to_delete, len(sim_info_manager.objects)))
def set_sims_in_household_to_lod(
        household_id: int = None,
        lod: SimInfoLODLevel = SimInfoLODLevel.MINIMUM,
        _connection=None):
    output = sims4.commands.CheatOutput(_connection)
    automation_output = sims4.commands.AutomationOutput(_connection)
    household = services.household_manager().get(household_id)
    if household is None:
        output('Household not found.')
        automation_output('set_sims_in_household_to_lod; Status:Failed')
        return False
    for sim_info in household.sim_info_gen():
        if sim_info.can_set_to_lod(lod):
            if not sim_info.can_change_lod(sim_info.lod):
                output(
                    'Not all sim infos can be set to {} LOD for household: {}'.
                    format(lod, household))
                automation_output(
                    'set_sims_in_household_to_lod; Status:Failed')
                return False
        output(
            'Not all sim infos can be set to {} LOD for household: {}'.format(
                lod, household))
        automation_output('set_sims_in_household_to_lod; Status:Failed')
        return False
    for sim_info in household.sim_info_gen():
        if sim_info.request_lod(lod):
            output('Sim set to {} LOD. ID:{} Name: {}'.format(
                lod, sim_info.id, sim_info.full_name))
        else:
            output('Sim NOT set to {} LOD. ID:{} Name: {}'.format(
                lod, sim_info.id, sim_info.full_name))
    if lod == SimInfoLODLevel.MINIMUM:
        household.set_to_hidden()
def autopay_bills(enable:bool=None, _connection=None):
    households = services.household_manager().get_all()
    for household in households:
        bills_manager = household.bills_manager
        autopay_bills = enable if enable is not None else not bills_manager.autopay_bills
        bills_manager.autopay_bills = autopay_bills
        sims4.commands.output('Autopay Bills for household {} set to {}.'.format(household, autopay_bills), _connection)
Beispiel #20
0
 def __call__(self, test_targets=None):
     target_household = None
     if self.household_to_test.household_source == UtilityTest.ACTIVE_LOT_HOUSEHOLD:
         target_household = services.owning_household_of_active_lot()
     elif self.household_to_test.household_source == UtilityTest.ACTIVE_HOUSEHOLD:
         target_household = services.active_household()
     elif self.household_to_test.household_source == UtilityTest.PARTICIPANT_HOUSEHOLD:
         target = next(iter(test_targets), None)
         if target is not None:
             if target.is_sim:
                 target_household = target.household
             else:
                 target_household = services.household_manager().get(target.get_household_owner_id())
     if target_household is not None:
         utilities_manager = services.get_utilities_manager_by_household_id(target_household.id)
     elif self.household_to_test.household_source == UtilityTest.ACTIVE_LOT_HOUSEHOLD and self.household_to_test.consider_non_household_lot:
         utilities_manager = services.get_utilities_manager_by_zone_id(services.current_zone_id())
     else:
         return TestResult(False, 'UtilitiesTest: Required to check utility, but there is no household. Check participant tuning.', tooltip=self.tooltip)
     if utilities_manager is None:
         return TestResult(False, 'UtilitiesTest: Required to check utility, but utilities manager is None. Check participant tuning.', tooltip=self.tooltip)
     for utility_state in self.utility_states:
         if utilities_manager.is_utility_active(utility_state.utility) != utility_state.require_active:
             return TestResult(False, 'UtilitiesTest: Utility status for the {} is not correct.', utility_state.utility, tooltip=self.tooltip)
     return TestResult.TRUE
 def _choose_world_from_candidates(self, candidate_world_ids):
     if not candidate_world_ids:
         return
     population_counts = defaultdict(int)
     for household in services.household_manager().values():
         if household.home_zone_id != 0:
             continue
         population_counts[household.get_home_world_id()] += len(household)
     target_counts = {}
     for world_id in candidate_world_ids:
         street = world.street.get_street_instance_from_world_id(world_id)
         if street is None or street.townie_demographics.target_population is None:
             target_counts[world_id] = 0
         else:
             target_counts[
                 world_id] = street.townie_demographics.target_population
     worlds_that_met_target = []
     worlds_below_target = []
     for world_id in candidate_world_ids:
         if population_counts[world_id] < target_counts[world_id]:
             worlds_below_target.append(world_id)
         else:
             worlds_that_met_target.append(world_id)
     if worlds_that_met_target and (len(worlds_that_met_target)
                                    == len(candidate_world_ids)
                                    or random.randint(0, 1) == 0):
         worlds_that_met_target.sort(key=lambda world_id: population_counts[
             world_id] - target_counts[world_id])
         return worlds_that_met_target[0]
     weighted_candidates = tuple(
         (target_counts[world_id] - population_counts[world_id], world_id)
         for world_id in worlds_below_target)
     world_id = sims4.random.weighted_random_item(weighted_candidates)
     return world_id
Beispiel #22
0
 def is_zone_valid_for_gathering(self, zone_id):
     persistence_service = services.get_persistence_service()
     household_manager = services.household_manager()
     try:
         venue_tuning_id = build_buy.get_current_venue(zone_id)
     except RuntimeError:
         return False
     venue_manager = services.get_instance_manager(
         sims4.resources.Types.VENUE)
     venue_tuning = venue_manager.get(venue_tuning_id)
     if venue_tuning is None:
         return False
     if not venue_tuning.allowed_for_clubs:
         return False
     if venue_tuning.is_residential or venue_tuning.is_university_housing:
         zone_data = persistence_service.get_zone_proto_buff(zone_id)
         if zone_data is None:
             return False
         lot_data = persistence_service.get_lot_data_from_zone_data(
             zone_data)
         if lot_data is None:
             return False
         household = household_manager.get(
             lot_data.lot_owner[0].household_id
         ) if lot_data.lot_owner else None
         if household is None:
             return False
         elif not any(club_member in self.members
                      for club_member in household):
             return False
     return True
def player_household_metrics(_connection=None):
    output = sims4.commands.CheatOutput(_connection)
    (active_sim_count, player_sim_count, played_sim_count) = (0, 0, 0)
    (active_household_count, player_household_count,
     played_household_count) = (0, 0, 0)
    households = services.household_manager().get_all()
    for household in households:
        if household.is_active_household:
            active_household_count += 1
            active_sim_count += len(household)
        if household.is_player_household:
            player_household_count += 1
            player_sim_count += len(household)
        if household.is_played_household:
            played_household_count += 1
            played_sim_count += len(household)
    for (name, value) in (('#sim_infos', len(services.sim_info_manager())),
                          ('#active sim_infos', active_sim_count),
                          ('#player sim_infos', player_sim_count),
                          ('#played sim_infos',
                           played_sim_count), ('#households', len(households)),
                          ('#active households', active_household_count),
                          ('#player households',
                           player_household_count), ('#played households',
                                                     played_household_count)):
        output('{:50} : {}'.format(name, value))
    return True
 def process_request_gen(self, timeline):
     (household_population_data, neighborhood_proto) = self._get_region_household_population_data_and_neighborhood_proto()
     if not (household_population_data or self._try_existing_households):
         logger.debug('There is no HouseholdPopulationRegionData for region: {}', neighborhood_proto.region_id)
         return
     while self._num_to_fill > 0:
         while self._available_zone_ids:
             zone_id = self._available_zone_ids.pop(random.randint(0, len(self._available_zone_ids) - 1))
             templates_and_bed_data = self._get_household_templates_and_bed_data(zone_id, household_population_data)
             (household_templates, total_beds, lot_has_double_bed, lot_has_kid_bed) = templates_and_bed_data
             if total_beds <= 0:
                 continue
             moved_household_into_zone = False
             if self._try_existing_households:
                 weighted_households = self._get_available_households(total_beds, lot_has_double_bed, lot_has_kid_bed)
                 if household_templates:
                     ideal_household_curve = NeighborhoodPopulationService.NUM_BEDS_TO_IDEAL_HOUSEHOLD_CURVE.get(total_beds, None)
                     if ideal_household_curve is not None:
                         ideal_household_weight = next(iter(sorted(ideal_household_curve.points, key=operator.itemgetter(1), reverse=True)))
                         weighted_households.append((ideal_household_weight[1], GENERATE_HOUSEHOLD_ID))
                 if weighted_households:
                     household_id = sims4.random.weighted_random_item(weighted_households)
                     if household_id != GENERATE_HOUSEHOLD_ID:
                         household = services.household_manager().get(household_id)
                         if household is not None:
                             self._move_household_into_zone(household, neighborhood_proto, zone_id)
                             moved_household_into_zone = True
             if not moved_household_into_zone and household_templates:
                 moved_household_into_zone = self._add_household_template_to_zone(household_templates, total_beds, lot_has_double_bed, lot_has_kid_bed, neighborhood_proto, zone_id)
             if moved_household_into_zone:
                 pass
             yield element_utils.run_child(timeline, element_utils.sleep_until_next_tick_element())
def get_valid_situation_locations(sim_id, situation_type, *guests, _connection=None):
    sim = get_optional_target(sim_id, _connection)
    if not sim:
        sims4.commands.output('Invalid Sim ID: {}'.format(sim_id), _connection)
        return
    sim_info = sim.sim_info
    possible_zones = []
    possible_zones.append(sim_info.household.home_zone_id)
    for guest_id in guests:
        guest_id = int(guest_id)
        guest_info = services.sim_info_manager().get(guest_id)
        while guest_info is not None:
            guest_zone_id = guest_info.household.home_zone_id
            if guest_zone_id is not None and guest_zone_id and guest_zone_id not in possible_zones:
                possible_zones.append(guest_zone_id)
    venue_service = services.current_zone().venue_service
    for venue_type in situation_type.venue_types:
        possible_zones.extend(venue_service.get_zones_for_venue_type(venue_type))
    venue_manager = services.get_instance_manager(sims4.resources.Types.VENUE)
    persistence_service = services.get_persistence_service()
    locations_msg = Situations_pb2.SituationLocations()
    cas_zones_msg = InteractionOps_pb2.CASAvailableZonesInfo()
    world_info_msg = cas_zones_msg.zones.add()
    for zone_id in possible_zones:
        zone_data = persistence_service.get_zone_proto_buff(zone_id)
        if zone_data is None:
            pass
        neighborhood_data = persistence_service.get_neighborhood_proto_buff(zone_data.neighborhood_id)
        if neighborhood_data is None:
            pass
        lot_data = None
        for lot_owner_data in neighborhood_data.lots:
            while zone_id == lot_owner_data.zone_instance_id:
                lot_data = lot_owner_data
                break
        while zone_data is not None and lot_data is not None:
            location_data = Dialog_pb2.LotInfoItem()
            location_data.zone_id = zone_data.zone_id
            location_data.name = zone_data.name
            location_data.world_id = zone_data.world_id
            location_data.lot_template_id = zone_data.lot_template_id
            location_data.lot_description_id = zone_data.lot_description_id
            venue_type_id = build_buy.get_current_venue(zone_id)
            venue_instance = venue_manager.get(venue_type_id)
            if venue_instance is not None:
                location_data.venue_type_name = venue_instance.display_name
            if lot_data.lot_owner:
                household_id = lot_data.lot_owner[0].household_id
                household = services.household_manager().get(household_id)
                if household is not None:
                    location_data.household_name = household.name
            locations_msg.situation_locations.append(location_data)
            with ProtocolBufferRollback(world_info_msg.zones) as zone_info_msg:
                zone_info_msg.id = zone_data.zone_id
                zone_info_msg.name = zone_data.name
                zone_info_msg.world_id = zone_data.world_id
                zone_info_msg.lot_template_id = zone_data.lot_template_id
                zone_info_msg.lot_description_id = zone_data.lot_description_id
    shared_messages.add_object_message_for_sim_id(sim.id, Consts_pb2.MSG_NS_AVAILABLE_ZONES_INFO, cas_zones_msg)
    shared_messages.add_object_message_for_sim_id(sim.id, Consts_pb2.MSG_SITUATION_LOCATIONS, locations_msg)
Beispiel #26
0
 def _owning_sim_in_owning_household(self, sim_id):
     owner_household_id = self.owner.get_household_owner_id()
     if sim_id is None or owner_household_id is None:
         return False
     household = services.household_manager().get(owner_household_id)
     if household is None:
         return False
     return household.sim_in_household(sim_id)
def get_target_household_id_for_zone(zone_id, account):
    target_household_id = services.get_persistence_service(
    ).get_household_id_from_zone_id(zone_id)
    if target_household_id is None or target_household_id == 0:
        household = services.household_manager().create_household(
            account, starting_funds=0)
        target_household_id = household.id
    return target_household_id
Beispiel #28
0
    def delete_household(household: Household) -> bool:
        """delete_household(household)

        Delete the specified household from the game.

        :param household: The Household to delete
        :type household: Household
        :return: True, if the Household was deleted successfully. False, if not.
        :rtype: bool
        """
        try:
            services.get_persistence_service().del_household_proto_buff(household.id)
            services.household_manager().remove(household)
        except Exception as ex:
            CommonExceptionHandler.log_exception(ModInfo.get_identity(), 'Failed to delete household \'{}\'.'.format(pformat(household)), exception=ex)
            return False
        return True
 def _owning_sim_in_owning_household(self, sim_id):
     owner_household_id = self.owner.get_household_owner_id()
     if sim_id is None or owner_household_id is None:
         return False
     household = services.household_manager().get(owner_household_id)
     if household is None:
         return False
     return household.sim_in_household(sim_id)
Beispiel #30
0
    def create_empty_household(starting_funds: int=0, as_hidden_household: bool=False) -> Household:
        """create_empty_household(starting_funds=0, as_hidden_household=False)

        Create an empty household.

        :param starting_funds: The funds the Household will start with.
        :type starting_funds: int, optional
        :param as_hidden_household: If True, the created household will be hidden.
        :type as_hidden_household: bool, optional
        :return: The created Household
        :rtype: Household
        """
        household = Household(SimSpawner._get_default_account(), starting_funds=starting_funds)
        if as_hidden_household:
            household.set_to_hidden()
        services.household_manager().add(household)
        return household
Beispiel #31
0
def move_object_to_household_inventory(
        obj,
        failure_flags=0,
        object_location_type=ObjectOriginLocation.ON_LOT):
    placement_flags = get_object_placement_flags(obj.definition.id)
    if PlacementFlags.NON_INVENTORYABLE in placement_flags:
        obj.destroy(
            cause="Can't add non inventoriable objects to household inventory."
        )
        return False
    else:
        household_id = obj.get_household_owner_id()
        active_household = services.active_household()
        household = services.household_manager().get(household_id)
        if household_id is None or household is None:
            if failure_flags & HouseholdInventoryFlags.FORCE_OWNERSHIP:
                household_id = active_household.id
                household = active_household
                obj.set_household_owner_id(household_id)
            else:
                if failure_flags & HouseholdInventoryFlags.DESTROY_OBJECT:
                    obj.destroy(
                        cause=
                        "Can't add unowned objects to household inventory.")
                    return False
                return False
    return False
    obj.on_hovertip_requested()
    obj.new_in_inventory = True
    obj.remove_reference_from_parent()
    stack_count = obj.stack_count()
    obj.set_stack_count(1)
    if is_household_inventory_available(household_id):
        zone_id = services.current_zone_id()
        try:
            _buildbuy.add_object_to_household_inventory(
                obj.id, household_id, zone_id, household.account.id,
                object_location_type, stack_count)
        except KeyError as e:
            logger.error('Failed to add {} to {} inventory. Exception: {}',
                         obj,
                         household,
                         e,
                         owner='manus')
            return False
    else:
        household_msg = services.get_persistence_service(
        ).get_household_proto_buff(household_id)
        if household_msg is not None:
            for i in range(stack_count):
                object_data = obj.save_object(household_msg.inventory.objects)
                if object_data is not None:
                    if i != 0:
                        object_data.id = id_generator.generate_object_id()
            obj.destroy(cause='Add to household inventory')
        else:
            return False
    return True
Beispiel #32
0
def c_api_house_inv_obj_added(zone_id, household_id, obj_id, obj_def_id):
    with sims4.zone_utils.global_zone_lock(zone_id):
        household = services.household_manager().get(household_id)
        if household is None:
            logger.error('Invalid Household id: {}', household_id)
            return
        collection_tracker = household.collection_tracker
        collection_tracker.check_add_collection_item(household, obj_id,
                                                     obj_def_id)
Beispiel #33
0
 def _send_money_update_internal(self, household_id, vfx_amount, reason=0):
     op = distributor.ops.SetMoney(self.money, vfx_amount, reason)
     household = services.household_manager().get(household_id)
     if household is not None:
         distributor.ops.record(household, op)
     else:
         logger.error('Failed to get household with id: {}',
                      household_id,
                      owner='tingyul')
Beispiel #34
0
 def transfer_balance_to_household(self):
     owner_household = services.household_manager().get(self._owner_household_id)
     if owner_household is None:
         return
     sim = next(owner_household.instanced_sims_gen(allow_hidden_flags=ALL_HIDDEN_REASONS))
     funds = self._funds.money
     if funds > 0:
         owner_household._funds.add(funds, Consts_pb2.FUNDS_RETAIL_PROFITS, sim)
     self._funds.try_remove(funds, Consts_pb2.FUNDS_RETAIL_PROFITS, sim)
def trigger_invite_over_phone_call(opt_sim:OptionalTargetParam=None, _connection=None):
    sim = get_optional_target(opt_sim, _connection)
    if sim is None:
        sims4.commands.output('No sim for households.debug_trigger_invite_over_phone_call.', _connection)
        return False
    if not services.household_manager().debug_trigger_invite_over_phone_call(sim):
        sims4.commands.output('households.debug_trigger_invite_over_phone_call failed to trigger phone call.', _connection)
        return False
    return True
def autopay_bills(enable: bool = None, _connection=None):
    households = services.household_manager().get_all()
    for household in households:
        bills_manager = household.bills_manager
        autopay_bills = enable if enable is not None else not bills_manager.autopay_bills
        bills_manager.autopay_bills = autopay_bills
        sims4.commands.output(
            'Autopay Bills for household {} set to {}.'.format(
                household, autopay_bills), _connection)
Beispiel #37
0
def c_api_house_inv_obj_added(zone_id, household_id, obj_id, obj_def_id):
    with sims4.zone_utils.global_zone_lock(zone_id):
        household = services.household_manager().get(household_id)
        if household is None:
            logger.error('Invalid Household id: {}', household_id)
            return
        collection_tracker = household.collection_tracker
        collection_tracker.check_add_collection_item(household, obj_id,
                                                     obj_def_id)
Beispiel #38
0
 def get_household_type(self):
     household_id = self.id
     if household_id in services.household_manager():
         if not self.is_persistent_npc:
             return HouseholdType.USER_CREATED_PLAYABLE
         account = self.account
         if account is not None:
             household_id = self.id
             if services.household_manager(
             ).is_household_stored_in_any_neighborhood_proto(household_id):
                 return HouseholdType.USER_CREATED_NPC
         return HouseholdType.GAME_CREATED
     logger.error(
         "Tried to get the household type of a household that isn't in the household manager. household name: {} household id: {}",
         self.name,
         household_id,
         owner='yshan')
     return HouseholdType.UNKNOWN
Beispiel #39
0
 def return_lost_objects(self):
     returned_objects = defaultdict(list)
     current_zone = services.current_zone()
     current_zone_id = services.current_zone_id()
     current_open_street_id = current_zone.open_street_id
     active_household = services.active_household()
     for locator in list(self._object_locators):
         if locator.zone_id != current_zone_id:
             if locator.open_street_id != current_open_street_id:
                 elapsed_time = services.time_service(
                 ).sim_now - locator.time_stamp
                 if elapsed_time.in_minutes() < locator.time_before_lost:
                     continue
                 if locator.object_data is None:
                     self.remove_object(locator.object_id)
                 else:
                     (obj_returned,
                      owner) = self._return_lost_object(locator)
                     if obj_returned is not None:
                         if owner is not None:
                             if isinstance(owner, int):
                                 if owner == active_household.id:
                                     returned_objects[owner].append(
                                         obj_returned)
                                     if owner.household is active_household:
                                         returned_objects[owner].append(
                                             obj_returned)
                             elif owner.household is active_household:
                                 returned_objects[owner].append(
                                     obj_returned)
     if not returned_objects:
         return
     returned_objects_string = None
     household_manager = services.household_manager()
     for (owner, objects) in returned_objects.items():
         if isinstance(owner, int):
             household = household_manager.get(owner)
             header = ObjectLostAndFoundService.FAMILY_NAME_HEADER(
                 household.name)
             next_string = LocalizationHelperTuning.get_bulleted_list(
                 header,
                 *(LocalizationHelperTuning.get_object_name(obj)
                   for obj in objects))
         else:
             next_string = LocalizationHelperTuning.get_bulleted_list(
                 LocalizationHelperTuning.get_sim_name(owner),
                 *(LocalizationHelperTuning.get_object_name(obj)
                   for obj in objects))
         if returned_objects_string is None:
             returned_objects_string = next_string
         else:
             returned_objects_string = LocalizationHelperTuning.NEW_LINE_LIST_STRUCTURE(
                 returned_objects_string, next_string)
     dialog = ObjectLostAndFoundService.OBJECTS_RETURN_MESSAGE_DIALOG(
         services.active_sim_info())
     dialog.show_dialog(additional_tokens=(returned_objects_string, ))
Beispiel #40
0
 def set_death_type(self, death_type):
     self._sim_info.inject_into_inactive_zone(self.DEATH_ZONE_ID)
     self._sim_info.household.remove_sim_info(self._sim_info, destroy_if_empty_gameplay_household=True)
     household = services.household_manager().create_household(self._sim_info.account)
     household.hidden = True
     household.add_sim_info(self._sim_info)
     self._sim_info.assign_to_household(household)
     self._death_type = death_type
     self._death_time = services.time_service().sim_now.absolute_ticks()
     self._sim_info.resend_death_type()
def toggle_bill_notifications(enable:bool=None, _connection=None):
    households = services.household_manager().get_all()
    for household in households:
        bills_manager = household.bills_manager
        enable_notifications = enable if enable is not None else not bills_manager.bill_notifications_enabled
        if enable_notifications:
            bills_manager.bill_notifications_enabled = True
            sims4.commands.output('Bill notifications for household {} enabled.'.format(household), _connection)
        else:
            bills_manager.bill_notifications_enabled = False
            sims4.commands.output('Bill notifications for household {} disabled.'.format(household), _connection)
def make_bills_delinquent(_connection=None):
    households = services.household_manager().get_all()
    for household in households:
        bills_manager = household.bills_manager
        previous_send_notification = bills_manager.bill_notifications_enabled
        bills_manager.bill_notifications_enabled = False
        if bills_manager.current_payment_owed is None:
            bills_manager._current_payment_owed = bills_manager.get_bill_amount()
        for utility in Utilities:
            bills_manager._shut_off_utility(utility)
        bills_manager.bill_notifications_enabled = previous_send_notification
 def __init__(self, *args, **kwargs):
     super().__init__(*args, **kwargs)
     self._service_npc = None
     self._service_start_time = None
     reader = self._seed.custom_init_params_reader
     self._service_npc_type = services.service_npc_manager().get(reader.read_uint64('service_npc_type_id', 0))
     if self._service_npc_type is None:
         raise ValueError('Invalid service npc type for situation: {}'.format(self))
     self._hiring_household = services.household_manager().get(reader.read_uint64('household_id', 0))
     if self._hiring_household is None:
         raise ValueError('Invalid household for situation: {}'.format(self))
     self._object_definition_to_craft = reader.read_uint64('user_specified_data_id', 0)
     self._crafted_object_id = reader.read_uint64('crafted_object_id', 0)
 def on_enter(self):
     super().on_enter()
     services.household_manager().load_households()
     zone = services.current_zone()
     zone_spin_up_service = zone.zone_spin_up_service
     household_id = zone_spin_up_service._client_connect_data.household_id
     household = zone.household_manager.get(household_id)
     client = zone_spin_up_service._client_connect_data.client
     services.account_service().on_load_options(client)
     for sim_info in household.sim_info_gen():
         client.add_selectable_sim_info(sim_info,
                                        send_relationship_update=False)
     zone.on_households_and_sim_infos_loaded()
     zone.service_manager.on_all_households_and_sim_infos_loaded(client)
     services.ui_dialog_service().send_dialog_options_to_client()
     client.clean_and_send_remaining_relationship_info()
     services.current_zone().lot.send_lot_display_info()
     for obj in itertools.chain(services.object_manager().values(),
                                services.inventory_manager().values()):
         while obj.live_drag_component is not None:
             obj.live_drag_component.set_active_household_live_drag_permission(
             )
     return _ZoneSpinUpStateResult.DONE
 def __init__(self, *args, **kwargs):
     super().__init__(*args, **kwargs)
     reader = self._seed.custom_init_params_reader
     self._service_npc_type = services.service_npc_manager().get(reader.read_uint64('service_npc_type_id', 0))
     if self._service_npc_type is None:
         raise ValueError('Invalid service npc type for situation: {}'.format(self))
     self._hiring_household = services.household_manager().get(reader.read_uint64('household_id', 0))
     if self._hiring_household is None:
         raise ValueError('Invalid household for situation: {}'.format(self))
     self._is_recurring = reader.read_bool('is_recurring', False)
     self._object_definition_to_craft = reader.read_uint64('user_specified_data_id', 0)
     self._crafted_object_id = reader.read_uint64('crafted_object_id', 0)
     self._service_start_time = services.time_service().sim_now
     self._had_preroll_work = True
     self._is_leaving = False
def get_household_display_info(lot_id, _connection=None):
    persistence_service = services.get_persistence_service()
    household_display_info = UI_pb2.HouseholdDisplayInfo()
    household_id = persistence_service.get_household_id_from_lot_id(lot_id)
    if household_id is None:
        household_id = 0
    household = services.household_manager().get(household_id)
    if household is None:
        household_id = 0
    else:
        household_display_info.at_home_sim_ids.extend(household.get_sims_at_home())
    household_display_info.household_id = household_id
    household_display_info.lot_id = lot_id
    op = shared_messages.create_message_op(household_display_info, Consts_pb2.MSG_UI_HOUSEHOLD_DISPLAY_INFO)
    Distributor.instance().add_op_with_no_owner(op)
def modify_household_funds(amount, household_id:int=0, reason=None, _connection=None):
    if reason is None:
        reason = Consts_pb2.TELEMETRY_MONEY_CHEAT
    if household_id == 0:
        tgt_client = services.client_manager().get(_connection)
        household = tgt_client.household
    else:
        household = services.household_manager().get(household_id)
    if household is not None:
        if amount > 0:
            household.funds.add(amount, reason, None)
        else:
            household.funds.remove(-amount, reason, None)
    else:
        sims4.commands.output('Invalid Household id: {}'.format(household_id), _connection)
 def __call__(self, target, context):
     sim = context.sim
     lot_id = context.pick.lot_id
     if lot_id is None:
         return
     persistence_service = services.get_persistence_service()
     to_zone_id = persistence_service.resolve_lot_id_into_zone_id(lot_id)
     if to_zone_id is None:
         return
     if sim.household.home_zone_id == to_zone_id:
         return self.go_home_name(sim)
     household_id = None
     lot_owner_info = persistence_service.get_lot_proto_buff(lot_id)
     if lot_owner_info is not None:
         for household in lot_owner_info.lot_owner:
             household_id = household.household_id
             break
     if household_id:
         household = services.household_manager().get(household_id)
     else:
         household = None
     if household is None:
         return self.go_here_name(sim)
     sim_infos_known = False
     sim_infos_known_at_home = []
     sim_infos_at_home = False
     same_last_name = True
     for sim_info in household.sim_info_gen():
         if sim_info.relationship_tracker.get_all_bits(sim.id):
             sim_infos_known = True
             if sim_info.zone_id == to_zone_id:
                 sim_infos_known_at_home.append(sim_info)
         elif sim_info.zone_id == to_zone_id:
             sim_infos_at_home = True
         while not sim_info.last_name == household.name:
             same_last_name = False
     if not sim_infos_known:
         travel_name = self.ring_doorbell_name(sim)
     else:
         if len(sim_infos_known_at_home) == 1:
             return self.visit_sim_name(sim, sim_infos_known_at_home[0])
         if same_last_name:
             travel_name = self.visit_the_household_plural_name(sim, household.name)
         else:
             travel_name = self.visit_household_name(sim, household.name)
     if not sim_infos_at_home:
         return self.no_one_home_encapsulation(travel_name)
     return travel_name
def make_bill_source_delinquent(additional_bill_source_name='Miscellaneous', _connection=None):
    try:
        additional_bill_source = AdditionalBillSource(additional_bill_source_name)
    except:
        sims4.commands.output('{0} is not a valid AdditionalBillSource.'.format(additional_bill_source_name), _connection)
        return False
    if additional_bill_source is not None:
        households = services.household_manager().get_all()
        for household in households:
            bills_manager = household.bills_manager
            bills_manager.add_additional_bill_cost(additional_bill_source, 1)
            if bills_manager.current_payment_owed is None:
                bills_manager._current_payment_owed = bills_manager.get_bill_amount()
            previous_send_notification = bills_manager.bill_notifications_enabled
            bills_manager.bill_notifications_enabled = False
            bills_manager._shut_off_utility(Utilities.POWER)
            bills_manager.bill_notifications_enabled = previous_send_notification
Beispiel #50
0
def move_object_to_household_inventory(
        obj, object_location_type=ObjectOriginLocation.ON_LOT):
    household_id = obj.get_household_owner_id()
    if household_id is None:
        logger.error(
            'This object {} is not owned by any household. Request to move to household inventory will be ignored.',
            obj,
            owner='mduke')
        return
    household = services.household_manager().get(household_id)
    obj.new_in_inventory = True
    obj.remove_reference_from_parent()
    stack_count = obj.stack_count()
    obj.set_stack_count(1)
    _buildbuy.add_object_to_household_inventory(
        obj.id, household_id, zone_utils.get_zone_id(), household.account.id,
        object_location_type, stack_count)
Beispiel #51
0
def c_api_modify_household_funds(amount, household_id, reason, zone_id):
    with sims4.zone_utils.global_zone_lock(zone_id):
        household_manager = services.household_manager()
        household = household_manager.get(household_id)
        if household is None:
            if household_manager.try_add_pending_household_funds(
                    household_id, amount, reason):
                return True
            logger.error(
                'Invalid Household id {} when attempting to modify household funds.',
                household_id)
            return False
        if amount > 0:
            household.funds.add(amount, reason, None, count_as_earnings=False)
        elif amount < 0:
            household.funds.remove(-amount, reason, None)
        return True
def list_households(household_id:int=None, _connection=None):
    household_manager = services.household_manager()
    output = sims4.commands.Output(_connection)
    output('Household report:')
    if household_id is not None:
        households = (household_manager.get(household_id),)
    else:
        households = household_manager.get_all()
    for household in households:
        output('{}, {} Sims'.format(str(household), len(household)))
        for sim_info in household.sim_info_gen():
            if sim_info.is_instanced(allow_hidden_flags=0):
                output(' Instanced: {}'.format(sim_info))
            elif sim_info.is_instanced(allow_hidden_flags=ALL_HIDDEN_REASONS):
                output(' Hidden: {}'.format(sim_info))
            else:
                output(' Off lot: {}'.format(sim_info))
 def _get_available_households(self, total_beds, lot_has_double_beds, lot_has_kid_beds):
     household_manager = services.household_manager()
     weighted_households = []
     for household in tuple(household_manager.values()):
         if not household.is_persistent_npc:
             pass
         if household.home_zone_id:
             pass
         num_sims = len(household)
         if not num_sims:
             pass
         nums_sims_to_weight_bonus = NeighborhoodPopulationService.NUM_BEDS_TO_IDEAL_HOUSEHOLD_CURVE.get(total_beds)
         if nums_sims_to_weight_bonus is not None:
             weight = nums_sims_to_weight_bonus.get(num_sims)
         else:
             weight = 1
         if weight <= 0:
             pass
         household_has_married_sims = False
         household_has_kids = False
         total_household_relationship_weight = 0
         sim_info_manager = services.sim_info_manager()
         for sim_info in household:
             if lot_has_double_beds:
                 spouse_sim_id = sim_info.spouse_sim_id
                 if not spouse_sim_id and household.get_sim_info_by_id(spouse_sim_id):
                     household_has_married_sims = True
             if lot_has_kid_beds and sim_info.age <= Age.TEEN:
                 household_has_kids = True
             total_sim_info_weight = 0
             for relationship in sim_info.relationship_tracker:
                 target_sim_info = sim_info_manager.get(relationship.target_sim_id)
                 while target_sim_info is not None and target_sim_info.household is not None and not target_sim_info.household.is_persistent_npc:
                     total_sim_info_weight = relationship.depth*self.RELATIONSHIP_DEPTH_WEIGHT
                     total_sim_info_weight += len(relationship.bit_track_tracker)*self.RELATIONSHIP_TRACK_MULTIPLIER
             total_household_relationship_weight += total_sim_info_weight
         total_household_relationship_weight /= num_sims
         if self.RELATIONSHIP_UTILITY_CURVE is not None:
             weight *= self.RELATIONSHIP_UTILITY_CURVE.get(total_household_relationship_weight)
         if household_has_kids:
             weight *= NeighborhoodPopulationService.KID_TO_KID_BED_MULTIPLIER
         if household_has_married_sims:
             weight *= NeighborhoodPopulationService.SIGNIFICANT_OTHER_MULTIPLIER
         weighted_households.append((weight, household.id))
     return weighted_households
 def __call__(self, sims=None, amount=None, skill_used=None, tags=None):
     if amount is None:
         return TestResultNumeric(False, 'SimoleonsEarnedTest: amount is none, valid during zone load.', current_value=0, goal_value=self.threshold.value, is_money=True)
     if not self.threshold.compare(amount):
         return TestResultNumeric(False, 'SimoleonsEarnedTest: not enough Simoleons earned.', current_value=amount, goal_value=self.threshold.value, is_money=True)
     if not (self.event_type_to_test is not None and self.event_type_to_test(skill_used, tags)):
         return TestResult(False, '\n                    SimoleonsEarnedTest: the skill used to earn Simoleons does\n                    not match the desired skill or tuned tags do not match\n                    object tags.\n                    ')
     if self.household_fund_threshold is not None:
         for sim_info in sims:
             household = services.household_manager().get_by_sim_id(sim_info.sim_id)
             if household is None:
                 return TestResult(False, "Couldn't find household for sim {}", sim_info)
             household_funds = household.funds.money
             if self.household_fund_threshold.test_before_earnings:
                 household_funds -= amount
             while not self.household_fund_threshold.threshold.compare(household_funds):
                 return TestResult(False, 'Threshold test on household funds failed for sim {}', sim_info)
     return TestResult.TRUE
def request_service(service_npc_type, household_id=None, _connection=None):
    service_npc_tuning = services.service_npc_manager().get(service_npc_type)
    if service_npc_tuning is not None:
        tgt_client = services.client_manager().get(_connection)
        if tgt_client is None:
            return False
        if household_id is None:
            household = tgt_client.household
        else:
            household_id = int(household_id)
            manager = services.household_manager()
            household = manager.get(household_id)
            if household is None:
                household = tgt_client.household
        services.current_zone().service_npc_service.request_service(household, service_npc_tuning)
        sims4.commands.output('Requesting service {0}'.format(service_npc_type), _connection)
        return True
    return False
 def on_spawn_sims_for_zone_spin_up(self, client):
     current_zone = services.current_zone()
     for sim_id in tuple(self._sims_traveled_to_zone):
         if sim_id == 0:
             self._sims_traveled_to_zone.remove(sim_id)
         sim_info = self.get(sim_id)
         if sim_info is None:
             logger.error('sim id {} for traveling did not spawn because sim info does not exist.', sim_id, owner='msantander')
         self._spawn_sim(sim_info, startup_location=None)
         while sim_info.get_current_outfit()[0] == OutfitCategory.SLEEP:
             random_everyday_outfit = sim_info.sim_outfits.get_random_outfit([OutfitCategory.EVERYDAY])
             sim_info.set_current_outfit(random_everyday_outfit)
     if self._sims_traveled_to_zone:
         play_tunable_audio(TravelTuning.TRAVEL_SUCCESS_AUDIO_STING)
     else:
         play_tunable_audio(TravelTuning.NEW_GAME_AUDIO_STING)
     current_zone_owner_household_id = current_zone.lot.owner_household_id
     if current_zone_owner_household_id != 0:
         zone_owner_household = services.household_manager().get(current_zone_owner_household_id)
         if zone_owner_household is not None:
             zone_household_is_active_household = client.household.id == zone_owner_household.id
             any_members_spawned = self._spawn_lot_owner_household(zone_owner_household, zone_household_is_active_household)
             if zone_household_is_active_household and not any_members_spawned:
                 self._clear_return_sim_to_home_lot_alarm_handles()
                 while True:
                     for sim_info in zone_owner_household.sim_info_gen():
                         while not sim_info.is_dead:
                             logger.debug('Force spawn household sim:{}', sim_info, owner='sscholl')
                             self._spawn_sim(sim_info, startup_location=None)
     for sim_info in self._sim_infos_saved_in_zone:
         result = self._should_spawn_zone_saved_sim(sim_info)
         logger.debug('Should spawn zone sim:{} {}', sim_info, bool(result), owner='sscholl')
         while result:
             self._spawn_sim(sim_info, startup_location=result.startup_location)
     for sim_info in self._sim_infos_saved_in_open_street:
         result = self._should_spawn_open_street_saved_sim(sim_info)
         logger.debug('Should spawn open street sim:{} {}', sim_info, bool(result), owner='sscholl')
         while result:
             self._spawn_sim(sim_info, startup_location=result.startup_location)
             if len(self._sims_traveled_to_zone) > 0 and (client.household is not None and client.household.get_sim_info_by_id(sim_info.sim_id)) and sim_info.sim_id not in self._sims_traveled_to_zone:
                 self._sim_ids_to_push_go_home.append(sim_info.sim_id)
     self._on_spawn_sim_for_zone_spin_up_completed(client)
 def _try_to_be_invited_in(self):
     owner_household = services.household_manager().get(services.current_zone().lot.owner_household_id)
     resolver = self.get_resolver()
     if owner_household is None:
         dialog = self._nobody_home_failure_notification(self.sim, resolver)
         dialog.show_dialog()
         return
     owner_household_sims = tuple(owner_household.instanced_sims_gen())
     if not owner_household_sims:
         dialog = self._nobody_home_failure_notification(self.sim, resolver)
         dialog.show_dialog()
         return
     for target_sim in owner_household_sims:
         relationship_resolver = DoubleSimResolver(self.sim.sim_info, target_sim.sim_info)
         while relationship_resolver(self._relationship_test):
             dialog = self._success_notification(self.sim, resolver)
             dialog.show_dialog()
             services.get_zone_situation_manager().make_waiting_player_greeted(self.sim)
             return
     dialog = self._bad_relationship_failure_notification(self.sim, resolver)
     dialog.show_dialog()
def pay_bills(_connection=None):
    households = services.household_manager().get_all()
    for household in households:
        bills_manager = household.bills_manager
        bills_manager.pay_bill()
 def open_reward(self, sim_info, _):
     household = services.household_manager().get(sim_info.household_id)
     if household is not None:
         household.funds.add(self._money, Consts_pb2.TELEMETRY_MONEY_ASPIRATION_REWARD, sim_info.get_sim_instance())