Example #1
0
def buildbuy_session_end(zone_id):
    services.object_manager(
        zone_id).rebuild_objects_to_ignore_portal_validation_cache()
    for obj in services.object_manager(zone_id).get_all():
        obj.on_buildbuy_exit()
    posture_graph_service = services.current_zone().posture_graph_service
    posture_graph_service.on_exit_buildbuy()
    _build_buy_exit_callbacks()
    pythonutils.try_highwater_gc()
    services.get_zone_modifier_service(
    ).check_for_and_apply_new_zone_modifiers(zone_id)
    if _sync_venue_service_to_zone_venue_type(zone_id):
        zone_director = services.venue_service().get_zone_director()
        if zone_director is not None:
            zone_director.on_exit_buildbuy()
    object_preference_tracker = services.object_preference_tracker()
    if object_preference_tracker is not None:
        object_preference_tracker.validate_objects(zone_id)
    services.business_service().on_build_buy_exit()
    services.current_zone().on_build_buy_exit()
    services.utilities_manager().on_build_buy_exit()
    services.get_reset_and_delete_service().on_build_buy_exit()
    street_service = services.street_service()
    if street_service is not None:
        street = services.current_street()
        if street is not None:
            provider = street_service.get_provider(street)
            if provider is not None:
                provider.on_build_buy_exit()
    services.object_manager().clear_objects_to_ignore_portal_validation_cache()
Example #2
0
def sell_lot_response(dialog):
    if not dialog.accepted:
        return
    business_manager = services.business_service(
    ).get_business_manager_for_zone()
    current_zone = services.current_zone()
    lot = current_zone.lot
    lot_value = lot.furnished_lot_value
    business_manager.modify_funds(lot_value)
    business_manager.transfer_balance_to_household()
    services.get_zone_manager().clear_lot_ownership(current_zone.id)
    business_tracker = services.business_service(
    ).get_business_tracker_for_household(business_manager.owner_household_id,
                                         business_manager.business_type)
    if business_tracker is None:
        logger.warn(
            'Business tracker is None for household {} for business type {}',
            business_manager.owner_household_id,
            business_manager.business_type)
        return
    business_tracker.remove_owner(current_zone.id)
    current_zone.disown_household_objects()
    with telemetry_helper.begin_hook(
            business_telemetry_writer,
            TELEMETRY_HOOK_BUSINESS_SOLD,
            household=services.household_manager().get(
                business_manager.owner_household_id)) as hook:
        hook.write_enum(TELEMETRY_HOOK_BUSINESS_TYPE,
                        business_manager.business_type)
    msg = InteractionOps_pb2.SellRetailLot()
    msg.retail_zone_id = current_zone.id
    distributor.system.Distributor.instance().add_event(
        Consts_pb2.MSG_SELL_RETAIL_LOT, msg)
 def open_reward(self, sim_info, **kwargs):
     household = sim_info.household
     if household is None:
         logger.error('SimInfo {} has no associated household.', sim_info)
         return
     services.business_service().increment_additional_markup(
         household.id, self.business_type, self.markup_increment)
Example #4
0
 def __call__(self, zone_id):
     business_manager = services.business_service().get_business_manager_for_zone(zone_id=zone_id)
     is_open_business = business_manager.is_open if business_manager is not None else False
     if is_open_business:
         return TestResult.TRUE
     else:
         return TestResult(False, 'Zone ID {} is not an open business zone.', zone_id)
