Exemplo n.º 1
0
 def event_handler_swap_carry(event_data):
     nonlocal got_callback
     if got_callback:
         logger.warn(
             'Animation({}) calling to start a carry multiple times',
             event_data.event_data.get('clip_name'))
         return
     got_callback = True
     arb_exit = Arb()
     original_carry_posture.append_exit_to_arb(arb_exit,
                                               None,
                                               carry_nothing_posture,
                                               carry_nothing_var_map,
                                               exit_while_holding=True)
     carry_nothing_posture.append_transition_to_arb(
         arb_exit, original_carry_posture, in_xevt_handler=True)
     distribute_arb_element(arb_exit)
     original_carry_posture.target.transient = True
     original_carry_posture.target.clear_parent(sim.transform,
                                                sim.routing_surface)
     original_carry_posture.target.remove_from_client()
     arb_enter = Arb()
     locked_params = final_posture.get_locked_params(None)
     if carry_nothing_posture is not None:
         carry_nothing_posture.append_exit_to_arb(
             arb_enter, final_posture_state, final_posture,
             final_var_map)
     final_posture.append_transition_to_arb(arb_enter,
                                            carry_nothing_posture,
                                            locked_params=locked_params,
                                            in_xevt_handler=True)
     distribute_arb_element(arb_enter)
Exemplo n.º 2
0
    def prepare(self, actor, setup_asm_override=None):
        def restart_asm(asm):
            asm.set_current_state('entry')
            return True

        target = self.get_target(actor)
        routing_component = actor.routing_component
        if actor.is_sim:
            route_interaction = routing_component.route_interaction
            if route_interaction is None:
                logger.error('Route Interaction was None for {}', actor)
                return
            route_event_animation = self.animation_element(
                route_interaction,
                setup_asm_additional=restart_asm
                if setup_asm_override is None else setup_asm_override,
                enable_auto_exit=False)
            asm = route_event_animation.get_asm()
            if asm is not None and target is not None and not asm.set_actor(
                    route_event_animation.target_name, target):
                logger.error('Route Event {} Failed to setup target.', self)
                return
            if asm is None:
                logger.warn(
                    'Unable to get a valid Route Event ASM ({}) for {}.',
                    route_event_animation, actor)
                return
        else:
            route_event_animation = self.animation_element(
                actor,
                target=target,
                setup_asm_func=restart_asm
                if setup_asm_override is None else setup_asm_override)
            animation_context = routing_component.animation_context
            asm = route_event_animation.get_asm(
                animation_context=animation_context)
            if asm is None:
                logger.warn(
                    'Unable to get a valid Route Event ASM ({}) for {}.',
                    route_event_animation, actor)
                return
        self.arb = Arb()
        route_event_animation.append_to_arb(asm, self.arb)
        route_event_animation.append_exit_to_arb(asm, self.arb)
        if self.arb is None:
            logger.error('Unable to create arb for Route Event: {}', self)
            return
        (self._duration_total, self._duration_must_run,
         self._duration_repeat) = self.arb.get_timing()
