Пример #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()
Пример #2
0
 def _stack_objects_transfer(self, objects_to_harvest, num_extra_objects):
     obj_count = {}
     dupe_objects = []
     if self.use_gardening_optimization:
         unique_objects = []
         while objects_to_harvest:
             obj = objects_to_harvest.pop()
             quality_value = obj.get_state(
                 GardeningTuning.QUALITY_STATE_VALUE) if obj.has_state(
                     GardeningTuning.QUALITY_STATE_VALUE) else 0
             object_count_key = (obj.guid64, quality_value)
             curr_count = obj_count.get(object_count_key, 0)
             if curr_count == 0:
                 unique_objects.append((obj, quality_value))
             else:
                 dupe_objects.append(obj)
             curr_count = curr_count + 1
             obj_count[object_count_key] = curr_count
         for (obj, quality_value) in unique_objects:
             object_count_key = (obj.guid64, quality_value)
             curr_count = obj_count.get(object_count_key, 0)
             obj.set_stack_count(curr_count)
     else:
         unique_objects = [(obj, 0) for obj in objects_to_harvest]
     if unique_objects:
         while num_extra_objects > 0:
             (obj, _) = random.choice(unique_objects)
             obj.update_stack_count(1)
             num_extra_objects -= 1
     if dupe_objects:
         services.get_reset_and_delete_service().trigger_batch_destroy(
             dupe_objects)
     return unique_objects
Пример #3
0
 def on_teardown(self, client):
     logger.debug('Zone teardown started')
     indexed_manager.IndexedManager.add_gc_collect_disable_reason(
         ZONE_OBJECT_LEAK_DISABLE_REASON)
     self.on_soak_end()
     self._set_zone_state(zone_types.ZoneState.SHUTDOWN_STARTED)
     logger.debug('Zone teardown: disable event manager')
     self.event_manager.disable_on_teardown()
     self.ui_dialog_service.disable_on_teardown()
     logger.debug('Zone teardown: destroy situations')
     self.situation_manager.destroy_situations_on_teardown()
     logger.debug('Zone teardown: flush sim_infos to client')
     self.sim_info_manager.flush_to_client_on_teardown()
     logger.debug('Zone teardown: remove Sims from master controller')
     self.master_controller.remove_all_sims_and_disable_on_teardown()
     logger.debug('Zone teardown: destroy objects and sims')
     all_objects = []
     all_objects.extend(self.prop_manager.values())
     all_objects.extend(self.inventory_manager.values())
     all_objects.extend(self.object_manager.values())
     services.get_reset_and_delete_service().trigger_batch_destroy(
         all_objects)
     logger.debug('Zone teardown: destroy sim infos')
     self.sim_info_manager.destroy_all_objects()
     logger.debug('Zone teardown:  services.on_client_disconnect')
     services.on_client_disconnect(client)
     logger.debug('Zone teardown:  time_service')
     self.time_service.on_teardown()
     logger.debug('Zone teardown:  complete')
     self.zone_spin_up_service.do_clean_up()
     self._client = None
Пример #4
0
def sim_inventory_sell_multiple(msg:str, _connection=None):
    proto = UI_pb2.InventorySellRequest()
    text_format.Merge(msg, proto)
    if proto is None:
        return
    sim_info = services.sim_info_manager().get(proto.sim_id)
    if sim_info is None:
        return
    inventory_component = sim_info.get_sim_instance().inventory_component
    if inventory_component is None:
        return
    sell_value = 0
    objs = []
    inventory_stack_items = inventory_component.get_stack_items_map(proto.stacks)
    if proto.stacks is not None:
        for stack_id in proto.stacks:
            stack_items = inventory_stack_items.get(stack_id, None)
            if stack_items is None:
                continue
            for item in stack_items:
                if item.non_deletable_by_user:
                    break
                sell_value += item.current_value*item.stack_count()
                objs.append(item)
    if proto.items is not None:
        inventory_manager = services.inventory_manager()
        for item_data in proto.items:
            if item_data not in inventory_component:
                continue
            item = inventory_manager.get(item_data.id)
            if item is None:
                continue
            if item.non_deletable_by_user:
                continue
            sell_value += item.current_value*item_data.count
            item.update_stack_count(-item_data.count)
            if item.stack_count() < 1:
                objs.append(item)
            else:
                inventory_component.push_inventory_item_update_msg(item)
    if objs:
        services.active_household().funds.add(sell_value, Consts_pb2.TELEMETRY_OBJECT_SELL, sim_info)
        services.get_reset_and_delete_service().trigger_batch_destroy(objs)
    op = SendUIMessage('InventorySellItemsComplete')
    Distributor.instance().add_op_with_no_owner(op)
