Beispiel #1
0
 def start_situation(self):
     services.get_persistence_service().lock_save(self)
     super().start_situation()
     self._change_state(_WaitForRepoPersonState())
     if self.auto_clear_debt_event is not None:
         services.get_event_manager().register_single_event(
             self, self.auto_clear_debt_event)
Beispiel #2
0
 def _destroy(self):
     super()._destroy()
     self.clear_current_object()
     services.get_persistence_service().unlock_save(self)
     if self.auto_clear_debt_event is not None:
         services.get_event_manager().unregister_single_event(
             self, self.auto_clear_debt_event)
Beispiel #3
0
 def start_situation(self):
     end_situation = True
     if self._kick_out_reason in self.start_dialog_map:
         sim_info = services.sim_info_manager().get(self._host_sim_id)
         map_entry = self.start_dialog_map[self._kick_out_reason]
         if sim_info is not None:
             if map_entry is not None:
                 resolver = SingleSimResolver(sim_info)
                 dialog = map_entry(None, resolver)
                 dialog.show_dialog()
                 end_situation = False
     if self._kick_out_reason == UniversityHousingKickOutReason.BABY and not self._additional_sim_ids:
         logger.error(
             'Attempting to kick sim out of university housing for {} without a valid parent',
             self._kick_out_reason,
             owner='bnguyen')
     if end_situation:
         self._self_destruct()
     services.get_persistence_service().lock_save(self)
     super().start_situation()
     self._change_state(self.preparation_state())
     services.get_event_manager().register(
         self, (TestEvent.HouseholdSplitPanelClosed, ))
     services.get_event_manager().register(
         self, (TestEvent.SimEnrolledInUniversity, ))
 def start_situation(self):
     services.get_persistence_service().lock_save(self)
     super().start_situation()
     self._change_state(PrepareForBattleSituationState())
     motherplant = self._get_motherplant()
     motherplant.set_stat_value(self.player_health_statistic, 0, add=True)
     motherplant.set_stat_value(self.motherplant_health_statisic,
                                self.motherplant_health_statisic.max_value,
                                add=True)
     for state_value in self.states_to_set_on_start:
         motherplant.set_state(state_value.state, state_value)
     statistic_tracker = motherplant.statistic_tracker
     self._statistic_watcher_handle = statistic_tracker.add_watcher(
         self._on_statistic_updated)
     self._setup_situation_meters()
     self._zombie_attack_alarm_handle = alarms.add_alarm(
         self,
         create_time_span(minutes=self.zombie_fight_interaction_timer),
         self._zombie_attack,
         repeating=True)
     for custom_key in itertools.chain(
             self.victory_interaction_of_interest.custom_keys_gen(),
             self.retreat_interaction_of_interest.custom_keys_gen()):
         custom_key_tuple = (TestEvent.InteractionComplete, custom_key)
         self._registered_test_events.add(custom_key_tuple)
         services.get_event_manager().register_with_custom_key(
             self, TestEvent.InteractionComplete, custom_key)
 def _spawn_fire(self, transform, routing_surface, run_placement_tests=True):
     if not fire_enabled:
         logger.info('Trying to spawn fire when fire is disabled. Please use |fire.toggle_enabled cheat to turn fire on.')
         return
     if not services.active_lot().is_position_on_lot(transform.translation):
         logger.info('Trying to spawn fire on a lot other than the active lot.')
         return
     if not services.venue_service().venue.allows_fire:
         logger.info("Trying to spawn a fire on a venue that doesn't allow fire.")
         return
     if not (run_placement_tests and self._placement_tests(transform.translation, routing_surface.secondary_id)):
         logger.info('Trying to spawn a fire on a lot at a position that is not valid.')
         return
     fire_object = system.create_object(self.FIRE_OBJECT_DEF)
     fire_object.move_to(transform=transform, routing_surface=routing_surface)
     first_fire_on_lot = False if self._fire_objects else True
     self._fire_objects.add(fire_object)
     fire_object.add_state_changed_callback(self._fire_object_state_changed_callback)
     self.start_objects_burning(fire_object)
     self.add_scorch_mark(fire_object.position, fire_object.location.level)
     self._derail_routing_sims_if_necessary(fire_object)
     if first_fire_on_lot:
         self._start_fire_situations()
         self.activate_fire_alarms()
         self.activate_sprinkler_system()
         self._show_fire_notification()
         self._create_or_replace_scorch_cleanup_alarm()
         services.get_persistence_service().lock_save(self)
         self.register_for_sim_active_lot_status_changed_callback()
     if self._fire_spread_alarm is None:
         time_span = date_and_time.create_time_span(minutes=self.FIRE_SPREAD_INTIAL_TIME_IN_SIM_MINUTES)
         repeating_time_span = date_and_time.create_time_span(minutes=self.FIRE_SPREAD_REPEATING_TIME_IN_SIM_MINUTES)
         self._fire_spread_alarm = alarms.add_alarm(self, time_span, self._fire_spread_alarm_callback, repeating=True, repeating_time_span=repeating_time_span)
Beispiel #6
0
 def _destroy(self):
     for sim in services.active_household().instanced_sims_gen():
         for si in sim.si_state:
             if self.sleep_category_tag in si.affordance.interaction_category_tags:
                 si.remove_liability(UNCANCELABLE_LIABILITY)
     super()._destroy()
     services.get_persistence_service().unlock_save(self)
Beispiel #7
0
 def destroy_travel_group_and_release_zone(self,
                                           travel_group,
                                           last_sim_info=None,
                                           return_objects=False):
     if travel_group.played:
         if last_sim_info is None:
             leader_sim_info = services.active_sim_info()
             if leader_sim_info not in travel_group:
                 leader_sim_info = next(iter(travel_group), None)
         else:
             leader_sim_info = last_sim_info
         with telemetry_helper.begin_hook(travel_group_telemetry_writer,
                                          TELEMETRY_HOOK_TRAVEL_GROUP_END,
                                          sim_info=leader_sim_info) as hook:
             hook.write_int(TELEMETRY_TRAVEL_GROUP_ID, travel_group.id)
             hook.write_int(TELEMETRY_TRAVEL_GROUP_ZONE_ID,
                            travel_group.zone_id)
             hook.write_int(TELEMETRY_TRAVEL_GROUP_SIZE, len(travel_group))
             hook.write_int(
                 TELEMETRY_TRAVEL_GROUP_DURATION,
                 int(travel_group.duration_time_span.in_minutes()))
     for sim_info in tuple(travel_group):
         travel_group.remove_sim_info(sim_info, destroy_on_empty=False)
     self.release_zone(travel_group.zone_id)
     services.get_persistence_service().del_travel_group_proto_buff(
         travel_group.id)
     services.travel_group_manager().remove(travel_group)
     if return_objects:
         self.return_objects_left_in_destination_world()
     return True
