def show_employee_management_dialog(opt_sim: OptionalSimInfoParam = None, _connection=None): sim_info = get_optional_target(opt_sim, target_type=OptionalSimInfoParam, _connection=_connection) if sim_info is None: return False business_services = services.business_service() business_manager = business_services.get_business_manager_for_zone() if business_manager is None: return False business_tracker = business_services.get_business_tracker_for_household( sim_info.household_id, business_manager.business_type) msg = Business_pb2.ManageEmployeesDialog() msg.hiring_sim_id = sim_info.sim_id def get_sim_filter_gsi_name(): return 'Business Command: Get New Possible Employees' for (business_employee_type, business_employee_data ) in business_manager.tuning_data.employee_data_map.items(): with ProtocolBufferRollback(msg.jobs) as employee_job_msg: total_unlocked_slots = business_employee_data.employee_count_default + business_tracker.get_additional_employee_slots( business_employee_type) employee_job_msg.open_slots = total_unlocked_slots - business_manager.get_employee_count( business_employee_type) employee_job_msg.locked_slots = business_employee_data.employee_count_max - total_unlocked_slots employee_job_msg.job_type = int(business_employee_type) employee_job_msg.job_name = business_employee_data.job_name employee_job_msg.job_icon = create_icon_info_msg( IconInfoData(business_employee_data.job_icon)) current_employees = business_manager.get_employees_by_type( business_employee_type) sim_info_manager = services.sim_info_manager() for employee_sim_id in current_employees: employee_sim_info = sim_info_manager.get(employee_sim_id) with ProtocolBufferRollback( employee_job_msg.employees) as employee_msg: business_manager.populate_employee_msg( employee_sim_info, employee_msg, business_employee_type, business_employee_data) results = services.sim_filter_service().submit_matching_filter( number_of_sims_to_find=business_employee_data. potential_employee_pool_size, sim_filter=business_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: with ProtocolBufferRollback( employee_job_msg.available_sims) as employee_msg: business_manager.populate_employee_msg( result.sim_info, employee_msg, business_employee_type, business_employee_data) op = shared_messages.create_message_op( msg, Consts_pb2.MSG_MANAGE_EMPLOYEES_DIALOG) Distributor.instance().add_op_with_no_owner(op)
def get_owned_retail_lot_count_message(_connection=None): lot_count = 0 active_household = services.active_household() if active_household is not None: retail_tracker = services.business_service( ).get_business_tracker_for_household(active_household.id, BusinessType.RETAIL) if retail_tracker is not None: lot_count = len(retail_tracker.business_managers) lot_count_msg = UI_pb2.OwnedRetailLotCountMessage() lot_count_msg.owned_lot_count = lot_count op = shared_messages.create_message_op( lot_count_msg, Consts_pb2.MSG_RETAIL_OWNED_LOT_COUNT) Distributor.instance().add_op_with_no_owner(op)
def get_household_display_info(lot_id, _connection=None): persistence_service = services.get_persistence_service() household_display_info = UI_pb2.HouseholdDisplayInfo() household_id = persistence_service.get_household_id_from_lot_id(lot_id) if household_id is None: household_id = 0 household = services.household_manager().get(household_id) if household is None: household_id = 0 else: household_display_info.at_home_sim_ids.extend(household.get_sims_at_home()) household_display_info.household_id = household_id household_display_info.lot_id = lot_id op = shared_messages.create_message_op(household_display_info, Consts_pb2.MSG_UI_HOUSEHOLD_DISPLAY_INFO) Distributor.instance().add_op_with_no_owner(op)
def get_household_display_info(lot_id, _connection=None): persistence_service = services.get_persistence_service() household_display_info = UI_pb2.HouseholdDisplayInfo() household_id = persistence_service.get_household_id_from_lot_id(lot_id) if household_id is None: household_id = 0 household = services.household_manager().get(household_id) if household is None: household_id = 0 else: household_display_info.at_home_sim_ids.extend( household.get_sims_at_home()) household_display_info.household_id = household_id household_display_info.lot_id = lot_id op = shared_messages.create_message_op( household_display_info, Consts_pb2.MSG_UI_HOUSEHOLD_DISPLAY_INFO) Distributor.instance().add_op_with_no_owner(op)
def get_sims_available_for_travel(opt_sim_id: OptionalTargetParam = None, _connection=None): actor_sim = get_optional_target(opt_sim_id, _connection) if actor_sim is not None: actor_sim_info = actor_sim.sim_info else: if not opt_sim_id: sims4.commands.output( 'No sim_info id specified for travel.get_sims_available', _connection) return False actor_sim_info = services.sim_info_manager().get(opt_sim_id) if actor_sim_info is None: sims4.commands.output('Invalid sim_info id: {}'.format(opt_sim_id), _connection) return False sim_filter = TravelTuning.TRAVEL_AVAILABILITY_SIM_FILTER filtered_sims = services.sim_filter_service().submit_filter( sim_filter, None, sim_constraints=None, requesting_sim_info=actor_sim_info, blacklist_sim_ids=EMPTY_SET, allow_yielding=False) msg = UI_pb2.AvailableSimsForTravel() msg.actor_sim_id = actor_sim_info.id msg.sim_ids_for_travel.extend( [filter_result.sim_info.id for filter_result in filtered_sims]) active_household_id = services.active_household_id() for filter_result in filtered_sims: with ProtocolBufferRollback(msg.available_sims) as sim_data: sim_info = filter_result.sim_info sim_data.sim_id = sim_info.id sim_data.is_active_household = sim_info.household_id == active_household_id sim_data.household_id = sim_info.household_id sim_data.is_at_work = sim_info.career_tracker.currently_at_work sim_data.zone_id = sim_info.zone_id sim_data.age = sim_info.age op = shared_messages.create_message_op( msg, Consts_pb2.MSG_AVAILABLE_SIMS_FOR_TRAVEL) Distributor.instance().add_op_with_no_owner(op) return True
def show_extend_vacation_dialog(self): if services.current_zone().ui_dialog_service.auto_respond: self.end_vacation() else: msg = UI_pb2.ExtendVacation() msg.travel_group_id = self.id msg.zone_id = self.zone_id for sim_info in self: msg.sim_ids.append(sim_info.id) delta_time = self.end_timestamp - services.time_service().sim_now delta_time = delta_time if delta_time > TimeSpan.ZERO else TimeSpan.ZERO days_remaining = float(delta_time.in_days()) msg.days_remaining = days_remaining persistence_service = services.get_persistence_service() zone_data = persistence_service.get_zone_proto_buff(self.zone_id) msg.household_description_id = persistence_service.get_house_description_id( self.zone_id) msg.lot_name = zone_data.name msg.lot_daily_cost = services.current_zone( ).lot.furnished_lot_value op = shared_messages.create_message_op( msg, Consts_pb2.MSG_EXTEND_VACATION) Distributor.instance().add_op_with_no_owner(op)
def send_perks_list_for_bucks_type(self, bucks_type, sort_key=None, reverse=True): bucks_msg = Dialog_pb2.GameplayPerkList() bucks_msg.bucks_type = bucks_type resolver = SingleSimResolver(self._owner) perk_messages = [] for perk in self.all_perks_of_type_gen(bucks_type): perk_message = Dialog_pb2.GameplayPerk() perk_message.id = perk.guid64 perk_message.display_name = perk.display_name() perk_message.description = self._get_description_string(perk) perk_message.icon = create_icon_info_msg( IconInfoData(icon_resource=perk.icon.key)) perk_message.cost = perk.unlock_cost if bucks_type not in self._bucks: self._bucks[bucks_type] = 0 perk_message.affordable = self._bucks[ bucks_type] >= perk.unlock_cost perk_message.ui_display_flags = perk.ui_display_flags if perk.required_unlocks is not None: locked = False for required_perk in perk.required_unlocks: if not self.is_perk_unlocked(required_perk): locked = True perk_message.required_perks.append(required_perk.guid64) perk_message.locked = locked result = perk.available_for_puchase_tests.run_tests( resolver=resolver, search_for_tooltip=True) if not result: perk_message.locked_from_tests = True if result.tooltip is not None: perk_message.disabled_tooltip = result.tooltip(self._owner) unlocked = self.is_perk_unlocked(perk) if unlocked: perk_message.purchased = unlocked timestamp = self._get_perk_unlock_timestamp(perk) if timestamp is not None: perk_message.unlock_timestamp = timestamp if not unlocked: if self.is_perk_recently_locked(perk): perk_message.recently_locked = True if unlocked: disabled_tooltip = self.get_disabled_tooltip_for_perk(perk) if disabled_tooltip is not None: perk_message.disabled_tooltip = disabled_tooltip if perk.lock_on_purchase: for perk_to_lock in perk.lock_on_purchase: perk_message.lock_on_purchase.append(perk_to_lock.guid64) if perk.next_level_perk is not None: perk_message.next_perk_id = perk.next_level_perk.guid64 if perk.conflicting_perks is not None: for conflicting_perk in perk.conflicting_perks: perk_message.conflicting_perks.append( conflicting_perk.guid64) perk_messages.append(perk_message) if sort_key is not None: perk_messages.sort(key=sort_key, reverse=reverse) bucks_msg.perk_list.extend(perk_messages) op = shared_messages.create_message_op( bucks_msg, Consts_pb2.MSG_GAMEPLAY_PERK_LIST) Distributor.instance().add_op_with_no_owner(op)
def show_retail_dialog(opt_sim: OptionalSimInfoParam = None, _connection=None): sim_info = get_optional_target(opt_sim, target_type=OptionalSimInfoParam, _connection=_connection) if sim_info is None: return False business_manager = services.business_service( ).get_business_manager_for_zone() if business_manager is None or business_manager.business_type != BusinessType.RETAIL: return False msg = Dialog_pb2.RetailManageEmployeesDialog() msg.hiring_sim_id = sim_info.sim_id def populate_employee_msg(sim_info, employee_msg): employee_msg.sim_id = sim_info.sim_id for skill_type in business_manager.EMPLOYEE_SKILLS: with ProtocolBufferRollback( employee_msg.skill_data) as employee_skill_msg: employee_skill_msg.skill_id = skill_type.guid64 employee_skill_msg.curr_points = int( sim_info.get_stat_value(skill_type)) if business_manager.is_employee(sim_info): satisfaction_stat = sim_info.get_statistic( business_manager.EMPLOYEE_SATISFACTION_COMMODITY) statisfaction_state_index = satisfaction_stat.get_state_index() if statisfaction_state_index is not None: employee_msg.satisfaction_string = satisfaction_stat.states[ statisfaction_state_index].buff.buff_type.buff_name( sim_info) career_level = business_manager.get_employee_career_level(sim_info) employee_msg.pay = career_level.simoleons_per_hour career = business_manager.get_employee_career(sim_info) employee_msg.current_career_level = career.level employee_msg.max_career_level = len( career.current_track_tuning.career_levels) - 1 else: desired_level = business_manager.get_employee_desired_career_level( sim_info) career_level = business_manager.RETAIL_CAREER.start_track.career_levels[ desired_level] employee_msg.pay = career_level.simoleons_per_hour employee_msg.current_career_level = desired_level employee_msg.max_career_level = len( business_manager.RETAIL_CAREER.start_track.career_levels) - 1 for employee_sim_info in business_manager.get_employees_gen(): with ProtocolBufferRollback(msg.employees) as employee_msg: populate_employee_msg(employee_sim_info, employee_msg) def get_sim_filter_gsi_name(): return 'Retail Command: Create Employees for Hire' results = services.sim_filter_service().submit_matching_filter( number_of_sims_to_find=business_manager.EMPLOYEE_POOL_SIZE, sim_filter=business_manager.EMPLOYEE_POOL_FILTER, requesting_sim_info=sim_info, allow_yielding=False, gsi_source_fn=get_sim_filter_gsi_name) for result in results: with ProtocolBufferRollback(msg.available_sims) as employee_msg: populate_employee_msg(result.sim_info, employee_msg) op = shared_messages.create_message_op( msg, Consts_pb2.MSG_RETAIL_MANAGE_EMPLOYEES) Distributor.instance().add_op_with_no_owner(op)