예제 #1
0
 def _on_zone_teardown(self, zone: Zone, client: Client):
     CommonEventRegistry.get().dispatch(
         S4CLZoneTeardownEvent(zone,
                               client,
                               game_loaded=self.game_loaded,
                               game_loading=self.game_loading))
     self._game_loading = True
 def _on_skill_leveled_up(self, skill: Skill, old_skill_level: int,
                          new_skill_level: int) -> None:
     if skill.tracker is None or skill.tracker._owner is None:
         return
     sim_info = CommonSimUtils.get_sim_info(skill.tracker._owner)
     CommonEventRegistry.get().dispatch(
         S4CLSimSkillLeveledUpEvent(sim_info, skill, old_skill_level,
                                    new_skill_level))
예제 #3
0
 def _on_save_loaded(self) -> None:
     from sims4communitylib.utils.save_load.common_save_utils import CommonSaveUtils
     current_save_slot_guid = CommonSaveUtils().get_save_slot_guid()
     if self._current_save_slot_guid is None:
         self._current_save_slot_guid = current_save_slot_guid
         CommonEventRegistry.get().dispatch(S4CLSaveLoadedEvent())
     elif self._current_save_slot_guid != current_save_slot_guid:
         self._current_save_slot_guid = current_save_slot_guid
         CommonEventRegistry.get().dispatch(S4CLSaveLoadedEvent())
