Esempio n. 1
0
 def handle_season_content_updated(self,
                                   setup_regional_params=True,
                                   delay=False):
     services.holiday_service().on_season_content_changed()
     if not delay:
         self._handle_season_content_delayed(
             setup_regional_params=setup_regional_params)
     self._send_season_ui_update()
Esempio n. 2
0
def update_holiday(holiday_data: str, _connection=None):
    holiday_service = services.holiday_service()
    if holiday_service is None:
        return
    proto = GameplaySaveData_pb2.Holiday()
    text_format.Merge(holiday_data, proto)
    holiday_service.modify_holiday(proto)
Esempio n. 3
0
 def factory(resolver,
             participant_type,
             balloon_target_override=None,
             **kwargs):
     if resolver is None:
         logger.callstack('Attempting to use a None resolver in an icon.',
                          level=LEVEL_ERROR,
                          owner='bosee')
         return EMPTY_ICON_INFO_DATA
     if balloon_target_override is not None:
         return IconInfoData(obj_instance=balloon_target_override)
     participant = resolver.get_participant(participant_type)
     if participant is None:
         logger.callstack(
             'Unable to retrieve participant for holiday icon variant.',
             level=LEVEL_ERROR,
             owner='bosee')
         return EMPTY_ICON_INFO_DATA
     else:
         holiday_tracker = participant.household.holiday_tracker
         holiday_service = services.holiday_service()
         if holiday_service is not None and holiday_tracker is not None and holiday_tracker.active_holiday_id is not None:
             return IconInfoData(
                 icon_resource=holiday_service.get_holiday_display_icon(
                     holiday_tracker.active_holiday_id))
     return EMPTY_ICON_INFO_DATA
 def _is_valid_deco_type_id(self, deco_type_id):
     if deco_type_id == 0:
         return True
     holiday_service = services.holiday_service()
     if holiday_service is None:
         return False
     return holiday_service.is_valid_holiday_id(deco_type_id)
Esempio n. 5
0
 def send_active_holiday_info_message(self, update_type):
     if self._active_holiday_id is None:
         logger.error("Trying to send active holiday info to UI when there isn't one.")
         return
     holiday_service = services.holiday_service()
     send_active_holiday_info = SendActiveHolidayInfo(update_type, self._active_holiday_id, holiday_service.get_holiday_display_name(self._active_holiday_id), holiday_service.get_holiday_display_icon(self._active_holiday_id), holiday_service.get_holiday_time_off_work(self._active_holiday_id), holiday_service.get_holiday_time_off_school(self._active_holiday_id), holiday_service.get_holiday_traditions(self._active_holiday_id), holiday_service.can_holiday_be_modified(self._active_holiday_id), holiday_service.get_decoration_preset(self._active_holiday_id))
     distributor = Distributor.instance()
     distributor.add_op_with_no_owner(send_active_holiday_info)
Esempio n. 6
0
 def start_audio_sting(self):
     active_household = services.active_household()
     if active_household is None:
         return
     holiday_id = active_household.holiday_tracker.active_holiday_id
     if holiday_id is None:
         return
     return services.holiday_service().get_holiday_audio_sting(holiday_id)
Esempio n. 7
0
 def preactivate_holiday(self, holiday_id):
     if self._pre_day_holiday_id is not None:
         logger.error('Holiday {} is already in pre-day holiday state.  Removing one holiday from the pre-day holiday state should occur before starting a different one.', self._pre_day_holiday_id)
         return
     self._pre_day_holiday_id = holiday_id
     for tradition_type in services.holiday_service().get_holiday_traditions(holiday_id):
         tradition = tradition_type()
         self._traditions[holiday_id].append(tradition)
         tradition.activate_pre_holiday()
Esempio n. 8
0
def add_holiday(holiday_data: str,
                season: SeasonType,
                day: int,
                _connection=None):
    holiday_service = services.holiday_service()
    if holiday_service is None:
        return
    proto = GameplaySaveData_pb2.Holiday()
    text_format.Merge(holiday_data, proto)
    holiday_service.add_a_holiday(proto, season, day)