def force_neighbors_home(_connection=None):
    client = services.client_manager().get_first_client()
    active_household = client.household
    if active_household is not None:
        active_household_home_zone_id = active_household.home_zone_id
        active_household_home_world_id = services.get_persistence_service(
        ).get_world_id_from_zone(active_household_home_zone_id)
        send_home = active_household_home_zone_id == services.current_zone().id
        blacklist_all_jobs_time = services.time_service(
        ).sim_now + date_and_time.create_time_span(days=7)
        for sim_info in services.sim_info_manager().values():
            if sim_info.is_selectable:
                continue
            sim_info_home_zone_id = sim_info.household.home_zone_id
            sim_info_home_world_id = services.get_persistence_service(
            ).get_world_id_from_zone(sim_info_home_zone_id)
            if sim_info_home_world_id == active_household_home_world_id:
                services.get_zone_situation_manager(
                ).add_sim_to_auto_fill_blacklist(
                    sim_info.id,
                    None,
                    blacklist_all_jobs_time=blacklist_all_jobs_time)
                if send_home:
                    if sim_info.zone_id != active_household_home_zone_id:
                        if sim_info.zone_id != sim_info_home_zone_id:
                            sim_info.inject_into_inactive_zone(
                                sim_info_home_zone_id)
Beispiel #9
0
    def prune_distant_relatives(self):
        with genealogy_caching():
            open_list = []
            closed_list = set()
            prune_list = set()
            active_household_id = services.active_household_id()
            for sim_info in self:
                while not sim_info.is_dead:
                    heapq.heappush(open_list,
                                   (-self.ANCESTRY_PURGE_DEPTH, sim_info.id))

            def visit(sim_info, depth):
                if sim_info not in closed_list:
                    closed_list.add(sim_info)
                    heapq.heappush(open_list, (depth, sim_info.id))
                    if depth > 0:
                        if sim_info.household_id != active_household_id and not sim_info.is_instanced(
                                allow_hidden_flags=ALL_HIDDEN_REASONS):
                            prune_list.add(sim_info)

            sim_info_manager = services.sim_info_manager()
            while open_list:
                (depth, sim_info_id) = heapq.heappop(open_list)
                sim_info = sim_info_manager.get(sim_info_id)
                while sim_info is not None:
                    while True:
                        for relative_id in sim_info.genealogy.get_immediate_family_sim_ids_gen(
                        ):
                            relative = sim_info_manager.get(relative_id)
                            while relative is not None:
                                visit(relative, depth + 1)
        for sim_info in prune_list:
            sim_info.household.remove_sim_info(sim_info)
            sim_info_manager.remove_permanently(sim_info)
            services.get_persistence_service().del_sim_proto_buff(sim_info.id)
 def _load_household(self, household_id):
     household = self.get(household_id)
     if household is not None:
         for sim_info in household.sim_info_gen():
             while sim_info.zone_id != sims4.zone_utils.get_zone_id(False):
                 householdProto = services.get_persistence_service().get_household_proto_buff(household_id)
                 if householdProto is None:
                     logger.error('unable to find household with household id {}'.household_id)
                     return
                 found_sim = False
                 if householdProto.sims.ids:
                     for sim_id in householdProto.sims.ids:
                         while sim_id == sim_info.sim_id:
                             found_sim = True
                             break
                 if found_sim:
                     sim_proto = services.get_persistence_service().get_sim_proto_buff(sim_id)
                     sim_info.load_sim_info(sim_proto)
         return household
     logger.info('Starting to load household id = {0}', household_id)
     household_proto = services.get_persistence_service().get_household_proto_buff(household_id)
     if household_proto is None:
         sims4.log.error('Persistence', 'Household proto could not be found id = {0}', household_id)
         return
     household = self._load_household_from_household_proto(household_proto)
     return household
Beispiel #11
0
 def add_neighbor_bit_if_necessary(self, sim_info):
     target_sim_info = self.find_target_sim_info()
     if target_sim_info is None:
         return
     if sim_info.household is None or target_sim_info.household is None:
         return
     home_zone_id = sim_info.household.home_zone_id
     target_home_zone_id = target_sim_info.household.home_zone_id
     if home_zone_id == target_home_zone_id:
         return
     if home_zone_id == 0 or target_home_zone_id == 0:
         return
     sim_home_zone_proto_buffer = services.get_persistence_service(
     ).get_zone_proto_buff(home_zone_id)
     target_sim_home_zone_proto_buffer = services.get_persistence_service(
     ).get_zone_proto_buff(target_home_zone_id)
     if sim_home_zone_proto_buffer is None or target_sim_home_zone_proto_buffer is None:
         logger.error(
             'Invalid zone protocol buffer in Relationship.add_neighbor_bit_if_necessary()'
         )
         return
     if sim_home_zone_proto_buffer.world_id != target_sim_home_zone_proto_buffer.world_id:
         return
     self.add_bit(global_relationship_tuning.RelationshipGlobalTuning.
                  NEIGHBOR_RELATIONSHIP_BIT,
                  notify_client=False)
     target_relationship = self._tracker._find_relationship(sim_info.id,
                                                            create=False)
     if target_relationship is not None:
         target_relationship.add_bit(
             global_relationship_tuning.RelationshipGlobalTuning.
             NEIGHBOR_RELATIONSHIP_BIT,
             notify_client=False)
Beispiel #12
0
 def pre_destroy(self):
     if not services.get_persistence_service(
     ).is_save_locked_exclusively_by_holder(self):
         self._self_destruct()
         return
     services.get_persistence_service().unlock_save(self)
     sim_info = services.sim_info_manager().get(self._host_sim_id)
     if sim_info is not None:
         sim_info.degree_tracker.clear_kickout_info()
     household = sim_info.household if sim_info is not None else None
     if household is None:
         self._self_destruct()
         return
     active_household = services.active_household()
     if active_household is None or sim_info not in active_household:
         self._self_destruct()
         return
     self_destruct = True
     destination_zone_occupied = is_zone_occupied(
         self._university_housing_destination_zone_id)
     if len(household) > 1 or destination_zone_occupied:
         self._show_household_split_dialog(household.id)
         self_destruct = False
     else:
         self._kickout_single_sim()
     services.venue_service().set_university_housing_kick_out_completed()
     if self_destruct:
         self._self_destruct()
Beispiel #13
0
 def get_main_career_event_zone_id_and_unlock_save(self):
     if self._save_lock is not None:
         services.get_persistence_service().unlock_save(self._save_lock)
         self._save_lock = None
     zone_id = self._main_career_event_zone_id
     self._main_career_event_zone_id = None
     return zone_id
 def _load_household(self, household_id):
     household = self.get(household_id)
     if household is not None:
         for sim_info in household.sim_info_gen():
             zone_id = services.current_zone_id()
             if sim_info.zone_id != zone_id:
                 householdProto = services.get_persistence_service().get_household_proto_buff(household_id)
                 if householdProto is None:
                     logger.error('unable to find household with household id {}'.household_id)
                     return
                 found_sim = False
                 if householdProto.sims.ids:
                     for sim_id in householdProto.sims.ids:
                         if sim_id == sim_info.sim_id:
                             found_sim = True
                             break
                 if found_sim:
                     sim_proto = services.get_persistence_service().get_sim_proto_buff(sim_id)
                     sim_info.load_sim_info(sim_proto)
         return household
     logger.info('Starting to load household id = {0}', household_id)
     household_proto = services.get_persistence_service().get_household_proto_buff(household_id)
     if household_proto is None:
         sims4.log.error('Persistence', 'Household proto could not be found id = {0}', household_id)
         return
     household = self._load_household_from_household_proto(household_proto)
     return household
