def on_add(self, *_, **__): services.sim_spawner_service().register_sim_spawned_callback(self._on_sim_spawned) owning_household = services.owning_household_of_active_lot() if owning_household is None: return for sim in owning_household.instanced_sims_gen(allow_hidden_flags=ALL_HIDDEN_REASONS_EXCEPT_UNINITIALIZED): self._add_commodities_to_sims(sim)
def activate_holiday(self, from_load=False, from_customization=False): if self._state >= HolidayState.RUNNING: logger.error( 'Tradition {} is trying to be put into the Running state, but is already in {} which is farther along.', self, self._state) return self._deactivate_pre_holiday() self._state = HolidayState.RUNNING if self.holiday_buffs: services.sim_spawner_service().register_sim_spawned_callback( self.on_sim_spawned) for sim_info in services.sim_info_manager().instanced_sims_gen(): for buff in self.holiday_buffs: buff_handle = sim_info.add_buff( buff, buff_reason=self.holiday_buff_reason) if buff_handle is not None: self._buffs_added[sim_info.sim_id].append(buff_handle) for (key, event) in enumerate(self.events): self._create_event_alarm(key, event) if not from_load: resolver = GlobalResolver() for actions in self.lifecycle_actions: actions.try_perform( resolver, TraditionActivationEvent.TRADITION_ADD if from_customization else TraditionActivationEvent.HOLIDAY_ACTIVATE) if self.drama_nodes_to_score: sim_timeline = services.time_service().sim_timeline self._drama_node_processor = sim_timeline.schedule( elements.GeneratorElement(self._process_scoring_gen)) drama_scheduler = services.drama_scheduler_service() for drama_node in self.drama_nodes_to_run: drama_scheduler.run_node(drama_node, resolver)
def on_remove_actions(cls): services.sim_spawner_service().unregister_sim_spawned_callback( cls.zone_wide_loot.apply_to_sim) cls.unregister_interaction_triggers() cls.stop_household_actions() cls.cleanup_loot.apply_all_actions() cls.revert_object_actions()
def on_update(self): super().on_update() self._countdown -= 1 if self._countdown <= 0: services.active_lot().on_hit_their_marks() services.sim_spawner_service().on_hit_their_marks() services.get_zone_situation_manager( ).on_hit_their_marks_during_zone_spin_up() services.current_zone().on_hit_their_marks() return _ZoneSpinUpStateResult.DONE services.game_clock_service().advance_for_hitting_their_marks() return _ZoneSpinUpStateResult.WAITING
def on_remove(self, *_, **__): sim_spawner_service = services.sim_spawner_service() sim_spawner_service.add_npc_cap_modifier(-self.cap_modifier) if self._sim_info_data is not None: self._sim_info_data.on_outfit_changed.remove(self._on_outfit_change) self._sim_info_data.on_outfit_generated.remove(self._on_outfit_generated) self._sim_info_data.on_preload_outfits_changed.remove(self._on_preload_outfits_changed)
def on_update(self): super().on_update() if not services.sim_spawner_service().batch_spawning_complete: return _ZoneSpinUpStateResult.WAITING client = services.client_manager().get_first_client() services.sim_info_manager().on_spawn_sim_for_zone_spin_up_completed( client) services.venue_service().get_zone_director( ).on_spawn_sim_for_zone_spin_up_completed() services.current_zone( ).venue_service.handle_active_lot_changing_edge_cases() services.get_zone_situation_manager( ).on_all_sims_spawned_during_zone_spin_up() club_service = services.get_club_service() if club_service is not None: club_service.on_finish_waiting_for_sim_spawner_service() else: current_zone_id = services.current_zone_id() household = services.active_household() if household.home_zone_id != current_zone_id: sim_info_manager = services.sim_info_manager() traveled_sims = sim_info_manager.get_traveled_to_zone_sim_infos( ) if len(traveled_sims) > 1: services.ensemble_service( ).create_travel_ensemble_if_neccessary(traveled_sims) services.ensemble_service().on_all_sims_spawned_during_zone_spin_up() return _ZoneSpinUpStateResult.DONE
def activate_pre_holiday(self): if self._state >= HolidayState.PRE_DAY: logger.error( 'Tradition {} is trying to be put into the pre_holiday, but is already in {} which is farther along.', self, self._state) return self._state = HolidayState.PRE_DAY if self.pre_holiday_buffs: services.sim_spawner_service().register_sim_spawned_callback( self.on_sim_spawned) for sim_info in services.active_household().instanced_sims_gen(): for buff in self.pre_holiday_buffs: buff_handle = sim_info.add_buff( buff, buff_reason=self.pre_holiday_buff_reason) if buff_handle is not None: self._buffs_added[sim_info.sim_id].append(buff_handle)
def on_add(self, *_, **__): sim_spawner_service = services.sim_spawner_service() sim_spawner_service.add_npc_cap_modifier(self.cap_modifier) zone = services.current_zone() if not zone.is_zone_loading and not self.owner.is_downloaded: self.reconcile_mannequin_data(is_add=True) self._update_outfit_state()
def generate_sim_spawner_service_global(zone_id: int = None): sim_spawner_service = services.sim_spawner_service() data = { 'npcs_here': sim_spawner_service.number_of_npcs_instantiated, 'npcs_leaving': sim_spawner_service.number_of_npcs_leaving, 'npc_soft_cap': sim_spawner_service.npc_soft_cap, 'npc_cap_modifier': sim_spawner_service._npc_cap_modifier } return data
def on_spin_up_actions(cls, is_build_eco_effects_enabled): sim_spawner_service = services.sim_spawner_service() if not sim_spawner_service.is_registered_sim_spawned_callback( cls.zone_wide_loot.apply_to_sim): sim_spawner_service.register_sim_spawned_callback( cls.zone_wide_loot.apply_to_sim) cls.spin_up_lot_loot.apply_all_actions() cls.zone_wide_loot.apply_all_actions() cls.apply_object_actions(is_build_eco_effects_enabled)
def deactivate_holiday(self, from_customization=False): if self._state != HolidayState.RUNNING: logger.error( 'Tradition {} is trying to deactivate the tradition, but it is in the {} state, not that one.', self, self._state) self._state = HolidayState.SHUTDOWN if self.holiday_buffs: services.sim_spawner_service().unregister_sim_spawned_callback( self.on_sim_spawned) self._remove_all_buffs() for alarm in self._event_alarm_handles.values(): alarms.cancel_alarm(alarm) self._event_alarm_handles.clear() resolver = GlobalResolver() for actions in self.lifecycle_actions: actions.try_perform( resolver, TraditionActivationEvent.TRADITION_REMOVE if from_customization else TraditionActivationEvent.HOLIDAY_DEACTIVATE)
def should_route_instantly(self): zone = services.current_zone() if zone.force_route_instantly: return True if self.owner.is_sim: if not (zone.are_sims_hitting_their_marks and self.owner._allow_route_instantly_when_hitting_marks): return False else: return not services.sim_spawner_service().sim_is_leaving(self.owner) return False
def on_add_actions(cls, is_build_eco_effects_enabled): sim_spawner_service = services.sim_spawner_service() if not sim_spawner_service.is_registered_sim_spawned_callback( cls.zone_wide_loot.apply_to_sim): sim_spawner_service.register_sim_spawned_callback( cls.zone_wide_loot.apply_to_sim) cls.register_interaction_triggers() cls.start_household_actions() cls.on_add_loot.apply_all_actions() cls.zone_wide_loot.apply_all_actions() cls.apply_object_actions(is_build_eco_effects_enabled)
def is_leaving_zone(sim_info: SimInfo) -> bool: """is_leaving_zone(sim_info) Determine if a Sim is currently leaving the zone. :param sim_info: The Sim to check. :type sim_info: SimInfo :return: True, if the Sim is leaving the zone. False, if the Sim is not leaving the zone. :rtype: bool """ sim = CommonSimUtils.get_sim_instance(sim_info) return sim is not None and services.sim_spawner_service().sim_is_leaving(sim)
def handle_late_violator(self, sim): self._cancel_unavailable_interactions((sim,)) self.add_override_for_sim(sim) liabilities = ((LATE_SHOO_LIABILITY, LateShooLiability(self, sim)),) result = self._route_sim_away(sim, liabilities=liabilities) if not result: return if not self._violators: context = InteractionContext(sim, InteractionContext.SOURCE_SCRIPT, Priority.High, insert_strategy=QueueInsertStrategy.NEXT) if self.interaction is None: result = sim.push_super_affordance(self.embarrassed_affordance, sim, context) else: result = sim.push_super_affordance(self.embarrassed_affordance, self.interaction.get_participant(ParticipantType.Actor), context) if not result and not services.sim_spawner_service().sim_is_leaving(sim): logger.warn('Failed to push the embarrassed affordance on Sim {}. Interaction {}. Result {}. Context {} ', sim, self.interaction, result, context, owner='tastle') return self._late_violators.add(sim)
def on_remove(self, *_, **__): services.sim_spawner_service().unregister_sim_spawned_callback(self._on_sim_spawned)
def _deactivate_pre_holiday(self): if self.pre_holiday_buffs: services.sim_spawner_service().unregister_sim_spawned_callback( self.on_sim_spawned) self._remove_all_buffs()
def on_enter(self): super().on_enter() sim_spawner_service = services.sim_spawner_service() sim_spawner_service.batch_spawn_during_zone_spin_up() return _ZoneSpinUpStateResult.WAITING
def is_leaving_zone(sim_info: SimInfo) -> bool: """ Determine if a sim is currently leaving the zone. """ sim = CommonSimUtils.get_sim_instance(sim_info) return sim is not None and services.sim_spawner_service().sim_is_leaving(sim)
def generate_sim_spawner_service_queue(zone_id: int = None): sim_spawner_service = services.sim_spawner_service() queue = sim_spawner_service.get_queue_for_gsi() return queue