Exemplo n.º 3
0
 def get_portal_duration(self, portal_instance, is_mirrored, walkstyle, age,
                         gender, species):
     stub_actor = StubActor(1, species=species)
     arb = Arb()
     portal_posture = postures.create_posture(self.posture_end, stub_actor,
                                              GLOBAL_STUB_CONTAINER)
     source_posture = postures.create_posture(self.posture_start,
                                              stub_actor, None)
     portal_posture.append_transition_to_arb(arb,
                                             source_posture,
                                             locked_params={
                                                 ('age', 'x'): age,
                                                 'is_mirrored': is_mirrored
                                             })
     (_, duration, _) = arb.get_timing()
     return duration
 def _get_arb(self, actor, portal_instance, *, is_mirrored):
     arb = Arb()
     asm = create_asm(self.animation_element.asm_key,
                      context=get_throwaway_animation_context())
     asm.set_actor(self.animation_element.actor_name, actor)
     if is_mirrored:
         entry_location = portal_instance.back_entry
         exit_location = portal_instance.back_exit
     else:
         entry_location = portal_instance.there_entry
         exit_location = portal_instance.there_exit
     asm.set_actor_parameter(self.animation_element.actor_name, actor,
                             animation_constants.ASM_INITIAL_TRANSLATION,
                             entry_location.position)
     asm.set_actor_parameter(self.animation_element.actor_name, actor,
                             animation_constants.ASM_INITIAL_ORIENTATION,
                             entry_location.orientation)
     asm.set_actor_parameter(self.animation_element.actor_name, actor,
                             animation_constants.ASM_TARGET_TRANSLATION,
                             exit_location.position)
     asm.set_actor_parameter(self.animation_element.actor_name, actor,
                             animation_constants.ASM_TARGET_ORIENTATION,
                             entry_location.orientation)
     self.animation_element.append_to_arb(asm, arb)
     return arb
 def _get_arb(self, actor, portal_instance, *, is_mirrored):
     arb = Arb()
     asm = create_asm(self.animation_element.asm_key,
                      context=get_throwaway_animation_context())
     asm.set_actor(self.animation_element.actor_name, actor)
     slide_end_location = self.slide_end_location(portal_instance.obj)
     if is_mirrored:
         entry_location = slide_end_location
         exit_location = portal_instance.back_exit
     else:
         entry_location = portal_instance.there_entry
         exit_location = slide_end_location
     initial_translation = sims4.math.Vector3(exit_location.position.x,
                                              entry_location.position.y,
                                              exit_location.position.z)
     asm.set_actor_parameter(self.animation_element.actor_name, actor,
                             animation_constants.ASM_INITIAL_TRANSLATION,
                             initial_translation)
     asm.set_actor_parameter(self.animation_element.actor_name, actor,
                             animation_constants.ASM_INITIAL_ORIENTATION,
                             entry_location.orientation)
     asm.set_actor_parameter(self.animation_element.actor_name, actor,
                             animation_constants.ASM_TARGET_TRANSLATION,
                             exit_location.position)
     asm.set_actor_parameter(self.animation_element.actor_name, actor,
                             animation_constants.ASM_TARGET_ORIENTATION,
                             exit_location.orientation)
     asm.set_actor_parameter(
         self.animation_element.actor_name, actor,
         animation_constants.ASM_LADDER_PORTAL_ALIGNMENT,
         PortalAlignment.get_asm_parameter_string(self.portal_alignment))
     self.animation_element.append_to_arb(asm, arb)
     return arb
Exemplo n.º 6
0
 def _on_linked_posture_exit(*_, **__):
     linked_arb = Arb()
     self._carried_linked_posture.append_exit_to_arb(
         linked_arb, *args, **kwargs)
     if destination_posture is not None:
         destination_posture.append_transition_to_arb(
             linked_arb, self._carried_linked_posture)
         destination_posture.append_idle_to_arb(linked_arb)
     distribute_arb_element(linked_arb, master=self.target)
 def _get_arb(self, actor, obj, *, is_mirrored):
     arb = Arb()
     asm = create_asm(self.animation_element.asm_key,
                      context=get_throwaway_animation_context())
     asm.set_actor(self.animation_element.actor_name, actor)
     asm.set_actor(self.animation_element.target_name, obj)
     asm.set_parameter('isMirrored', is_mirrored)
     self.animation_element.append_to_arb(asm, arb)
     return arb
Exemplo n.º 8
0
 def change_outfit(timeline):
     arb = Arb()
     self.try_set_current_outfit(outfit_category_and_index,
                                 do_spin=do_spin,
                                 arb=arb,
                                 interaction=interaction)
     if not arb.empty:
         clothing_element = create_run_animation(arb)
         yield from element_utils.run_child(timeline, clothing_element)
Exemplo n.º 9
0
 def kickstart_linked_carried_posture_gen(self, timeline):
     yield from element_utils.run_child(
         timeline,
         (self.target.posture.get_idle_behavior(), flush_all_animations))
     begin_element = self._carried_linked_posture.get_begin(
         Arb(), self.target.posture_state, self.target.routing_surface)
     yield from element_utils.run_child(timeline, begin_element)
     yield from self._carried_linked_posture.kickstart_source_interaction_gen(
         timeline)
     yield from element_utils.run_child(
         timeline, self._carried_linked_previous_posture_state.body.end())
Exemplo n.º 10
0
 def event_handler_exit_carry(event_data):
     nonlocal exited_carry
     exited_carry = True
     arb = Arb()
     old_carry_posture.append_exit_to_arb(arb,
                                          None,
                                          new_posture,
                                          var_map,
                                          exit_while_holding=True)
     new_posture.append_transition_to_arb(arb,
                                          old_carry_posture,
                                          in_xevt_handler=True)
     distribute_arb_element(arb, master=sim)
