def create_vacation(zone_id: int, duration: int = 0, cost: int = 0, *sim_ids, _connection=None): output = sims4.commands.Output(_connection) if not sim_ids: output('Cannot create a travel group with 0 Sims.') return sim_info_manager = services.sim_info_manager() create_timestamp = services.time_service().sim_now end_timestamp = create_timestamp + clock.interval_in_sim_days(duration) sim_infos = [] for sim_id in sim_ids: sim_info = sim_info_manager.get(int(sim_id, base=0)) if sim_info is not None: sim_infos.append(sim_info) else: output('Cannot find Sim with id {}'.format(sim_id)) travel_group_manager = services.travel_group_manager() travel_group_manager.create_travel_group_and_rent_zone( sim_infos=sim_infos, zone_id=zone_id, played=True, create_timestamp=create_timestamp, end_timestamp=end_timestamp, cost=cost)
def setup_rented_zone_alarms(self): if self._end_vacation_alarm is not None: alarms.cancel_alarm(self._end_vacation_alarm) time_now = services.time_service().sim_now self._end_vacation_alarm = alarms.add_alarm( self, self.end_timestamp - time_now, self._travel_group_end_callback, repeating=False) if self._days_left_notification_alarm is not None: alarms.cancel_alarm(self._days_left_notification_alarm) days_before_vacation_ends = clock.interval_in_sim_days( TravelGroupTuning.VACATION_ENDING_DAYS_TNS. days_before_vacation_ends) days_left_timestamp = self.end_timestamp + -days_before_vacation_ends if days_left_timestamp > time_now: self._days_left_notification_alarm = alarms.add_alarm( self, days_left_timestamp - time_now, self._days_left_notification_callback, repeating=False) if self._hours_left_notification_alarm is not None: alarms.cancel_alarm(self._hours_left_notification_alarm) hours_before_vacation_ends = clock.interval_in_sim_hours( TravelGroupTuning.VACATION_ENDING_HOURS_TNS. hours_before_vacation_ends) hours_left_timestamp = self.end_timestamp + -hours_before_vacation_ends if hours_left_timestamp > time_now: self._hours_left_notification_alarm = alarms.add_alarm( self, hours_left_timestamp - time_now, self._hours_left_notification_callback, repeating=False)
def on_activate(self, reader=None): super().on_activate(reader) now = services.game_clock_service().now() time_till_first_count = now.time_till_next_day_time( self.time_to_start_count) time_till_celebration = now.time_till_next_day_time( self.celebrate_time) repeat_time_span = clock.interval_in_sim_minutes( self.interval_between_counts) if time_till_first_count > time_till_celebration: time_of_first_count = now + time_till_first_count + clock.interval_in_sim_days( -1) time_since_first_count = now - time_of_first_count time_of_next_count = time_of_first_count + repeat_time_span * ( int(time_since_first_count.in_ticks() / repeat_time_span.in_ticks()) + 1) time_till_first_count = time_of_next_count - now self._count_timer = alarms.add_alarm( self, time_till_first_count, self._count_callback, repeating=True, repeating_time_span=repeat_time_span) self._celebrate_timer = alarms.add_alarm(self, time_till_celebration, self._celebrate_callback)
def _set_expected_time(self, target_hours, target_minutes, days_ahead): clock = services.game_clock_service() self._current_date_and_time = clock.now() clock_days = int(self._current_date_and_time.absolute_days()) time_span = self._current_date_and_time - DateAndTime(interval_in_sim_days(clock_days).in_ticks()) current_date_and_time_minus_days = DateAndTime(time_span.in_ticks()) clock_hours = int(current_date_and_time_minus_days.absolute_hours()) time_span = current_date_and_time_minus_days - DateAndTime(interval_in_sim_hours(clock_hours).in_ticks()) current_date_and_time_minus_hours = DateAndTime(time_span.in_ticks()) clock_minutes = int(current_date_and_time_minus_hours.absolute_minutes()) delta_days = days_ahead clock_day_minutes = clock_hours*60 + clock_minutes target_day_minutes = target_hours*60 + target_minutes delta_day_minutes = target_day_minutes - clock_day_minutes if delta_day_minutes < 0: delta_day_minutes += 1440 self._expected_data_and_time = self._current_date_and_time + interval_in_sim_days(delta_days) + interval_in_sim_minutes(delta_day_minutes)
def _create_fake_total_time_alive(self): age = Age.BABY time_alive = TimeSpan.ZERO while age != self.age: age_time = interval_in_sim_days(AgeTransitions.get_duration(Age(self._base.age))) time_alive += age_time age = Age.next_age(age) setting_multiplier = AgeTransitions.get_speed_multiple(self._age_speed_setting) time_alive /= setting_multiplier return time_alive
def _create_fake_total_time_alive(self): aging_service = services.get_aging_service() age = self.get_birth_age() time_alive = TimeSpan.ZERO while age < self.age: age_transition_data = self.get_age_transition_data(age) time_alive += interval_in_sim_days( age_transition_data.get_age_duration(self)) age = self.get_next_age(age) setting_multiplier = aging_service.get_speed_multiple( self._age_speed_setting) time_alive /= setting_multiplier return time_alive
def _send_sims_on_vacation(self, zone_id, sim_infos_to_send_to_vacation, duration): create_timestamp = services.time_service().sim_now end_timestamp = create_timestamp + clock.interval_in_sim_days(duration) travel_group_manager = services.travel_group_manager() travel_group_created = travel_group_manager.create_travel_group_and_rent_zone( sim_infos=sim_infos_to_send_to_vacation, zone_id=zone_id, played=False, create_timestamp=create_timestamp, end_timestamp=end_timestamp) if travel_group_created: for sim_info in sim_infos_to_send_to_vacation: sim_info.inject_into_inactive_zone(zone_id) return True return False
def extend_vacation(self, duration_days, cost=0): extension = clock.interval_in_sim_days(duration_days) self.end_timestamp = self.end_timestamp + extension self.setup_rented_zone_alarms() services.active_household().funds.try_remove( cost, reason=Consts_pb2.FUNDS_MONEY_VACATION, sim=services.get_active_sim()) leader_sim_info = services.active_sim_info() if leader_sim_info not in self: leader_sim_info = self._sim_infos[0] with telemetry_helper.begin_hook(travel_group_telemetry_writer, TELEMETRY_HOOK_TRAVEL_GROUP_EXTEND, sim_info=leader_sim_info) as hook: hook.write_int(TELEMETRY_TRAVEL_GROUP_ID, self.id) hook.write_int(TELEMETRY_TRAVEL_GROUP_ZONE_ID, self.zone_id) hook.write_int(TELEMETRY_TRAVEL_GROUP_SIZE, len(self)) hook.write_int(TELEMETRY_TRAVEL_GROUP_DURATION, int(self.duration_time_span.in_minutes()))
def _schedule_phone_call_alarm(self): delay = random.randint(HouseholdManager.PHONE_CALL_INFO.minimum_time_between_calls, HouseholdManager.PHONE_CALL_INFO.maximum_time_between_calls) time_delay = interval_in_sim_minutes(delay) current_time = services.time_service().sim_now alarm_end_time = current_time + time_delay if alarm_end_time.time_between_day_times(HouseholdManager.PHONE_CALL_INFO.availible_time_of_day.start_time, HouseholdManager.PHONE_CALL_INFO.availible_time_of_day.end_time): time_till_alarm_end_time = alarm_end_time - current_time self._phone_call_alarm_handle = alarms.add_alarm(self, time_till_alarm_end_time, self._trigger_phone_call_callback) return if current_time.time_between_day_times(HouseholdManager.PHONE_CALL_INFO.availible_time_of_day.start_time, HouseholdManager.PHONE_CALL_INFO.availible_time_of_day.end_time): time_till_next_end_time = current_time.time_till_next_day_time(HouseholdManager.PHONE_CALL_INFO.availible_time_of_day.end_time) else: time_till_next_end_time = TimeSpan.ZERO time_delay -= time_till_next_end_time time_available_per_day = HouseholdManager.PHONE_CALL_INFO.availible_time_of_day.end_time - HouseholdManager.PHONE_CALL_INFO.availible_time_of_day.start_time cycles_left = time_delay.in_ticks()//time_available_per_day.in_ticks() time_till_next_start_time = current_time.time_till_next_day_time(HouseholdManager.PHONE_CALL_INFO.availible_time_of_day.start_time) time_till_alarm_end_time = time_till_next_start_time + interval_in_sim_days(cycles_left) time_delay -= time_available_per_day*cycles_left time_till_alarm_end_time += time_delay self._phone_call_alarm_handle = alarms.add_alarm(self, time_till_alarm_end_time, self._trigger_phone_call_callback)