def print_venues(_connection=None):
    current_zone = services.current_zone()
    lot = current_zone.lot
    neighborhood_id = current_zone.neighborhood_id
    lot_description_id = services.get_lot_description_id(lot.lot_id)
    world_description_id = services.get_world_description_id(
        current_zone.world_id)
    neighborhood_description_id = services.get_persistence_service(
    ).get_neighborhood_proto_buff(neighborhood_id).region_id

    def print_line():
        sims4.commands.output('-' * 150, _connection)

    print_line()
    sims4.commands.output(
        'Current Game Stats: \nLot: {}\nWorld/Street: {}\nRegion/Neighborhood: {}'
        .format(lot_description_id, world_description_id,
                neighborhood_description_id), _connection)
    print_line()
    venue_manager = services.get_instance_manager(sims4.resources.Types.VENUE)
    venues = []
    for neighborhood_proto in services.get_persistence_service(
    ).get_neighborhoods_proto_buf_gen():
        for lot_owner_info in neighborhood_proto.lots:
            zone_id = lot_owner_info.zone_instance_id
            while zone_id is not None:
                venue_type_id = build_buy.get_current_venue(zone_id)
                venue_type = venue_manager.get(venue_type_id)
                if venue_type is not None:
                    log = PrintVenueLog._make(
                        (neighborhood_proto.name, neighborhood_proto.region_id,
                         lot_owner_info.lot_description_id, zone_id,
                         venue_type.__name__, lot_owner_info.lot_name))
                    venues.append(log)
    str_format = '{:20} ({:{center}15}) {:{center}20} {:15} ({:{center}20}) {:20}'

    def print_columns():
        sims4.commands.output(
            str_format.format('Neighborhood_Name',
                              'Neighborhood_ID',
                              'Lot_Description_ID',
                              'Zone_Instance_ID',
                              'Venue_Tuning_Name',
                              'Lot_Name',
                              center='^'), _connection)

    print_columns()
    print_line()
    for venue in sorted(venues):
        sims4.commands.output(
            str_format.format(venue.Neighborhood_Name,
                              venue.Neighborhood_ID,
                              venue.Lot_Description_ID,
                              venue.Zone_Instance_ID,
                              venue.Venue_Tuning_Name,
                              venue.Lot_Name,
                              center='^'), _connection)
    print_line()
    print_columns()
Beispiel #16
0
 def save_data(self):
     household_msg = services.get_persistence_service(
     ).get_household_proto_buff(self.id)
     if household_msg is None:
         household_msg = services.get_persistence_service(
         ).add_household_proto_buff()
     inventory = serialization.ObjectList()
     inventory.CopyFrom(household_msg.inventory)
     household_msg.Clear()
     household_msg.account_id = self.account.id
     household_msg.household_id = self.id
     household_msg.name = self.name
     household_msg.description = self.description
     household_msg.home_zone = self.home_zone_id
     household_msg.last_modified_time = self.last_modified_time
     household_msg.money = self.funds.money
     household_msg.hidden = self.hidden
     household_msg.creator_id = self.creator_id
     household_msg.creator_name = self.creator_name
     if self.creator_uuid is not None:
         household_msg.creator_uuid = self.creator_uuid
     household_msg.inventory = inventory
     household_msg.reward_inventory = self._reward_inventory
     household_msg.gameplay_data.build_buy_unlock_list = ResourceKey_pb2.ResourceKeyList(
     )
     for unlock in self.build_buy_unlocks:
         if isinstance(unlock, int):
             unlock = sims4.resources.Key(Types.OBJCATALOG, unlock, 0)
         key_proto = sims4.resources.get_protobuff_for_key(unlock)
         household_msg.gameplay_data.build_buy_unlock_list.resource_keys.append(
             key_proto)
     household_msg.gameplay_data.situation_scoring_enabled = self._situation_scoring_enabled
     if self.sim_in_household(self._last_active_sim_id):
         household_msg.last_played = self._last_active_sim_id
     household_msg.is_npc = self.is_persistent_npc
     household_msg.gameplay_data.billable_household_value = self.household_net_worth(
         billable=True)
     household_msg.gameplay_data.ClearField(
         'highest_earned_situation_medals')
     for (situation_id,
          medal) in self._highest_earned_situation_medals.items():
         with ProtocolBufferRollback(
                 household_msg.gameplay_data.highest_earned_situation_medals
         ) as situation_medal:
             situation_medal.situation_id = situation_id
             situation_medal.medal = medal
     self.bills_manager.save_data(household_msg)
     self.collection_tracker.save_data(household_msg)
     if self._service_npc_record is not None:
         for service_record in self._service_npc_record.values():
             with ProtocolBufferRollback(household_msg.gameplay_data.
                                         service_npc_records) as record_msg:
                 service_record.save_npc_record(record_msg)
     id_list = serialization.IdList()
     for sim_info in self:
         id_list.ids.append(sim_info.id)
     household_msg.sims = id_list
     return True
Beispiel #17
0
    def load(self, zone_data=None):
        persistence_service = services.get_persistence_service()

        def _get_current_venue(zone_id):
            neighborhood_data = persistence_service.get_neighborhood_proto_buf_from_zone_id(
                zone_id)
            for lot_data in neighborhood_data.lots:
                if zone_id == lot_data.zone_instance_id:
                    return lot_data.venue_key

        current_zone_id = services.current_zone_id()
        zones = services.get_persistence_service().get_save_game_data_proto(
        ).zones
        for zone_data_msg in zones:
            if zone_data_msg is None:
                continue
            if zone_data_msg.zone_id == current_zone_id:
                active_venue_tuning_id = get_current_venue(
                    zone_data_msg.zone_id)
                raw_active_venue_tuning_id = get_current_venue(
                    zone_data_msg.zone_id, allow_ineligible=True)
            else:
                active_venue_tuning_id = _get_current_venue(
                    zone_data_msg.zone_id)
                raw_active_venue_tuning_id = active_venue_tuning_id
            if active_venue_tuning_id is None:
                self.set_provider(zone_data_msg.zone_id, None)
            else:
                active_venue_type = services.venue_manager().get(
                    active_venue_tuning_id)
                raw_active_venue_type = services.venue_manager().get(
                    raw_active_venue_tuning_id)
                source_venue_type = VenueService.get_variable_venue_source_venue(
                    raw_active_venue_type)
                if source_venue_type is None:
                    self.set_provider(zone_data_msg.zone_id, None)
                elif source_venue_type.variable_venues is None:
                    self.set_provider(zone_data_msg.zone_id, None)
                else:
                    existing_provider = self.get_provider(
                        zone_data_msg.zone_id)
                    if existing_provider is not None and existing_provider.source_venue_type is source_venue_type:
                        continue
                    provider = source_venue_type.variable_venues.civic_policy(
                        source_venue_type, active_venue_type)
                    if not provider:
                        self.set_provider(zone_data_msg.zone_id, None)
                    else:
                        self.set_provider(zone_data_msg.zone_id, provider)
                        if zone_data_msg.HasField('gameplay_zone_data'):
                            if zone_data_msg.gameplay_zone_data.HasField(
                                    'venue_data'):
                                if zone_data_msg.gameplay_zone_data.venue_data.HasField(
                                        'civic_provider_data'):
                                    provider.load(
                                        zone_data_msg.gameplay_zone_data.
                                        venue_data.civic_provider_data)