Пример #5
0
def c_api_buildbuy_session_begin(zone_id: int, account_id: int):
    current_zone = services.current_zone()
    posture_graph_service = current_zone.posture_graph_service
    posture_graph_service.on_enter_buildbuy()
    current_zone.on_build_buy_enter()
    object_leak_tracker = services.get_object_leak_tracker()
    if object_leak_tracker is not None:
        object_leak_tracker.add_disable_reason(BUILD_BUY_OBJECT_LEAK_DISABLED)
    resource_keys = []
    if services.get_career_service().get_career_event_situation_is_running():
        household = services.active_household()
    else:
        household = current_zone.get_active_lot_owner_household()
    if household is not None:
        for unlock in household.build_buy_unlocks:
            resource_keys.append(unlock)
    update_gameplay_unlocked_products(resource_keys, zone_id, account_id)
    services.business_service().on_build_buy_enter()
    services.get_reset_and_delete_service().on_build_buy_enter()
    services.object_manager(zone_id).cleanup_build_buy_transient_objects()
    _build_buy_enter_callbacks()
    return True
 def _on_fruit_support_state_changed(self, state, old_value, new_value):
     if state not in GardeningTuning.FRUIT_STATES:
         return
     fruit_state_data = GardeningTuning.FRUIT_STATES[state]
     if new_value in fruit_state_data.states:
         return
     objs_to_destroy = []
     fruit_state_behavior = fruit_state_data.behavior
     for fruit in tuple(self.owner.children):
         gardening_component = fruit.get_component(
             types.GARDENING_COMPONENT)
         if gardening_component is None:
             continue
         if not gardening_component.is_on_tree:
             continue
         if fruit_state_behavior is not None and random.random(
         ) < fruit_state_behavior and self._on_fruit_fall_to_ground(fruit):
             gardening_component.update_hovertip()
         else:
             objs_to_destroy.append(fruit)
     if objs_to_destroy:
         services.get_reset_and_delete_service().trigger_batch_destroy(
             objs_to_destroy)
Пример #7
0
 def destroy(self, source=None, cause=None):
     services.get_reset_and_delete_service().trigger_destroy(self,
                                                             source=source,
                                                             cause=cause)
Пример #8
0
 def reset(self, reset_reason, source=None, cause=None):
     services.get_reset_and_delete_service().trigger_reset(
         self, reset_reason, source, cause)
Пример #9
0
 def reset_reason(self):
     return services.get_reset_and_delete_service().get_reset_reason(self)
Пример #10
0
 def _process(self, *sims):
     if not self._enabled or self._processing or self._reset_in_progress:
         return
     self._processing = True
     sims_filtered = list(sims)
     try:
         requested_sims = set(self._global_required_resources)
         requested_resources = set()
         for work_entry in self._active_work.values():
             if work_entry.additional_resources:
                 requested_resources.update(work_entry.additional_resources)
         new_work_accepted = []
         self._gsi_entry_initialize(*sims)
         self._gsi_add_sim_time_line_for_sims(sims, 'Start',
                                              'Begin processing')
         sims_filtered = [
             sim for sim in sims if sim not in self._denied_sims
             if sim in self._sims
         ]
         for sim in self._sorted_sims(
                 itertools.chain(self._denied_sims, sims_filtered)):
             self._gsi_add_log_entry(sim, 'PROCESS', '----- START -----')
             if sim not in self._sims:
                 continue
             if sim in requested_sims:
                 continue
             existing_entry = self._active_work.get(sim)
             if existing_entry is not None and not existing_entry.cancelable:
                 continue
             if sim in self._denied_sims and sim.is_sim:
                 sim.queue.on_head_changed.remove(self._process)
             try:
                 work_request = sim.get_next_work()
             finally:
                 if sim in self._denied_sims and sim.is_sim:
                     sim.queue.on_head_changed.append(self._process)
             if work_request.work_element is None:
                 self._gsi_add_log_entry(sim, 'PROCESS', 'No Work Element')
             else:
                 work_entry = WorkEntry(
                     work_element=work_request.work_element,
                     resources=work_request.required_sims,
                     additional_resources=work_request.additional_resources,
                     owner=sim,
                     master_controller=self,
                     on_accept=work_request.on_accept,
                     debug_name=work_request._debug_name)
                 self._gsi_add_sim_time_line_for_sim(
                     sim, 'Create', 'Work Entry Created')
                 self._gsi_add_log_entry(
                     sim, 'PROCESS', 'Work Entry Created: required_sims:{}',
                     str(work_request.required_sims))
                 if self._process_work_entry(sim, work_entry,
                                             requested_sims,
                                             requested_resources):
                     if sim in self._denied_sims:
                         if sim.is_sim:
                             sim.queue.on_head_changed.remove(self._process)
                         del self._denied_sims[sim]
                     new_work_accepted.append((sim, work_entry))
                     if work_request.set_work_timestamp:
                         self.set_timestamp_for_sim_to_now(sim)
         for (sim, work_entry) in new_work_accepted:
             self._gsi_add_log_entry(sim, 'PROCESS',
                                     'Work Entry Start Called: {}',
                                     work_entry)
             self._gsi_add_sim_time_line_for_sim(sim, 'Start',
                                                 'Work Entry Started')
             work_entry.start()
         for sim in self._sims:
             if sim not in self._active_work:
                 (work_element_idle,
                  cancel_callable) = sim.get_idle_element()
                 if work_element_idle is not None:
                     work_entry = WorkEntry(work_element=work_element_idle,
                                            cancel_callable=cancel_callable,
                                            resources=(sim, ),
                                            owner=sim,
                                            master_controller=self)
                     self._active_work[sim] = work_entry
                     self._gsi_add_log_entry(
                         sim, 'PROCESS',
                         'No active work - run idle behavior')
                     if sim not in self._denied_sims and sim.is_sim:
                         sim.queue.on_head_changed.append(self._process)
                     self._denied_sims[sim] = work_entry
                     work_entry.start()
         self._gsi_entry_finalize()
         self._processing = False
     except:
         logger.exception(
             'Exception while processing the Master Controller.')
     finally:
         if self._processing:
             self._processing = False
             services.get_reset_and_delete_service().trigger_batch_reset(
                 sims_filtered, ResetReason.RESET_ON_ERROR, None,
                 'Exception in _process in the MasterController.')