예제 #4
0
 def _on_late_zone_load(self, zone: Zone, household_id: int,
                        active_sim_id: int):
     CommonEventRegistry.get().dispatch(
         S4CLZoneLateLoadEvent(zone,
                               household_id,
                               active_sim_id,
                               game_loaded=self.game_loaded,
                               game_loading=self.game_loading))
     self._game_loaded = True
     self._game_loading = False
 def _on_sim_change_age(self, sim_info: SimInfo, new_age: Age,
                        current_age: Age) -> bool:
     from sims4communitylib.utils.sims.common_sim_utils import CommonSimUtils
     return CommonEventRegistry.get().dispatch(
         S4CLSimChangedAgeEvent(CommonSimUtils.get_sim_info(sim_info),
                                CommonAge.convert_from_vanilla(current_age),
                                CommonAge.convert_from_vanilla(new_age)))
 def _on_interaction_cancelled(self,
                               interaction: Interaction,
                               finishing_type: FinishingType,
                               cancel_reason_msg: str,
                               ignore_must_run: bool = False,
                               **__) -> None:
     if finishing_type is None:
         return None
     try:
         CommonEventRegistry().dispatch(
             S4CLInteractionCancelledEvent(interaction,
                                           finishing_type,
                                           cancel_reason_msg,
                                           ignore_must_run=ignore_must_run,
                                           **__))
     except Exception as ex:
         self.log.error(
             'Error occurred while running _on_interaction_cancelled for interaction {} with short name \'{}\' and display name {}. Finishing Type: {}, Cancel Reason: {}, Ignore Must Run: {}, Kwargs: {}'
             .format(
                 pformat(interaction),
                 CommonInteractionUtils.get_interaction_short_name(
                     interaction),
                 CommonInteractionUtils.get_interaction_display_name(
                     interaction), finishing_type, cancel_reason_msg,
                 ignore_must_run, __),
             exception=ex)
     return None
 def _on_sim_spawned(self, sim_info: SimInfo, *_, **__):
     from sims4communitylib.events.zone_spin.common_zone_spin_event_dispatcher import CommonZoneSpinEventDispatcher
     if CommonZoneSpinEventDispatcher.get().game_loading:
         return False
     from sims4communitylib.utils.sims.common_sim_utils import CommonSimUtils
     return CommonEventRegistry.get().dispatch(
         S4CLSimSpawnedEvent(CommonSimUtils.get_sim_info(sim_info)))
 def _on_interaction_outcome(self, interaction: Interaction,
                             outcome: InteractionOutcome,
                             result: OutcomeResult):
     if interaction.sim is None:
         return False
     return CommonEventRegistry.get().dispatch(
         S4CLInteractionOutcomeEvent(interaction, outcome, result))
 def _on_interaction_cancelled(self,
                               interaction: Interaction,
                               finishing_type: FinishingType,
                               cancel_reason_msg: str,
                               ignore_must_run: bool = False,
                               **kwargs) -> Union[bool, None]:
     if finishing_type is None:
         return None
     try:
         if not CommonEventRegistry.get().dispatch(
                 S4CLInteractionCancelledEvent(
                     interaction,
                     finishing_type,
                     cancel_reason_msg,
                     ignore_must_run=ignore_must_run,
                     **kwargs)):
             return False
     except Exception as ex:
         CommonExceptionHandler.log_exception(
             ModInfo.get_identity(),
             'Error occurred while running _on_interaction_cancelled for interaction {} with short name {} and display name {}'
             .format(
                 pformat(interaction),
                 CommonInteractionUtils.get_interaction_short_name(
                     interaction),
                 CommonInteractionUtils.get_interaction_display_name(
                     interaction)),
             exception=ex)
     return None
 def _on_sim_change_gender(self, sim_info: SimInfo) -> bool:
     from sims4communitylib.utils.sims.common_gender_utils import CommonGenderUtils
     new_gender = CommonGenderUtils.get_gender(sim_info)
     if CommonGenderUtils.is_male_gender(new_gender):
         # If they are now Male, it means they used to be Female.
         old_gender = Gender.FEMALE
     else:
         # If they are now Female, it means they used to be Male.
         old_gender = Gender.MALE
     return CommonEventRegistry.get().dispatch(S4CLSimChangedGenderEvent(sim_info, old_gender, new_gender))
 def _on_interaction_queued(self, interaction_queue: InteractionQueue,
                            interaction: Interaction, *_,
                            **__) -> Union[TestResult, None]:
     if interaction is None or interaction.sim is None:
         return None
     if not CommonEventRegistry.get().dispatch(
             S4CLInteractionQueuedEvent(interaction, interaction_queue)):
         return TestResult(
             False, 'Interaction \'{}\' Failed to Queue'.format(
                 pformat(interaction)))
     return None
 def _on_interaction_outcome(self, interaction: Interaction,
                             outcome: InteractionOutcome,
                             result: OutcomeResult) -> None:
     if interaction.sim is None:
         return None
     try:
         CommonEventRegistry().dispatch(
             S4CLInteractionOutcomeEvent(interaction, outcome, result))
     except Exception as ex:
         self.log.error(
             'Error occurred while running _on_interaction_outcome for interaction {} with short name \'{}\' and display name {}. Outcome: {}, Result: {}'
             .format(
                 pformat(interaction),
                 CommonInteractionUtils.get_interaction_short_name(
                     interaction),
                 CommonInteractionUtils.get_interaction_display_name(
                     interaction), outcome, result),
             exception=ex)
     return None
 def _on_interaction_run(self, interaction_queue: InteractionQueue,
                         timeline: Timeline, interaction: Interaction,
                         run_result: bool, *_, **__) -> None:
     if interaction is None or interaction.sim is None:
         return None
     try:
         CommonEventRegistry().dispatch(
             S4CLInteractionRunEvent(interaction, interaction_queue,
                                     run_result))
     except Exception as ex:
         self.log.error(
             'Error occurred while running _on_interaction_run for interaction {} with short name \'{}\' and display name {}. Original Run Result: {}, Args: {}, Kwargs: {}'
             .format(
                 pformat(interaction),
                 CommonInteractionUtils.get_interaction_short_name(
                     interaction),
                 CommonInteractionUtils.get_interaction_display_name(
                     interaction), str(run_result), _, __),
             exception=ex)
     return None