Beispiel #18
0
        def _lock_save_for_aging(_):
            nonlocal lock_handle
            if is_baby_age_up or not sim_info.is_npc:

                class _AgeUpSaveLockHandle:
                    def get_lock_save_reason(self):
                        return AgingTuning.AGING_SAVE_LOCK_TOOLTIP(sim_info)

                lock_handle = _AgeUpSaveLockHandle()
                services.get_persistence_service().lock_save(lock_handle)
Beispiel #19
0
    def set_main_career_event_zone_id_and_lock_save(self, main_zone_id):

        class _SaveLock:

            def get_lock_save_reason(self):
                return LocalizationHelperTuning.get_raw_text('')

        self._save_lock = _SaveLock()
        services.get_persistence_service().lock_save(self._save_lock)
        self._main_career_event_zone_id = main_zone_id
Beispiel #20
0
 def prune_household(self, household_id):
     household = self.get(household_id)
     if household is not None:
         if household.get_household_type() != sims.household.HouseholdType.GAME_CREATED:
             logger.warn('Trying to prune a non-game created household:{}', household.id, owner='msantander')
             return
         sim_info_manager = services.sim_info_manager()
         for sim_info in tuple(household):
             household.remove_sim_info(sim_info, destroy_if_empty_gameplay_household=True)
             sim_info_manager.remove_permanently(sim_info)
             services.get_persistence_service().del_sim_proto_buff(sim_info.id)
Beispiel #21
0
 def clear_household_lot_ownership(self, zone_id):
     zone_data_proto = services.get_persistence_service(
     ).get_zone_proto_buff(zone_id)
     zone_data_proto.household_id = 0
     neighborhood_id = zone_data_proto.neighborhood_id
     neighborhood_proto = services.get_persistence_service(
     ).get_neighborhood_proto_buff(neighborhood_id)
     for lot_owner_info in neighborhood_proto.lots:
         while lot_owner_info.zone_instance_id == zone_id:
             lot_owner_info.ClearField('lot_owner')
             break
Beispiel #22
0
 def on_lod_update(self, old_lod, new_lod):
     if new_lod == SimInfoLODLevel.ACTIVE:
         sim_msg = services.get_persistence_service().get_sim_proto_buff(
             self.owner_sim_info.id)
         if sim_msg is not None:
             self.load(sim_msg.attributes.event_data_tracker)
     else:
         sim_msg = services.get_persistence_service().get_sim_proto_buff(
             self.owner_sim_info.id)
         sim_msg.attributes.event_data_tracker.Clear()
         self.save(sim_msg.attributes.event_data_tracker)
         self.clear_update_alarm()
 def _exited_pipeline(self, *args, **kwargs):
     try:
         should_die_on_transition_failure = self.should_die_on_transition_failure
         super()._exited_pipeline(*args, **kwargs)
     finally:
         try:
             if not should_die_on_transition_failure and self.finishing_type == FinishingType.TRANSITION_FAILURE:
                 return
             while self.outcome_result != OutcomeResult.SUCCESS:
                 self.run_death_behavior(from_reset=True)
         finally:
             services.get_persistence_service().unlock_save(self)
 def _exited_pipeline(self, *args, **kwargs):
     try:
         should_die_on_transition_failure = self.should_die_on_transition_failure
         super()._exited_pipeline(*args, **kwargs)
     finally:
         try:
             if not should_die_on_transition_failure and self.finishing_type == FinishingType.TRANSITION_FAILURE:
                 return
             while self.outcome_result != OutcomeResult.SUCCESS:
                 self.run_death_behavior(from_reset=True)
         finally:
             services.get_persistence_service().unlock_save(self)
Beispiel #25
0
 def load_travel_groups(self):
     delete_group_ids = []
     for travel_group_proto in services.get_persistence_service(
     ).all_travel_group_proto_gen():
         travel_group_id = travel_group_proto.travel_group_id
         travel_group = self.get(travel_group_id)
         if travel_group is None:
             travel_group = self.load_travel_group(travel_group_proto)
         if travel_group is None:
             delete_group_ids.append(travel_group_id)
     for travel_group_id in delete_group_ids:
         services.get_persistence_service().del_travel_group_proto_buff(
             travel_group_id)
Beispiel #26
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 #27
0
 def save_zone(self, save_slot_data=None):
     zone_data_msg = self._get_zone_proto()
     zone_data_msg.ClearField('gameplay_zone_data')
     gameplay_zone_data = zone_data_msg.gameplay_zone_data
     gameplay_zone_data.lot_owner_household_id_on_save = self.lot.owner_household_id
     gameplay_zone_data.venue_type_id_on_save = self.venue_service.venue.guid64 if self.venue_service.venue is not None else 0
     gameplay_zone_data.active_household_id_on_save = services.active_household_id(
     )
     self.lot.save(gameplay_zone_data)
     if self.lot.front_door_id:
         zone_data_msg.front_door_id = self.lot.front_door_id
     num_spawn_points = len(self._spawner_data)
     spawn_point_ids = [0] * num_spawn_points
     for (spawn_point_id, spawn_point) in self._spawner_data.items():
         spawn_point_ids[spawn_point.spawn_point_index] = spawn_point_id
     zone_data_msg.ClearField('spawn_point_ids')
     zone_data_msg.spawn_point_ids.extend(spawn_point_ids)
     zone_objects_message = serialization.ZoneObjectData()
     object_list = serialization.ObjectList()
     zone_objects_message.zone_id = self.id
     persistence_service = services.get_persistence_service()
     open_street_data = persistence_service.get_open_street_proto_buff(
         self.open_street_id)
     if open_street_data is not None:
         open_street_data.Clear()
         add_proto_to_persistence = False
     else:
         open_street_data = serialization.OpenStreetsData()
         add_proto_to_persistence = True
     open_street_data.world_id = self.open_street_id
     open_street_data.nbh_id = self.neighborhood_id
     open_street_data.sim_time_on_save = services.time_service(
     ).sim_timeline.now.absolute_ticks()
     open_street_data.active_household_id_on_save = services.active_household_id(
     )
     open_street_data.active_zone_id_on_save = self.id
     self.service_manager.save_all_services(
         persistence_service,
         persistence_error_types.ErrorCodes.ZONE_SERVICES_SAVE_FAILED,
         object_list=object_list,
         zone_data=zone_data_msg,
         open_street_data=open_street_data,
         save_slot_data=save_slot_data)
     zone_objects_message.objects = object_list
     if add_proto_to_persistence:
         services.get_persistence_service().add_open_street_proto_buff(
             open_street_data)
     persistence_module.run_persistence_operation(
         persistence_module.PersistenceOpType.kPersistenceOpSaveZoneObjects,
         zone_objects_message, 0, None)
