def turn_on(self, global_policy_id, from_load=False): self._schedule = self.schedule_data( start_callback=self.scheduled_start_action, schedule_immediate=True) if not from_load: services.global_policy_service().add_utility_effect( global_policy_id, self)
def turn_off(self, global_policy_id): household_id = services.active_household().id self.stop_action(household_id) if self._schedule is not None: self._schedule.destroy() if self._stop_schedule_entry is not None: alarms.cancel_alarm(self._stop_schedule_entry) services.global_policy_service().remove_utility_effect( global_policy_id)
def _apply_to_subject_and_target(self, participent, target, resolver, **kwargs): if self.global_policy is None: logger.error( 'Add Global Policy Progress Loot has a global policy with None value, loot from interaction {} will not be executed.', resolver._interaction) return services.global_policy_service().add_global_policy_progress( self.global_policy, self.amount, resolver=resolver)
def test(self, progress_state, tooltip): global_policies = services.global_policy_service().get_global_policies() all_policies_in_state = not self.inverse if all_policies_in_state: for policy in global_policies: if policy.progress_state != progress_state: return TestResult(False, 'Failed to pass Global Policies Test, {} is not in state {}.'.format(policy, progress_state)) else: for policy in global_policies: if policy.progress_state == progress_state: return TestResult(False, 'Failed to pass Global Policies Test, {} is in state {}.'.format(policy, progress_state)) return TestResult(True)
def test(self, progress_state, tooltip): global_policy_service = services.global_policy_service() if not self.policies and progress_state != GlobalPolicyProgressEnum.NOT_STARTED: return TestResult(False, "Trying to test for policies that have been started when those policies don't exist in current pack configuration.") for policy in self.policies: global_policy = global_policy_service.get_global_policy(policy, create=False) if global_policy is None: if progress_state != GlobalPolicyProgressEnum.NOT_STARTED: return TestResult(False, 'Global Policy {} has never been started, has no progress state.'.format(global_policy)) if global_policy.progress_state != progress_state: return TestResult(False, 'Global Policy {} is in state {} not the specified state {}.'.format(global_policy, global_policy.progress_state, progress_state)) elif global_policy.progress_state != progress_state: return TestResult(False, 'Global Policy {} is in state {} not the specified state {}.'.format(global_policy, global_policy.progress_state, progress_state)) return TestResult(True)
def generate_global_policy_data(): policy_data = [] for policy in services.global_policy_service().get_global_policies(): entry = { 'policy': repr(policy).split('sims4.tuning.instances.', 1)[1].split('object', 1)[0], 'progress_value': str(policy.progress_value) + '/' + str(policy.progress_max_value), 'decay_days': 0 if policy.decay_handler is None or policy.decay_handler.when is None else str(policy.decay_handler.when - services.time_service().sim_now), 'progress_state': str(policy.progress_state) } policy_data.append(entry) return policy_data
def remove_global_policy_value_mod(self): if self._active_global_policy_modifiers is None: return global_policy_service = services.global_policy_service() if global_policy_service is None: return total_percent_decrease = 1.0 policies_to_remove = [] enacted_policies = global_policy_service.get_enacted_global_policies() for modifying_policy in self._active_global_policy_modifiers: if modifying_policy not in enacted_policies: total_percent_decrease += self.global_policy_value_mapping.get( type(modifying_policy)) services.get_event_manager().register_with_custom_key( self, TestEvent.GlobalPolicyProgress, type(modifying_policy)) policies_to_remove.append(modifying_policy) for policy_to_remove in policies_to_remove: self._active_global_policy_modifiers.remove(policy_to_remove) if total_percent_decrease != 0: self.base_value = int(self.base_value / total_percent_decrease)
def add_global_policy_value_mod(self): if not self.global_policy_value_mapping: return global_policy_service = services.global_policy_service() if global_policy_service is None: return total_percent_increase = 0 active_global_policy_modifiers = self._active_global_policy_modifiers is not None for enacted_policy in global_policy_service.get_enacted_global_policies( ): if active_global_policy_modifiers and enacted_policy in self._active_global_policy_modifiers: continue policy_percent_increase = self.global_policy_value_mapping.get( type(enacted_policy)) if policy_percent_increase: if not active_global_policy_modifiers: self._active_global_policy_modifiers = [enacted_policy] else: self._active_global_policy_modifiers.append(enacted_policy) services.get_event_manager().register_with_custom_key( self, TestEvent.GlobalPolicyProgress, type(enacted_policy)) total_percent_increase += policy_percent_increase self.base_value += int(self.base_value * total_percent_increase)
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
def turn_off(self, _): services.global_policy_service().remove_bill_reduction( self.percent_reduction.reduction_reason)
def turn_on(self, _, from_load=False): services.global_policy_service().add_bill_reduction( self.percent_reduction.reduction_reason, self.percent_reduction.reduction_amount)
def set_global_policy_progress( policy: TunableInstanceParam(sims4.resources.Types.SNIPPET), progress_amount: int, _connection=None): services.global_policy_service().add_global_policy_progress( policy, progress_amount)
def decay_policy(self, timeline): yield timeline.run_child(SleepElement(TimeSpan.ZERO)) services.global_policy_service().set_global_policy_progress( self, self.progress_initial_value) self.decay_handler = None self.apply_policy_loot_to_active_sim(self.loot_on_decay)