Esempio n. 9
0
 def perform_test(self, tooltip):
     holiday_service = services.holiday_service()
     if holiday_service is None:
         return TestResult(False, 'Lot decoration service not available.', tooltip=tooltip)
     holiday_id = self.occasion()
     if holiday_id is None:
         return TestResult(False, 'Could not find an applicable holiday for test. {}', self, tooltip=tooltip)
     if holiday_service.get_decoration_preset(holiday_id) is None:
         return TestResult(False, 'Holiday with id {} has no decorations.', self.occasion(), tooltip=tooltip)
     return TestResult.TRUE
Esempio n. 10
0
 def on_sim_added(self, sim_info):
     if self._state != HolidayState.RUNNING:
         return
     holiday_goals = list(
         tradition.situation_goal
         for tradition in services.holiday_service().get_holiday_traditions(
             self.holiday_id))
     situation_id = self._create_holiday_situation(sim_info, holiday_goals)
     if situation_id:
         services.get_zone_situation_manager().register_for_callback(
             situation_id, SituationCallbackOption.END_OF_SITUATION,
             self._on_holiday_situation_ended)
Esempio n. 11
0
 def create_calendar_entry(self):
     calendar_entry = super().create_calendar_entry()
     active_household = services.active_household()
     if active_household is not None:
         holiday_service = services.holiday_service()
         build_icon_info_msg(
             IconInfoData(icon_resource=holiday_service.
                          get_holiday_display_icon(self.holiday_id)),
             holiday_service.get_holiday_display_name(self.holiday_id),
             calendar_entry.icon_info)
         calendar_entry.holiday_id = self.holiday_id
         for tradition in holiday_service.get_holiday_traditions(
                 self.holiday_id):
             calendar_entry.tradition_ids.append(tradition.guid64)
     return calendar_entry
Esempio n. 12
0
 def create_calendar_alert(self):
     if self.ui_display_type == DramaNodeUiDisplayType.POP_UP_HOLIDAY:
         return
     holiday_service = services.holiday_service()
     calendar_alert = super().create_calendar_alert()
     calendar_alart_description = holiday_service.get_holiday_calendar_alert_notification(
         self.holiday_id)
     if calendar_alart_description is not None:
         calendar_alert.description = calendar_alart_description(
             holiday_service.get_holiday_display_name(self.holiday_id))
     build_icon_info_msg(
         IconInfoData(icon_resource=holiday_service.
                      get_holiday_display_icon(self.holiday_id)),
         holiday_service.get_holiday_display_name(self.holiday_id),
         calendar_alert.calendar_icon)
     for tradition in holiday_service.get_holiday_traditions(
             self.holiday_id):
         calendar_alert.tradition_ids.append(tradition.guid64)
     return calendar_alert
Esempio n. 13
0
 def on_first_assignment_pass_completed(self):
     super().on_first_assignment_pass_completed()
     active_holiday_id = services.active_household(
     ).holiday_tracker.active_holiday_id
     current_traditions = services.holiday_service().get_holiday_traditions(
         active_holiday_id)
     ordered_goals = [
         tradition.situation_goal for tradition in current_traditions
     ]
     current_goals = set(ordered_goals)
     saved_goals = {type(goal) for goal in self._goal_tracker.goals}
     added_goals = current_goals - saved_goals
     removed_goals = saved_goals - current_goals
     if added_goals or removed_goals:
         self._goal_tracker.update_goals(added_goals,
                                         removed_goals,
                                         goal_type_order=ordered_goals)
     self._goal_tracker.send_goal_update_to_client()
     self._progress_meter.send_update()