Beispiel #28
0
 def merge(self, merge_with_id):
     otherhouse = services.get_persistence_service(
     ).get_household_proto_buff(merge_with_id)
     self._funds.add(otherhouse.money, TELEMETRY_HOUSEHOLD_TRANSFER_GAIN,
                     None)
     self._reward_inventory.reward_parts.extend(
         otherhouse.reward_inventory.reward_parts)
     for sim_id in otherhouse.sims.ids:
         self.refresh_sim_data(sim_id,
                               assign=True,
                               spawn=True,
                               selectable=True)
     services.get_persistence_service().del_household_proto_buff(
         merge_with_id)
Beispiel #29
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
Beispiel #30
0
 def clear_lot_ownership(self, zone_id):
     zone_data_proto = services.get_persistence_service(
     ).get_zone_proto_buff(zone_id)
     if zone_data_proto is not None:
         zone_data_proto.household_id = 0
         lot_decoration_service = services.lot_decoration_service()
         neighborhood_proto = services.get_persistence_service(
         ).get_neighborhood_proto_buff(zone_data_proto.neighborhood_id)
         for lot_owner_info in neighborhood_proto.lots:
             if lot_owner_info.zone_instance_id == zone_id:
                 lot_owner_info.ClearField('lot_owner')
                 if lot_decoration_service is not None:
                     lot_decoration_service.handle_lot_owner_changed(
                         zone_id, None)
                 break
 def __init__(self, aop, context, **kwargs):
     if self.destination_lot is None:
         zone_id = context.sim.household.home_zone_id
     else:
         lot_id = get_lot_id_from_instance_id(self.destination_lot)
         zone_id = services.get_persistence_service().resolve_lot_id_into_zone_id(lot_id, ignore_neighborhood_id=True)
     super().__init__(aop, context, from_zone_id=context.sim.zone_id, to_zone_id=zone_id, on_complete_callback=None, on_complete_context=None, **kwargs)
Beispiel #32
0
 def load_zone(self):
     zone_data_proto = self._get_zone_proto()
     self.neighborhood_id = zone_data_proto.neighborhood_id
     self.open_street_id = zone_data_proto.world_id
     self.service_manager.load_all_services(zone_data=zone_data_proto)
     self._first_visit_to_zone = not protocol_buffer_utils.has_field(
         zone_data_proto.gameplay_zone_data, 'venue_type_id_on_save')
     open_street_data = services.get_persistence_service(
     ).get_open_street_proto_buff(self.open_street_id)
     if open_street_data is not None:
         self._time_of_last_open_street_save = DateAndTime(
             open_street_data.sim_time_on_save)
     spawn_points = {}
     if zone_data_proto.spawn_point_ids:
         for (index,
              spawn_point_id) in enumerate(zone_data_proto.spawn_point_ids):
             spawn_point = self._spawner_data[index]
             spawn_point.spawn_point_id = spawn_point_id
             spawn_points[spawn_point_id] = spawn_point
     else:
         for (index, spawn_point) in enumerate(self._spawner_data.values()):
             spawn_point_id = id_generator.generate_object_id()
             spawn_point.spawn_point_id = spawn_point_id
             spawn_points[spawn_point_id] = spawn_point
     self._spawner_data = spawn_points
     self.lot.load(zone_data_proto.gameplay_zone_data)
     for spawn_point in self._spawner_data.values():
         while spawn_point.has_tag(
                 SpawnPoint.
                 ARRIVAL_SPAWN_POINT_TAG) and spawn_point.lot_id == self.lot.lot_id:
             self._active_lot_arrival_spawn_point = spawn_point
     return True
 def travel_to_venue(self):
     if self._zone_id is None:
         logger.error('Failed to travel to venue')
         return
     active_sim_info = services.active_sim_info()
     active_sim = active_sim_info.get_sim_instance(
         allow_hidden_flags=ALL_HIDDEN_REASONS_EXCEPT_UNINITIALIZED)
     if active_sim is None:
         return
     lot_id = None
     zone = services.get_zone_manager().get(self._zone_id)
     if zone is None:
         lot_id = services.get_persistence_service(
         ).get_lot_id_from_zone_id(self._zone_id)
     else:
         lot_id = zone.lot.lot_id
     if lot_id is None:
         return
     pick = PickInfo(pick_type=PickType.PICK_TERRAIN,
                     lot_id=lot_id,
                     ignore_neighborhood_id=True)
     context = interactions.context.InteractionContext(
         active_sim,
         interactions.context.InteractionContext.
         SOURCE_SCRIPT_WITH_USER_INTENT,
         interactions.priority.Priority.High,
         insert_strategy=interactions.context.QueueInsertStrategy.NEXT,
         pick=pick)
     active_sim.push_super_affordance(
         VenueEventDramaNode.GO_TO_VENUE_ZONE_INTERACTION, None, context)
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)
def travel_sims_to_zone(opt_sim_id:OptionalTargetParam, zone_id:int, *traveling_sim_ids, _connection=None):
    sim_or_sim_info = get_optional_target(opt_sim_id, _connection)
    if sim_or_sim_info is None:
        if opt_sim_id:
            sim_or_sim_info = services.sim_info_manager().get(opt_sim_id)
            if sim_or_sim_info is None:
                sims4.commands.output('Invalid Sim id: {} specified for travel.travel_sims_to_zone'.format(opt_sim_id), _connection)
                return False
        else:
            sims4.commands.output('No Sim id specified for travel.travel_sims_to_zone', _connection)
            return False
    zone_proto_buff = services.get_persistence_service().get_zone_proto_buff(zone_id)
    if zone_proto_buff is None:
        sims4.commands.output('Invalid Zone Id: {}. Zone does not exist.'.format(zone_id), _connection)
        return False
    situation_manager = services.get_zone_situation_manager()
    situation = situation_manager.DEFAULT_TRAVEL_SITUATION
    guest_list = situation.get_predefined_guest_list()
    if guest_list is None:
        guest_list = SituationGuestList(invite_only=True, host_sim_id=sim_or_sim_info.id)
        default_job = situation.default_job()
        sim_info_manager = services.sim_info_manager()
        roommate_service = services.get_roommate_service()
        if roommate_service is not None:
            traveling_sim_ids = tuple(itertools.chain(traveling_sim_ids, (sim_info.sim_id for sim_info in roommate_service.get_auto_invite_sim_infos(sim_or_sim_info, situation))))
        for sim_id in traveling_sim_ids:
            sim_id = int(sim_id)
            sim_info = sim_info_manager.get(sim_id)
            if sim_info is None:
                continue
            guest_info = SituationGuestInfo.construct_from_purpose(sim_id, default_job, SituationInvitationPurpose.INVITED)
            guest_list.add_guest_info(guest_info)
        guest_info = SituationGuestInfo.construct_from_purpose(sim_or_sim_info.id, default_job, SituationInvitationPurpose.INVITED)
        guest_list.add_guest_info(guest_info)
    situation_manager.create_situation(situation, guest_list=guest_list, user_facing=False, zone_id=zone_id)
