def _update_current_mood(self): (largest_mood, largest_weight, changeable_buffs) = self._get_largest_mood() if largest_mood is not None: intensity = self._get_intensity_from_mood(largest_mood, largest_weight) if self._should_update_mood(largest_mood, intensity, changeable_buffs): if self._active_mood_buff_handle is not None: active_mood_buff_handle = self._active_mood_buff_handle self.remove_buff(active_mood_buff_handle, update_mood=False) if active_mood_buff_handle == self._active_mood_buff_handle: self._active_mood_buff_handle = None else: return self._active_mood = largest_mood self._active_mood_intensity = intensity if len(largest_mood.buffs) >= intensity: tuned_buff = largest_mood.buffs[intensity] if tuned_buff is not None and tuned_buff.buff_type is not None: self._active_mood_buff_handle = self.add_buff(tuned_buff.buff_type, update_mood=False) if gsi_handlers.buff_handlers.sim_mood_log_archiver.enabled and self.owner.valid_for_distribution and self.owner.visible_to_client == True: gsi_handlers.buff_handlers.archive_mood_message(self.owner.id, self._active_mood, self._active_mood_intensity, self._active_buffs, changeable_buffs) caches.clear_all_caches() self.on_mood_changed() for (changeable_buff, mood_override) in changeable_buffs: changeable_buff.mood_override = mood_override self.send_buff_update_msg(changeable_buff, True)
def set_value(self, value, **kwargs): old_value = self._value self._value = value self._clamp() if old_value != self._value and self._tracker is not None: self._tracker.notify_watchers(self.stat_type, old_value, self._value) caches.clear_all_caches()
def _notify_change(self, old_value): value = self.get_value() if old_value != value and self._tracker is not None: self._tracker.notify_watchers(self.stat_type, old_value, value) if not caches.skip_cache: caches.clear_all_caches() self._update_callback_listeners(old_value, value)
def process_events_for_household(self, event_type, household, exclude_sim=None, **kwargs): if not self._enabled: return if household is None: household = services.owning_household_of_active_lot() if household is None: return caches.clear_all_caches() with sims4.callback_utils.invoke_enter_exit_callbacks( CallbackEvent. ENTER_CONTENT_SET_GEN_OR_PROCESS_HOUSEHOLD_EVENTS, CallbackEvent.EXIT_CONTENT_SET_GEN_OR_PROCESS_HOUSEHOLD_EVENTS ): callbacks = data_store_event_test_event_callback_map.get( event_type) has_not_triggered_achievement_data_object = True for sim_info in household._sim_infos: if sim_info == exclude_sim: continue if callbacks is not None: self._process_data_map_for_aspiration( sim_info, event_type, callbacks, **kwargs) if has_not_triggered_achievement_data_object: if callbacks is not None: self._process_data_map_for_achievement( sim_info, event_type, callbacks, **kwargs) has_not_triggered_achievement_data_object = False self._process_test_event(sim_info, event_type, **kwargs)
def _gc_callback(self, phase, info): generation = info['generation'] if generation != 2: return if self._disable_reasons: logger.debug('ignoring gc callback due to disable reasons: {}', self._disable_reasons) return if phase == 'start': caches.clear_all_caches(force=True) interactions.constraints.RequiredSlot.clear_required_slot_cache() return self._gc_pass_count += 1 logger.debug('Gc pass {}', self._gc_pass_count) for node in tuple(self._node_buckets[NodeStatus.LEAKED]): obj = node.get_object() if obj is None: self._move_node_to_status(node, NodeStatus.FALSE_POSITIVE) leaked_nodes = set() now = self._get_time_stamp() for node in tuple(self._node_buckets[NodeStatus.PENDING]): if node.get_object() is None: self._node_buckets[NodeStatus.PENDING].remove(node) else: node_time = node.time_stamps[NodeStatus.PENDING] if now.gc_pass < node_time.gc_pass + GC_PASS_THRESHOLD: continue if node_time.time is not None and now.time is not None and (now.time - node_time.time).in_hours() < SIM_HOUR_THRESHOLD: continue self._move_node_to_status(node, NodeStatus.LEAKED) leaked_nodes.add(node) self._report_leaks(leaked_nodes)
def _run_preroll_autonomy(self): used_target_list = [] sim_list = list(self._startup_sims_set) for sim_id in sim_list: sim_info = self.get(sim_id) if sim_info is None: self._startup_sims_set.discard(sim_id) if sim_info in self._sim_infos_excluded_from_preroll: self._startup_sims_set.discard(sim_id) sim = sim_info.get_sim_instance() if sim is None: self._startup_sims_set.discard(sim_id) caches.clear_all_caches() sim.set_allow_route_instantly_when_hitting_marks(True) (interaction_started, interaction_target) = sim.run_preroll_autonomy(used_target_list) if interaction_started: logger.debug( 'sim: {} started interaction:{} as part of preroll autonomy.', sim, interaction_started) used_target_list.append(interaction_target) else: logger.debug( 'sim: {} failed to choose interaction as part of preroll autonomy.', sim) self._startup_sims_set.discard(sim_id)
def process_event(self, event_type, sim_info=None, **kwargs): if not self._enabled: return caches.clear_all_caches() if sim_info is not None: callbacks = data_store_event_test_event_callback_map.get(event_type) if callbacks is not None: self._process_data_map_for_aspiration(sim_info, event_type, callbacks, **kwargs) self._process_data_map_for_achievement(sim_info, event_type, callbacks, **kwargs) self._process_test_event(sim_info, event_type, **kwargs)
def process_event(self, event_type, sim_info=None, **kwargs): if not self._enabled: return caches.clear_all_caches() if sim_info is not None: callbacks = data_store_event_test_event_callback_map.get( event_type) if callbacks is not None: self._process_data_map_for_aspiration(sim_info, event_type, callbacks, **kwargs) self._process_data_map_for_achievement(sim_info, event_type, callbacks, **kwargs) self._process_test_event(sim_info, event_type, **kwargs)
def _run_preroll_autonomy(self): used_target_list = [] for sim_info in self.get_sims_for_spin_up_action(SimZoneSpinUpAction.PREROLL): sim = sim_info.get_sim_instance() if sim is None: continue caches.clear_all_caches() sim.set_allow_route_instantly_when_hitting_marks(True) (interaction_started, interaction_target) = sim.run_preroll_autonomy(used_target_list) if interaction_started: logger.debug('sim: {} started interaction:{} as part of preroll autonomy.', sim, interaction_started) if interaction_target is not None and not interaction_target.allow_preroll_multiple_targets: used_target_list.append(interaction_target) logger.debug('sim: {} failed to choose interaction as part of preroll autonomy.', sim) else: logger.debug('sim: {} failed to choose interaction as part of preroll autonomy.', sim)
def on_remove(self): logger.assert_log( self.is_zone_shutting_down, 'Attempting to shutdown the zone when it is not ready:{}', self._zone_state, owner='sscholl') self.client_object_managers.clear() interactions.constraints.RequiredSlot.clear_required_slot_cache() self.service_manager.stop_services(self) self.ensure_callable_list_is_empty(self.navmesh_change_callbacks) self.ensure_callable_list_is_empty(self.wall_contour_update_callbacks) self.ensure_callable_list_is_empty( self.foundation_and_level_height_update_callbacks) self._zone_state_callbacks.clear() caches.clear_all_caches(force=True) gc.collect() if self.id != areaserver.WORLDBUILDER_ZONE_ID: indexed_manager.IndexedManager.remove_gc_collect_disable_reason( ZONE_OBJECT_LEAK_DISABLE_REASON)
def _run_preroll_autonomy(self): used_target_list = [] sim_list = list(self._startup_sims_set) for sim_id in sim_list: sim_info = self.get(sim_id) if sim_info is None: self._startup_sims_set.discard(sim_id) if sim_info in self._sim_infos_excluded_from_preroll: self._startup_sims_set.discard(sim_id) sim = sim_info.get_sim_instance() if sim is None: self._startup_sims_set.discard(sim_id) caches.clear_all_caches() sim.set_allow_route_instantly_when_hitting_marks(True) (interaction_started, interaction_target) = sim.run_preroll_autonomy(used_target_list) if interaction_started: logger.debug('sim: {} started interaction:{} as part of preroll autonomy.', sim, interaction_started) used_target_list.append(interaction_target) else: logger.debug('sim: {} failed to choose interaction as part of preroll autonomy.', sim) self._startup_sims_set.discard(sim_id)
def process_events_for_household(self, event_type, household, exclude_sim=None, **kwargs): if not self._enabled: return if household is None: household = services.owning_household_of_active_lot() if household is None: return caches.clear_all_caches() with sims4.callback_utils.invoke_enter_exit_callbacks(CallbackEvent.ENTER_CONTENT_SET_GEN_OR_PROCESS_HOUSEHOLD_EVENTS, CallbackEvent.EXIT_CONTENT_SET_GEN_OR_PROCESS_HOUSEHOLD_EVENTS): callbacks = data_store_event_test_event_callback_map.get(event_type) has_not_triggered_achievment_data_object = True for sim_info in household._sim_infos: if sim_info == exclude_sim: pass if callbacks is not None: self._process_data_map_for_aspiration(sim_info, event_type, callbacks, **kwargs) if has_not_triggered_achievment_data_object: if callbacks is not None: self._process_data_map_for_achievement(sim_info, event_type, callbacks, **kwargs) has_not_triggered_achievment_data_object = False self._process_test_event(sim_info, event_type, **kwargs)
def unlock_perk(self, perk, unlocked_by=None, suppress_telemetry=False): self._award_rewards(perk) self._award_buffs(perk) self._award_loots(perk.loots_on_unlock) if perk.temporary_perk_information is not None and not self._set_up_temporary_perk_timer( perk): return self._perk_unlocked_callbacks[perk.associated_bucks_type](perk) timestamp = services.time_service().sim_now self._unlocked_perks[perk.associated_bucks_type][perk] = PerkData( unlocked_by, timestamp, True) for sim_info in self._owner_sim_info_gen(): services.get_event_manager().process_event( TestEvent.BucksPerkUnlocked, sim_info=sim_info) for linked_perk in perk.linked_perks: if not self.is_perk_unlocked(linked_perk): self.unlock_perk(linked_perk, unlocked_by=perk, suppress_telemetry=suppress_telemetry) if not suppress_telemetry: self._handle_perk_unlock_telemetry(perk) caches.clear_all_caches()
def _gc_callback(self, phase, info): generation = info['generation'] if phase != 'stop' or generation < 1: return if self.gc_callback_disable_reasons: return new_list = [] caches.clear_all_caches(force=True) for indexed_object in self._remove_indexed_object_tracker: obj = None if indexed_object.ref: obj = indexed_object.ref() if obj is None: pass if generation == 1: self._should_trigger_full = True new_list.append(indexed_object) if indexed_object.gc_gen_two_iteration > 0: self._print_leaked_object(obj) _weakrefutils.clear_weak_refs(obj) else: indexed_object.gc_gen_two_iteration = 1 new_list.append(indexed_object) self._remove_indexed_object_tracker = new_list
def enable_all_caches(enable: bool = True, _connection=None): caches.skip_cache = not enable caches.clear_all_caches(force=True) output = sims4.commands.CheatOutput(_connection) output('Caches are now on.'. format(enable) if enable is True else 'Caches are off.')
def on_enter(self): super().on_enter() caches.skip_cache = False caches.clear_all_caches(force=True) return _ZoneSpinUpStateResult.DONE
def enable_all_caches(enable: bool = True, _connection=None): caches.skip_cache = not enable caches.clear_all_caches(force=True)
def update_object_tooltip(self): if not self.hovertip_requested: return if services.client_manager() is None: return caches.clear_all_caches() tooltip_component = None tooltip_override = self.owner.get_tooltip_override() if tooltip_override is not None: tooltip_component = tooltip_override.get_component( types.TOOLTIP_COMPONENT) if tooltip_component is None: tooltip_component = self old_handles = dict(self._ui_metadata_handles) try: self._ui_metadata_handles = {} subtext_field = None resolver = SingleObjectResolver(self.owner) if self.tooltip_tests.run_tests(resolver): for (name, value, tooltip_override_data ) in tooltip_component._ui_metadata_gen(): external_field_data_tuple = tooltip_component._external_field_to_data.get( name) if external_field_data_tuple: if tooltip_override_data is not None: if tooltip_override_data.concatenation_type == TooltipFieldConcatenationType.CONCATENATE_BEFORE: value = LocalizationHelperTuning.get_separated_string_by_style( tooltip_override_data.concatenation_style, value, external_field_data_tuple.field_data) else: value = LocalizationHelperTuning.get_separated_string_by_style( tooltip_override_data.concatenation_style, external_field_data_tuple.field_data, value) handle = self.owner.add_ui_metadata(name, value) self._ui_metadata_handles[name] = handle if name == self.SUBTEXT_HANDLE: subtext_field = value if tooltip_component._ui_metadata_handles: subtext = tooltip_component.get_state_strings( subtext_field) if subtext is not None: if self.SUBTEXT_HANDLE in self._ui_metadata_handles: self.owner.remove_ui_metadata( self._ui_metadata_handles[self.SUBTEXT_HANDLE]) handle = self.owner.add_ui_metadata( self.SUBTEXT_HANDLE, subtext) self._ui_metadata_handles[self.SUBTEXT_HANDLE] = handle for index_unused in tooltip_component._external_field_to_data.keys( ) - self._ui_metadata_handles.keys(): external_field_data = tooltip_component._external_field_to_data.get( index_unused) handle = self.owner.add_ui_metadata( index_unused, external_field_data.field_data) self._ui_metadata_handles[index_unused] = handle finally: for handle in old_handles.values(): self.owner.remove_ui_metadata(handle) self.owner.update_ui_metadata() if not self._ui_metadata_handles: self.owner.hover_tip = ui_protocols.UiObjectMetadata.HOVER_TIP_DISABLED self.owner.update_ui_metadata()
def _check_need_full_gc(self): if self._should_trigger_full: self._should_trigger_full = False caches.clear_all_caches(force=True) gc.collect()
def on_parent_change(self, parent): caches.clear_all_caches() if parent is None: self.parent_type = ObjectParentType.PARENT_NONE else: self.parent_type = ObjectParentType.PARENT_OBJECT
def enable_all_caches(enable:bool=True, _connection=None): caches.skip_cache = not enable caches.clear_all_caches(force=True)