Example #5
0
 def _on_remove_sim_from_situation(self, sim):
     if not services.current_zone().is_zone_running:
         super()._on_remove_sim_from_situation(sim)
         return
     sim_job = self.get_current_job_for_sim(sim)
     services.get_zone_situation_manager().add_sim_to_auto_fill_blacklist(
         sim.id, sim_job=sim_job)
     (pet_sim_info,
      pet_owner_sim_info) = self._get_pet_and_owner_sim_infos()
     pet_sim_info.remove_linked_sim(pet_owner_sim_info.sim_id)
     pet_owner_sim_info.remove_linked_sim(pet_sim_info.sim_id)
     pet_owner = self.get_pet_owner()
     is_pet_owner = False if pet_owner is None else sim is pet_owner
     super()._on_remove_sim_from_situation(sim)
     business_manager = services.business_service(
     ).get_business_manager_for_zone()
     if business_manager is not None and is_pet_owner:
         business_manager.remove_customer(
             sim, review_business=self._should_leave_review)
         customer_msg = Business_pb2.BusinessCustomerUpdate()
         customer_msg.sim_id = pet_owner_sim_info.sim_id
         op = GenericProtocolBufferOp(
             DistributorOps_pb2.Operation.BUSINESS_CUSTOMER_REMOVE,
             customer_msg)
         Distributor.instance().add_op_with_no_owner(op)
Example #6
0
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')
Example #7
0
 def __call__(self):
     business_manager = services.business_service(
     ).get_business_manager_for_zone()
     if business_manager is None:
         return TestResult(False, 'Not currently on a business lot.')
     zone_director = services.venue_service().get_zone_director()
     if zone_director is None:
         return TestResult(False,
                           'There is no zone_director for this zone.')
     from business.business_zone_director_mixin import BusinessZoneDirectorMixin
     if not isinstance(zone_director, BusinessZoneDirectorMixin):
         return TestResult(
             False,
             'The current zone director does not implement the BusinessZoneDirectorMixin interface.'
         )
     if zone_director.allows_new_customers():
         if not self.customers_allowed:
             return TestResult(
                 False,
                 'Business does allow new customers but the test is for not allowing them.'
             )
     elif self.customers_allowed:
         return TestResult(
             False,
             'Business does not allow new customers and the test is for allowing them.'
         )
     return TestResult.TRUE
Example #8
0
def get_retail_info(_connection=None):
    output = sims4.commands.Output(_connection)
    business_manager = services.business_service(
    ).get_business_manager_for_zone()
    if business_manager is None:
        output("This doesn't appear to be a retail lot.")
        return False
    is_open = business_manager.is_open
    output('Funds: {}'.format(business_manager.funds.money))
    output('Curb Appeal: {}'.format(business_manager.get_curb_appeal()))
    output('Employee Count: {}'.format(business_manager.employee_count))
    output('Markup Multiplier: {}X'.format(business_manager.markup_multiplier))
    output('Median Item Price: {}'.format(
        business_manager.get_median_item_value()))
    output('The store is {}.'.format('OPEN' if is_open else 'CLOSED'))
    if is_open:
        output('Items Sold: {}'.format(business_manager.daily_items_sold))
        output('Gross Income: {}'.format(business_manager.funds))
    format_msg = '{sim:>24} {career_level:>32} {salary:>12} {desired_salary:>12}'
    output(
        format_msg.format(sim='Sim',
                          career_level='Career Level',
                          salary='Current Salary',
                          desired_salary='Desired Salary'))
    for employee_sim in business_manager.get_employees_gen():
        career_level = business_manager.get_employee_career_level(employee_sim)
        desired_career_level = business_manager.RETAIL_CAREER.start_track.career_levels[
            business_manager.get_employee_desired_career_level(employee_sim)]
        output(
            format_msg.format(
                sim=employee_sim.full_name,
                career_level=str(career_level.__name__),
                salary=career_level.simoleons_per_hour,
                desired_salary=desired_career_level.simoleons_per_hour))
    return True