Beispiel #36
0
 def request_client_disconnect_gen(timeline):
     try:
         zone = services.current_zone()
         if zone is not None:
             client_manager = zone.client_manager
             client = client_manager.get(session_id)
             logger.info('Client {0} starting save of zone {1}', session_id,
                         zone_id)
             yield services.get_persistence_service(
             ).save_to_scratch_slot_gen(timeline)
             logger.info('Client {0} save completed for {1}', session_id,
                         zone_id)
             with telemetry_helper.begin_hook(
                     area_telemetry_writer,
                     TELEMETRY_HOOK_ZONE_EXIT,
                     household=client.household) as hook:
                 (player_sims, npc_sims) = services.sim_info_manager(
                 ).get_player_npc_sim_count()
                 hook.write_int(TELEMETRY_FIELD_PLAYER_COUNT, player_sims)
                 hook.write_int(TELEMETRY_FIELD_NPC_COUNT, npc_sims)
             zone.on_teardown(client)
             if client is None:
                 logger.error(
                     'Client {0} not in client manager from zone {1}',
                     session_id, zone_id)
                 return callback(zone_id, session_id, NO_CLIENT_ERROR_CODE)
             client_manager.remove(client)
         return callback(zone_id, session_id, SUCCESS_CODE)
     except:
         logger.exception('Error disconnecting the client')
         return callback(zone_id, session_id, EXCEPTION_ERROR_CODE)
Beispiel #37
0
 def send_selectable_sims_update(self):
     msg = Sims_pb2.UpdateSelectableSims()
     for sim_info in self._selectable_sims:
         with ProtocolBufferRollback(msg.sims) as new_sim:
             new_sim.id = sim_info.sim_id
             if sim_info.career_tracker is None:
                 logger.error(
                     'CareerTracker is None for selectable Sim {}'.format(
                         sim_info))
             else:
                 career = sim_info.career_tracker.get_currently_at_work_career(
                 )
                 new_sim.at_work = career is not None and not career.is_at_active_event
             new_sim.is_selectable = sim_info.is_enabled_in_skewer
             (selector_visual_type,
              career_category) = self._get_selector_visual_type(sim_info)
             new_sim.selector_visual_type = selector_visual_type
             if career_category is not None:
                 new_sim.career_category = career_category
             new_sim.can_care_for_toddler_at_home = sim_info.can_care_for_toddler_at_home
             if not sim_info.is_instanced(
                     allow_hidden_flags=ALL_HIDDEN_REASONS):
                 new_sim.instance_info.zone_id = sim_info.zone_id
                 new_sim.instance_info.world_id = sim_info.world_id
                 new_sim.firstname = sim_info.first_name
                 new_sim.lastname = sim_info.last_name
                 zone_data_proto = services.get_persistence_service(
                 ).get_zone_proto_buff(sim_info.zone_id)
                 if zone_data_proto is not None:
                     new_sim.instance_info.zone_name = zone_data_proto.name
     distributor = Distributor.instance()
     distributor.add_op_with_no_owner(
         GenericProtocolBufferOp(Operation.SELECTABLE_SIMS_UPDATE, msg))
 def _on_dialog_accepted(self):
     if services.get_persistence_service().is_save_locked():
         return
     travel_info = InteractionOps_pb2.TravelSimsToZone()
     travel_info.zone_id = self._target.household.home_zone_id
     travel_info.sim_ids.append(self._sim.id)
     distributor.system.Distributor.instance().add_event(Consts_pb2.MSG_TRAVEL_SIMS_TO_ZONE, travel_info)
     services.game_clock_service().set_clock_speed(ClockSpeedMode.PAUSED)
 def _load_account_by_id(self, account_id):
     if account_id == SimSpawner.SYSTEM_ACCOUNT_ID:
         new_account = account.Account(SimSpawner.SYSTEM_ACCOUNT_ID, 'SystemAccount')
         return new_account
     account_proto = services.get_persistence_service().get_account_proto_buff()
     new_account = account.Account(account_proto.nucleus_id, account_proto.persona_name)
     new_account.load_account(account_proto)
     return new_account
def force_neighbors_home(_connection=None):
    client = services.client_manager().get_first_client()
    active_household = client.household
    if active_household is not None:
        active_household_home_zone_id = active_household.home_zone_id
        active_household_home_world_id = services.get_persistence_service().get_world_id_from_zone(active_household_home_zone_id)
        send_home = active_household_home_zone_id == services.current_zone().id
        blacklist_until = services.time_service().sim_now + date_and_time.create_time_span(days=7)
        for sim_info in services.sim_info_manager().values():
            if sim_info.is_selectable:
                pass
            sim_info_home_zone_id = sim_info.household.home_zone_id
            sim_info_home_world_id = services.get_persistence_service().get_world_id_from_zone(sim_info_home_zone_id)
            while sim_info_home_world_id == active_household_home_world_id:
                services.get_zone_situation_manager().add_sim_to_auto_fill_blacklist(sim_info.id, blacklist_until=blacklist_until)
                if send_home and sim_info.zone_id != active_household_home_zone_id and sim_info.zone_id != sim_info_home_zone_id:
                    sim_info.inject_into_inactive_zone(sim_info_home_zone_id)
Beispiel #41
0
def start_baby_neglect(baby):
    baby._started_neglect_moment = True
    sim_info = baby.sim_info
    dialog = Baby.NEGLECT_NOTIFICATION(sim_info, SingleSimResolver(sim_info))
    dialog.show_dialog()
    neglect_effect = vfx.PlayEffect(sim_info, 's40_Sims_neglected', sims4.hash_util.hash32('_FX_'))
    neglect_effect.start()
    camera.focus_on_sim(sim_info, follow=False)
    sim_info_manager = services.sim_info_manager()
    with genealogy_caching():
        for member_id in sim_info.genealogy.get_immediate_family_sim_ids_gen():
            member_info = sim_info_manager.get(member_id)
            member_info.add_buff_from_op(Baby.NEGLECT_BUFF_IMMEDIATE_FAMILY.buff_type, Baby.NEGLECT_BUFF_IMMEDIATE_FAMILY.buff_reason)
    empty_bassinet = _replace_bassinet(sim_info)
    empty_bassinet.set_state(Baby.NEGLECT_EMPTY_BASSINET_STATE.state, Baby.NEGLECT_EMPTY_BASSINET_STATE)
    services.client_manager().get_first_client().selectable_sims.remove_selectable_sim_info(sim_info)
    services.get_persistence_service().del_sim_proto_buff(sim_info.id)
    sim_info_manager.remove_permanently(sim_info)
 def load_households(self):
     for household_proto in services.get_persistence_service().all_household_proto_gen():
         household_id = household_proto.household_id
         household = self.get(household_id)
         while household is None:
             self._load_household_from_household_proto(household_proto)
     for household_id in self._pending_household_funds.keys():
         logger.error('Household {} has pending funds leftover from BB after all households were loaded.', household_id, owner='camilogarcia')
     self._pending_household_funds = None
