Exemple #1
0
 def _trigger_phone_call_gen(self, timeline):
     client = services.client_manager().get_first_client()
     if client is None:
         return
     client_household = client.household
     if client_household is None:
         return
     sims_to_check = [sim for sim in client_household.instanced_sims_gen()]
     random.shuffle(sims_to_check)
     for sim in sims_to_check:
         call_types = []
         ask_to_come_over_phone_call = HouseholdManager.PHONE_CALL_INFO.ask_to_come_over(sim)
         call_types.append((ask_to_come_over_phone_call.weight, ask_to_come_over_phone_call))
         chat_phone_call = HouseholdManager.PHONE_CALL_INFO.chat(sim)
         call_types.append((chat_phone_call.weight, chat_phone_call))
         invite_over_phone_call = HouseholdManager.PHONE_CALL_INFO.invite_over(sim)
         call_types.append((invite_over_phone_call.weight, invite_over_phone_call))
         while call_types:
             call_type = pop_weighted(call_types)
             if call_type.try_and_setup():
                 call_type.execute()
                 self._phone_call_element = None
                 return
             yield element_utils.run_child(timeline, element_utils.sleep_until_next_tick_element())
     self._phone_call_element = None
 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 _run_gen(self, timeline):
     if self._duration_must_run > 0:
         sequence = build_animation_drift_monitor_sequence(
             self,
             elements.SleepElement(
                 clock.interval_in_real_seconds(self._duration_must_run)))
         yield from element_utils.run_child(timeline, sequence)
     if self._stop_requested:
         return False
         yield
     if self._duration_repeat > 0.0:
         while True:
             while not self._stop_requested:
                 yield from element_utils.run_child(
                     timeline,
                     elements.SleepElement(
                         clock.interval_in_real_seconds(
                             self._duration_repeat)))
     elif self.enable_optional_sleep_time and self._duration_interrupt > 0:
         then = timeline.now
         yield from element_utils.run_child(
             timeline,
             elements.SoftSleepElement(
                 clock.interval_in_real_seconds(self._duration_interrupt)))
         now = timeline.now
         self._optional_time_elapsed = (now - then).in_real_world_seconds()
     else:
         yield from element_utils.run_child(
             timeline, element_utils.sleep_until_next_tick_element())
     return True
     yield
 def process_request_gen(self, timeline):
     households = [(template_data.weight, template_data.household_template) for template_data in NeighborhoodPopulationService.HOMELESS_HOUSEHOLD_TEMPLATES]
     if not households:
         return
     while self._num_to_fill > 0:
         household_template = sims4.random.weighted_random_item(households)
         self._create_household_from_template_and_add_to_zone(household_template, None, 0, creation_source='neigh_pop_service: homeless')
         yield element_utils.run_child(timeline, element_utils.sleep_until_next_tick_element())
 def _apply_to_subject_and_target(self, subject, target, resolver):
     if subject.is_sim and subject.sim_info is subject:
         subject = subject.get_sim_instance()
         if subject is None:
             logger.error('Requested broadcaster for uninstanced Sim')
             return
     sim_timeline = services.time_service().sim_timeline
     sim_timeline.schedule(self.broadcaster_request(subject, sequence=(element_utils.sleep_until_next_tick_element(),)))
 def _get_valid_choices_gen(self, timeline):
     self.sim_ids = []
     requesting_sim_info = self.sim.sim_info
     blacklist = {sim_info.id for sim_info in services.sim_info_manager().instanced_sims_gen(allow_hidden_flags=ALL_HIDDEN_REASONS)}
     for sim_filter in self.sim_filters:
         for _ in range(sim_filter.number_of_sims):
             sim_infos = services.sim_filter_service().submit_matching_filter(1, sim_filter.filter, None, blacklist_sim_ids=blacklist, requesting_sim_info=requesting_sim_info, allow_yielding=False, zone_id=0)
             for sim_info in sim_infos:
                 self.sim_ids.append(sim_info.id)
                 blacklist.add(sim_info.id)
             yield element_utils.run_child(timeline, element_utils.sleep_until_next_tick_element())
 def do_routes(timeline):
     result = False
     for route in self._route_data.get_routes_gen():
         result = yield from self._do_single_route_gen(timeline, route)
         if not result:
             break
     if not result:
         yield from element_utils.run_child(
             timeline, element_utils.sleep_until_next_tick_element())
     return result
     yield