Example #9
0
 def _create_serving(self):
     chef_station = self.get_staffed_object()
     if chef_station is None:
         logger.error('Trying to create the serving platter for the chef station but the situation has no Chef Station.')
         return
     if self._current_order is None:
         logger.error('Trying to create a meal for the chef to serve at the chef station but the situation has no current order.')
         return
     if isinstance(self._current_order, GroupOrder):
         if not self._current_order.is_canceled:
             serving_platter = self._create_and_slot_cooking_object(chef_station, ChefTuning.CHEF_STATION_SERVING_PLATTER_OBJECT, ChefTuning.CHEF_STATION_SERVE_SLOT_TYPE)
             self._current_order.assign_serving_from_chef(serving_platter)
             business_manager = services.business_service().get_business_manager_for_zone()
             if business_manager is not None:
                 business_manager.calculate_and_apply_expense_for_group_order(self._current_order)
             self._zone_director.set_order_status(self._current_order, OrderStatus.ORDER_READY)
         else:
             self._chef_remove_order()
     else:
         ordered_recipe = self._current_order.ordered_recipe
         ordered_recipe_definition = ordered_recipe.final_product_definition
         created_order = self._create_and_slot_cooking_object(chef_station, ordered_recipe_definition, ChefTuning.CHEF_STATION_SERVE_SLOT_TYPE)
         for initial_state in reversed(ordered_recipe.final_product.initial_states):
             created_order.set_state(initial_state.state, initial_state, from_init=True)
         for apply_state in reversed(ordered_recipe.final_product.apply_states):
             created_order.set_state(apply_state.state, apply_state, from_init=True)
         crafting_process = CraftingProcess(crafter=self.get_staff_member(), recipe=ordered_recipe)
         crafting_process.setup_crafted_object(created_order, is_final_product=True)
         self._push_sim_to_pick_up_order(self._current_order.ordering_sim, created_order)
         services.get_event_manager().process_event(test_events.TestEvent.RestaurantOrderDelivered, sim_info=self._current_order.ordering_sim.sim_info)
     self._chef_remove_order()
Example #10
0
def show_summary_dialog(zone_id: int = None, _connection=None):
    business_manager = services.business_service(
    ).get_business_manager_for_zone(zone_id)
    if business_manager is None:
        return False
    business_manager.show_summary_dialog()
    return True
Example #11
0
 def __init__(self, *arg, **kwargs):
     super().__init__(*arg, **kwargs)
     self._business_manager = services.business_service(
     ).get_business_manager_for_zone()
     if self._business_manager is not None:
         self._business_manager.on_store_closed.register(
             self._on_business_closed)
Example #12
0
 def _destroy(self):
     business_manager = services.business_service(
     ).get_business_manager_for_zone()
     if business_manager is not None and self._on_business_closed in business_manager.on_store_closed:
         business_manager.on_store_closed.unregister(
             self._on_business_closed)
     super()._destroy()
Example #13
0
 def get_order_for_npc_sim(cls, sim):
     zone_director = get_restaurant_zone_director()
     if zone_director is None:
         logger.error(
             'Trying to get an order for an NPC sim but there is no restaurant zone director.'
         )
         return
     menu_items = []
     for course in cls.FOOD_COURSES:
         menu_items.extend(zone_director.get_menu_for_course(course))
     possible_orders = list(
         cls.get_possible_orders(sim, menu_items).items())
     food_choice = random.weighted_random_item(possible_orders,
                                               flipped=True)
     business_manager = services.business_service(
     ).get_business_manager_for_zone()
     if business_manager is not None:
         bucks_tracker = services.active_household().bucks_tracker
         if bucks_tracker.is_perk_unlocked(
                 RestaurantTuning.CUSTOMERS_ORDER_EXPENSIVE_FOOD_PERK_DATA.
                 perk):
             food_choice_2 = random.weighted_random_item(possible_orders,
                                                         flipped=True)
             if food_choice_2 is not food_choice:
                 choice_1_price = business_manager.get_value_with_markup(
                     food_choice.restaurant_base_price)
                 choice_2_price = business_manager.get_value_with_markup(
                     food_choice_2.restaurant_base_price)
                 if choice_2_price > choice_1_price:
                     food_choice = food_choice_2
     drink_choice = cls.get_choice_for_npc_sim(sim, cls.DRINK_COURSE)
     if food_choice is None and drink_choice is None:
         return (None, cls.WATER_ORDER_FOR_BACKUP)
     return (food_choice, drink_choice)
