def put_on_cooldown(self): delta = self._cur_state.current_score_delta if delta > 0: end_notification = self._light_win_end_notification( services.active_sim_info()) end_notification.show_dialog() for sim in self.all_sims_in_situation_gen(): if sim.sim_info.is_selectable: if self.sim_has_job( sim, self._cur_state. _light_sim_job_and_default_role_state.job): resolver = SingleSimResolver(sim.sim_info) self._light_win_rewards.apply_to_resolver(resolver) self._change_state(self._light_win_state()) elif delta < 0: end_notification = self._dark_win_end_notification( services.active_sim_info()) end_notification.show_dialog() for sim in self.all_sims_in_situation_gen(): if sim.sim_info.is_selectable: if self.sim_has_job( sim, self._cur_state. _dark_sim_job_and_default_role_state.job): resolver = SingleSimResolver(sim.sim_info) self._dark_win_rewards.apply_to_resolver(resolver) self._change_state(self._dark_win_state()) else: end_notification = self._tie_end_notification( services.active_sim_info()) end_notification.show_dialog() for sim in self.all_sims_in_situation_gen(): if sim.sim_info.is_selectable: resolver = SingleSimResolver(sim.sim_info) self._tie_rewards.apply_to_resolver(resolver) self._change_state(self._tie_state())
def timer_expired(self): for sim_info in services.active_household(): resolver = DoubleSimResolver(sim_info, self.owner._neighbor_sim.sim_info) for loot_action in self._early_exit_loot: loot_action.apply_to_resolver(resolver) resolver = DoubleSimResolver(services.active_sim_info(), self.owner._neighbor_sim.sim_info) early_exit_notification = self._early_exit_notification( services.active_sim_info(), resolver=resolver) early_exit_notification.show_dialog() self.owner._self_destruct()
def show_add_club_member_picker(criteria_data: str, max_selectable: int = 8, *excluded_sim_ids: int, _connection=None): club_service = _get_club_service(_connection) if club_service is None: return False criteria_msg = Clubs_pb2.ClubBuildingInfo() text_format.Merge(criteria_data, criteria_msg) criterias = [ club_service._load_specific_criteria(data) for data in criteria_msg.criterias ] active_sim_info = services.active_sim_info() sim_filter_service = services.sim_filter_service() dialog = ClubTunables.CLUB_ADD_MEMBER_PICKER_DIALOG( services.active_sim_info(), club_building_info=criteria_msg, max_selectable=max_selectable) def get_sim_filter_gsi_name(): return 'Club Command: Add Club Member' valid_sim_infos = [] for sim_info in services.sim_info_manager().get_all(): if sim_info.sim_id in excluded_sim_ids: continue if sim_info.is_baby: continue if sim_info.is_ghost and not sim_info.is_selectable: continue if not club_service.can_sim_info_join_more_clubs(sim_info): continue if not all(criteria.test_sim_info(sim_info) for criteria in criterias): continue results = sim_filter_service.submit_filter( ClubTunables.CLUB_ADD_MEMBER_FILTER, callback=None, requesting_sim_info=active_sim_info, sim_constraints=(sim_info.sim_id, ), allow_yielding=False, gsi_source_fn=get_sim_filter_gsi_name) if results: valid_sim_infos.append((sim_info, results[0].score)) for (sim_info, _) in sorted(valid_sim_infos, key=operator.itemgetter(1), reverse=True)[:ClubTunables.CLUB_ADD_MEMBER_CAP]: dialog_row = ClubSimPickerRow(sim_info.sim_id) dialog.add_row(dialog_row) dialog.show_dialog(additional_tokens=(max_selectable, )) return True
def _end_venue_behavior(self): if self.zone_director is not None: venue_service = services.venue_service() if type(venue_service.get_zone_director()) is self.zone_director: if self.ending_notification is not None: dialog = self.ending_notification( services.active_sim_info()) dialog.show_dialog() venue_service.change_zone_director( venue_service.active_venue.zone_director(), True) elif self.ending_notification is not None: dialog = self.ending_notification(services.active_sim_info()) dialog.show_dialog()
def move_sim_inventory_to_household(self): active_sim = services.get_active_sim() active_sim_info = services.active_sim_info() active_sim.inventory_component.push_items_to_household_inventory() self._show_dialog( "Moved all items in {} {}'s inventory to household inventory.". format(active_sim_info.first_name, active_sim_info.last_name))
def _get_default_guest_list(self): host_sim_id = 0 if self.set_host_as_active_sim: active_sim_info = services.active_sim_info() if active_sim_info is not None: host_sim_id = active_sim_info.sim_id return SituationGuestList(invite_only=True, host_sim_id=host_sim_id)
def _remove_vfx_mask(self, trait): if trait.vfx_mask is None: return for mask in trait.vfx_mask: self.trait_vfx_mask ^= mask if self._sim_info is services.active_sim_info(): generate_mask_message(self.trait_vfx_mask, self._sim_info)
def travel_to_venue(self): if self._zone_id is None: logger.error('Failed to travel to venue') return active_sim_info = services.active_sim_info() active_sim = active_sim_info.get_sim_instance( allow_hidden_flags=ALL_HIDDEN_REASONS_EXCEPT_UNINITIALIZED) if active_sim is None: return lot_id = None zone = services.get_zone_manager().get(self._zone_id) if zone is None: lot_id = services.get_persistence_service( ).get_lot_id_from_zone_id(self._zone_id) else: lot_id = zone.lot.lot_id if lot_id is None: return pick = PickInfo(pick_type=PickType.PICK_TERRAIN, lot_id=lot_id, ignore_neighborhood_id=True) context = interactions.context.InteractionContext( active_sim, interactions.context.InteractionContext. SOURCE_SCRIPT_WITH_USER_INTENT, interactions.priority.Priority.High, insert_strategy=interactions.context.QueueInsertStrategy.NEXT, pick=pick) active_sim.push_super_affordance( VenueEventDramaNode.GO_TO_VENUE_ZONE_INTERACTION, None, context)
def get_predefined_guest_list(cls): active_sim_info = services.active_sim_info() door_knocker_results = services.sim_filter_service().submit_filter(cls._door_knocker_situation_job.filter, callback=None, requesting_sim_info=active_sim_info, allow_yielding=False, gsi_source_fn=cls.get_sim_filter_gsi_name) if not door_knocker_results: return door_knocker = random.choice(door_knocker_results) guest_list = SituationGuestList(invite_only=True, host_sim_id=door_knocker.sim_info.sim_id, filter_requesting_sim_id=active_sim_info.sim_id) guest_list.add_guest_info(SituationGuestInfo(door_knocker.sim_info.sim_id, cls._door_knocker_situation_job, RequestSpawningOption.DONT_CARE, BouncerRequestPriority.EVENT_VIP, expectation_preference=True)) blacklist = set() blacklist.add(door_knocker.sim_info.sim_id) kava_carrier_results = services.sim_filter_service().submit_filter(cls._fruitcake_bearer_situation_job.filter, callback=None, requesting_sim_info=active_sim_info, allow_yielding=False, blacklist_sim_ids=blacklist, gsi_source_fn=cls.get_sim_filter_gsi_name) if not kava_carrier_results: return kava_carrier = random.choice(kava_carrier_results) guest_list.add_guest_info(SituationGuestInfo(kava_carrier.sim_info.sim_id, cls._fruitcake_bearer_situation_job, RequestSpawningOption.DONT_CARE, BouncerRequestPriority.EVENT_VIP, expectation_preference=True)) blacklist.add(kava_carrier.sim_info.sim_id) lei_carrier_results = services.sim_filter_service().submit_filter(cls._lei_carrier_situation_job.filter, callback=None, requesting_sim_info=active_sim_info, allow_yielding=False, blacklist_sim_ids=blacklist, gsi_source_fn=cls.get_sim_filter_gsi_name) if not lei_carrier_results: return lei_carrier = random.choice(lei_carrier_results) guest_list.add_guest_info(SituationGuestInfo(lei_carrier.sim_info.sim_id, cls._lei_carrier_situation_job, RequestSpawningOption.DONT_CARE, BouncerRequestPriority.EVENT_VIP, expectation_preference=True)) blacklist.add(lei_carrier.sim_info.sim_id) other_neighbors_results = services.sim_filter_service().submit_filter(cls._other_neighbors_job.filter, callback=None, requesting_sim_info=active_sim_info, allow_yielding=False, blacklist_sim_ids=blacklist, gsi_source_fn=cls.get_sim_filter_gsi_name) if not other_neighbors_results: return guest_list if len(other_neighbors_results) > cls._number_of_neighbors: neighbors = random.sample(other_neighbors_results, cls._number_of_neighbors) else: neighbors = other_neighbors_results for neighbor in neighbors: guest_list.add_guest_info(SituationGuestInfo(neighbor.sim_info.sim_id, cls._other_neighbors_job, RequestSpawningOption.DONT_CARE, BouncerRequestPriority.EVENT_VIP, expectation_preference=True)) return guest_list
def start_situation(self): super().start_situation() self._change_state(self.contest_state()) if self.start_notification is not None: start_notification = self.start_notification( services.active_sim_info()) start_notification.show_dialog()
def show_festival_info(cls): if cls.festival_dynamic_sign_info is None: return ui_info = cls.festival_dynamic_sign_info festival_info = UI_pb2.DynamicSignView() festival_info.drama_node_guid = cls.guid64 festival_info.name = ui_info.festival_name lot_id = cls.get_travel_lot_id() persistence_service = services.get_persistence_service() zone_id = persistence_service.resolve_lot_id_into_zone_id(lot_id, ignore_neighborhood_id=True) zone_protobuff = persistence_service.get_zone_proto_buff(zone_id) if zone_protobuff is not None: festival_info.venue = LocalizationHelperTuning.get_raw_text(zone_protobuff.name) festival_info.time = ui_info.festival_time festival_info.image = sims4.resources.get_protobuff_for_key(ui_info.display_image) festival_info.background_image = sims4.resources.get_protobuff_for_key(ui_info.background_image) festival_info.action_label = ui_info.travel_to_festival_text running_nodes = services.drama_scheduler_service().get_running_nodes_by_class(cls) active_sim_info = services.active_sim_info() if all(active_node.is_during_pre_festival() for active_node in running_nodes): festival_info.disabled_tooltip = ui_info.festival_not_started_tooltip elif any(active_node.is_on_festival_street() for active_node in running_nodes): festival_info.disabled_tooltip = ui_info.on_street_tooltip elif active_sim_info.is_in_travel_group(): festival_info.disabled_tooltip = ui_info.on_vacation_tooltip for activity in ui_info.activity_info: with ProtocolBufferRollback(festival_info.activities) as activity_msg: activity_msg.name = activity.activity_name activity_msg.description = activity.activity_description activity_msg.icon = create_icon_info_msg(IconInfoData(activity.icon)) distributor = Distributor.instance() distributor.add_op(active_sim_info, GenericProtocolBufferOp(Operation.DYNAMIC_SIGN_VIEW, festival_info))
def _get_active_household_provider(self): active_sim = services.active_sim_info() if active_sim is None or active_sim.household is None or active_sim.household.home_zone_id == 0: return street = get_street_instance_from_zone_id( active_sim.household.home_zone_id) return self.get_provider(street)
def show_notification(self, recipients=DEFAULT, **kwargs): if not self.allow_autonomous and self.interaction.is_autonomous: return if recipients is DEFAULT: if self.recipient_subject == ParticipantType.ActiveHousehold: recipients = (services.active_sim_info(), ) else: recipients = self.interaction.get_participants( self.recipient_subject) simless = self.interaction.simless for recipient in recipients: if not simless: if recipient.is_selectable: resolver = self.interaction.get_resolver() dialog = self.dialog(recipient, resolver=resolver) if dialog is not None: dialog.show_dialog(**kwargs) if self.limit_to_one_notification: break resolver = self.interaction.get_resolver() dialog = self.dialog(recipient, resolver=resolver) if dialog is not None: dialog.show_dialog(**kwargs) if self.limit_to_one_notification: break
def on_state_activated(self, reader=None, preroll_time_override=None): super().on_state_activated(reader=reader, preroll_time_override=preroll_time_override) for situation in self._owner.get_running_festival_situations(): situation.put_on_cooldown() notification = self.notification(services.active_sim_info()) notification.show_dialog()
def remove_employee(self, sim_info): self._employee_manager.remove_employee(sim_info) self.send_min_employee_req_met_update_message() if self.should_show_no_way_to_make_money_notification(): active_sim_info = services.active_sim_info() notification = self.tuning_data.no_way_to_make_money_notification(active_sim_info, resolver=SingleSimResolver(active_sim_info)) notification.show_dialog()
def _setup_gates(self, object_manager): active_sim_info = services.active_sim_info() gates = object_manager.get_objects_matching_tags( (TempleTuning.GATE_TAG, )) for gate in gates: if not gate.state_component: logger.error( 'Trying to randomize temple gates but the gate, {}, has no state component. Ignoring it.', gate) else: (front_position, back_position) = gate.get_door_positions() front_plex_id = build_buy.get_location_plex_id( front_position, gate.level) back_plex_id = build_buy.get_location_plex_id( back_position, gate.level) if front_plex_id == 0 and back_plex_id == 0: logger.error( "Found a gate, {}, but it doesn't seem to have a plex on either side. Ignoring it.", gate) else: belonging_room = min(front_plex_id, back_plex_id) self._rooms[belonging_room].gate = gate gate_state_value = self._get_random_gate_state( belonging_room) gate_state = TempleTuning.GATE_STATE if not gate.has_state(gate_state): logger.error( 'Trying to apply a random state to a temple gate but the gate, {}, has no state value, {} for state {}.', gate, gate_state_value, gate_state) else: gate.set_state(gate_state, gate_state_value) resolver = SingleActorAndObjectResolver( active_sim_info, gate, source=self) TempleTuning.GATE_LOCK_LOOT.apply_to_resolver(resolver)
def _add_vfx_mask(self, trait, send_op=False): if trait.vfx_mask is None: return for mask in trait.vfx_mask: self.trait_vfx_mask |= mask if send_op and self._sim_info is services.active_sim_info(): generate_mask_message(self.trait_vfx_mask, self._sim_info)
def get_hireable_employees(employee_type: BusinessEmployeeType, _connection=None): automation_output = sims4.commands.AutomationOutput(_connection) automation_output('GetHireableEmployees; Status:Begin') business_services = services.business_service() business_manager = business_services.get_business_manager_for_zone() if business_manager is not None: employee_data = business_manager.tuning_data.employee_data_map.get( employee_type) if employee_data is not None: sim_info = services.active_sim_info() def get_sim_filter_gsi_name(): return '[Automation] Business Command: Get New Possible Employees' results = services.sim_filter_service().submit_matching_filter( number_of_sims_to_find=employee_data. potential_employee_pool_size, sim_filter=employee_data.potential_employee_pool_filter, requesting_sim_info=sim_info, allow_yielding=False, gsi_source_fn=get_sim_filter_gsi_name) for result in results: automation_output( 'GetHireableEmployees; Status:Data, SimId:{}'.format( result.sim_info.id)) automation_output('GetHireableEmployees; Status:End')
def destroy_travel_group_and_release_zone(self, travel_group, last_sim_info=None, return_objects=False): if travel_group.played: if last_sim_info is None: leader_sim_info = services.active_sim_info() if leader_sim_info not in travel_group: leader_sim_info = next(iter(travel_group), None) else: leader_sim_info = last_sim_info with telemetry_helper.begin_hook(travel_group_telemetry_writer, TELEMETRY_HOOK_TRAVEL_GROUP_END, sim_info=leader_sim_info) as hook: hook.write_int(TELEMETRY_TRAVEL_GROUP_ID, travel_group.id) hook.write_int(TELEMETRY_TRAVEL_GROUP_ZONE_ID, travel_group.zone_id) hook.write_int(TELEMETRY_TRAVEL_GROUP_SIZE, len(travel_group)) hook.write_int( TELEMETRY_TRAVEL_GROUP_DURATION, int(travel_group.duration_time_span.in_minutes())) for sim_info in tuple(travel_group): travel_group.remove_sim_info(sim_info, destroy_on_empty=False) self.release_zone(travel_group.zone_id) services.get_persistence_service().del_travel_group_proto_buff( travel_group.id) services.travel_group_manager().remove(travel_group) if return_objects: self.return_objects_left_in_destination_world() return True
def _show_notification(self): if self.notification is None: return if self._shown_notification: return dialog = self.notification(services.active_sim_info()) dialog.show_dialog() self._shown_notification = True
def situation_meets_starting_requirements(cls, **kwargs): neighbor_results = cls.get_filter_results_for_job() for neighbor_result in neighbor_results: resolver = DoubleSimResolver(services.active_sim_info(), neighbor_result.sim_info) if cls.scheduling_tests.run_tests(resolver): return True return False
def situation_meets_starting_requirements(cls, **kwargs): if not cls.starting_requirements: return True else: resolver = SingleSimResolver(services.active_sim_info()) if not cls.starting_requirements.run_tests(resolver): return False return True
def _apply_lot_load_loot(self, object_manager): active_sim_info = services.active_sim_info() for (tag, loots) in self.lot_load_loot.items(): objects = object_manager.get_objects_matching_tags((tag,)) for obj in objects: resolver = SingleActorAndObjectResolver(active_sim_info, obj, source=self) for loot in loots: loot.apply_to_resolver(resolver)
def on_remove(self): if self._should_show_end_notification(): (resolver, additional_tokens ) = self._get_end_notification_resolver_and_tokens() end_notification = self.end_notification( services.active_sim_info(), resolver=resolver) end_notification.show_dialog(additional_tokens=additional_tokens) super().on_remove()
def request_club_invite(club_id: int, _connection=None): sim_info = services.active_sim_info() if sim_info is None: return club_service = services.get_club_service() if club_service is None: return club = club_service.get_club_by_id(club_id) if club is None: return if any(club_member.is_selectable for club_member in club.members): club.show_club_notification( sim_info, ClubTunables.CLUB_GATHERING_DIALOG_REQUEST_INVITE_ACTIVE_SIM) elif club in club_service.clubs_to_gatherings_map: club.show_club_notification( sim_info, ClubTunables.CLUB_GATHERING_DIALOG_REQUEST_INVITE_CURRENT_LOT) else: club_hangout_zone_id = club.get_hangout_zone_id() if club.hangout_setting == ClubHangoutSetting.HANGOUT_LOT: current_region = services.current_region() hangout_region = get_region_instance_from_zone_id( club_hangout_zone_id) if not current_region.is_region_compatible(hangout_region): club.show_club_notification( sim_info, ClubTunables. CLUB_GATHERING_DIALOG_REQUEST_INVITE_UNAVAILABLE, target_sim_id=club.leader.sim_id) return elif not club_hangout_zone_id: if services.active_lot_id() == services.active_household_lot_id(): def on_response(dialog): if dialog.accepted: club_service.start_gathering( club, host_sim_id=sim_info.sim_id, invited_sims=(sim_info, ), ignore_zone_validity=True) club.show_club_notification( sim_info, ClubTunables.CLUB_GATHERING_DIALOG_REQUEST_INVITE_NO_LOT, target_sim_id=club.leader.sim_id, on_response=on_response) else: club.show_club_notification( sim_info, ClubTunables. CLUB_GATHERING_DIALOG_REQUEST_INVITE_NO_LOT_NOT_HOME, target_sim_id=club.leader.sim_id) return club.show_club_gathering_dialog( sim_info, flavor_text=ClubTunables.CLUB_GATHERING_DIALOG_TEXT_REQUEST_INVITE, start_source=ClubGatheringStartSource.APPLY_FOR_INVITE)
def _show_appropriate_open_business_notification(self): if self.is_owned_by_npc or not self.is_owner_household_active: return active_sim_info = services.active_sim_info() if self.should_show_no_way_to_make_money_notification(): notification = self.tuning_data.no_way_to_make_money_notification(active_sim_info, resolver=SingleSimResolver(active_sim_info)) else: notification = self.tuning_data.open_business_notification(active_sim_info, resolver=SingleSimResolver(active_sim_info)) notification.show_dialog()
def _adjust_star_rating_value(self, delta, send_update_message=True): previous_whole_star_rating = int(self.get_star_rating()) self._star_rating_value = sims4.math.clamp(self.tuning_data.min_and_max_star_rating_value.lower_bound, self._star_rating_value + delta, self.tuning_data.min_and_max_star_rating_value.upper_bound) current_whole_star_rating = int(self.get_star_rating()) if current_whole_star_rating > previous_whole_star_rating and current_whole_star_rating in self.tuning_data.star_rating_to_screen_slam_map: screen_slam = self.tuning_data.star_rating_to_screen_slam_map.get(current_whole_star_rating) screen_slam.send_screen_slam_message(services.active_sim_info()) if send_update_message: self._send_review_update_message()
def _get_placement_resolver(self): additional_participants = {} if self._target_id is not None: target = services.object_manager().get(self._target_id) additional_participants[ParticipantType.Object] = (target,) if target is not None: if target.is_sim: additional_participants[ParticipantType.TargetSim] = (target.sim_info,) return SingleSimResolver(services.active_sim_info(), additional_participants=additional_participants)
def handle_event(self, sim_info, event, resolver): if event == TestEvent.InteractionComplete: if resolver(self.owner.expel_smog): self._change_state(self.owner.expelling_smog_state()) elif resolver(self.owner.leave): if self.owner.leave_notification is not None: notification = self.owner.leave_notification(services.active_sim_info(), resolver=SingleSimResolver(services.active_sim_info())) notification.show_dialog() self._change_state(self.owner.leaving_state())
def get_predefined_guest_list(cls): active_sim_info = services.active_sim_info() fire_brigade_volunteers = services.sim_filter_service().submit_matching_filter(number_of_sims_to_find=cls.number_of_volunteers, sim_filter=cls.fire_brigade_job.filter, requesting_sim_info=active_sim_info, allow_yielding=False, blacklist_sim_ids={sim_info.sim_id for sim_info in services.active_household()}, gsi_source_fn=cls.get_sim_filter_gsi_name) if len(fire_brigade_volunteers) < cls.number_of_volunteers: return guest_list = SituationGuestList(invite_only=True, host_sim_id=fire_brigade_volunteers[0].sim_info.sim_id, filter_requesting_sim_id=active_sim_info.sim_id) for volunteer in fire_brigade_volunteers: guest_list.add_guest_info(SituationGuestInfo(volunteer.sim_info.sim_id, cls.fire_brigade_job, RequestSpawningOption.DONT_CARE, BouncerRequestPriority.EVENT_VIP, expectation_preference=True)) return guest_list