Exemple #8
0
 def process_request_gen(self, timeline):
     if self._region_renting_data is None:
         return
     while self._num_to_fill > 0:
         while self._available_zone_ids:
             zone_id = random.choice(self._available_zone_ids)
             self._available_zone_ids.remove(zone_id)
             (max_group_size, total_sleeping_spots
              ) = self._get_max_travel_group_size(zone_id)
             if not max_group_size == 0:
                 if total_sleeping_spots == 0:
                     continue
                 possible_travel_groups = self._find_households_to_rent_lot(
                 )
                 if possible_travel_groups:
                     (sim_infos_that_can_lead_travel_group,
                      sim_infos_available_for_vacation
                      ) = random.choice(possible_travel_groups)
                     sim_to_lead_group = random.choice(
                         sim_infos_that_can_lead_travel_group)
                     sim_infos_available_for_vacation.remove(
                         sim_to_lead_group)
                     random_sample_size = max_group_size - 1
                     sim_infos_to_send_to_vacation = []
                     if random_sample_size > 0:
                         if random_sample_size < len(
                                 sim_infos_available_for_vacation):
                             sim_infos_to_send_to_vacation = random.sample(
                                 sim_infos_available_for_vacation,
                                 random_sample_size)
                         else:
                             sim_infos_to_send_to_vacation = sim_infos_available_for_vacation
                     sim_infos_to_send_to_vacation.append(sim_to_lead_group)
                 else:
                     household_template = self._region_renting_data.travel_group_size_to_household_template(
                         max_group_size)
                     if household_template is None:
                         continue
                     household = household_template.create_household(
                         zone_id,
                         self._account,
                         creation_source='neigh_pop_service:rentable_lot')
                     sim_infos_to_send_to_vacation = [
                         sim_info for sim_info in household
                     ]
                 if self._send_sims_on_vacation(
                         zone_id, sim_infos_to_send_to_vacation,
                         self._region_renting_data.duration.random_int()):
                     self._num_to_fill -= 1
                 yield from element_utils.run_child(
                     timeline,
                     element_utils.sleep_until_next_tick_element())
 def _process_population_request_gen(self, timeline):
     while self._requests:
         request = self._requests.pop(0)
         try:
             yield request.process_request_gen(timeline)
             request.process_completed(True)
         except GeneratorExit:
             raise
         except BaseException:
             request.process_completed(False)
             logger.exception('Exception raised while processing creating npc households')
         while self._requests:
             yield element_utils.run_child(timeline, element_utils.sleep_until_next_tick_element())
             continue
     self._processing_element_handle = None
 def _update_gen(self, timeline):
     while self.queue:
         cur_request = self.queue.pop(0)
         cur_request.autonomy_mode.set_process_start_time()
         try:
             next_sim = cur_request.sim
             if next_sim is not None:
                 autonomy_queue_logger.debug('Processing {}', next_sim)
                 self._active_sim = next_sim
                 yield self._execute_request_gen(timeline, cur_request, self.MAX_SECONDS_PER_LOOP)
             else:
                 autonomy_queue_logger.debug('Skipping removed sim.')
         except autonomy.autonomy_exceptions.AutonomyExitException:
             pass
         finally:
             cur_request.sleep_element.trigger_soft_stop()
             cur_request.sleep_element = None
             self._update_automation_load_test()
             self._check_for_automated_performance_test_sim()
             self._active_sim = None
         sleep_element = element_utils.sleep_until_next_tick_element()
         yield timeline.run_child(sleep_element)
Exemple #11
0
 def _update_gen(self, timeline):
     while self.queue:
         cur_request = self.queue.pop(0)
         cur_request.autonomy_mode.set_process_start_time()
         try:
             next_sim = cur_request.sim
             if next_sim is not None:
                 autonomy_queue_logger.debug('Processing {}', next_sim)
                 self._active_sim = next_sim
                 yield from self._execute_request_gen(
                     timeline, cur_request, self.MAX_SECONDS_PER_LOOP)
             else:
                 autonomy_queue_logger.debug('Skipping removed sim.')
         except autonomy.autonomy_exceptions.AutonomyExitException:
             pass
         finally:
             cur_request.sleep_element.trigger_soft_stop()
             cur_request.sleep_element = None
             self._update_automation_load_test()
             self._check_for_automated_performance_test_sim()
             self._active_sim = None
         sleep_element = element_utils.sleep_until_next_tick_element()
         yield timeline.run_child(sleep_element)
 def _get_valid_choices_gen(self, timeline):
     self.sim_ids = []
     requesting_sim_info = self.sim.sim_info
     blacklist = {
         sim_info.id
         for sim_info in services.sim_info_manager().instanced_sims_gen(
             allow_hidden_flags=ALL_HIDDEN_REASONS)
     }
     for sim_filter in self.sim_filters:
         for _ in range(sim_filter.number_of_sims):
             sim_infos = services.sim_filter_service(
             ).submit_matching_filter(
                 1,
                 sim_filter.filter,
                 None,
                 blacklist_sim_ids=blacklist,
                 requesting_sim_info=requesting_sim_info,
                 allow_yielding=False,
                 zone_id=0)
             for sim_info in sim_infos:
                 self.sim_ids.append(sim_info.id)
                 blacklist.add(sim_info.id)
             yield element_utils.run_child(
                 timeline, element_utils.sleep_until_next_tick_element())