예제 #14
0
 def _on_zone_update(self, zone: Zone, absolute_ticks: int):
     try:
         if not zone.is_zone_running:
             return False
         is_paused = CommonTimeUtils.game_is_paused()
         if not is_paused:
             diff_ticks = absolute_ticks - self._last_absolute_ticks
             if diff_ticks < 0:
                 return False
             self._update_ticks(diff_ticks)
         self._last_absolute_ticks = absolute_ticks
         return CommonEventRegistry.get().dispatch(
             S4CLZoneUpdateEvent(zone, is_paused,
                                 self.ticks_since_last_zone_update))
     except Exception as ex:
         self.log.error(
             'Failed to run internal method \'{}\' at \'{}\'.'.format(
                 CommonZoneUpdateEventDispatcherService._on_zone_update.
                 __name__, Zone.update.__name__),
             exception=ex)
 def _on_interaction_run(self, interaction_queue: InteractionQueue,
                         timeline: Timeline, interaction: Interaction, *_,
                         **__) -> Union[bool, None]:
     if interaction is None or interaction.sim is None:
         return None
     try:
         return CommonEventRegistry.get().dispatch(
             S4CLInteractionRunEvent(interaction, interaction_queue))
     except Exception as ex:
         CommonExceptionHandler.log_exception(
             ModInfo.get_identity(),
             'Error occurred while running _on_interaction_run for interaction {} with short name {} and display name {}'
             .format(
                 pformat(interaction),
                 CommonInteractionUtils.get_interaction_short_name(
                     interaction),
                 CommonInteractionUtils.get_interaction_display_name(
                     interaction)),
             exception=ex)
     return False
 def _on_interaction_outcome(self, interaction: Interaction,
                             outcome: InteractionOutcome,
                             result: OutcomeResult) -> Union[bool, Any]:
     if interaction.sim is None:
         return False
     try:
         return CommonEventRegistry.get().dispatch(
             S4CLInteractionOutcomeEvent(interaction, outcome, result))
     except Exception as ex:
         CommonExceptionHandler.log_exception(
             ModInfo.get_identity(),
             'Error occurred while running _on_interaction_outcome for interaction {} with short name {} and display name {}'
             .format(
                 pformat(interaction),
                 CommonInteractionUtils.get_interaction_short_name(
                     interaction),
                 CommonInteractionUtils.get_interaction_display_name(
                     interaction)),
             exception=ex)
     return False
 def _on_interaction_post_queued(self, interaction_queue: InteractionQueue,
                                 interaction: Interaction,
                                 queue_result: TestResult, *_,
                                 **__) -> None:
     if interaction is None or interaction.sim is None:
         return None
     try:
         CommonEventRegistry().dispatch(
             S4CLInteractionPostQueuedEvent(interaction, interaction_queue,
                                            queue_result))
     except Exception as ex:
         self.log.error(
             'Error occurred while running _on_interaction_post_queued for interaction {} with short name \'{}\' and display name {}. Queue Result: {}, Args: {}, Kwargs: {}'
             .format(
                 pformat(interaction),
                 CommonInteractionUtils.get_interaction_short_name(
                     interaction),
                 CommonInteractionUtils.get_interaction_display_name(
                     interaction), queue_result, _, __),
             exception=ex)
     return None
 def _on_interaction_pre_run(self, interaction_queue: InteractionQueue,
                             timeline: Timeline, interaction: Interaction,
                             *_, **__) -> Union[bool, None]:
     if interaction is None or interaction.sim is None:
         return None
     try:
         if not CommonEventRegistry().dispatch(
                 S4CLInteractionPreRunEvent(interaction, interaction_queue,
                                            timeline)):
             return False
     except Exception as ex:
         self.log.error(
             'Error occurred while running _on_interaction_pre_run for interaction {} with short name \'{}\' and display name {}. Args: {}, Kwargs: {}'
             .format(
                 pformat(interaction),
                 CommonInteractionUtils.get_interaction_short_name(
                     interaction),
                 CommonInteractionUtils.get_interaction_display_name(
                     interaction), _, __),
             exception=ex)
     return None
 def _on_zone_update(self, zone: Zone, absolute_ticks: int):
     try:
         if not zone.is_zone_running:
             return False
         is_paused = CommonTimeUtils.game_is_paused()
         if not is_paused:
             diff_ticks = absolute_ticks - self._last_absolute_ticks
             if diff_ticks < 0:
                 return False
             self._update_ticks(diff_ticks)
         self._last_absolute_ticks = absolute_ticks
         return CommonEventRegistry.get().dispatch(
             S4CLZoneUpdateEvent(zone, is_paused,
                                 self.ticks_since_last_zone_update))
     except Exception as ex:
         from sims4communitylib.exceptions.common_exceptions_handler import CommonExceptionHandler
         CommonExceptionHandler.log_exception(
             ModInfo.get_identity(),
             'Failed to run internal method \'{}\' at \'{}\'.'.format(
                 CommonZoneUpdateEventDispatcherService._on_zone_update.
                 __name__, Zone.update.__name__),
             exception=ex)
 def _on_interaction_queued(self, interaction_queue: InteractionQueue,
                            interaction: Interaction, *_,
                            **__) -> Union[TestResult, None]:
     if interaction is None or interaction.sim is None:
         return None
     try:
         if not CommonEventRegistry().dispatch(
                 S4CLInteractionQueuedEvent(interaction,
                                            interaction_queue)):
             return TestResult(
                 False, 'Interaction \'{}\' Failed to Queue'.format(
                     pformat(interaction)))
     except Exception as ex:
         self.log.error(
             'Error occurred while running _on_interaction_queued for interaction {} with short name \'{}\' and display name {}. Args: {}, Kwargs: {}'
             .format(
                 pformat(interaction),
                 CommonInteractionUtils.get_interaction_short_name(
                     interaction),
                 CommonInteractionUtils.get_interaction_display_name(
                     interaction), _, __),
             exception=ex)
     return None