Example #14
0
 def on_state_changed(self, state, old_value, new_value, from_init):
     reapply_state = False
     if old_value is new_value:
         if state is not self.FOR_SALE_STATE.state:
             return
         reapply_state = True
     retail_manager = services.business_service(
     ).get_retail_manager_for_zone()
     if retail_manager is None:
         return
     if new_value is self.NOT_FOR_SALE_STATE or new_value is self.DEFAULT_SALE_STATE:
         show_vfx = not reapply_state and (
             old_value is self.FOR_SALE_STATE
             or old_value is self.DEFAULT_SALE_STATE)
         if show_vfx:
             if self.owner.swapping_to_parent is not None:
                 if self.FOR_SALE_STATE in self.owner.swapping_to_parent.slot_component.state_values:
                     show_vfx = False
         self._set_not_for_sale_internal(show_vfx=show_vfx)
     elif new_value is self.FOR_SALE_STATE:
         show_vfx = not reapply_state and (
             old_value is self.NOT_FOR_SALE_STATE
             or old_value is self.DEFAULT_SALE_STATE)
         if show_vfx:
             if self.owner.swapping_to_parent is not None:
                 if self.NOT_FOR_SALE_STATE in self.owner.swapping_to_parent.slot_component.state_values:
                     show_vfx = False
         self._set_for_sale_internal(show_vfx=show_vfx)
         if old_value is self.SOLD_STATE:
             self.owner.remove_client_state_suppressor(state)
             self.owner.reset_states_to_default()
     elif new_value is self.SOLD_STATE:
         self.owner.add_client_state_suppressor(self.SOLD_STATE.state)
         self._set_sold_internal()
     self.owner.update_component_commodity_flags()
 def get_outfit_sim_info(self, interaction, **_):
     business_manager = services.business_service(
     ).get_business_manager_for_zone()
     if business_manager is None:
         return
     elif business_manager.is_valid_employee_type(self.employee_type):
         return business_manager.get_employee_uniform_data(
             self.employee_type, self.gender)
Example #16
0
def add_retail_funds(amount: int = 1000, _connection=None):
    output = sims4.commands.Output(_connection)
    business_manager = services.business_service(
    ).get_business_manager_for_zone()
    if business_manager is None:
        output("This doesn't appear to be a retail lot.")
        return False
    business_manager.modify_funds(amount, from_item_sold=False)
Example #17
0
 def _do_behavior(self):
     zone_id = self.interaction.get_participant(self.lot_participant)
     if self.lot_participant == ParticipantTypeLot.Lot:
         zone_id = zone_id.id
     actor_household = self.interaction.sim.household
     business_service = services.business_service()
     business_service.make_owner(actor_household.id, self.business_type,
                                 zone_id)
Example #18
0
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)
Example #19
0
def demote_business_employee(sim: RequiredTargetParam, _connection=None):
    business_manager = services.business_service(
    ).get_business_manager_for_zone()
    if business_manager is None:
        return False
    target_sim = sim.get_target(manager=services.sim_info_manager())
    if target_sim is None:
        return False
    return business_manager.run_demote_employee_interaction(target_sim)
Example #20
0
 def _set_not_for_sale_internal(self, show_vfx=True):
     self.set_interactable(propagate_to_children=True)
     retail_manager = services.business_service(
     ).get_retail_manager_for_zone()
     if retail_manager is None:
         return
     retail_manager.refresh_for_sale_vfx_for_object(self.owner)
     if show_vfx:
         self.SET_NOT_FOR_SALE_VFX(self.owner).start_one_shot()
