def post_career_event_travel(cls, sim_info, zone_id_override=None, outfit_change_reason=None): target_zone_id = sim_info.household.home_zone_id sims_to_move = set() if sim_info.zone_id != target_zone_id: sims_to_move.add(sim_info) if outfit_change_reason is not None: outfit_change = sim_info.get_outfit_for_clothing_change( None, outfit_change_reason, SingleSimResolver(sim_info)) sim_info.set_current_outfit(outfit_change) if zone_id_override is not None: main_zone_id = zone_id_override else: main_zone_id = services.get_career_service( ).get_main_career_event_zone_id_and_unlock_save() services.get_career_service().last_career_event_zone_id = None if main_zone_id is not None: if main_zone_id != target_zone_id: for household_sim_info in sim_info.household: if household_sim_info is not sim_info: if household_sim_info.zone_id == main_zone_id: sims_to_move.add(household_sim_info) if target_zone_id == services.current_zone_id(): for sim_to_move in sims_to_move: SimSpawner.spawn_sim(sim_to_move) return sims_ids_to_travel = set() for sim_to_move in sims_to_move: if sim_to_move.is_instanced(allow_hidden_flags=ALL_HIDDEN_REASONS): sims_ids_to_travel.add(sim_to_move.sim_id) else: sim_to_move.inject_into_inactive_zone(target_zone_id) if sims_ids_to_travel: persistence_service = services.get_persistence_service() if persistence_service.is_save_locked(): household = sim_info.household def post_save_lock_travel(): household_sims = { sim.sim_id: sim for sim in household.instanced_sims_gen() } sim_ids = set( sim_id for sim_id in sims_ids_to_travel if sim_id in household_sims if get_death_interaction(household_sims[sim_id]) is None) if sim_ids: travel_sims_to_zone(sim_ids, target_zone_id) persistence_service.add_save_unlock_callback( post_save_lock_travel) else: travel_sims_to_zone(sims_ids_to_travel, target_zone_id)
def get_join_career_pb(sim_info, num_careers_to_show=0, check_for_conflicting_schedule=False): msg = protocolbuffers.Sims_pb2.CareerSelectionUI() msg.sim_id = sim_info.sim_id msg.is_branch_select = False msg.reason = career_ops.CareerOps.JOIN_CAREER all_possible_careers = services.get_career_service().get_shuffled_career_list() careers_added = 0 resolver = event_testing.resolver.SingleSimResolver(sim_info) for career_tuning in all_possible_careers: if num_careers_to_show > 0 and careers_added >= num_careers_to_show: break test_result = career_tuning.career_availablity_tests.run_tests(resolver) while test_result and sim_info.career_tracker.get_career_by_uid(career_tuning.guid64) is None: (new_level, _, current_track) = career_tuning.get_career_entry_level(career_tuning, career_history=sim_info.career_tracker.career_history, resolver=resolver) if current_track is not None: career_track = current_track.guid64 elif career_tuning.start_track is not None: career_track = career_tuning.start_track.guid64 else: logger.error('Career {} is unjoinable because it is missing Start Track tuning.', career_tuning) career_info_msg = msg.career_choices.add() career_info_msg.uid = career_tuning.guid64 career_info_msg.career_track = career_track career_info_msg.career_level = new_level career_info_msg.company.hash = career_tuning.get_random_company_name_hash(career_tuning) career_info_msg.conflicted_schedule = sim_info.career_tracker.conflicting_with_careers(career_tuning) if check_for_conflicting_schedule else False careers_added += 1 return msg
def enable_careers(enable: bool = None, _connection=None): if enable is None: logger.error( 'Not all of the data needed for the careers.enable_careers was passed.' ) return services.get_career_service().enabled = enable
def on_enter(self): super().on_enter() situation_manager = services.get_zone_situation_manager() situation_manager.create_situations_during_zone_spin_up() venue_service = services.current_zone().venue_service venue_service.create_situations_during_zone_spin_up() zone_director = venue_service.get_zone_director() if zone_director.open_street_director is not None: zone_director.open_street_director.create_situations_during_zone_spin_up( ) services.get_career_service( ).create_career_event_situations_during_zone_spin_up() situation_manager.on_all_situations_created_during_zone_spin_up() services.drama_scheduler_service( ).on_situation_creation_during_zone_spin_up() return _ZoneSpinUpStateResult.DONE
def _get_ideal_candidate_for_employment(self): def _get_weight(candidate, career): if not career.is_valid_career(sim_info=candidate): return 0 if candidate.career_tracker.has_career_by_uid(career.guid64): return 0 return career.career_story_progression.joining.get_multiplier( SingleSimResolver(candidate)) career_service = services.get_career_service() weights = [ (_get_weight(candidate, career), candidate, career) for (candidate, career) in itertools.product(( candidate for candidate in self._unemployed if self._is_valid_candidate(candidate)), ( career for career in career_service.get_career_list() if career.career_story_progression.joining is not None)) ] if not weights: return selected_candidate_index = weighted_random_index(weights) if selected_candidate_index is None: return selected_candidate = weights[selected_candidate_index] return (selected_candidate[1], selected_candidate[2])
def _handle_timed_out_performance_hit(self): career_service = services.get_career_service() active_career = career_service.get_career_in_career_event() if active_career is not None: active_career.add_work_performance( self.owner.waiting_timedout_performance_penalty) active_career.resend_career_data()
def handle_event(self, sim_info, event, resolver): career = services.get_career_service().get_career_in_career_event() if career.sim_info is not sim_info: return if event == TestEvent.InteractionComplete and isinstance(resolver.interaction, self.start_performance_interaction) and not resolver.interaction.has_been_reset: self._start_performance() elif event == TestEvent.MainSituationGoalComplete: self._end_performance(career)
def get_predefined_guest_list(cls): if not cls.force_patient_on_active_career_sim: return career = services.get_career_service().get_career_in_career_event() if career is None: return guest_list = SituationGuestList(invite_only=True) guest_list.add_guest_info(SituationGuestInfo(career.sim_info.sim_id, cls.default_job(), RequestSpawningOption.CANNOT_SPAWN, BouncerRequestPriority.EVENT_VIP)) return guest_list
def set_avg_careers(average_careers: float, _connection=None): sim_info_manager = services.sim_info_manager() sim_count = len(sim_info_manager) adult_career_sims_infos = [] adult_jobless_sim_infos = [] target_careers = sim_count * average_careers career_count = 0 for sim_info_id in sim_info_manager: sim_info = sim_info_manager.get(sim_info_id) if sim_info is not None: if sim_info.lod != SimInfoLODLevel.MINIMUM: if sim_info.career_tracker.has_career: career_count += 1 if sim_info.is_young_adult_or_older and sim_info.is_npc: adult_career_sims_infos.append(sim_info) if sim_info.is_young_adult_or_older: if sim_info.is_npc: adult_jobless_sim_infos.append(sim_info) elif sim_info.is_young_adult_or_older: if sim_info.is_npc: adult_jobless_sim_infos.append(sim_info) needed_careers = target_careers - career_count career_delta = 0 if needed_careers > 0: random.shuffle(adult_jobless_sim_infos) career_service = services.get_career_service() careers = list(career for career in career_service.get_career_list() if career.career_story_progression.joining is not None) for sim_info in adult_jobless_sim_infos: random.shuffle(careers) for career in careers: if career.is_valid_career(sim_info, from_join=True): sim_info.career_tracker.add_career(career(sim_info)) career_delta += 1 needed_careers -= 1 break if needed_careers <= 0: break elif needed_careers < 0: random.shuffle(adult_career_sims_infos) for sim_info in adult_career_sims_infos: for career_uid in sim_info.career_tracker.get_quittable_careers(): sim_info.career_tracker.remove_career(career_uid) career_delta -= 1 needed_careers += 1 if needed_careers >= 0: break if needed_careers >= 0: break sims4.commands.output( 'Number of Target Careers: {}\nNumber of Initial Careers: {}\nCareer count delta:{} ' .format(target_careers, career_count, career_delta), _connection)
def c_api_buildbuy_session_begin(zone_id: int, account_id: int): current_zone = services.current_zone() posture_graph_service = current_zone.posture_graph_service posture_graph_service.on_enter_buildbuy() current_zone.on_build_buy_enter() object_leak_tracker = services.get_object_leak_tracker() if object_leak_tracker is not None: object_leak_tracker.add_disable_reason(BUILD_BUY_OBJECT_LEAK_DISABLED) resource_keys = [] if services.get_career_service().get_career_event_situation_is_running(): household = services.active_household() else: household = current_zone.get_active_lot_owner_household() if household is not None: for unlock in household.build_buy_unlocks: resource_keys.append(unlock) update_gameplay_unlocked_products(resource_keys, zone_id, account_id) services.business_service().on_build_buy_enter() services.get_reset_and_delete_service().on_build_buy_enter() services.object_manager(zone_id).cleanup_build_buy_transient_objects() _build_buy_enter_callbacks() return True
def on_enter(self): super().on_enter() services.get_career_service().restore_career_state() return _ZoneSpinUpStateResult.DONE
def stay_late(_connection=None): career = services.get_career_service().get_career_in_career_event() if career is not None: career.extend_career_session()
def on_enter(self): super().on_enter() services.get_career_service().restore_career_state() coworker.fixup_coworker_relationship_bit() return _ZoneSpinUpStateResult.DONE
def get_potenial_subactions_gen(self, sim_info): career_service = services.get_career_service() for career in career_service.get_career_list(): if career.career_story_progression.joining is not None: yield _CareerSubactionJoin(sim_info, career=career)
def get_particpants_shared(participant_type): if participant_type == ParticipantType.Lot: return (services.active_lot(), ) elif participant_type == ParticipantType.LotOwners: owning_household = services.owning_household_of_active_lot() if owning_household is not None: return tuple(sim_info for sim_info in owning_household.sim_info_gen()) return () return () if participant_type == ParticipantType.LotOwnersOrRenters: owning_household = services.owning_household_of_active_lot() if owning_household is not None: return tuple(sim_info for sim_info in owning_household.sim_info_gen()) else: current_zone = services.current_zone() travel_group = services.travel_group_manager( ).get_travel_group_by_zone_id(current_zone.id) if travel_group is not None: return tuple(sim_info for sim_info in travel_group.sim_info_gen()) return () if participant_type == ParticipantType.LotOwnerSingleAndInstanced: owning_household = services.owning_household_of_active_lot() if owning_household is not None: for sim_info in owning_household.sim_info_gen(): if sim_info.is_instanced(): return (sim_info, ) return () elif participant_type == ParticipantType.ActiveHousehold: active_household = services.active_household() if active_household is not None: return tuple(active_household.sim_info_gen()) return () elif participant_type == ParticipantType.AllInstancedActiveHouseholdSims: active_household = services.active_household() if active_household is not None: return tuple(active_household.instanced_sims_gen()) return () elif participant_type == ParticipantType.CareerEventSim: career = services.get_career_service().get_career_in_career_event() if career is not None: return (career.sim_info.get_sim_instance() or career.sim_info, ) return () return () if participant_type == ParticipantType.AllInstancedActiveHouseholdSims: active_household = services.active_household() if active_household is not None: return tuple(active_household.instanced_sims_gen()) return () elif participant_type == ParticipantType.CareerEventSim: career = services.get_career_service().get_career_in_career_event() if career is not None: return (career.sim_info.get_sim_instance() or career.sim_info, ) return () return () if participant_type == ParticipantType.AllInstancedSims: return tuple(services.sim_info_manager().instanced_sims_gen()) if participant_type == ParticipantType.Street: street = services.current_zone().street street_service = services.street_service() if street_service is None: return () street_civic_policy_provider = street_service.get_provider(street) if street_civic_policy_provider is None: return () return (street_civic_policy_provider, ) if participant_type == ParticipantType.VenuePolicyProvider: venue_service = services.venue_service() if venue_service.source_venue is None or venue_service.source_venue.civic_policy_provider is None: return () else: return (venue_service.source_venue.civic_policy_provider, )