Пример #11
0
 def _process(self, *sims):
     if not self._enabled or self._processing or self._reset_in_progress:
         return
     self._processing = True
     sims_filtered = list(sims)
     try:
         requested_sims = set()
         requested_resources = set()
         for work_entry in self._active_work.values():
             while work_entry.additional_resources:
                 requested_resources.update(work_entry.additional_resources)
         new_work_accepted = []
         self._gsi_entry_initialize(*sims)
         self._gsi_add_sim_time_line_for_sims(sims, 'Start', 'Begin processing')
         sims_filtered = [sim for sim in sims if sim in self._sims]
         for sim in self._sorted_sims(itertools.chain(self._denied_sims, sims_filtered)):
             self._gsi_add_log_entry(sim, 'PROCESS', '----- START -----')
             if sim not in self._sims:
                 pass
             if sim in requested_sims:
                 pass
             existing_entry = self._active_work.get(sim)
             if existing_entry is not None and not existing_entry.cancelable:
                 pass
             if sim in self._denied_sims:
                 sim.queue.on_head_changed.remove(self._process)
             try:
                 work_request = sim.get_next_work()
             finally:
                 if sim in self._denied_sims:
                     sim.queue.on_head_changed.append(self._process)
             if work_request.work_element is None:
                 self._gsi_add_log_entry(sim, 'PROCESS', 'No Work Element')
             work_entry = WorkEntry(work_element=work_request.work_element, resources=work_request.required_sims, additional_resources=work_request.additional_resources, owner=sim, master_controller=self, on_accept=work_request.on_accept, debug_name=work_request._debug_name)
             self._gsi_add_sim_time_line_for_sim(sim, 'Create', 'Work Entry Created')
             self._gsi_add_log_entry(sim, 'PROCESS', 'Work Entry Created: required_sims:{}', str(work_request.required_sims))
             while self._process_work_entry(sim, work_entry, requested_sims, requested_resources):
                 if sim in self._denied_sims:
                     sim.queue.on_head_changed.remove(self._process)
                     del self._denied_sims[sim]
                 new_work_accepted.append((sim, work_entry))
                 if work_request.set_work_timestamp:
                     self.set_timestamp_for_sim_to_now(sim)
         for (sim, work_entry) in new_work_accepted:
             self._gsi_add_log_entry(sim, 'PROCESS', 'Work Entry Start Called: {}', work_entry)
             self._gsi_add_sim_time_line_for_sim(sim, 'Start', 'Work Entry Started')
             work_entry.start()
         for sim in self._sims:
             while sim not in self._active_work:
                 (work_element_idle, cancel_callable) = sim.get_idle_element()
                 if work_element_idle is not None:
                     work_entry = WorkEntry(work_element=work_element_idle, cancel_callable=cancel_callable, resources=(sim,), owner=sim, master_controller=self)
                     self._active_work[sim] = work_entry
                     self._gsi_add_log_entry(sim, 'PROCESS', 'No active work - run idle behavior')
                     if sim not in self._denied_sims:
                         sim.queue.on_head_changed.append(self._process)
                     self._denied_sims[sim] = work_entry
                     work_entry.start()
         self._gsi_entry_finalize()
         self._processing = False
     finally:
         if self._processing:
             self._processing = False
             services.get_reset_and_delete_service().trigger_batch_reset(sims_filtered, ResetReason.RESET_ON_ERROR, None, 'Exception in _process in the MasterController.')
Пример #12
0
 def _hard_stop(self):
     super()._hard_stop()
     if self._registered:
         self.obj.on_reset_element_hard_stop()
     else:
         services.get_reset_and_delete_service().start_processing()