class _PushInteractionState(CommonInteractionCompletedSituationState): FACTORY_TUNABLES = { 'interaction_to_push': Interaction.TunableReference( description= '\n Interaction to push on a random target that was specified by the target\n filter method.\n ' ), 'iterations': Tunable( description= '\n Number of times we want to push the interaction one after the other.\n ', tunable_type=int, default=1) } def __init__(self, interaction_to_push, iterations, **kwargs): super().__init__(**kwargs) self._interaction_to_push = interaction_to_push self._iterations = iterations self._iteration_count = 0 def on_activate(self, reader=None): super().on_activate(reader) self._push_interaction_or_next_state() def _on_interaction_of_interest_complete(self, **kwargs): self._iteration_count += 1 self.owner.selected_target = self.owner.get_random_target() self._push_interaction_or_next_state() def _push_interaction_or_next_state(self): holiday_visitor_npc_sim = self.owner.holiday_visitor_npc() if self._iteration_count >= self._iterations or holiday_visitor_npc_sim is None or self.owner.selected_target is None: self._change_state( self.owner.holiday_visitor_npc_job.hang_out_state()) return context = interactions.context.InteractionContext( holiday_visitor_npc_sim, interactions.context.InteractionContext.SOURCE_SCRIPT, interactions.priority.Priority.High, insert_strategy=QueueInsertStrategy.NEXT) enqueue_result = holiday_visitor_npc_sim.push_super_affordance( self._interaction_to_push, self.owner.selected_target, context) if not enqueue_result: logger.error('interaction failed to push with result {}', enqueue_result) self._change_state( self.owner.holiday_visitor_npc_job.hang_out_state()) def timer_expired(self): self._on_interaction_of_interest_complete()
def get_interaction_short_name(interaction: Interaction) -> Union[str, None]: """get_interaction_short_name(interaction) Retrieve the Short Name of an Interaction. :param interaction: An instance of an interaction. :type interaction: Interaction :return: The short name of an interaction or None if a problem occurs. :rtype: Union[str, None] """ if interaction is None: return None # noinspection PyBroadException try: return str(interaction.shortname() or '') or interaction.__class__.__name__ except: return ''
class _BiteState(VampireInterruptableStateMixin): FACTORY_TUNABLES = { 'bite_interaction': Interaction.TunableReference( description= '\n Bite interaction to push on the selected Sim to be run by the\n visiting vampire.\n ' ) } def __init__(self, bite_interaction, **kwargs): super().__init__(**kwargs) self._bite_interaction = bite_interaction def on_activate(self, reader=None): super().on_activate(reader) for si in self.owner.selected_sim.si_state: si.cancel(FinishingType.SITUATIONS, cancel_reason_msg='Vampire bite required cancelation.') vampire_sim = self.owner.vampire_sim() context = interactions.context.InteractionContext( vampire_sim, interactions.context.InteractionContext.SOURCE_SCRIPT, interactions.priority.Priority.High, insert_strategy=QueueInsertStrategy.NEXT) enqueue_result = vampire_sim.push_super_affordance( self._bite_interaction, self.owner.selected_sim, context) if not enqueue_result: logger.error( 'Bite state interaction failed to push with result {}', enqueue_result) self._change_state(_LeaveState()) def _on_interaction_of_interest_complete(self, **kwargs): self._change_state(_LeaveState()) def handle_event(self, sim_info, event, resolver): if event == TestEvent.InteractionComplete: vampire_sim = self.owner.vampire_sim() if vampire_sim is None or vampire_sim.sim_info is not sim_info: return if resolver(self._interaction_of_interest): self._on_interaction_of_interest_complete()
class _AnswerDoorState(CommonSituationState): FACTORY_TUNABLES = { 'interaction_to_push': Interaction.TunableReference( description= '\n The interaction that will be pushed on all non-selectable sims\n when this situation state begins if there is a front door.\n ' ) } def __init__(self, *args, interaction_to_push=None, **kwargs): super().__init__(*args, **kwargs) self._interaction_to_push = interaction_to_push def on_activate(self, reader=None): super().on_activate(reader) if self.owner._neighbor_sim is not None: context = InteractionContext( self.owner._neighbor_sim, InteractionContext.SOURCE_SCRIPT, Priority.High, insert_strategy=QueueInsertStrategy.NEXT) self.owner._neighbor_sim.push_super_affordance( self._interaction_to_push, self.owner._neighbor_sim, context)
def get_asm(self, *args, **kwargs): if self._can_share_asm(): return super().get_asm(*args, **kwargs) return Interaction.get_asm(self, *args, **kwargs)
def get_asm(self, *args, **kwargs): return Interaction.get_asm(self, *args, **kwargs)