예제 #21
0
 def _on_zone_save(self, zone: Zone, save_slot_data: Any = None):
     CommonEventRegistry.get().dispatch(
         S4CLZoneSaveEvent(zone,
                           save_slot_data=save_slot_data,
                           game_loaded=self.game_loaded,
                           game_loading=self.game_loading))
예제 #22
0
 def _on_early_zone_load(self, zone: Zone):
     CommonEventRegistry.get().dispatch(
         S4CLZoneEarlyLoadEvent(zone,
                                game_loaded=self.game_loaded,
                                game_loading=self.game_loading))
 def _on_sim_change_gender_options_can_reproduce(self,
                                                 sim_info: SimInfo) -> bool:
     return CommonEventRegistry.get().dispatch(
         S4CLSimChangedGenderOptionsCanReproduceEvent(sim_info))
 def _on_sim_change_gender_options_can_be_impregnated(
         self, sim_info: SimInfo) -> bool:
     return CommonEventRegistry.get().dispatch(
         S4CLSimChangedGenderOptionsCanBeImpregnatedEvent(sim_info))
 def _on_sim_change_gender_options_clothing_preference(
         self, sim_info: SimInfo) -> bool:
     return CommonEventRegistry.get().dispatch(
         S4CLSimChangedGenderOptionsClothingPreferenceEvent(sim_info))
 def _on_sim_change_gender_options_body_frame(self,
                                              sim_info: SimInfo) -> bool:
     return CommonEventRegistry.get().dispatch(
         S4CLSimChangedGenderOptionsBodyFrameEvent(sim_info))
 def _on_sim_change_gender_options_toilet_usage(self,
                                                sim_info: SimInfo) -> bool:
     return CommonEventRegistry.get().dispatch(
         S4CLSimChangedGenderOptionsToiletUsageEvent(sim_info))
 def _on_sim_change_gender_options_breasts(self, sim_info: SimInfo) -> bool:
     return CommonEventRegistry.get().dispatch(
         S4CLSimChangedGenderOptionsBreastsEvent(sim_info))
 def _on_sim_buff_removed(self, buff: Buff, sim_id: int) -> None:
     sim_info = CommonSimUtils.get_sim_info(sim_id)
     if sim_info is None:
         return
     CommonEventRegistry.get().dispatch(
         S4CLSimBuffRemovedEvent(sim_info, buff))
 def _on_sim_remove_occult_type(self, occult_tracker: OccultTracker,
                                occult_type: OccultType) -> bool:
     sim_info = occult_tracker._sim_info
     return CommonEventRegistry.get().dispatch(
         S4CLSimRemovedOccultTypeEvent(sim_info, occult_type,
                                       occult_tracker))