def generate_lot_info_data(*args, zone_id:int=None, filter=None, **kwargs):
    lot_infos = []
    current_zone = services.current_zone()
    lot = current_zone.lot
    neighborhood_id = current_zone.neighborhood_id
    lot_description_id = services.get_lot_description_id(lot.lot_id)
    world_description_id = services.get_world_description_id(current_zone.world_id)
    neighborhood_description_id = services.get_persistence_service().get_neighborhood_proto_buff(neighborhood_id).region_id
    venue_manager = services.get_instance_manager(sims4.resources.Types.VENUE)
    for neighborhood_proto in services.get_persistence_service().get_neighborhoods_proto_buf_gen():
        for lot_owner_info in neighborhood_proto.lots:
            zone_id = lot_owner_info.zone_instance_id
            while zone_id is not None:
                venue_type_id = build_buy.get_current_venue(zone_id)
                venue_type = venue_manager.get(venue_type_id)
                if venue_type is not None:
                    cur_info = {'neighborhood': neighborhood_proto.name, 'region_id': neighborhood_proto.region_id, 'lot_desc_id': lot_owner_info.lot_description_id, 'zone_id': zone_id, 'venue_type': venue_type.__name__, 'lot_name': lot_owner_info.lot_name, 'cur_lot': 'X' if lot_owner_info.zone_instance_id == lot.zone_id else ''}
                    lot_infos.append(cur_info)
    return lot_infos
Beispiel #44
0
def c_api_zone_init(zone_id,
                    world_id,
                    world_file,
                    gameplay_zone_data_bytes=None,
                    save_slot_data_bytes=None):
    zone_data_proto = services.get_persistence_service().get_zone_proto_buff(
        zone_id)
    if zone_data_proto is not None:
        gameplay_zone_data = zone_data_proto.gameplay_zone_data
    save_slot_data = services.get_persistence_service(
    ).get_save_slot_proto_buff()
    zone = services._zone_manager.create_zone(zone_id, gameplay_zone_data,
                                              save_slot_data)
    zone.world_id = world_id
    zone_number = sims4.zone_utils.zone_numbers[zone_id]
    status.info('Zone {:#08x} (Zone #{}) initialized'.format(zone_id,
                                                             zone_number))
    zone = services._zone_manager.get(zone_id)
    return SUCCESS_CODE
def save_current_houshold(slot_id:int=0, slot_name='Unnamed', _connection=None):
    output = sims4.commands.Output(_connection)
    try:
        sim_info.save_active_household_command_start()
        save_slot_data_msg = services.get_persistence_service().get_save_slot_proto_buff()
        save_slot_data_msg.slot_id = slot_id
        active_household = services.active_household()
        if active_household is not None:
            save_slot_data_msg.active_household_id = active_household.id
        sims4.core_services.service_manager.save_all_services(None, persistence_error_types.ErrorCodes.CORE_SERICES_SAVE_FAILED, save_slot_data=save_slot_data_msg)
        save_game_buffer = services.get_persistence_service().get_save_game_data_proto()
        persistence_module.run_persistence_operation(persistence_module.PersistenceOpType.kPersistenceOpSaveHousehold, save_game_buffer, 0, None)
    except Exception as e:
        output('Exception thrown while executing command persistence.save_active_household.\n{}'.format(e))
        output('No household file generated. Please address all the exceptions.')
        raise
    finally:
        sim_info.save_active_household_command_stop()
    output('Exported active household to T:\\InGame\\Households\\{}.household'.format(active_household.name))
    return 1
Beispiel #46
0
 def on_client_connect(self, client):
     if client.account.save_slot_id is not None:
         save_slot_data_msg = services.get_persistence_service(
         ).get_save_slot_proto_buff()
         if save_slot_data_msg.HasField('gameplay_data'):
             world_game_time = save_slot_data_msg.gameplay_data.world_game_time
             current_ticks = self.now().absolute_ticks()
             difference = world_game_time - current_ticks
             self._add_to_game_time_and_send_update(difference)
             self._client_connect_world_time = self.now()
             logger.debug('Clock.on_client_connect {}', self.now())
 def get_zones_for_venue_type(self, venue_type):
     possible_zones = []
     venue_manager = services.get_instance_manager(sims4.resources.Types.VENUE)
     for neighborhood_proto in services.get_persistence_service().get_neighborhoods_proto_buf_gen():
         for lot_owner_info in neighborhood_proto.lots:
             zone_id = lot_owner_info.zone_instance_id
             while zone_id is not None:
                 venue_type_id = build_buy.get_current_venue(zone_id)
                 if venue_manager.get(venue_type_id) is venue_type:
                     possible_zones.append(lot_owner_info.zone_instance_id)
     return possible_zones
Beispiel #48
0
 def _load_options(self):
     account_data_msg = services.get_persistence_service().get_account_proto_buff()
     options_proto = account_data_msg.gameplay_account_data.gameplay_options
     if options_proto is None:
         logger.warn('Trying to load options in account.py but options_proto is None.')
         return
     zone = services.current_zone()
     if zone is None:
         logger.warn('Trying to load game options but zone is None.')
         return
     zone.service_manager.load_options(options_proto)
 def remove_fire_object(self, fire_object):
     if self._burning_objects and fire_object in self._burning_objects:
         for obj in self._burning_objects[fire_object]:
             self._stop_object_burning(obj, fire_object)
         del self._burning_objects[fire_object]
     if fire_object in self._fire_objects:
         self._fire_objects.remove(fire_object)
         fire_object.remove_state_changed_callback(self._fire_object_state_changed_callback)
     tracker = fire_object.get_tracker(self.FIRE_BEEN_EXTINGUISHED_COMMODITY)
     if tracker is not None:
         stat = tracker.get_statistic(self.FIRE_BEEN_EXTINGUISHED_COMMODITY)
         if stat is not None and stat.get_value() > 0:
             self._remove_fire_from_quadtree(fire_object)
     if not self._fire_objects:
         self._fire_quadtree = None
         self._advance_situations_to_postfire()
         self._award_insurance_money()
         services.get_persistence_service().unlock_save(self)
         self.unregister_for_panic_callback()
         self.unregister_for_sim_active_lot_status_changed_callback()
         self.deactivate_fire_alarms()