Exemplo n.º 11
0
    def update_overlay(self):
        def restart_overlay_asm(asm):
            asm.set_current_state('entry')
            return True

        if self._overlay_interaction is None:
            return
        overlay_animation = self._overlay_animation(
            self._overlay_interaction,
            setup_asm_additional=restart_overlay_asm,
            enable_auto_exit=False)
        asm = overlay_animation.get_asm()
        if asm is None:
            logger.warn(' Unable to get a valid overlay ASM ({}) for {}.',
                        self._overlay_animation, self._sim)
            return
        arb = Arb()
        overlay_animation.append_to_arb(asm, arb)
        distribute_arb_element(arb)
Exemplo n.º 12
0
 def event_handler_enter_carry(event_data):
     nonlocal got_callback
     if got_callback:
         logger.warn(
             'Animation({}) calling to start a carry multiple times',
             event_data.event_data.get('clip_name'))
         return
     got_callback = True
     arb = Arb()
     locked_params = new_posture.get_locked_params(None)
     old_carry_posture = sim.posture_state.get_aspect(track)
     if old_carry_posture is not None:
         old_carry_posture.append_exit_to_arb(arb, new_posture_state,
                                              new_posture, var_map)
     new_posture.append_transition_to_arb(arb,
                                          old_carry_posture,
                                          locked_params=locked_params,
                                          in_xevt_handler=True)
     distribute_arb_element(arb)
Exemplo n.º 13
0
class RouteEventTypeAnimation(RouteEventDataBase, HasTunableFactory,
                              AutoFactoryInit):
    FACTORY_TUNABLES = {
        'animation_element':
        TunableAnimationReference(
            description=
            '\n            The animation that Sims play during the Route Event.\n            ',
            callback=None,
            class_restrictions=()),
        '_duration_override':
        OptionalTunable(
            description=
            "\n            If enabled, we override the must run duration we expect this route\n            event to take. We do this for animations that will freeze the\n            locomotion so that we don't actually take time away from the rest of\n            the path where other route events could play.\n            ",
            tunable=TunableRange(
                description=
                '\n                The duration we want this route event to have. This modifies how\n                much of the route time this event will take up to play the\n                animation. For route events that freeze locomotion, you might\n                want to set this to a very low value. Bear in mind that high\n                values are less likely to be scheduled for shorter routes.\n                ',
                tunable_type=float,
                default=0.1,
                minimum=0.1)),
        'target_participant':
        OptionalTunable(
            description=
            '\n            The target of the animation based on the resolver of the actor\n            playing the route event.\n            ',
            tunable=TunableEnumEntry(
                description=
                '\n                The participant related to the actor that plays the route event.\n                ',
                tunable_type=ParticipantType,
                default=ParticipantType.ObjectChildren))
    }

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.arb = None
        self._duration_total = MAX_INT32
        self._duration_must_run = MAX_INT32
        self._duration_repeat = MAX_INT32

    @classmethod
    def test(cls, actor, event_data_tuning, ignore_carry=False):
        if actor is None:
            return TestResult(False, 'Route Event Actor is None.')
        if actor.is_sim:
            postures = event_data_tuning.animation_element.get_supported_postures(
            )
            sim_posture_state = actor.posture_state
            provided_postures = sim_posture_state.body.get_provided_postures(
                surface_target=MATCH_NONE)
            supported_postures = provided_postures.intersection(postures)
            if not supported_postures:
                return TestResult(
                    False, 'Animation Route Event does not support {} for {}.',
                    actor.posture_state, actor)
            if not ignore_carry:
                carry_state = sim_posture_state.get_carry_state()
                if not any(
                        are_carry_compatible(entry, carry_state)
                        for entry in supported_postures):
                    return TestResult(
                        False,
                        'Animation Route Event does not support {} for {}.',
                        actor.posture_state, actor)
        return TestResult.TRUE

    @property
    def duration_override(self):
        if self._duration_override is not None:
            return self._duration_override
        return self._duration_must_run

    def get_target(self, actor):
        if self.target_participant is None:
            return
        else:
            if actor.is_sim:
                resolver = SingleSimResolver(actor.sim_info)
            else:
                resolver = SingleObjectResolver(actor)
            targets = resolver.get_participants(self.target_participant)
            if targets:
                return next(iter(targets))

    def prepare(self, actor, setup_asm_override=None):
        def restart_asm(asm):
            asm.set_current_state('entry')
            return True

        target = self.get_target(actor)
        routing_component = actor.routing_component
        if actor.is_sim:
            route_interaction = routing_component.route_interaction
            if route_interaction is None:
                logger.error('Route Interaction was None for {}', actor)
                return
            route_event_animation = self.animation_element(
                route_interaction,
                setup_asm_additional=restart_asm
                if setup_asm_override is None else setup_asm_override,
                enable_auto_exit=False)
            asm = route_event_animation.get_asm()
            if asm is not None and target is not None and not asm.set_actor(
                    route_event_animation.target_name, target):
                logger.error('Route Event {} Failed to setup target.', self)
                return
            if asm is None:
                logger.warn(
                    'Unable to get a valid Route Event ASM ({}) for {}.',
                    route_event_animation, actor)
                return
        else:
            route_event_animation = self.animation_element(
                actor,
                target=target,
                setup_asm_func=restart_asm
                if setup_asm_override is None else setup_asm_override)
            animation_context = routing_component.animation_context
            asm = route_event_animation.get_asm(
                animation_context=animation_context)
            if asm is None:
                logger.warn(
                    'Unable to get a valid Route Event ASM ({}) for {}.',
                    route_event_animation, actor)
                return
        self.arb = Arb()
        route_event_animation.append_to_arb(asm, self.arb)
        route_event_animation.append_exit_to_arb(asm, self.arb)
        if self.arb is None:
            logger.error('Unable to create arb for Route Event: {}', self)
            return
        (self._duration_total, self._duration_must_run,
         self._duration_repeat) = self.arb.get_timing()

    def is_valid_for_scheduling(self, actor, path):
        if self.arb is None or self.arb.empty:
            return False
        return True

    def execute(self, actor, **kwargs):
        if actor.primitives:
            for primitive in tuple(actor.primitives):
                if isinstance(primitive, FollowPath):
                    primitive.set_animation_sleep_end(self._duration_must_run)
                    return

    def process(self, actor):
        if self.arb is not None:
            distribute_arb_element(self.arb, master=actor, immediate=True)