Esempio n. 14
0
 def _run_holiday(self, from_load=False):
     self._state = HolidayState.RUNNING
     if not from_load:
         self._holiday_end_time = services.time_service(
         ).sim_now + HolidayTuning.HOLIDAY_DURATION()
         holiday_duration = HolidayTuning.HOLIDAY_DURATION()
     else:
         holiday_duration = self._holiday_end_time - services.time_service(
         ).sim_now
     self._holiday_alarm = alarms.add_alarm(self, holiday_duration,
                                            self._holiday_end_callback)
     active_household = services.active_household()
     holiday_tracker = active_household.holiday_tracker
     if holiday_tracker.is_holiday_cancelled(self.holiday_id):
         return
     holiday_tracker.activate_holiday(self.holiday_id, from_load=from_load)
     self._active_household_id = active_household.id
     lot_decoration_service = services.lot_decoration_service()
     if lot_decoration_service is not None:
         lot_decoration_service.request_holiday_decorations(
             self, from_load=from_load)
     if from_load:
         (situation_ids, sims_needing_situations
          ) = holiday_tracker.load_holiday_situations(self.holiday_id)
         self._situation_ids.extend(situation_ids)
         if not sims_needing_situations:
             self._register_situation_ended_callbacks()
             return
     else:
         sims_needing_situations = [
             sim_info for sim_info in active_household.sim_infos
             if sim_info.is_human
         ]
     holiday_service = services.holiday_service()
     holiday_goals = list(
         tradition.situation_goal
         for tradition in holiday_service.get_holiday_traditions(
             self.holiday_id))
     for sim_info in sims_needing_situations:
         situation_id = self._create_holiday_situation(
             sim_info, holiday_goals)
     self._register_situation_ended_callbacks()
Esempio n. 15
0
 def show_holiday_end_notification(self, active_holiday_id):
     if self._max_score == self.DOES_NOT_CARE_MAX_SCORE:
         return
     holiday_notifications = HolidayTuning.HOLIDAY_NOTIFICATION_INFORMATION
     medal = self.get_level()
     sim = self.get_situation_goal_actor()
     holiday_service = services.holiday_service()
     for (notification_key,
          notification_value) in holiday_notifications.items():
         if notification_key is medal:
             holiday_end_dialog = notification_value(sim)
             holiday_name = holiday_service.get_holiday_display_name(
                 active_holiday_id)
             holiday_icon = holiday_service.get_holiday_display_icon(
                 active_holiday_id)
             holiday_end_dialog.show_dialog(
                 additional_tokens=(sim, holiday_name),
                 icon_override=IconInfoData(icon_resource=holiday_icon),
                 secondary_icon_override=IconInfoData(obj_instance=sim))
             break
Esempio n. 16
0
 def get_time_off_reason(self, sim_info, career_category, career_end_time):
     holiday_service = services.holiday_service()
     if self._state == HolidayState.SHUTDOWN or holiday_service is None:
         return CareerTimeOffReason.NO_TIME_OFF
     take_time_off = False
     if career_category == CareerCategory.School:
         take_time_off = holiday_service.get_holiday_time_off_school(
             self.holiday_id)
     elif career_category in WORK_CAREER_CATEGORIES:
         take_time_off = holiday_service.get_holiday_time_off_work(
             self.holiday_id)
     elif career_category == CareerCategory.Volunteer or career_category == CareerCategory.UniversityCourse:
         take_time_off = False
     else:
         logger.error(
             'Unexpected CareerCategory {} when determining if a holiday should give Sims time off.',
             career_category)
     if take_time_off and (
             self.is_running
             or self.get_calendar_start_time() < career_end_time):
         return HolidayTuning.HOLIDAY_TIME_OFF_REASON
     return CareerTimeOffReason.NO_TIME_OFF
Esempio n. 17
0
 def activate_holiday(self, holiday_id, from_load=False):
     if self._active_holiday_id is not None:
         holiday_manager = services.get_instance_manager(sims4.resources.Types.HOLIDAY_DEFINITION)
         active_holiday = holiday_manager.get(self._active_holiday_id)
         if active_holiday is None:
             active_holiday = self._active_holiday_id
         new_holiday = holiday_manager.get(holiday_id)
         if new_holiday is None:
             new_holiday = holiday_id
         logger.error('Trying to start holiday, {}, when holiday, {}, is already active.  Removing one holiday from the active holiday state should occur before starting a different one.', new_holiday, active_holiday)
         return
     self._active_holiday_id = holiday_id
     holiday_service = services.holiday_service()
     if self._pre_day_holiday_id == holiday_id:
         self._pre_day_holiday_id = None
         for tradition in self._traditions[holiday_id]:
             tradition.activate_holiday(from_load=from_load)
     else:
         for tradition_type in holiday_service.get_holiday_traditions(holiday_id):
             tradition = tradition_type()
             self._traditions[holiday_id].append(tradition)
             tradition.activate_holiday(from_load=from_load)
     self.send_active_holiday_info_message(DistributorOps_pb2.SendActiveHolidayInfo.START)