Beispiel #50
0
def get_venue_instance_from_pick_location(pick):
    if pick is None:
        return
    lot_id = pick.lot_id
    if lot_id is None:
        return
    persistence_service = services.get_persistence_service()
    lot_owner_info = persistence_service.get_lot_proto_buff(lot_id)
    if lot_owner_info is not None:
        venue_key = lot_owner_info.venue_key
        venue_instance = services.get_instance_manager(sims4.resources.Types.VENUE).get(venue_key)
        return venue_instance
 def save_once(_):
     global g_soak_save_counter
     if services.get_persistence_service().is_save_locked():
         output('Saving the game skipped since saving is locked. Next attempt in {}.'.format(time_span))
         return
     save_name = 'SoakSave{}'.format(g_soak_save_counter)
     slot_id = g_soak_save_slot_start + g_soak_save_counter
     if g_soak_save_counter < g_maximum_soak_save_slots:
         save_to_new_slot(slot_id=slot_id, slot_name=save_name, _connection=_connection)
     else:
         override_save_slot(slot_id=slot_id, slot_name=save_name, _connection=_connection)
     g_soak_save_counter = (g_soak_save_counter + 1) % g_maximum_soak_save_slots
     output('Game saved {} at slot {}. Next attempt in {}.'.format(save_name, slot_id, time_span))
 def add_neighbor_bit_if_necessary(self, sim_info):
     target_sim_info = self.find_target_sim_info()
     if target_sim_info is None:
         return
     if sim_info.household is None or target_sim_info.household is None:
         return
     home_zone_id = sim_info.household.home_zone_id
     target_home_zone_id = target_sim_info.household.home_zone_id
     if home_zone_id == target_home_zone_id:
         return
     if home_zone_id == 0 or target_home_zone_id == 0:
         return
     sim_home_zone_proto_buffer = services.get_persistence_service().get_zone_proto_buff(home_zone_id)
     target_sim_home_zone_proto_buffer = services.get_persistence_service().get_zone_proto_buff(target_home_zone_id)
     if sim_home_zone_proto_buffer is None or target_sim_home_zone_proto_buffer is None:
         logger.error('Invalid zone protocol buffer in Relationship.add_neighbor_bit_if_necessary()')
         return
     if sim_home_zone_proto_buffer.world_id != target_sim_home_zone_proto_buffer.world_id:
         return
     self.add_bit(global_relationship_tuning.RelationshipGlobalTuning.NEIGHBOR_RELATIONSHIP_BIT, notify_client=False)
     target_relationship = self._tracker._find_relationship(sim_info.id, create=False)
     if target_relationship is not None:
         target_relationship.add_bit(global_relationship_tuning.RelationshipGlobalTuning.NEIGHBOR_RELATIONSHIP_BIT, notify_client=False)
Beispiel #53
0
 def _run_interaction_gen(self, timeline):
     to_zone_id = get_zone_id_from_pick_location(self.context.pick)
     if to_zone_id is None:
         logger.error('Could not resolve lot id: {} into a valid zone id when traveling to adjacent lot.', self.context.pick.lot_id, owner='rmccord')
         return
     if services.get_persistence_service().is_save_locked():
         return
     travel_info = InteractionOps_pb2.TravelSimsToZone()
     travel_info.zone_id = to_zone_id
     travel_info.sim_ids.append(self.sim.id)
     for traveling_sim_id in self._traveling_sim_ids:
         travel_info.sim_ids.append(traveling_sim_id)
     distributor.system.Distributor.instance().add_event(Consts_pb2.MSG_TRAVEL_SIMS_TO_ZONE, travel_info)
     services.game_clock_service().set_clock_speed(ClockSpeedMode.PAUSED)
 def has_zone_for_venue_type(self, venue_types):
     venue_manager = services.get_instance_manager(sims4.resources.Types.VENUE)
     for neighborhood_proto in services.get_persistence_service().get_neighborhoods_proto_buf_gen():
         for lot_owner_info in neighborhood_proto.lots:
             zone_id = lot_owner_info.zone_instance_id
             while zone_id is not None:
                 venue_type_id = build_buy.get_current_venue(zone_id)
                 venue_type = venue_manager.get(venue_type_id)
                 if venue_type and venue_type in venue_types:
                     return True
     instance_manager = services.get_instance_manager(sims4.resources.Types.MAXIS_LOT)
     for lot_instance in instance_manager.types.values():
         while lot_instance.supports_any_venue_type(venue_types):
             return True
     return False
 def __init__(self, zone_data, **kwargs):
     super().__init__(**kwargs)
     self.zone_id = zone_data.zone_id
     self.name = zone_data.name
     self.world_id = zone_data.world_id
     self.lot_template_id = zone_data.lot_template_id
     self.lot_description_id = zone_data.lot_description_id
     venue_manager = services.get_instance_manager(sims4.resources.Types.VENUE)
     venue_type_id = build_buy.get_current_venue(zone_data.zone_id)
     if venue_type_id is not None:
         venue_type = venue_manager.get(venue_type_id)
         if venue_type is not None:
             self.venue_type_name = venue_type.display_name
     householdProto = services.get_persistence_service().get_household_proto_buff(zone_data.household_id)
     self.household_name = householdProto.name if householdProto is not None else None
def print_venues(_connection=None):
    current_zone = services.current_zone()
    lot = current_zone.lot
    neighborhood_id = current_zone.neighborhood_id
    lot_description_id = services.get_lot_description_id(lot.lot_id)
    world_description_id = services.get_world_description_id(current_zone.world_id)
    neighborhood_description_id = services.get_persistence_service().get_neighborhood_proto_buff(neighborhood_id).region_id

    def print_line():
        sims4.commands.output('-'*150, _connection)

    print_line()
    sims4.commands.output('Current Game Stats: \nLot: {}\nWorld/Street: {}\nRegion/Neighborhood: {}'.format(lot_description_id, world_description_id, neighborhood_description_id), _connection)
    print_line()
    venue_manager = services.get_instance_manager(sims4.resources.Types.VENUE)
    venues = []
    for neighborhood_proto in services.get_persistence_service().get_neighborhoods_proto_buf_gen():
        for lot_owner_info in neighborhood_proto.lots:
            zone_id = lot_owner_info.zone_instance_id
            while zone_id is not None:
                venue_type_id = build_buy.get_current_venue(zone_id)
                venue_type = venue_manager.get(venue_type_id)
                if venue_type is not None:
                    log = PrintVenueLog._make((neighborhood_proto.name, neighborhood_proto.region_id, lot_owner_info.lot_description_id, zone_id, venue_type.__name__, lot_owner_info.lot_name))
                    venues.append(log)
    str_format = '{:20} ({:{center}15}) {:{center}20} {:15} ({:{center}20}) {:20}'

    def print_columns():
        sims4.commands.output(str_format.format('Neighborhood_Name', 'Neighborhood_ID', 'Lot_Description_ID', 'Zone_Instance_ID', 'Venue_Tuning_Name', 'Lot_Name', center='^'), _connection)

    print_columns()
    print_line()
    for venue in sorted(venues):
        sims4.commands.output(str_format.format(venue.Neighborhood_Name, venue.Neighborhood_ID, venue.Lot_Description_ID, venue.Zone_Instance_ID, venue.Venue_Tuning_Name, venue.Lot_Name, center='^'), _connection)
    print_line()
    print_columns()
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 __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