Exemplo n.º 14
0
    def _execute_internal(self, actor):
        left_carry_target = actor.posture_state.left.target
        right_carry_target = actor.posture_state.right.target
        carry_target = None
        if left_carry_target is not None and left_carry_target.has_tag(
                self.stop_carry_object_tag):
            carry_target = left_carry_target
        elif right_carry_target is not None:
            if right_carry_target.has_tag(self.stop_carry_object_tag):
                carry_target = right_carry_target
        if carry_target is None:
            actor.routing_component.remove_route_event_by_data(self)
            return
        for exit_carry_event in actor.routing_component.route_event_context.route_event_of_data_type_gen(
                type(self)):
            if exit_carry_event.event_data._owned_object is carry_target:
                actor.routing_component.remove_route_event_by_data(self)
                return
        self._owned_object = carry_target

        def set_target(asm):
            asm.set_current_state('entry')
            asm.set_actor(self.animation_element.actor_name, actor)
            asm.set_actor(self.animation_element.target_name, carry_target)
            return True

        route_interaction = actor.routing_component.route_interaction
        route_event_animation = self.animation_element(
            route_interaction,
            setup_asm_additional=set_target,
            enable_auto_exit=False)
        asm = route_event_animation.get_asm(use_cache=False)
        if asm is None:
            logger.warn('Unable to get a valid Route Event ASM ({}) for {}.',
                        route_event_animation, actor)
            actor.routing_component.remove_route_event_by_data(self)
            return
        self.arb = Arb()

        def _send_arb(timeline):
            route_event_animation.append_to_arb(asm, self.arb)
            route_event_animation.append_exit_to_arb(asm, self.arb)
            distribute_arb_element(self.arb, master=actor, immediate=True)
            return True

        exit_carry_element = exit_carry_while_holding(
            route_interaction,
            target=carry_target,
            sequence=build_element(_send_arb),
            arb=self.arb)

        def event_finished(_):
            self._owned_object = None
            if actor.routing_component is None:
                return
            actor.routing_component.remove_route_event_by_data(self)

        exit_carry_element = build_critical_section_with_finally(
            exit_carry_element, event_finished)
        umbrella_timeline = services.time_service().sim_timeline
        umbrella_timeline.schedule(exit_carry_element)