Example #21
0
def set_markup_multiplier(markup_multiplier: float, _connection=None):
    business_manager = services.business_service(
    ).get_business_manager_for_zone()
    if business_manager is None:
        logger.error(
            'Trying to set business markup when not in a business zone.',
            owner='camilogarcia')
        return
    business_manager.set_markup_multiplier(markup_multiplier)
Example #22
0
def set_quality(quality: BusinessQualityType, _connection=None):
    business_manager = services.business_service(
    ).get_business_manager_for_zone()
    if business_manager is None:
        sims4.commands.output(
            'Trying to set the quality for a business but there was no valid business manager found for the current zone.'
        )
        return False
    business_manager.set_quality_setting(quality)
Example #23
0
def toggle_for_sale_vfx(_connection=None):
    business_manager = services.business_service(
    ).get_business_manager_for_zone()
    if business_manager is None:
        logger.error(
            'Trying to toggle for sale VFX when not in a retail zone.',
            owner='tastle')
        return
    business_manager.toggle_for_sale_vfx()
Example #24
0
 def on_finalize_load(self):
     self.owner.update_component_commodity_flags()
     retail_manager = services.business_service(
     ).get_retail_manager_for_zone()
     if retail_manager is None:
         if self.is_sold or self.is_for_sale:
             self.set_not_for_sale()
     elif self.is_sold:
         self.owner.add_client_state_suppressor(self.SOLD_STATE.state)
Example #25
0
 def get_value_with_markup(self, value) -> int:
     markup_multiplier = self.markup_multiplier
     if self.owner_household_id is not None:
         tracker = services.business_service().get_business_tracker_for_household(self.owner_household_id, self.business_type)
         markup_multiplier += tracker.additional_markup_multiplier
     else:
         active_household = services.active_household()
         if active_household is not None:
             markup_multiplier *= active_household.holiday_tracker.get_active_holiday_business_price_multiplier(self.business_type)
     return int(value*markup_multiplier)
Example #26
0
 def _on_set_sim_job(self, sim, job_type):
     super()._on_set_sim_job(sim, job_type)
     if job_type is not self.owner_job:
         return
     if self.current_state_type in (_SpawnGate, _ArrivalState):
         return
     self._business_manager = services.business_service(
     ).get_business_manager_for_zone()
     if self._business_manager is not None:
         self._business_manager.add_customer(sim.sim_info)
Example #27
0
 def is_valid_career_location(self):
     if not super().is_valid_career_location():
         return False
     business_manager = services.business_service(
     ).get_business_manager_for_zone(self._zone_id)
     if business_manager is None:
         return True
     elif business_manager.is_owner_household_active:
         return business_manager.is_employee(self._career.sim_info)
     return True
def set_ingredient_quality(ingredient_quality: RestaurantIngredientQualityType,
                           _connection=None):
    business_manager = services.business_service(
    ).get_business_manager_for_zone()
    if business_manager is None:
        sims4.commands.output(
            'Trying to set the ingredient quality for a restaurant but there was no valid business manager found for the current zone.'
        )
        return False
    business_manager.set_ingredient_quality(ingredient_quality)
Example #29
0
 def _apply_to_subject_and_target(self, subject, target, resolver):
     business_manager = services.business_service().get_business_manager_for_zone()
     if business_manager is None:
         return
     zone_director = services.venue_service().get_zone_director()
     if zone_director is None:
         return
     if not isinstance(zone_director, BusinessZoneDirectorMixin):
         return
     zone_director.set_customers_allowed(self._allow_customers)
Example #30
0
 def get_sell_price(self):
     base_value = self.get_retail_value()
     retail_manager = services.business_service(
     ).get_retail_manager_for_zone()
     if retail_manager is None:
         logger.error(
             "Trying to get the sell price of a retail item but no retail_manager was found for this lot. Defaulting to the object's value without a markup applied."
         )
         return base_value
     return retail_manager.get_value_with_markup(base_value)