Esempio n. 18
0
 def _get_token(self, resolver, token_data):
     if token_data.token_type == self.TOKEN_PARTICIPANT:
         participants = token_data.objects.get_objects(resolver)
         return token_data.formatter(participants)
     if token_data.token_type == self.TOKEN_PARTICIPANT_COUNT:
         participants = token_data.objects.get_objects(resolver)
         if not participants:
             return 0
         return len(participants)
     if token_data.token_type == self.TOKEN_DEFINITION:
         return token_data.definition
     elif token_data.token_type == self.TOKEN_MONEY:
         interaction = getattr(resolver, 'interaction', None)
         if interaction is not None:
             from interactions.money_payout import MoneyLiability
             money_liability = interaction.get_liability(
                 MoneyLiability.LIABILITY_TOKEN)
             if money_liability is not None:
                 return money_liability.amounts[token_data.participant]
             return 0
     return 0
     if token_data.token_type == self.TOKEN_BUCK:
         participant = resolver.get_participant(
             participant_type=token_data.participant)
         tracker = BucksUtils.get_tracker_for_bucks_type(
             token_data.bucks_type, owner_id=participant.id)
         if not tracker:
             return 0
         return tracker.get_bucks_amount_for_type(token_data.bucks_type)
     if token_data.token_type == self.TOKEN_STATISTIC:
         participant = resolver.get_participant(
             participant_type=token_data.participant)
         if participant is not None:
             tracker = participant.get_tracker(token_data.statistic)
             if tracker is not None:
                 return tracker.get_value(token_data.statistic)
     if token_data.token_type == self.TOKEN_OBJECT_PROPERTY:
         participant = resolver.get_participant(ParticipantType.Object)
         if participant is None:
             return
         return participant.get_object_property(token_data.obj_property)
     if token_data.token_type == self.TOKEN_INTERACTION_COST:
         interaction = getattr(resolver, 'interaction', None)
         if interaction is not None:
             return interaction.get_simoleon_cost()
         affordance = getattr(resolver, 'affordance', None)
         if affordance is not None:
             return affordance.get_simoleon_cost(target=resolver.target,
                                                 context=resolver.context)
     if token_data.token_type == self.TOKEN_INTERACTION_PAYOUT:
         interaction = getattr(resolver, 'interaction', None)
         if interaction is not None:
             return interaction.get_simoleon_payout()
         affordance = getattr(resolver, 'affordance', None)
         if affordance is not None:
             return affordance.get_simoleon_payout(target=resolver.target,
                                                   context=resolver.context)
     if token_data.token_type == self.TOKEN_ASSOCIATED_CLUB:
         if resolver.interaction is not None:
             club = getattr(resolver.interaction, 'associated_club')
         else:
             club = resolver.interaction_parameters.get('associated_club')
         if club is not None:
             return club.name
     if token_data.token_type == self.TOKEN_CAREER_DATA:
         participant = resolver.get_participant(
             participant_type=token_data.participant)
         if participant is not None:
             if participant.career_tracker is None:
                 return
             career = participant.career_tracker.get_career_by_uid(
                 token_data.career_type.guid64)
             if career is not None:
                 if token_data.career_data == self.TOKEN_CAREER_DATA_CURRENT_LEVEL_NAME:
                     current_level = career.current_level_tuning
                     return current_level.get_title(participant)
                 if token_data.career_data == self.TOKEN_CAREER_DATA_CURRENT_LEVEL_SALARY:
                     current_level = career.current_level_tuning
                     return current_level.simoleons_per_hour
                 if token_data.career_data == self.TOKEN_CAREER_DATA_NEXT_LEVEL_NAME:
                     next_level = career.next_level_tuning
                     if next_level is not None:
                         return next_level.get_title(participant)
                 elif token_data.career_data == self.TOKEN_CAREER_DATA_NEXT_LEVEL_SALARY:
                     next_level = career.next_level_tuning
                     if next_level is not None:
                         return next_level.simoleons_per_hour
                 elif token_data.career_data == self.TOKEN_CAREER_DATA_PREVIOUS_LEVEL_NAME:
                     previous_level = career.previous_level_tuning
                     if previous_level is not None:
                         return previous_level.get_title(participant)
                 elif token_data.career_data == self.TOKEN_CAREER_DATA_PREVIOUS_LEVEL_SALARY:
                     previous_level = career.previous_level_tuning
                     if previous_level is not None:
                         return previous_level.simoleons_per_hour
     if token_data.token_type == self.TOKEN_GAME_COMPONENT:
         participant = resolver.get_participant(
             participant_type=token_data.participant)
         if participant is not None:
             game = participant.game_component
             if game is None:
                 return
             if token_data.game_component_data == self.TOKEN_GAME_COMPONENT_DATA_HIGH_SCORE and game.high_score is not None:
                 return game.high_score
             if token_data.game_component_data == self.TOKEN_GAME_COMPONENT_DATA_HIGH_SCORE_SIM and game.high_score_sim_ids:
                 high_score_sim_id = game.high_score_sim_ids[0]
                 return services.sim_info_manager().get(high_score_sim_id)
     if token_data.token_type == self.TOKEN_SCHOLARSHIP_LETTER:
         participant = resolver.get_participant(
             participant_type=token_data.participant)
         if participant is not None:
             scholarship_letter_component = participant.scholarship_letter_component
             if scholarship_letter_component is None:
                 return
             if token_data.scholarship_letter_component_data == self.TOKEN_SCHOLARSHIP_LETTER_APPLICANT_NAME:
                 return scholarship_letter_component.get_applicant_name()
             if token_data.scholarship_letter_component_data == self.TOKEN_SCHOLARSHIP_LETTER_DATA_AMOUNT:
                 return scholarship_letter_component.get_scholarship_amount(
                 )
             if token_data.scholarship_letter_component_data == self.TOKEN_SCHOLARSHIP_LETTER_DATA_NAME:
                 return scholarship_letter_component.get_scholarship_name()
             if token_data.scholarship_letter_component_data == self.TOKEN_SCHOLARSHIP_LETTER_DATA_DESCRIPTION:
                 return scholarship_letter_component.get_scholarship_description(
                 )
     if token_data.token_type == self.TOKEN_SICKNESS:
         participant = resolver.get_participant(
             participant_type=token_data.participant)
         if participant is None or not participant.is_sim:
             return
         current_sickness = participant.current_sickness
         if current_sickness is None:
             return
         return current_sickness.display_name(participant)
     if token_data.token_type == self.TOKEN_GLOBAL_POLICY:
         global_policy = services.global_policy_service().get_global_policy(
             token_data.global_policy, create=False)
         if global_policy is None:
             return token_data.global_policy.get_non_active_display(
                 token_data)
         return global_policy.get_active_policy_display(token_data)
     if token_data.token_type == self.TOKEN_HOLIDAY:
         active_household = services.active_household()
         if active_household.holiday_tracker is None:
             return
         holiday_id = active_household.holiday_tracker.get_active_or_upcoming_holiday(
         )
         if holiday_id is None:
             return
         return services.holiday_service().get_holiday_display_name(
             holiday_id)
     if token_data.token_type == self.TOKEN_CURRENT_TRENDS:
         trend_service = services.trend_service()
         if trend_service is None:
             return
         return trend_service.get_current_trends_loc_string()
     if token_data.token_type == self.TOKEN_LIFESTYLE_BRAND:
         participant = resolver.get_participant(
             participant_type=token_data.participant)
         lifestyle_brand_tracker = participant.lifestyle_brand_tracker
         if lifestyle_brand_tracker is None:
             return
         return lifestyle_brand_tracker.brand_name
     if token_data.token_type == self.TOKEN_PICKED_PART:
         participant = resolver.get_participant(ParticipantType.Object)
         if participant is None:
             return
         context = getattr(resolver, 'context', None)
         if context is not None and context.pick is not None:
             target_objects = participant.get_closest_parts_to_position(
                 context.pick.location, has_name=True)
             if target_objects:
                 part = target_objects.pop()
                 return part.part_name
     if token_data.token_type == self.TOKEN_CIVIC_POLICY:
         if token_data.civic_policy_data == self.TOKEN_CIVIC_POLICY_VOTING_START_TIME:
             return services.street_service().voting_open_time
         if token_data.civic_policy_data == self.TOKEN_CIVIC_POLICY_VOTING_END_TIME:
             return services.street_service().voting_close_time
     if token_data.token_type == self.TOKEN_STREET:
         if token_data.street_data == self.TOKEN_STREET_POLICY_NAME_UP_FOR_REPEAL:
             provider = token_data.street.get_street_provider()
             if provider is not None:
                 policies = provider.get_up_for_repeal_policies()
                 if policies:
                     return list(policies)[0].display_name()
         if token_data.street_data == self.TOKEN_STREET_POLICY_NAME_BALLOTED_RANDOM_LOSING:
             provider = token_data.street.get_street_provider()
             if provider is None:
                 return
             policies = list(provider.get_balloted_policies())
             if policies and len(policies) > 1:
                 winning_policy = max(
                     policies,
                     key=lambda policy: provider.get_stat_value(
                         policy.vote_count_statistic))
                 policies.remove(winning_policy)
                 random_losing_policy = random.choice(policies)
                 return random_losing_policy.display_name()
         if token_data.street_data == self.TOKEN_STREET_POLICY_NAME_BALLOTED_WINNING:
             provider = token_data.street.get_street_provider()
             if provider is None:
                 return
             policies = list(provider.get_balloted_policies())
             if policies:
                 winning_policy = max(
                     policies,
                     key=lambda policy: provider.get_stat_value(
                         policy.vote_count_statistic))
                 return winning_policy.display_name()
     if token_data.token_type == self.TOKEN_VENUE:
         if token_data.venue_data == self.TOKEN_VENUE_ACTIVE_VENUE_NAME:
             raw_active_venue_tuning_id = build_buy.get_current_venue(
                 services.current_zone_id(), allow_ineligible=True)
             raw_active_venue_tuning = services.venue_manager().get(
                 raw_active_venue_tuning_id)
             if raw_active_venue_tuning is None:
                 return
             source_venue_tuning = type(
                 services.venue_service().source_venue)
             if source_venue_tuning is raw_active_venue_tuning and source_venue_tuning.variable_venues is not None:
                 return raw_active_venue_tuning.variable_venues.variable_venue_display_name(
                 )
             return raw_active_venue_tuning.display_name
         elif token_data.venue_data == self.TOKEN_VENUE_SOURCE_VENUE_NAME:
             source_venue_tuning = type(
                 services.venue_service().source_venue)
             if source_venue_tuning is not None:
                 return source_venue_tuning.display_name
Esempio n. 19
0
def get_holiday_data(holiday_id: int, _connection=None):
    holiday_service = services.holiday_service()
    if holiday_service is None:
        return
    holiday_service.send_holiday_info_message(holiday_id)
Esempio n. 20
0
def remove_holiday(holiday_id: int, _connection=None):
    holiday_service = services.holiday_service()
    if holiday_service is None:
        return
    holiday_service.remove_a_holiday(holiday_id)
Esempio n. 21
0
 def get_active_holiday_display_icon(self):
     if self._active_holiday_id is None:
         return
     return services.holiday_service().get_holiday_display_icon(self._active_holiday_id)
Esempio n. 22
0
 def decoration_preset(self):
     return services.holiday_service().get_decoration_preset(self._holiday_id)